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

move CTFE engine snapshot state out of miri engine into CTFE machine instance #54380

Merged
merged 7 commits into from
Sep 23, 2018

Conversation

RalfJung
Copy link
Member

It still lives in the interpret module as it needs access to all sorts of private stuff. Also rename a thing to make @eddyb happy :D

The goal was not to change any behavior.

@rust-highfive
Copy link
Collaborator

r? @michaelwoerister

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 20, 2018
@@ -310,7 +310,7 @@ impl<'b, 'a, 'tcx:'b> ConstPropagator<'b, 'a, 'tcx> {
// cannot use `const_eval` here, because that would require having the MIR
// for the current function available, but we're producing said MIR right now
let res = self.use_ecx(source_info, |this| {
eval_promoted(&mut this.ecx, cid, this.mir, this.param_env)
eval_promoted(this.tcx, cid, this.mir, this.param_env)
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the part I am least certain about: This is the only caller of eval_promoted, and it now operates in a new EvalContext instead of doing horrible things to the existing one. Seems to work fine...

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-5.0 of 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.
[00:13:31]    Compiling rustc_metadata_utils v0.0.0 (file:///checkout/src/librustc_metadata_utils)
[00:13:31]    Compiling rustc_mir v0.0.0 (file:///checkout/src/librustc_mir)
[00:13:31]    Compiling rustc_typeck v0.0.0 (file:///checkout/src/librustc_typeck)
[00:13:31]    Compiling rustc_traits v0.0.0 (file:///checkout/src/librustc_traits)
[00:14:20] error[E0502]: cannot borrow `*ecx` as immutable because `ecx.machine.loop_detector` is also borrowed as mutable
[00:14:20]     |
[00:14:20]     |
[00:14:20] 365 |         ecx.machine.loop_detector.observe_and_analyze(
[00:14:20]     |         ------------------------- mutable borrow occurs here
[00:14:20] 366 |             &ecx.tcx,
[00:14:20] 367 |             ecx.frame().span,
[00:14:20] ...
[00:14:20] 370 |         )
[00:14:20] 370 |         )
[00:14:20]     |         - mutable borrow ends here
[00:14:20] error: aborting due to previous error
[00:14:20] 
[00:14:20] For more information about this error, try `rustc --explain E0502`.
[00:14:20] error: Could not compile `rustc_mir`.

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 @TimNN. (Feature Requests)

@RalfJung RalfJung mentioned this pull request Sep 20, 2018
@RalfJung
Copy link
Member Author

RalfJung commented Sep 20, 2018

Eh, what? I compiled this locally...

EDIT: Funny, this compiled in stage 2 but not stage 1.

@RalfJung
Copy link
Member Author

r? @eddyb

{
fn hash_stable<W: StableHasherResult>(
&self,
hcx: &mut StableHashingContext<'b>,
hasher: &mut StableHasher<W>)
{
// Not hashing memory: Avoid hashing memory all the time during execution
Copy link
Member

Choose a reason for hiding this comment

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

You only need HashStable if you're putting these snapshots through queries (because incremental needs to save/reload them) - is that the case?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have no idea. I didn't write this code and I do not understand why they are using stable hashing. See #54384 and ask @oli-obk ;)

The purpose of this PR is mostly to get the loop detector out of my way, so that my next PR does not have to be concerned with this so much.

Copy link
Member

Choose a reason for hiding this comment

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

The answer is at #54384 (comment)

@@ -291,6 +335,28 @@ struct FrameSnapshot<'a, 'tcx: 'a> {
stmt: usize,
}

// Not using the macro because that does not support types depending on 'tcx
Copy link
Member

Choose a reason for hiding this comment

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

That's surprising, I'd expect it's because 'mir, not 'tcx - lots of types depend on 'tcx.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah no the problem is that it doesn't support things depending on TWO lifetimes.

Just one lifetime and any number of types.

When can we #[derive] this? :D

Copy link
Member

Choose a reason for hiding this comment

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

When can we #[derive] this? :D

#49219, which is lower priority than the edition :(

@eddyb
Copy link
Member

eddyb commented Sep 22, 2018

@bors r+

@bors
Copy link
Contributor

bors commented Sep 22, 2018

📌 Commit 8e74ee0 has been approved by eddyb

@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 Sep 22, 2018
@bors
Copy link
Contributor

bors commented Sep 23, 2018

⌛ Testing commit 8e74ee0 with merge be91c35...

bors added a commit that referenced this pull request Sep 23, 2018
move CTFE engine snapshot state out of miri engine into CTFE machine instance

It still lives in the `interpret` module as it needs access to all sorts of private stuff. Also rename a thing to make @eddyb happy :D

The goal was not to change any behavior.
@bors
Copy link
Contributor

bors commented Sep 23, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: eddyb
Pushing be91c35 to master...

@bors bors merged commit 8e74ee0 into rust-lang:master Sep 23, 2018
@rust-highfive
Copy link
Collaborator

📣 Toolstate changed by #54380!

Tested on commit be91c35.
Direct link to PR: #54380

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

rust-highfive added a commit to rust-lang-nursery/rust-toolstate that referenced this pull request Sep 23, 2018
Tested on commit rust-lang/rust@be91c35.
Direct link to PR: <rust-lang/rust#54380>

💔 miri on windows: test-pass → build-fail (cc @oli-obk @RalfJung @eddyb, @rust-lang/infra).
💔 miri on linux: test-pass → build-fail (cc @oli-obk @RalfJung @eddyb, @rust-lang/infra).
@bors bors mentioned this pull request Sep 23, 2018
bors added a commit that referenced this pull request Oct 10, 2018
miri engine: basic support for pointer provenance tracking

This enriches pointers with a new member, `tag`, that can be used to do provenance tracking. This is a new type parameter that propagates up through everything. It defaults to `()` (no tag), which is also the value used by CTFE -- but miri will use another type.

The only actually interesting piece here, I think, is what I had to do in the memory's `get`. The problem is that `tcx` (storing the allocations for statics) uses `()` for provenance information. But the machine might need another tag. The machine has a function to do the conversion, but if a conversion actually happened, we need to store the result of this *somewhere* -- we cannot return a pointer into `tcx` as we usually would.
So I introduced `MonoHashMap` which uses `RefCell` to be able to insert new entries even when we just have a shared ref. However, it is important that we can also return shared refs into the map without holding the `RefCell` opan. This is achieved by boxing the values stored in the map, so their addresses remain stable even when the map's table gets reallocated. This is all implemented in `mono_hash_map.rs`.

NOTE: This PR also contains the commits from #54380 (comment). Only the [last two commits](https://github.com/rust-lang/rust/pull/54461/files/8e74ee0998a5b11f28d61600dbb881c7168a4a40..HEAD) are new.
@RalfJung RalfJung deleted the miri-snapshot branch November 9, 2018 15:34
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.

None yet

5 participants