Skip to content

Lazily normalize inside trait ref during orphan check & consider ty params in rigid alias types to be uncovered#117164

Merged
bors merged 1 commit intorust-lang:masterfrom
fmease:orphan-norm
Apr 30, 2024
Merged

Lazily normalize inside trait ref during orphan check & consider ty params in rigid alias types to be uncovered#117164
bors merged 1 commit intorust-lang:masterfrom
fmease:orphan-norm

Conversation

@fmease
Copy link
Member

@fmease fmease commented Oct 25, 2023

Fixes #99554, fixes rust-lang/types-team#104.
Fixes #114061.

Supersedes #100555.

Tracking issue for the future compatibility lint: #124559.

r? lcnr

@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 Oct 25, 2023
LL | impl<T> foreign::Trait<Local, T, ()> for <T as Identity>::Output {}
| ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`)
|
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type
Copy link
Member Author

@fmease fmease Oct 25, 2023

Choose a reason for hiding this comment

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

While I could update the diagnostic to say something like

Suggested change
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no type parameters not covered by a nominal type appear before that first local type

or

- error[E0210]: type parameter `T` must be covered by another type
+ error[E0210]: type parameter `T` must be covered by a nominal type

we could instead change the definition of "covered" (e.g., in the Rust Reference) to reflect that the covering type has to be nominal for the contained type to be considered covered.

@fmease fmease added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Oct 25, 2023
@rust-log-analyzer

This comment has been minimized.

@fmease fmease 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 Oct 26, 2023
@bors

This comment was marked as resolved.

@fmease fmease force-pushed the orphan-norm branch 2 times, most recently from f22fadd to 719c089 Compare October 27, 2023 07:50
@fmease fmease marked this pull request as draft October 27, 2023 07:53
@fmease fmease changed the title Normalize trait ref before orphan check Normalize trait ref before orphan check & consider ty params in projections to be uncovered Oct 27, 2023
@rust-log-analyzer

This comment has been minimized.

@fmease fmease added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 27, 2023
@rust-log-analyzer

This comment has been minimized.

@fmease fmease force-pushed the orphan-norm branch 2 times, most recently from 878f995 to f5df0d1 Compare October 28, 2023 11:09
@rust-log-analyzer

This comment has been minimized.

@fmease fmease 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. S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Nov 9, 2023
local_ty,
}))
}
Ok(OrphanCheckResult::Err(OrphanCheckErr::NonLocalInputType(tys))) => {
Copy link
Member Author

@fmease fmease Mar 26, 2024

Choose a reason for hiding this comment

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

not using FmtPrinter since remapping of ty vars now happens here, not over at the diagnostic code. Furthermore, the diagnostic code in hir analysis does further Ty processing so we can't fmt it here to a String.

Note that doing the remapping here allows us not to pass around an InferCtxt / Box<_> from trait selection to hir analysis which was super gross. You can see the perks of the new structuring by cmp'ing commit 2 and 3. I'm so happy I've managed to get rid of that.

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

vibe: the current structure of orphan_check_trait_ref is confusing to me and I didn't fully get how the backcompat is handled (only spent a few minutes on the train on this tbf).

Have you considered to instead toggle the behavior of fn orphan_check_trait_ref depending on its input, e.g. by changing InCrate to the following?

enum InCrate {
   Local { orphan_check_backcompat: bool },
   Remote,
}

This way it should be more clear that the behavior for "consider aliases which may normalize to unconvered ty" does not accidentally change the desired behavior outside of linting[^1]

separate vibe: while I know that there's precendent to name things Issue69420, I really dislike this as it requires looking up the issue to figure out the purpose of such a variant. Actually referring to the underlying issue, e.g. AliasMayNormToUncovered or whatever and then linking to the issue in a doc comment feels a lot more desirable to me. We should ideally rename all the functions and enums which currently use issue numbers.

@bors
Copy link
Collaborator

bors commented Mar 30, 2024

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

@lcnr
Copy link
Contributor

lcnr commented Apr 30, 2024

@bors r+ rollup=never

@bors
Copy link
Collaborator

bors commented Apr 30, 2024

📌 Commit c68c273 has been approved by lcnr

It is now in the queue for this repository.

@fmease
Copy link
Member Author

fmease commented Apr 30, 2024

I've added regression tests for #114061.

@bors r=lcnr

@bors
Copy link
Collaborator

bors commented Apr 30, 2024

📌 Commit 951e902 has been approved by lcnr

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Apr 30, 2024

⌛ Testing commit 951e902 with merge f705de5...

@bors
Copy link
Collaborator

bors commented Apr 30, 2024

☀️ Test successful - checks-actions
Approved by: lcnr
Pushing f705de5 to master...

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f705de5): 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)

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)
- - 0
Improvements ✅
(primary)
-1.7% [-2.4%, -0.9%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.7% [-2.4%, -0.9%] 2

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)
1.4% [1.4%, 1.4%] 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: 672.826s -> 673.884s (0.16%)
Artifact size: 315.97 MiB -> 316.00 MiB (0.01%)

@apiraino
Copy link
Contributor

apiraino commented Jul 5, 2024

we have some crater run regressions, maybe these changes need to be in the changelog

@rustbot label +relnotes

@lcnr
Copy link
Contributor

lcnr commented Jul 5, 2024

The changes belong into the changelog, we automatically go through all T-types FCP'd PRs for each release, so the explicit relnotes tag isn't necessary imo (and easy to forget, which is why I want us to go through all FCPs when writing the release notes).

@apiraino
Copy link
Contributor

apiraino commented Jul 5, 2024

The changes belong into the changelog, we automatically go through all T-types FCP'd PRs for each release, so the explicit relnotes tag isn't necessary imo (and easy to forget, which is why I want us to go through all FCPs when writing the release notes).

oh interesting I wasn't aware (or just forgot) about this flow, thanks for explaining!

(I thought that the only workflow was T-release getting all relnotes patches and put them into human-redable form in the changelog 🙂 )

@lcnr
Copy link
Contributor

lcnr commented Jul 5, 2024

yeah, it's fairly new and also not really formalized anywhere, see https://rust-lang.zulipchat.com/#narrow/stream/241545-t-release/topic/1.2E78/near/430856836 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. merged-by-bors This PR was explicitly merged by bors. relnotes Marks issues that should be documented in the release notes of the next release. 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. T-types Relevant to the types team, which will review and decide on the PR/issue.

Projects

Status: Done

9 participants