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".

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