Skip to content

Fix type resolution of associated const equality bounds (take 2)#119385

Merged
bors merged 3 commits into
rust-lang:masterfrom
fmease:assoc-const-eq-fixes-2
Mar 11, 2024
Merged

Fix type resolution of associated const equality bounds (take 2)#119385
bors merged 3 commits into
rust-lang:masterfrom
fmease:assoc-const-eq-fixes-2

Conversation

@fmease

@fmease fmease commented Dec 28, 2023

Copy link
Copy Markdown
Member

Instead of trying to re-resolve the type of assoc const bindings inside the type_of query impl in an incomplete manner, transfer the already (correctly) resolved type from add_predicates_for_ast_type_binding to type_of/anon_type_of through query feeding.


Together with #118668 (merged) and #121258, this supersedes #118360.
Fixes #118040.

r? @ghost

@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 Dec 28, 2023
@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-types Relevant to the types team, which will review and decide on the PR/issue. F-associated_const_equality `#![feature(associated_const_equality)]` and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 28, 2023
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@fmease fmease force-pushed the assoc-const-eq-fixes-2 branch from 8bf6e86 to 809f68c Compare January 10, 2024 14:04
let term: ty::Term<'_> = match term {
hir::Term::Ty(ty) => self.ast_ty_to_ty(ty).into(),
hir::Term::Const(ct) => {
ty::Const::from_anon_const(tcx, ct.def_id).into()

@fmease fmease Jan 10, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This might leak {type error} since we haven't actually resolved & feed the type to type_of(AnonConst) if we reach this case. The pretty-printer doesn't seem to care though (not sure if it can actually crash on certain inputs involving ty::TyKind::Error though).

Alternatively, I could pretty-print the HIR of the const but I'd need to create a public helper, const_to_string, since rustc_hir_pretty doesn't seem to expose anything like that yet?

@fmease fmease force-pushed the assoc-const-eq-fixes-2 branch 3 times, most recently from 7938112 to ecf2aba Compare January 10, 2024 15:35
Comment thread compiler/rustc_hir_analysis/src/collect/type_of.rs Outdated
@fmease fmease changed the title [WIP] Fix type resolution of associated const equality bounds (take 2) Fix type resolution of associated const equality bounds (take 2) Jan 10, 2024
@fmease fmease marked this pull request as ready for review January 10, 2024 15:58
@rust-lang rust-lang deleted a comment from rustbot Jan 10, 2024
@fmease

fmease commented Jan 10, 2024

Copy link
Copy Markdown
Member Author

Best reviewed commit by commit.
r? compiler-errors (no rush though)

@fmease fmease 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 Jan 10, 2024
@bors

This comment was marked as outdated.

@fmease fmease force-pushed the assoc-const-eq-fixes-2 branch 3 times, most recently from cfc3f0f to ca6ac84 Compare January 14, 2024 11:33
Comment thread compiler/rustc_hir_analysis/src/collect/type_of.rs Outdated
Comment thread compiler/rustc_hir_analysis/src/astconv/bounds.rs Outdated
@fmease

fmease commented Feb 23, 2024

Copy link
Copy Markdown
Member Author

We can directly feed the AnonConst's type instead of adding another indirection.

Oh, that makes perfect sense, thanks! Apart from eliminating indirection, does your change affect incremental query evaluation? Just out of curiosity I'd like to ask if the previous approach was unsound?

As for next steps, is this change ready to be merged? Who should review it lol?

@rust-log-analyzer

This comment has been minimized.

@fmease

This comment was marked as resolved.

@oli-obk

oli-obk commented Feb 23, 2024

Copy link
Copy Markdown
Contributor

Just out of curiosity I'd to ask if the previous approach was unsound?

It fed a hir id query, which we haven't considered yet at all. We could have marked whichever query did that as depending on the forever red node, meaning it would get rerun always. That would have been sound, but horrible for perf.

Then again, it's not really worse than what I did with the other query, just fewer moving parts. Also DefIds are a bit more stable than hir ids, due to their tree style relative nature.

I did not think about hir id query feeding soundness too much, so it may have been fine

@oli-obk

oli-obk commented Feb 23, 2024

Copy link
Copy Markdown
Contributor

Just out of curiosity I'd to ask if the previous approach was unsound?

It fed a hir id query, which we haven't considered yet at all. We could have marked whichever query did that as depending on the forever red node, meaning it would get rerun always. That would have been sound, but horrible for perf.

Then again, it's not really worse than what I did with the other query, just fewer moving parts. Also DefIds are a bit more stable than hir ids, due to their tree style relative nature.

I did not think about hir id query feeding soundness too much, so it may have been fine

As for next steps, is this change ready to be merged? Who should review it lol?

We can cross review each other's changes 😅 or get cjgillot to chime in

@fmease

fmease commented Feb 27, 2024

Copy link
Copy Markdown
Member Author

Hey, @cjgillot. If you have time and energy, could you skim this PR and double-check if the query feeding performed here roughly makes sense from a soundness perspective wrt. incr comp? Thanks a lot in advance!

We can cross review each other's changes

Otherwise the changes look good to me!

@compiler-errors compiler-errors removed their assignment Mar 4, 2024
@cjgillot

Copy link
Copy Markdown
Contributor

LGTM. Sorry for the delay.
@bors r=oli-obk,cjgillot

@bors

bors commented Mar 10, 2024

Copy link
Copy Markdown
Collaborator

📌 Commit 858d336 has been approved by oli-obk,cjgillot

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 Mar 10, 2024
@bors bors merged commit a450339 into rust-lang:master Mar 11, 2024
@rustbot rustbot added this to the 1.78.0 milestone Mar 11, 2024
@fmease fmease deleted the assoc-const-eq-fixes-2 branch March 11, 2024 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-associated_const_equality `#![feature(associated_const_equality)]` 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.

Development

Successfully merging this pull request may close these issues.

ICEs with assoc const equality where assoc const comes from supertrait

7 participants