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

Only memoize const fn calls during const eval #66866

Merged
merged 4 commits into from
Dec 4, 2019

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Nov 29, 2019

Miri and other engines may want to execute the function in order to detect UB inside of them.

r? @RalfJung

Miri and other engines may want to execute the function in order to detect UB inside of them.
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 29, 2019
@RalfJung

This comment has been minimized.

@oli-obk

This comment has been minimized.

// evaluation immediately.
//
// For the moment we only do this for functions which take no arguments
// (or all arguments are ZSTs) so that we don't memoize too much.
Copy link
Member

Choose a reason for hiding this comment

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

I'm guessing the other thing you check for, longer-term, is that there are no relocations in the arguments, so no memory outside of the call could be modified from inside.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we want to do that. Otherwise every single const fn call without relocations will get monomorphized, likely causing a significant increase in memory usage (e.g. if you call i32::abs in a loop over 0..10000, you'll get a cached query for every single call).

While the same thing is true for different ZSTs being passed to generic functions, I think that's less extreme since the user needs to write down each type anyway

@@ -463,7 +451,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {

/// Evaluate a const function where all arguments (if any) are zero-sized types.
/// The evaluation is memoized thanks to the query system.
fn eval_const_fn_call(
pub (crate) fn eval_const_fn_call(
Copy link
Member

Choose a reason for hiding this comment

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

Does this function need to live inside the Miri engine at all? Looks like most everything it does, const_eval.rs could also do.

Copy link
Member

Choose a reason for hiding this comment

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

Though I feel like that file could really benefit from being split into the basic CTFE machine definition, and the rest... (similar to machine.rs vs eval.rs in Miri).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to open a separate PR for pulling out all CTFE code to where it is actually needed

Copy link
Member

Choose a reason for hiding this comment

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

All CTFE code? Isn't eval_const_fn_call the only one that's inside interpret/ when it shouldn't be?
I cleaned this up during my refactorings, and I don't think anything besides this fn here sneaked in since then. But I might have missed some PRs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well I was gonna do a full review again, maybe that's the only one

Copy link
Member

Choose a reason for hiding this comment

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

Okay. Then please just add a FIXME in this PR.

@RalfJung
Copy link
Member

RalfJung commented Dec 2, 2019

r=me with that FIXME added.

@RalfJung RalfJung added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 3, 2019
@RalfJung
Copy link
Member

RalfJung commented Dec 4, 2019

@bors p=1 (fixing toolstate)

Co-Authored-By: Ralf Jung <post@ralfj.de>
@oli-obk
Copy link
Contributor Author

oli-obk commented Dec 4, 2019

@bors r=RalfJung

@bors
Copy link
Contributor

bors commented Dec 4, 2019

📌 Commit af8f141 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 4, 2019
@bors
Copy link
Contributor

bors commented Dec 4, 2019

⌛ Testing commit af8f141 with merge 6d77e45...

bors added a commit that referenced this pull request Dec 4, 2019
Only memoize const fn calls during const eval

Miri and other engines may want to execute the function in order to detect UB inside of them.

r? @RalfJung
@bors
Copy link
Contributor

bors commented Dec 4, 2019

☀️ Test successful - checks-azure
Approved by: RalfJung
Pushing 6d77e45 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 4, 2019
@bors bors merged commit af8f141 into rust-lang:master Dec 4, 2019
@rust-highfive
Copy link
Collaborator

📣 Toolstate changed by #66866!

Tested on commit 6d77e45.
Direct link to PR: #66866

💔 miri on windows: test-fail → build-fail (cc @oli-obk @eddyb @RalfJung, @rust-lang/infra).
💔 miri on linux: test-fail → build-fail (cc @oli-obk @eddyb @RalfJung, @rust-lang/infra).

rust-highfive added a commit to rust-lang-nursery/rust-toolstate that referenced this pull request Dec 4, 2019
Tested on commit rust-lang/rust@6d77e45.
Direct link to PR: <rust-lang/rust#66866>

💔 miri on windows: test-fail → build-fail (cc @oli-obk @eddyb @RalfJung, @rust-lang/infra).
💔 miri on linux: test-fail → build-fail (cc @oli-obk @eddyb @RalfJung, @rust-lang/infra).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

5 participants