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

Delay interning errors to after validation #122684

Merged

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Mar 18, 2024

fixes #122398
fixes #122548

This improves diagnostics since validation errors are usually more helpful compared with interning errors that just make broad statements about the entire constant

r? @RalfJung

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 18, 2024
@rustbot
Copy link
Collaborator

rustbot commented Mar 18, 2024

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

Copy link
Member

@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.

Thanks for trying this! IMO it looks promising.

it's not much simpler than the other PR, because now we need to handle nested statics generated by interning.

It seems a lot simpler to me, now we can entirely avoid that extra "patch mutability" stage?

I'm still not sure whether validation should truly also be responsible for handling pointers that can't be "seen" by the type system; this needs a full recursive traversal after all -- a traversal that interning already performs. It's also conceptually no longer about "validating a value".

The alternative would be for interning to return a Result<(), DelayedInternError> and for the queries to do something like

let intern_res = intern();
validate()?;
if let Err(intern_err) = intern_res {
  intern_err.emit();
}

DelayedInternError could have a panicking drop to make sure we catch cases where emit is forgotten.

We can still have validation opportunistically check for dangling pointers to get nice errors (in raw pointers, and maybe inside unions by just scanning the provenance map) -- but we'd not have to do a full second recursive traversal of everything reachable by such hidden pointers.

compiler/rustc_const_eval/src/interpret/validity.rs Outdated Show resolved Hide resolved
tests/ui/consts/miri_unleashed/mutable_references.rs Outdated Show resolved Hide resolved

error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:13:1
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.v: encountered `UnsafeCell` in read-only memory
Copy link
Member

Choose a reason for hiding this comment

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

The obvious reaction to this will be "so why is that memory read-only"...

tests/ui/consts/std/cell.stderr Outdated Show resolved Hide resolved
compiler/rustc_const_eval/src/interpret/validity.rs Outdated Show resolved Hide resolved
tests/ui/consts/miri_unleashed/mutable_references.rs Outdated Show resolved Hide resolved
compiler/rustc_const_eval/src/interpret/intern.rs Outdated Show resolved Hide resolved
compiler/rustc_const_eval/src/interpret/validity.rs Outdated Show resolved Hide resolved
@oli-obk oli-obk force-pushed the delay_interning_errors_to_after_validaiton branch from c7b86c3 to 8f21f22 Compare March 19, 2024 17:20
@oli-obk
Copy link
Contributor Author

oli-obk commented Mar 19, 2024

I removed all the untyped validation and will create a separate PR for it

@oli-obk oli-obk force-pushed the delay_interning_errors_to_after_validaiton branch 2 times, most recently from 592f674 to 7517beb Compare March 19, 2024 17:41
@RalfJung
Copy link
Member

I removed all the untyped validation and will create a separate PR for it

Ah, good idea, thanks.

compiler/rustc_const_eval/src/const_eval/valtrees.rs Outdated Show resolved Hide resolved
compiler/rustc_const_eval/src/interpret/intern.rs Outdated Show resolved Hide resolved
compiler/rustc_const_eval/src/interpret/validity.rs Outdated Show resolved Hide resolved
.type_of(did)
.no_bound_vars()
.expect("statics should not have generic parameters")
.is_freeze(*self.ecx.tcx, ty::ParamEnv::reveal_all()) =>
Copy link
Member

Choose a reason for hiding this comment

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

I know this is pre-existing, but... why is reveal_all okay here? Shouldn't this be ecx.param_env()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're asking for information about a static item's type. If anything we should get the param env of the static (but we know that is just ParamEnv::reveal_all() anyway.

tests/ui/consts/miri_unleashed/mutable_references.rs Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors commented Mar 26, 2024

☔ The latest upstream changes (presumably #111769) made this pull request unmergeable. Please resolve the merge conflicts.

@RalfJung
Copy link
Member

@rustbot author

@rustbot rustbot 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 Mar 26, 2024
@oli-obk oli-obk force-pushed the delay_interning_errors_to_after_validaiton branch from 7517beb to 6290e5f Compare March 26, 2024 09:47
@oli-obk
Copy link
Contributor Author

oli-obk commented Mar 26, 2024

The new state is effectively a full rewrite. So I rebased, split it up into two commits and force pushed.

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

RalfJung commented Apr 1, 2024

@rustbot author

@rustbot rustbot 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 Apr 1, 2024
@oli-obk
Copy link
Contributor Author

oli-obk commented Apr 2, 2024

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 2, 2024
@bors
Copy link
Contributor

bors commented Apr 3, 2024

☔ The latest upstream changes (presumably #123385) made this pull request unmergeable. Please resolve the merge conflicts.

@oli-obk oli-obk force-pushed the delay_interning_errors_to_after_validaiton branch from 35bea5a to 2d936b4 Compare April 4, 2024 07:37
@RalfJung
Copy link
Member

RalfJung commented Apr 7, 2024

@rustbot author
(sorry for the slow reviews, I mostly only have time on week-ends for stuff like this and it's been extra busy the last few weeks... though that does seem to become the new normal...)

@rustbot rustbot 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 Apr 7, 2024
@oli-obk
Copy link
Contributor Author

oli-obk commented Apr 8, 2024

No worries. I got enough stuff to do 😆

@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the delay_interning_errors_to_after_validaiton branch from 586145a to acb817a Compare April 16, 2024 15:15
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the delay_interning_errors_to_after_validaiton branch from acb817a to a3d987f Compare April 16, 2024 16:19
@RalfJung
Copy link
Member

All my comments are resolved, r=me with or without some commit squashing.

@oli-obk oli-obk force-pushed the delay_interning_errors_to_after_validaiton branch from a3d987f to 126dcc6 Compare April 17, 2024 09:51
@oli-obk
Copy link
Contributor Author

oli-obk commented Apr 17, 2024

@bors r=RalfJung

@bors
Copy link
Contributor

bors commented Apr 17, 2024

📌 Commit 126dcc6 has been approved by RalfJung

It is now in the queue for this repository.

@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 Apr 17, 2024
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Apr 17, 2024
…after_validaiton, r=RalfJung

Delay interning errors to after validation

fixes rust-lang#122398
fixes rust-lang#122548

This improves diagnostics since validation errors are usually more helpful compared with interning errors that just make broad statements about the entire constant

r? `@RalfJung`
@bors
Copy link
Contributor

bors commented Apr 18, 2024

⌛ Testing commit 126dcc6 with merge 5260893...

@bors
Copy link
Contributor

bors commented Apr 18, 2024

☀️ Test successful - checks-actions
Approved by: RalfJung
Pushing 5260893 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 18, 2024
@bors bors merged commit 5260893 into rust-lang:master Apr 18, 2024
13 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Apr 18, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (5260893): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.9% [0.2%, 4.2%] 7
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.0% [3.0%, 3.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.2% [-2.2%, -2.2%] 1
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 676.169s -> 679.408s (0.48%)
Artifact size: 316.07 MiB -> 315.39 MiB (-0.21%)

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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
6 participants