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

Emit dropck normalization errors in borrowck #136539

Merged
merged 4 commits into from
Feb 19, 2025

Conversation

matthewjasper
Copy link
Contributor

Borrowck generally assumes that any queries it runs for type checking will succeed, thinking that HIR typeck will have errored first if there was a problem. However as of #98641, dropck isn't run on HIR, so there's no direct guarantee that it doesn't error. While a type being well-formed might be expected to ensure that its fields are well-formed, this is not the case for types containing a type projection:

pub trait AuthUser {
    type Id;
}

pub trait AuthnBackend {
    type User: AuthUser;
}

pub struct AuthSession<Backend: AuthnBackend> {
    data: Option<<<Backend as AuthnBackend>::User as AuthUser>::Id>,
}

pub trait Authz: Sized {
    type AuthnBackend: AuthnBackend<User = Self>;
}

pub fn run_query<User: Authz>(auth: AuthSession<User::AuthnBackend>) {}
// ^ No User: AuthUser bound is required or inferred.

While improvements to trait solving might fix this in the future, for now we go for a pragmatic solution of emitting an error from borrowck (by rerunning dropck outside of a query) and making drop elaboration check if an error has been emitted previously before panicking for a failed normalization.

Closes #103899
Closes #135039

r? @compiler-errors (feel free to re-assign)

@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 Feb 4, 2025
@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 4, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 4, 2025
… r=<try>

Emit dropck normalization errors in borrowck

Borrowck generally assumes that any queries it runs for type checking will succeed, thinking that HIR typeck will have errored first if there was a problem. However as of rust-lang#98641, dropck isn't run on HIR, so there's no direct guarantee that it doesn't error. While a type being well-formed might be expected to ensure that its fields are well-formed, this is not the case for types containing a type projection:

```rust
pub trait AuthUser {
    type Id;
}

pub trait AuthnBackend {
    type User: AuthUser;
}

pub struct AuthSession<Backend: AuthnBackend> {
    data: Option<<<Backend as AuthnBackend>::User as AuthUser>::Id>,
}

pub trait Authz: Sized {
    type AuthnBackend: AuthnBackend<User = Self>;
}

pub fn run_query<User: Authz>(auth: AuthSession<User::AuthnBackend>) {}
// ^ No User: AuthUser bound is required or inferred.
```

While improvements to trait solving might fix this in the future, for now we go for a pragmatic solution of emitting an error from borrowck (by rerunning dropck outside of a query) and making drop elaboration check if an error has been emitted previously before panicking for a failed normalization.

Closes rust-lang#103899
Closes rust-lang#135039

r? `@compiler-errors` (feel free to re-assign)
@bors
Copy link
Contributor

bors commented Feb 4, 2025

⌛ Trying commit abfa754 with merge 40f1f75...

@bors
Copy link
Contributor

bors commented Feb 4, 2025

☀️ Try build successful - checks-actions
Build commit: 40f1f75 (40f1f75bb4cd41066f6e5b10d25251675eacd0d7)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (40f1f75): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

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

Max RSS (memory usage)

Results (secondary -0.7%)

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)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.7% [-0.7%, -0.7%] 1
All ❌✅ (primary) - - 0

Cycles

Results (secondary 3.3%)

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.3% [3.3%, 3.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 778.8s -> 781.102s (0.30%)
Artifact size: 328.88 MiB -> 328.83 MiB (-0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 4, 2025
@compiler-errors

This comment was marked as resolved.

@craterbot

This comment was marked as resolved.

@matthewjasper

This comment was marked as outdated.

@craterbot

This comment was marked as outdated.

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 7, 2025
@lqd

This comment was marked as outdated.

@matthewjasper

This comment was marked as outdated.

@craterbot

This comment was marked as outdated.

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Feb 7, 2025
@matthewjasper
Copy link
Contributor Author

@craterbot run start=master end=try#40f1f75bb4cd41066f6e5b10d25251675eacd0d7 mode=check-only

@craterbot
Copy link
Collaborator

👌 Experiment pr-136539 created and queued.
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 7, 2025
@craterbot
Copy link
Collaborator

🚧 Experiment pr-136539 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added the S-waiting-on-crater Status: Waiting on a crater run to be completed. label Feb 8, 2025
@craterbot
Copy link
Collaborator

🚧 Experiment pr-136539 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-136539 is completed!
📊 2 regressed and 8 fixed (579475 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Feb 8, 2025
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Feb 14, 2025

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

@compiler-errors
Copy link
Member

whoops, r=me after rebase

HIR type checking no longer runs dropck, so we may get new errors when
we run it in borrowck. If this happens then rerun the query in a local
infcx and report errors for it.
Drop elaboration looks at fields of a type, which may error when we try
to normalize them. Borrowck will have detected this if HIR typeck
didn't, but we don't delete the MIR body for errors in borrowck so
still have to handle this happening in drop elaboration by checking
whether an error has been emitted.
- Remove `Result` that couldn't be Err on valid compilation.
- Always compute errors on failure.
@rustbot
Copy link
Collaborator

rustbot commented Feb 17, 2025

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@matthewjasper
Copy link
Contributor Author

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Feb 17, 2025

📌 Commit 49cf00c has been approved by compiler-errors

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-review Status: Awaiting review from the assignee but also interested parties. labels Feb 17, 2025
@bors
Copy link
Contributor

bors commented Feb 19, 2025

⌛ Testing commit 49cf00c with merge ed49386...

@bors
Copy link
Contributor

bors commented Feb 19, 2025

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing ed49386 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 19, 2025
@bors bors merged commit ed49386 into rust-lang:master Feb 19, 2025
7 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Feb 19, 2025
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ed49386): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

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

Max RSS (memory usage)

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

Cycles

Results (primary 4.3%)

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)
4.3% [1.7%, 6.4%] 7
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 4.3% [1.7%, 6.4%] 7

Binary size

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

Bootstrap: 773.598s -> 773.063s (-0.07%)
Artifact size: 360.32 MiB -> 362.34 MiB (0.56%)

@matthewjasper matthewjasper deleted the late-normalize-errors branch February 19, 2025 14:54
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
Development

Successfully merging this pull request may close these issues.

ICE in mir_drops_elaborated_and_const_checked ICE: delay_span_bug: error performing ParamEnvAnd
8 participants