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

generalize: handle occurs check failure in aliases #117088

Merged
merged 4 commits into from
Dec 5, 2023

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Oct 23, 2023

mostly fixes #105787, except for the for<'a> fn(<<?x as OtherTrait>::Assoc as Trait<'a>>::Assoc) eq ?x case in rust-lang/trait-system-refactor-initiative#8.

r? @compiler-errors

@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 23, 2023
Comment on lines 159 to 161
/// incorrect errors when relating `?0` with `<?0 as Trait>::Assoc`.
in_alias: bool,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

exists because of <() as Trait<<?0 as Trait<()>>::Assoc>>::Assoc == ?0 have to update comment. With Projection goals the behavior is still broken, but I want to change it to emit alias-relate in the new solver in a different PR, at which point this should work.

Comment on lines 345 to 354
if !infer_replacement_is_complete {
warn!("incomplete generalization of an alias type: {t:?}");
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

handling this correctly is HARD. We'd have to push the infer var to the place which introduced the binder and then have a nested Equate goal or sth.

idk how to handle this during coherence, ideally just succeed with equating and emit an Ambiguity predicate?


let ty = value.may_be_infer();
if ty.is_ty_var() {
span_bug!(self.delegate.span(), "occurs check failure in MIR typeck");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

potentially reachable with user type annotations? Probably not as the actual type inferred by HIR typeck also needs to contain an inference variable? 🤔

@lcnr lcnr force-pushed the generalize-alias branch from 96204ee to 6fdb8cb Compare October 23, 2023 16:09
@lcnr lcnr added the needs-fcp This change is insta-stable, so needs a completed FCP to proceed. label Oct 23, 2023
@rust-log-analyzer

This comment has been minimized.

@lcnr lcnr force-pushed the generalize-alias branch from 6fdb8cb to 768015f Compare October 23, 2023 18:13
@rust-log-analyzer

This comment has been minimized.

@lcnr lcnr force-pushed the generalize-alias branch 2 times, most recently from 5840c9d to f817a32 Compare October 24, 2023 07:38
@rust-log-analyzer

This comment has been minimized.

@lcnr lcnr force-pushed the generalize-alias branch from f817a32 to ea6e393 Compare October 24, 2023 07:49
@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member

this is still in draft, so marking as author so i can clean up my queue :>

@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 Oct 25, 2023
@lcnr lcnr force-pushed the generalize-alias branch from ea6e393 to 6913673 Compare October 26, 2023 08:08
@lcnr lcnr marked this pull request as ready for review October 26, 2023 08:08
@lcnr
Copy link
Contributor Author

lcnr commented Oct 26, 2023

This PR mostly fixes generalization for aliases, fixing #105787. It is therefore a (theoretical) breaking change.

Equating ?x == Alias<?x> previously failed. This is incomplete (and therefore allows overlaps via the implicit negative overlap check in coherence). This PR instead delays equality in this case, emitting a Projection goal. This projection goal then stalls until the projection can be normalized to a rigid type, in which case the occurs check is correct, or the projection cannot be normalized and stays rigid (due to a ParamEnv candidate).

It is non-trivial whether we can get trait solver overflow (in the old solver) for rigid projections, e.g.

trait Unnormalizable<T> {
    type Assoc;
}

struct Inv<T>(*mut T);

fn unconstrained<T>() -> T {
    todo!()
}

fn create<T, U: Unnormalizable<T>>(
    x: &U,
) -> (Inv<T>, Inv<<U as Unnormalizable<T>>::Assoc>) {
    todo!()
}

fn foo<T: Unnormalizable<U> + Unnormalizable<V>, U, V>() {
    let q = unconstrained();
    let (mut x, y) = create::<_, _>(&q);
    x = y; // equate `?x` with `<T as Unnormalizable<?x>>::Assoc`
    drop::<T>(q);
}

However, projection goals only constrain the term to the projection itself if we were able to select a ParamEnv candidate. As we do not have non-lifetime binders, this only happens if the projection does not contain type inference variables.

I believe that you can get solver overflow with specialization and default associated items, but idc 😁

This only fixes problem case 2 of rust-lang/trait-system-refactor-initiative#8. However, this is by far the easiest way to get an incorrect occurs check failure (and the only one I bothered to write a coherence unsoundness test for). This only impacts the old solver for projections containing bound variables (as we otherwise eagerly normalize and replace the projection with an inference variable).

I consider this to 1) be a step in the right direction and 2) necessary for future work on the new trait solver.

