Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upUse ScalarPair for tagged enums #49420
Conversation
rust-highfive
assigned
petrochenkov
Mar 27, 2018
This comment has been minimized.
This comment has been minimized.
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @petrochenkov (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
rust-highfive
added
the
S-waiting-on-review
label
Mar 27, 2018
frewsxcv
reviewed
Mar 27, 2018
| FieldPlacement::Arbitrary { ref offsets, .. } => offsets, | ||
| _ => bug!(), | ||
| }; | ||
| let mut fields = field_layouts.iter().zip(offsets).filter(|p| !p.0.is_zst()); |
This comment has been minimized.
This comment has been minimized.
frewsxcv
Mar 27, 2018
Member
hi nox
tidy error: /checkout/src/librustc/ty/layout.rs:1682: line longer than 100 chars
This comment has been minimized.
This comment has been minimized.
nox
force-pushed the
nox:enum-scalarpair
branch
from
7c50101
to
97543cd
Mar 27, 2018
petrochenkov
assigned
eddyb
and unassigned
petrochenkov
Mar 27, 2018
nox
force-pushed the
nox:enum-scalarpair
branch
from
97543cd
to
b168f84
Mar 27, 2018
eddyb
reviewed
Mar 28, 2018
| @@ -139,6 +139,12 @@ pub fn return_slice(x: &[u16]) -> &[u16] { | |||
| x | |||
| } | |||
|
|
|||
| // CHECK: i64 @enum_id(i64) | |||
This comment has been minimized.
This comment has been minimized.
eddyb
Mar 28, 2018
Member
Isn't this pre-existing? You'd have to take in two arguments and return { i32, i32 } for the ScalarPair to be there.
This comment has been minimized.
This comment has been minimized.
nox
force-pushed the
nox:enum-scalarpair
branch
from
b168f84
to
f4d784c
Mar 28, 2018
eddyb
reviewed
Mar 28, 2018
| @@ -139,6 +139,12 @@ pub fn return_slice(x: &[u16]) -> &[u16] { | |||
| x | |||
| } | |||
|
|
|||
| // CHECK: { i64, i64 } @enum_id(i64 %x.0, i64 %x.1) | |||
| #[no_mangle] | |||
| pub fn enum_id(x: Result<i64, i64>) -> Result<i64, i64> { | |||
This comment has been minimized.
This comment has been minimized.
eddyb
Mar 28, 2018
Member
Why does Option around this create problems? Does it require the combination of your 2 PRs? Can we wait to land one and actually have an Option<Result<i64, i64>> test too?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
nox
Mar 28, 2018
Author
Contributor
Indeed, with the combination of the two optimisations, Option<Result<i64, i64>> also ends up returned as { i64, i64 }.
This comment has been minimized.
This comment has been minimized.
|
r? @eddyb |
This comment has been minimized.
This comment has been minimized.
|
Cc @rkruppe. For #49437, this produces: ; bar::foo
; Function Attrs: norecurse nounwind readnone uwtable
define { i32, i32 } @_ZN3bar3foo17h361da50dc86c3b65E(i32, i32) unnamed_addr #0 {
start:
%switch = icmp eq i32 %0, 0
%. = zext i1 %switch to i32
%2 = insertvalue { i32, i32 } undef, i32 %., 0
%3 = insertvalue { i32, i32 } %2, i32 %1, 1
ret { i32, i32 } %3
}
; bar::bar
; Function Attrs: norecurse nounwind readnone uwtable
define { i32, i32 } @_ZN3bar3bar17h01d34a35402b7c22E(i32 %x.0, i32 %x.1) unnamed_addr #0 {
start:
%switch.i = icmp ne i32 %x.0, 0
%. = zext i1 %switch.i to i32
%0 = insertvalue { i32, i32 } undef, i32 %., 0
%1 = insertvalue { i32, i32 } %0, i32 %x.1, 1
ret { i32, i32 } %1
}For #38349, this produces: ; Function Attrs: norecurse nounwind readnone uwtable
define { i32, i32 } @id_result(i32, i32) unnamed_addr #0 {
start:
%switch = icmp ne i32 %0, 0
%. = zext i1 %switch to i32
%2 = insertvalue { i32, i32 } undef, i32 %., 0
%3 = insertvalue { i32, i32 } %2, i32 %1, 1
ret { i32, i32 } %3
}@eddyb says it's an LLVM limitation: it can't put range metadata on arguments. |
nox
force-pushed the
nox:enum-scalarpair
branch
from
f4d784c
to
54c29dc
Mar 28, 2018
This comment has been minimized.
This comment has been minimized.
That matches my knowledge. We could add an |
This comment has been minimized.
This comment has been minimized.
|
Ping from triage, @eddyb — it looks like there are new commits for you. |
eddyb
reviewed
Apr 10, 2018
| } | ||
| } | ||
| if let Some((prim, _)) = common_prim { | ||
| Abi::ScalarPair(discr.clone(), scalar_unit(prim)) |
This comment has been minimized.
This comment has been minimized.
eddyb
Apr 10, 2018
Member
You have to do the dance where you use scalar_pair and check that the offset inside common_prim matches that computed by scalar_pair itself.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
eddyb
Apr 10, 2018
Member
You check that they all have the same offset, but that might still not be the same as the offset that scalar_pair would compute for the second scalar (the one from common_prim).
This comment has been minimized.
This comment has been minimized.
|
Your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
|
Can someone reproduce this on Linux? I can't reproduce the failure, but it seems to me like the generated code with this PR is way worse. |
This comment has been minimized.
This comment has been minimized.
|
Disregard my last comment, it took me an embarrassingly long time to notice the test changed upstream. |
This comment has been minimized.
This comment has been minimized.
nox
force-pushed the
nox:enum-scalarpair
branch
from
f0daf55
to
cded855
Apr 12, 2018
This comment has been minimized.
This comment has been minimized.
|
Your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
nox
referenced this pull request
Apr 14, 2018
Closed
Surprising optimization differences between variants of the same code #48200
This comment has been minimized.
This comment has been minimized.
|
I'll try to reduce the failing test that causes some memset optimisation to not trigger in LLVM. |
This comment has been minimized.
This comment has been minimized.
|
|
nox
force-pushed the
nox:enum-scalarpair
branch
from
cded855
to
3755e0d
Apr 18, 2018
This comment has been minimized.
This comment has been minimized.
|
Your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Oh, you should use |
nox
force-pushed the
nox:enum-scalarpair
branch
from
0af1297
to
3ca6ad9
Apr 26, 2018
This comment has been minimized.
This comment has been minimized.
|
@bors-servo r=eddyb pub fn enum_id_1(x: Option<Result<u16, u16>>) -> Option<Result<u16, u16>> { |
This comment has been minimized.
This comment has been minimized.
|
@nox: |
This comment has been minimized.
This comment has been minimized.
|
@bors r+ |
This comment has been minimized.
This comment has been minimized.
|
|
bors
added
S-waiting-on-bors
and removed
S-waiting-on-review
labels
Apr 26, 2018
bors
added a commit
that referenced
this pull request
Apr 26, 2018
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
bors
added
S-waiting-on-review
and removed
S-waiting-on-bors
labels
Apr 26, 2018
This comment was marked as resolved.
This comment was marked as resolved.
|
Your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
|
@bors retry AppVeyor problem:
|
bors
added
S-waiting-on-bors
and removed
S-waiting-on-review
labels
Apr 26, 2018
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Apr 27, 2018
This comment has been minimized.
This comment has been minimized.
|
|
nox commentedMar 27, 2018
No description provided.