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

Fix conversion from Miri Value to ConstValue #50710

Merged
merged 1 commit into from
May 16, 2018

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented May 13, 2018

This fixes an error compiling the immeta 0.3.6 crate. #50707 may be fixed too.

r? @oli-obk

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 13, 2018
@@ -0,0 +1,12 @@

#[derive(Eq, PartialEq)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The playpen is probably not on the latest nightly.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah indeed. sorry

.get_alloc(ptr.alloc_id)
.expect("miri allocation never successfully created");
assert_eq!(align, alloc.align);
let alloc = ecx.memory.get(ptr.alloc_id)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't this change simply turn a panic into an error? How does that fix the regression?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The alloc ID we are trying to read is stored in the EvalContext and isn't in the global table.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah. makes sense. Is there any reason reading this should ever fail? If so, then this code is fine. Otherwise it should probably have the panic, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should really recurse into allocations like mark_static_initialized and could replace it by calling value_to_const_value at the end of const_eval.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah. makes sense. Is there any reason reading this should ever fail?

I don't think this can fail. Value::ByRef here must always point to a valid AllocId right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Might point to an integer address in general, but not as the result of const_eval

Copy link
Contributor Author

Choose a reason for hiding this comment

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

value_to_const_value is really just converting between different representation of Rust values, so it shouldn't fail. I've changed it to use unwrap so it will panic if it happens to fail.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 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:05:37] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:05:37] tidy error: /checkout/src/test/run-pass/match-larger-const.rs: incorrect license
[00:05:37] tidy error: /checkout/src/test/run-pass/match-larger-const.rs: missing trailing newline
[00:05:38] some tidy checks failed
[00:05:38] 
[00:05:38] 
[00:05:38] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:05:38] 
[00:05:38] 
[00:05:38] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:05:38] Build completed unsuccessfully in 0:02:12
[00:05:38] Build completed unsuccessfully in 0:02:12
[00:05:38] make: *** [tidy] Error 1
[00:05:38] Makefile:79: recipe for target 'tidy' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:03afe735
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

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)

@Zoxc Zoxc force-pushed the value_to_constvalue branch 3 times, most recently from 3d50de3 to 81915af Compare May 13, 2018 16:41
ty: Ty<'tcx>,
) -> &'tcx ty::Const<'tcx> {
let layout = tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)).unwrap();
// Convert to ByVal or ByValPair if possible
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've moved the code to convert to ByVal and ByValPair in here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Possibly. It is obsolete when it's called from const_eval at least.

.get_alloc(ptr.alloc_id)
.expect("miri allocation never successfully created");
assert_eq!(align, alloc.align);
let alloc = ecx.memory.get(ptr.alloc_id).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

please use expect so we can find it quickly if it fails (even if the issue reported has no backtrace)

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've changed this to report any miri errors then panic.

@Zoxc Zoxc force-pushed the value_to_constvalue branch from 81915af to 41a032d Compare May 13, 2018 17:04
@oli-obk
Copy link
Contributor

oli-obk commented May 13, 2018

@bors r+

@bors
Copy link
Contributor

bors commented May 13, 2018

📌 Commit 41a032d has been approved by oli-obk

@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 May 13, 2018
@kennytm
Copy link
Member

kennytm commented May 16, 2018

@bors
Copy link
Contributor

bors commented May 16, 2018

⌛ Testing commit 41a032d with merge 2f2a11d...

bors added a commit that referenced this pull request May 16, 2018
Fix conversion from Miri Value to ConstValue

This fixes an error compiling the `immeta` 0.3.6 crate. #50707 may be fixed too.

r? @oli-obk
@bors
Copy link
Contributor

bors commented May 16, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: oli-obk
Pushing 2f2a11d to master...

@bors bors merged commit 41a032d into rust-lang:master May 16, 2018
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.

5 participants