@lcnr lcnr closed this Oct 26, 2023
@lcnr lcnr reopened this Oct 26, 2023
@lcnr lcnr 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 Oct 26, 2023
@lcnr
Copy link
Contributor Author

lcnr commented Oct 26, 2023

should have done perf + crater 😅

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rfcbot
Copy link

rfcbot commented Dec 3, 2023

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@compiler-errors
Copy link
Member

r=me after rebase

@lcnr lcnr force-pushed the generalize-alias branch from 6913673 to cf8a2bd Compare December 4, 2023 09:49
@lcnr
Copy link
Contributor Author

lcnr commented Dec 4, 2023

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented Dec 4, 2023

📌 Commit cf8a2bd has been approved by lcnr

It is now in the queue for this repository.

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Dec 4, 2023
@compiler-errors
Copy link
Member

@bors r+

approver is wrong

@bors
Copy link
Contributor

bors commented Dec 4, 2023

💡 This pull request was already approved, no need to approve it again.

@bors
Copy link
Contributor

bors commented Dec 4, 2023

📌 Commit cf8a2bd has been approved by compiler-errors

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Dec 4, 2023

⌛ Testing commit cf8a2bd with merge 90f22e7...

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 4, 2023
…rors

generalize: handle occurs check failure in aliases

mostly fixes rust-lang#105787, except for the `for<'a> fn(<<?x as OtherTrait>::Assoc as Trait<'a>>::Assoc) eq ?x` case in rust-lang/trait-system-refactor-initiative#8.

r? `@compiler-errors`
@lnicola
Copy link
Member

lnicola commented Dec 4, 2023

This is going to fail, CC #118597. Maybe you can take a look, @compiler-errors, since you seem to be around.

Actually, @pietroalbini might be a better person to tag, sorry for the mix-up.

@compiler-errors
Copy link
Member

compiler-errors commented Dec 4, 2023

@bors retry

kicking the job to avoid failure

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-aux failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
thread 'main' panicked at src/tools/cargotest/main.rs:148:13:
assertion failed: status.success()
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Build completed unsuccessfully in 0:36:43
make: *** [Makefile:51: check-aux] Error 1
  network time: Mon, 04 Dec 2023 11:09:26 GMT
##[error]Process completed with exit code 2.
Post job cleanup.

@bors
Copy link
Contributor

bors commented Dec 5, 2023

⌛ Testing commit cf8a2bd with merge 25dca40...

@bors
Copy link
Contributor

bors commented Dec 5, 2023

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

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 5, 2023
@bors bors merged commit 25dca40 into rust-lang:master Dec 5, 2023
12 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Dec 5, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (25dca40): 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.3% [0.3%, 0.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

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)
1.7% [1.7%, 1.7%] 1
Regressions ❌
(secondary)
2.7% [2.6%, 2.7%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.1% [-1.1%, -1.1%] 1
All ❌✅ (primary) 1.7% [1.7%, 1.7%] 1

Cycles

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

Binary size

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

Bootstrap: 672.674s -> 673.516s (0.13%)
Artifact size: 314.14 MiB -> 314.15 MiB (0.00%)

@lcnr lcnr deleted the generalize-alias branch December 5, 2023 13:26
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 8, 2023
…3, r=BoxyUwU

split `NormalizesTo` out of `Projection` 3

third attempt at rust-lang#112658. Rebasing rust-lang#116262 is very annoying, so I am doing it again from scratch. We should now be able to merge it without regressing anything as we handle occurs check failures involving aliases correctly since rust-lang#117088.

see https://hackmd.io/ktEL8knTSYmtdfrMMnA-Hg

fixes rust-lang/trait-system-refactor-initiative#1

r? `@compiler-errors`
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Dec 14, 2023
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. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

occurs check with aliases results in error, not ambiguity