Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't actually create a full MIR stack frame when not needed #57351

Merged
merged 6 commits into from
Jan 13, 2019

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Jan 5, 2019

r? @dotdash

This should significantly reduce overhead during const propagation and reduce overhead after copy propagation (cc #36673)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 5, 2019
@oli-obk
Copy link
Contributor Author

oli-obk commented Jan 5, 2019

@bors try

@bors
Copy link
Contributor

bors commented Jan 5, 2019

⌛ Trying commit c0f0f45 with merge 0ca2dc0...

bors added a commit that referenced this pull request Jan 5, 2019
Don't actually create a full MIR stack frame when not needed

r? @dotdash

This should significantly reduce overhead during const propagation and reduce overhead *after* copy propagation (cc #36673)
@bors
Copy link
Contributor

bors commented Jan 5, 2019

☀️ Test successful - status-travis
State: approved= try=True

@dotdash
Copy link
Contributor

dotdash commented Jan 5, 2019

Together with my (still WIP) fixes to the copy propagation pass, this makes enabling copy propagation pretty much free for the test case given in #36673

I don't feel comfortable to r+ as I have essentially no idea how const eval actually works.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jan 6, 2019

This is actually not a part of const eval, but of reading fields from evaluated constants which is used for pattern matching and const propagation

cc @RalfJung do you want to take this?

@oli-obk
Copy link
Contributor Author

oli-obk commented Jan 7, 2019

@rust-timer build 0ca2dc0

@rust-timer
Copy link
Collaborator

Success: Queued 0ca2dc0 with parent 2fba17f, comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit 0ca2dc0

@oli-obk
Copy link
Contributor Author

oli-obk commented Jan 7, 2019

Looks like a 1-2% perf improvement on a bunch of crates with only tuple-stress-check showing a regression (2% in clean incremental-check)

Vec::new(), // upvar_decls
DUMMY_SP, // span
Vec::new(), // control_flow_destroyed
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this function is only ever called when we don't even want to execute any code? But then why even bother pushing a stack frame at all...? Basically I don't understand why this even works.

That entire mir variable is "fake" and takes no input, right? This could be made clearer by having a separate function to construct it.

How does this relate to mk_borrowck_eval_cx, which creates a "less fake" frame but also for some reason cannot use push_stack_frame. Could this function also just directly push to the stack instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this function is only ever called when we don't even want to execute any code? But then why even bother pushing a stack frame at all...? Basically I don't understand why this even works.

We do call all kinds of methods on the ecx that check the current stack frame for e.g. substs and other info. These methods would fail without a stack frame. I remember talking about this before (not sure with whom), and we decided not to hack some sort of global substitutions into the ecx.

How does this relate to mk_borrowck_eval_cx, which creates a "less fake" frame but also for some reason cannot use push_stack_frame. Could this function also just directly push to the stack instead?

Jup, I unified it, good idea. This works much better.

Copy link
Member

@RalfJung RalfJung Jan 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do call all kinds of methods on the ecx that check the current stack frame for e.g. substs and other info. These methods would fail without a stack frame.

I know.

But somewhere we also run some actual code, and then we need a real stack frame. I guess neither of these two mk*_eval_cx functions is called then?

Could you please add doc comments to all of these mk*_eval_cx functions explaining when they should be called, what the difference between them is, and what can and cannot be done with the context they return (e.g., you can project to fields of a constant etc., but you cannot actually run any code)?

@RalfJung
Copy link
Member

RalfJung commented Jan 7, 2019

r? @RalfJung

with only tuple-stress-check showing a regression (2% in clean incremental-check)

How is that even possible? Isn't this doing strictly less work?
Clear Incremental is a very short benchmark though so this might very well be spurious.

@rust-highfive rust-highfive assigned RalfJung and unassigned dotdash Jan 7, 2019
@Mark-Simulacrum
Copy link
Member

I suspect the 2% regression on tuple-stress is indeed spurious (we could try to confirm be re-running try and perf; but I don't personally think there's really any need to -- 2% is small anyway).

@RalfJung
Copy link
Member

RalfJung commented Jan 9, 2019

@bors r+

@bors
Copy link
Contributor

bors commented Jan 9, 2019

📌 Commit dec79e4 has been approved by RalfJung

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 9, 2019
@bors
Copy link
Contributor

bors commented Jan 10, 2019

⌛ Testing commit dec79e4 with merge d5c50f5d9e85cfc8c603e6b80500f6a044d99e40...

@bors
Copy link
Contributor

bors commented Jan 10, 2019

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 10, 2019
@RalfJung
Copy link
Member

Log is empty. Probably spurious.

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 10, 2019
@bors
Copy link
Contributor

bors commented Jan 10, 2019

⌛ Testing commit dec79e4 with merge 431eb66b636a03a24ef2159211e378dd064f515a...

@bors
Copy link
Contributor

bors commented Jan 10, 2019

💔 Test failed - checks-travis

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 10, 2019
@RalfJung
Copy link
Member

Eh, aha?

[01:43:39] test vec::test_swap_remove_empty ... ok
[01:43:40] died due to signal 11
[01:43:40] �[0m�[0m�[1m�[31merror:�[0m test failed, to rerun pass '--test collectionstests'
[01:43:40] 
[01:43:40] 
[01:43:40] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "test" "--target" "arm-linux-androideabi" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "-p" "alloc" "--"
[01:43:40] expected success, got: exit code: 3

No idea. (And the "raw log" view makes it impossible to even tell the number of failed tests, or so.)

@pietroalbini
Copy link
Member

@bors retry #55861

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 10, 2019
pietroalbini added a commit to pietroalbini/rust that referenced this pull request Jan 12, 2019
Don't actually create a full MIR stack frame when not needed

r? @dotdash

This should significantly reduce overhead during const propagation and reduce overhead *after* copy propagation (cc rust-lang#36673)
Centril added a commit to Centril/rust that referenced this pull request Jan 13, 2019
Don't actually create a full MIR stack frame when not needed

r? @dotdash

This should significantly reduce overhead during const propagation and reduce overhead *after* copy propagation (cc rust-lang#36673)
bors added a commit that referenced this pull request Jan 13, 2019
Rollup of 16 pull requests

Successful merges:

 - #57351 (Don't actually create a full MIR stack frame when not needed)
 - #57353 (Optimise floating point `is_finite` (2x) and `is_infinite` (1.6x).)
 - #57412 (Improve the wording)
 - #57436 (save-analysis: use a fallback when access levels couldn't be computed)
 - #57453 (lldb_batchmode.py: try `import _thread` for Python 3)
 - #57454 (Some cleanups for core::fmt)
 - #57461 (Change `String` to `&'static str` in `ParseResult::Failure`.)
 - #57473 (std: Render large exit codes as hex on Windows)
 - #57474 (save-analysis: Get path def from parent in case there's no def for the path itself.)
 - #57494 (Speed up item_bodies for large match statements involving regions)
 - #57496 (re-do docs for core::cmp)
 - #57508 (rustdoc: Allow inlining of reexported crates and crate items)
 - #57547 (Use `ptr::eq` where applicable)
 - #57557 (resolve: Mark extern crate items as used in more cases)
 - #57560 (hygiene: Do not treat `Self` ctor as a local variable)
 - #57564 (Update the const fn tracking issue to the new metabug)

Failed merges:

r? @ghost
@bors bors merged commit dec79e4 into rust-lang:master Jan 13, 2019
@oli-obk oli-obk deleted the cheap_const_ops branch June 15, 2020 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants