Skip to content

GCI: During reachability analysis don't try to evaluate the initializer of overly generic free const items#153269

Open
fmease wants to merge 1 commit intorust-lang:mainfrom
fmease:gci-reach-no-eval
Open

GCI: During reachability analysis don't try to evaluate the initializer of overly generic free const items#153269
fmease wants to merge 1 commit intorust-lang:mainfrom
fmease:gci-reach-no-eval

Conversation

@fmease
Copy link
Member

@fmease fmease commented Mar 2, 2026

We generally don't want the initializer of free const items to get evaluated if they have any non-lifetime generic parameters. However, while I did account for that in HIR analysis & mono item collection (#136168 & #136429), I didn't account for reachability analysis so far which means that on main we still evaluate such items if they are public for example.

The closed PR #142293 from a year ago did address that as a byproduct but of course it wasn't merged since its primary goal was misguided. This PR extracts & improves upon the relevant parts of that PR which are necessary to fix said issue.

Follow up to #136168 & #136429.
Partially supersedes #142293.
Part of #113521.

r? @BoxyUwU

@fmease fmease added the F-generic_const_items `#![feature(generic_const_items)]` label Mar 2, 2026
@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 2, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 2, 2026

BoxyUwU is currently at their maximum review capacity.
They may take a while to respond.

Copy link
Member Author

@fmease fmease Mar 2, 2026

Choose a reason for hiding this comment

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

Going off on a tangent, the whole "don't eval the initializer for non-lifetime-parametric free const items" thing doesn't apply to mGCA's type-level consts which I'm pretty sure is very intentional (IINM) and thus fine, it's also not GCI-specific, e.g., trait T { type const K: usize = const { panic!(); }; } (Self in scope).

I'm only concerned about const items with bodies anyway since the whole idea is to prevent const eval's "bespoke" handling of "too generic" consts "being user observable" / load-bearing for program correctness (the other motivation being consts should behave like fns in this specific scenario) or rephrased "type based" > "value based".

Copy link
Member

Choose a reason for hiding this comment

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

yeah type const stuff is whatever here. those should be handled by whatever normal:tm: thing we do for wfchecks of type system stuff

Err(ErrorHandled::TooGeneric(_)) => self.visit_const_item_rhs(init),
// We've checked at the start that there aren't any non-lifetime params
// in scope. The const initializer can't possibly be too generic.
Err(ErrorHandled::TooGeneric(_)) => bug!(),
Copy link
Member

Choose a reason for hiding this comment

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

I'm unsure if this is true 🤔 I would expect it to be possible to get TooGeneric back when there are trivial bounds on the const item which prevent normalization in the const's body.

I guess that's fine for now anyhow... The whole setup here needs to be completely reworked to not evaluate stuff with false bounds or with generic parameters. And once that's done we should start evaluating with TypingEnv::fully_monomorphized which would fix that 🤔

Copy link
Member

Choose a reason for hiding this comment

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

I intend to get back to that work.... somewhat soon, I think mGCA stuff is finally calming down so I should be able to put more time towards pushing on that again

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

Labels

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

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants