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

Miri: improve spans of required_const failures #75396

Merged
merged 6 commits into from
Aug 12, 2020

Conversation

RalfJung
Copy link
Member

In #75339 I added a loop evaluating all consts required by a function body. Unfortunately, if one of their evaluations fails, then the span used for that was that of the first statement in the function body, which happened to work form some existing test but is not sensible in general.

This PR changes it to point to the whole function instead, which is at least not wrong.

r? @oli-obk

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 11, 2020
@RalfJung
Copy link
Member Author

To do better, we'd have to either

  • pass a span through the error machinery (i.e., add a Span field to InterpError) which (if present) overwrites the span of the topmost frame, or
  • make it so that the frame knows it is currently evaluating a const, and can report its span.

In the light of this chaos, I am not sure I want to add yet another Span field to errors, and such "overwriting" behavior is often confusing. So if we think that we should try to do better, my proposal would be to replace this field of Frame

    pub loc: Option<mir::Location>,

by something of a type like Result<mir::Location, Span>, so that we can say what the span is when we are not currently evaluating a statement in that frame.

@oli-obk
Copy link
Contributor

oli-obk commented Aug 11, 2020

Yes, I also prefer that proposal. Although Result isn't the best type here, I'm not sure the situation warrants its own enum (though that could make it more obvious that something unusual is going on here). The current None situation could be represented by Err(DUMMY_SP)

@RalfJung
Copy link
Member Author

Or rather, Err(self.body.span). Yes.

@RalfJung
Copy link
Member Author

All right, I implemented that now.

Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

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

r=me with nits

src/librustc_mir/interpret/eval_context.rs Outdated Show resolved Hide resolved
src/librustc_mir/interpret/eval_context.rs Outdated Show resolved Hide resolved
src/librustc_mir/interpret/intrinsics/caller_location.rs Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member Author

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Aug 12, 2020

📌 Commit 8fc28352e8f99df9a8fd965587ffccc3bd682dcd 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 Aug 12, 2020
@RalfJung
Copy link
Member Author

@bors r-
investigating branch CI failure

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 12, 2020
@RalfJung
Copy link
Member Author

Hu, a test failure but local runs don't show anything??

@RalfJung
Copy link
Member Author

Ah looks like that test was changed recently even though it already existed before... very strange.

@RalfJung
Copy link
Member Author

RalfJung commented Aug 12, 2020

@oli-obk for some reason uninhabited-const-issue-61744.stderr changed a lot, but only after I rebased. No idea what is happening.

@RalfJung
Copy link
Member Author

Also how horrible is GitHub? Why can I not go to the git log from https://github.com/rust-lang/rust/blob/d45dcb509527d847c7c3bf459a0e796801067b33/src/test/ui/consts/uninhabited-const-issue-61744.stderr ? I thought that used to be possible?

@RalfJung
Copy link
Member Author

Hm, that test also did not change recently. So it must be some other change on the rustc side that makes it such that in combination with this PR, the output for that test changes. WTF.

@RalfJung
Copy link
Member Author

Oh I see, this is a stack overflow, so it likely interacts with #75338.

Copy link
Member Author

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

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

(wow GitHub is really making my life as hard as possible today. now it started a review...)

Comment on lines 697 to +698
M::after_stack_push(self)?;
self.frame_mut().loc = Ok(mir::Location::START);
Copy link
Member Author

Choose a reason for hiding this comment

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

It's about the order of these two lines: for errors that happen during after_stack_push, so we want to use the span of the first statement, or the span of the entire body? IMO the latter makes more sense, the first statement has nothing to do with this.

For the stack overflow, probably the best span to use would be that of the call site.

Copy link
Contributor

Choose a reason for hiding this comment

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

yea, the body's span is good here, though it's actually the call site's fault. But lets leave such refactorings (using the call site span) to the future, I remember trying something similar a while back and it just complicated the span scheme even more

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, this wouldn't even be that hard I think... we can just call cur_span before pushing the new frame, then we should get the call site.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's just not clear to me that we always want the call site. The callee could also be responsible for the problem -- in fact I'd usually think they are.

Copy link
Contributor

Choose a reason for hiding this comment

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

at runtime the decision whose job it is to create the stack frame is an ABI decision, but that doesn't really make sense for CTFE. But I also think your alluding to a different thing? If an required_const will fail regardless of the concrete generic parameters, then that's indeed the function's fault and not the caller's

Copy link
Member Author

Choose a reason for hiding this comment

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

If an required_const will fail regardless of the concrete generic parameters, then that's indeed the function's fault and not the caller's

