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 upImplement optimization fuel and re-enable struct field reordering #40377
Conversation
rust-highfive
assigned
arielb1
Mar 9, 2017
This comment has been minimized.
This comment has been minimized.
|
r? @arielb1 (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
To be honest, we probably want: r? @eddyb |
rust-highfive
assigned
eddyb
and unassigned
arielb1
Mar 9, 2017
eddyb
approved these changes
Mar 9, 2017
|
LGTM, except for the (accidental) submodule changes. |
camlorn
force-pushed the
camlorn:optimization_fuel
branch
from
8bd1709
to
de905e3
Mar 9, 2017
retep998
reviewed
Mar 9, 2017
| @@ -504,6 +518,33 @@ impl Session { | |||
| println!("Total time spent decoding DefPath tables: {}", | |||
| duration_to_secs_str(self.perf_stats.decode_def_path_tables_time.get())); | |||
| } | |||
|
|
|||
| /// We want to know if we're allowed to do an optimization for crate crate. | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
camlorn
Mar 9, 2017
Author
Contributor
Weirdly I'm going to go with yes, though crate foo might be a better choice for this phrasing. It's something I would write, though, with the intent that the redundant crate is a variable.
This comment has been minimized.
This comment has been minimized.
|
I was going to cc @rust-lang/compiler, but I think I'll also nominate it for discussion tomorrow. |
eddyb
added
I-nominated
T-compiler
labels
Mar 9, 2017
Mark-Simulacrum
reviewed
Mar 9, 2017
| // The odd pattern here avoids a warning about the value never being read. | ||
| if can_optimize { can_optimize = false; } | ||
| let can_optimize = (fields.len() > 2 || StructKind::EnumVariant == kind) | ||
| && ! (repr.c || repr.packed || repr.linear || repr.simd); |
This comment has been minimized.
This comment has been minimized.
Mark-Simulacrum
Mar 9, 2017
Member
This seems to be a change in behavior (and though seemingly correct, I want to make sure): before we didn't optimize for repr(c) and repr(packed), now repr(linear) and repr(simd) are presumably added.
This comment has been minimized.
This comment has been minimized.
camlorn
Mar 9, 2017
Author
Contributor
We didn't optimize for repr(simd) before. There might be a case for removing it from the condition. Simd vectors (used to?) go through Layout::Vector. I'm not as familiar with the details as I used to be: I had to leave this for a month in the middle. But I think leaving it for clarity is fine.
repr(linear) is not a thing externally. It exists because we need to be able to remember which structs reordering was disabled for when using optimization fuel. It is so named because there has been talk of making an RFC that adds it, and at this point it would just be exposing it via the parser.
This comment has been minimized.
This comment has been minimized.
eddyb
Mar 9, 2017
•
Member
Layout::Vector is still unchanged, so repr.simd should never be true here.
This comment has been minimized.
This comment has been minimized.
camlorn
Mar 9, 2017
Author
Contributor
Do you want me to kill it? I can, but it seems like the kind of thing where we might get rid of Layout::Vector and get mysterious breakage and I don't think it's doing any harm.
This comment has been minimized.
This comment has been minimized.
nikomatsakis
removed
the
I-nominated
label
Mar 9, 2017
This comment has been minimized.
This comment has been minimized.
|
Discussed in @rust-lang/compiler -- let's land this thing! It'd be nice to have some sort of tests. We talked about having a test that checks that we disabled reordering on one out of two structs (by supplying one unit of fuel). We might have to adjust the test in the future but for now it's ok. |
This comment has been minimized.
This comment has been minimized.
|
I hope to do the tests this evening when I get back. Should they be under |
This comment has been minimized.
This comment has been minimized.
|
@camlorn Maybe an |
This comment has been minimized.
This comment has been minimized.
|
@eddyb But this means it won't have a UI. |
This comment has been minimized.
This comment has been minimized.
|
@camlorn It's in AST order, i.e. |
This comment has been minimized.
This comment has been minimized.
|
@eddyb I can't get to this tonight, it's going to have to be the morning. It will not be some morning in a month from now, it will be tomorrow morning. |
This comment has been minimized.
This comment has been minimized.
|
Okay. There we go. 100% test coverage. And I don't think any of them are even fragile. |
This comment has been minimized.
This comment has been minimized.
|
@bors r+ |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors retry |
This comment has been minimized.
This comment has been minimized.
|
|
alexcrichton
force-pushed the
camlorn:optimization_fuel
branch
from
94a0375
to
3fb94b7
Mar 13, 2017
This comment has been minimized.
This comment has been minimized.
|
@bors: r=eddyb |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Wait, what happened here? |
This comment has been minimized.
This comment has been minimized.
|
bors is getting confused nowadays due to submodule updates and such, so it'll think there's a merge conflict when there isn't one. I rebased the branch and r+'d it. |
bors
added a commit
that referenced
this pull request
Apr 11, 2017
This comment has been minimized.
This comment has been minimized.
|
@nagisa Closure arguments. Figures. This was the weird bug last time. Hoping this merges. |
This comment has been minimized.
This comment has been minimized.
|
@camlorn I'm really sorry I forgot about it, I thought it got fixed and never checked. |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@eddyb No one is really sure how in the world the compiler passed all the tests in January at this point, but, well, it did. |
This comment has been minimized.
This comment has been minimized.
|
I figured out what was happening: in However, @arielb1's #39628 resulted in the shims in those cases (e.g. again, The only reason it didn't break before is because such functions are rare and require unstable Rust to write - the only semi-common example I can think of is |
camlorn commentedMar 9, 2017
•
edited by eddyb
See this discussion for background.
This pull request adds two new compilation options:
-Z print-fuel=crateprints the optimization fuel used by a crate and-Z fuel=crate=nsets the optimization fuel for a crate.It also turns field reordering back on. There is no way to test this feature without something consuming fuel. We can roll this back if we want, but then the optimization fuel bits will be dead code.
The one notable absence from this PR is a test case. I'm not sure how to do one that's worth having. The only thing I can think of to test is
-Z fuel=foo=0. The problem with other tests is that either (1) they're so big that future optimizations will apply, thus breaking them or (2) we don't know which order the optimizations will be applied in, so we can't guess the message that will be printed. If someone has a useful proposal for a good test, I certainly want to add one.