Skip to content

Commit

Permalink
Bug 1613517 - Make rust generate better code for derive(Animate) and …
Browse files Browse the repository at this point in the history
…derive(ComputeSquaredDistance). r=heycam

See rust-lang/rust#68867.

This technically changes the semantics of #[animate(fallback)] and such when
combined with #[animate(error)]. But no such combination exists and the new
semantics are perfectly reasonable as well, IMHO.

Differential Revision: https://phabricator.services.mozilla.com/D61761

UltraBlame original commit: bd4711d31ec6ab173b77406cb4ede0fa7a484af3
  • Loading branch information
marco-c committed Feb 12, 2020
1 parent a50a0c1 commit 89119d2
Show file tree
Hide file tree
Showing 4 changed files with 485 additions and 325 deletions.
6 changes: 3 additions & 3 deletions servo/components/style/values/animated/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,9 +883,9 @@ corresponding
/
match
arm
is
not
generated
returns
an
error
.
/
/
Expand Down
6 changes: 3 additions & 3 deletions servo/components/style/values/distance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ corresponding
/
match
arm
is
not
generated
returns
an
error
.
/
/
Expand Down
255 changes: 148 additions & 107 deletions servo/components/style_derive/animate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ input
)
;
let
input_attrs
=
cg
:
:
parse_input_attrs
:
:
<
AnimateInputAttrs
>
(
&
input
)
;
let
no_bound
=
animation_input_attrs
Expand Down Expand Up @@ -225,7 +242,7 @@ let
(
mut
match_body
append_error_clause
needs_catchall_branch
)
=
{
Expand All @@ -242,8 +259,7 @@ input
)
;
let
mut
append_error_clause
needs_catchall_branch
=
s
.
Expand Down Expand Up @@ -284,39 +300,13 @@ variant
let
arm
=
match
derive_variant_arm
(
variant
&
mut
where_clause
)
{
Ok
(
arm
)
=
>
arm
Err
(
(
)
)
=
>
{
append_error_clause
=
true
;
return
body
;
}
}
;
quote
!
Expand All @@ -331,7 +321,7 @@ arm
;
(
match_body
append_error_clause
needs_catchall_branch
)
}
;
Expand All @@ -344,82 +334,59 @@ where_clause
where_clause
;
if
append_error_clause
needs_catchall_branch
{
let
input_attrs
=
cg
:
:
parse_input_attrs
:
/
/
This
ideally
shouldn
'
t
be
needed
but
see
/
/
https
:
<
AnimateInputAttrs
>
(
&
input
)
;
if
let
Some
(
fallback
)
=
input_attrs
/
/
github
.
fallback
{
com
/
rust
-
lang
/
rust
/
issues
/
68867
match_body
.
append_all
(
quote
!
{
(
this
other
)
_
=
>
#
fallback
(
this
other
procedure
)
}
)
;
}
else
unsafe
{
match_body
.
append_all
(
quote
debug_unreachable
!
{
_
=
>
Err
(
(
)
)
}
}
)
;
}
}
let
name
=
Expand All @@ -443,6 +410,45 @@ split_for_impl
(
)
;
let
fallback
=
match
input_attrs
.
fallback
{
Some
(
fallback
)
=
>
quote
!
{
#
fallback
(
self
other
procedure
)
}
None
=
>
quote
!
{
Err
(
(
)
)
}
}
;
quote
!
{
Expand Down Expand Up @@ -510,6 +516,35 @@ Self
)
>
{
if
std
:
:
mem
:
:
discriminant
(
self
)
!
=
std
:
:
mem
:
:
discriminant
(
other
)
{
return
#
fallback
;
}
match
(
self
Expand Down Expand Up @@ -541,12 +576,7 @@ WhereClause
)
-
>
Result
<
TokenStream
(
)
>
{
let
variant_attrs
Expand All @@ -569,19 +599,6 @@ ast
)
)
;
if
variant_attrs
.
error
{
return
Err
(
(
)
)
;
}
let
(
this_pattern
Expand Down Expand Up @@ -618,6 +635,33 @@ other
"
)
;
if
variant_attrs
.
error
{
return
quote
!
{
(
&
#
this_pattern
&
#
other_pattern
)
=
>
Err
(
(
)
)
}
;
}
let
(
result_value
Expand Down Expand Up @@ -833,8 +877,6 @@ procedure
)
)
;
Ok
(
quote
!
{
Expand All @@ -858,7 +900,6 @@ result_value
)
}
}
)
}
#
[
Expand Down
Loading

0 comments on commit 89119d2

Please sign in to comment.