Yes, that is one possible scenario I had in mind where blaming the caller seems wrong.

@bors
Copy link
Contributor

bors commented Aug 12, 2020

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

bors commented Aug 12, 2020

⌛ Testing commit fd32fe9 with merge 5c8f1c241f7babd2356f080b77258174dcbf5da6...

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, 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.
Build completed successfully in 0:02:06
+ /scripts/validate-toolstate.sh
Cloning into 'rust-toolstate'...
<Nothing changed>
error: embedded-book maintainer @ryankurte is not assignable in the rust-lang/rust repo
error: embedded-book maintainer @thejpster is not assignable in the rust-lang/rust repo
error: embedded-book maintainer @korken89 is not assignable in the rust-lang/rust repo

  To be assignable, a person needs to be explicitly listed as a
  collaborator in the repository settings. The simple way to
  fix this is to ask someone with 'admin' privileges on the repo
  to add the person or whole team as a collaborator with 'read'
  privileges. Those privileges don't grant any extra permissions
  so it's safe to apply them.
The build will fail due to this.
== clock drift check ==
  local time: Wed Aug 12 11:14:19 UTC 2020
  network time: Wed, 12 Aug 2020 11:14:20 GMT
  network time: Wed, 12 Aug 2020 11:14:20 GMT
== end clock drift check ==
##[error]Process completed with exit code 1.
Terminate orphan process: pid (3081) (node)
Terminate orphan process: pid (3109) (python)

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 @rust-lang/infra. (Feature Requests)

@bors
Copy link
Contributor

bors commented Aug 12, 2020

💔 Test failed - checks-actions

@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 Aug 12, 2020
@RalfJung
Copy link
Member Author

error: embedded-book maintainer @ryankurte is not assignable in the rust-lang/rust repo
error: embedded-book maintainer @thejpster is not assignable in the rust-lang/rust repo
error: embedded-book maintainer @korken89 is not assignable in the rust-lang/rust repo

Seems spurious to me... I hope.^^
@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 Aug 12, 2020
@bors
Copy link
Contributor

bors commented Aug 12, 2020

⌛ Testing commit fd32fe9 with merge 0ac354c868c8238b48198d9bac75bd17719505e3...

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, 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.
Build completed successfully in 0:01:55
+ /scripts/validate-toolstate.sh
Cloning into 'rust-toolstate'...
<Nothing changed>
error: embedded-book maintainer @thejpster is not assignable in the rust-lang/rust repo
error: embedded-book maintainer @korken89 is not assignable in the rust-lang/rust repo
error: embedded-book maintainer @ryankurte is not assignable in the rust-lang/rust repo

  To be assignable, a person needs to be explicitly listed as a
  collaborator in the repository settings. The simple way to
  fix this is to ask someone with 'admin' privileges on the repo
  to add the person or whole team as a collaborator with 'read'
  privileges. Those privileges don't grant any extra permissions
  so it's safe to apply them.
The build will fail due to this.
== clock drift check ==
  local time: Wed Aug 12 11:35:32 UTC 2020
  network time: Wed, 12 Aug 2020 11:35:33 GMT
  network time: Wed, 12 Aug 2020 11:35:33 GMT
== end clock drift check ==
##[error]Process completed with exit code 1.
Terminate orphan process: pid (3052) (node)
Terminate orphan process: pid (3077) (python)

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 @rust-lang/infra. (Feature Requests)

@bors
Copy link
Contributor

bors commented Aug 12, 2020

💔 Test failed - checks-actions

@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 Aug 12, 2020
@RalfJung
Copy link
Member Author

@rust-lang/infra
second time in a row that I got

error: embedded-book maintainer @thejpster is not assignable in the rust-lang/rust repo
error: embedded-book maintainer @korken89 is not assignable in the rust-lang/rust repo
error: embedded-book maintainer @ryankurte is not assignable in the rust-lang/rust repo

Any idea what is happening?
@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 Aug 12, 2020
@pietroalbini
Copy link
Member

@bors treeclosed=1000

@pietroalbini
Copy link
Member

Fixing CI in #75450.

@bors
Copy link
Contributor

bors commented Aug 12, 2020

⌛ Testing commit fd32fe9 with merge 576d27c...

@bors
Copy link
Contributor

bors commented Aug 12, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: oli-obk
Pushing 576d27c to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 12, 2020
@bors bors merged commit 576d27c into rust-lang:master Aug 12, 2020
@RalfJung RalfJung deleted the miri-spans branch August 13, 2020 07:18
@cuviper cuviper added this to the 1.47.0 milestone May 2, 2024
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.

7 participants