Skip to content

Support DefKind::InlineConst in ConstKind::Unevaluated#158375

Open
khyperia wants to merge 1 commit into
rust-lang:mainfrom
khyperia:inline-consts-in-type-system
Open

Support DefKind::InlineConst in ConstKind::Unevaluated#158375
khyperia wants to merge 1 commit into
rust-lang:mainfrom
khyperia:inline-consts-in-type-system

Conversation

@khyperia

@khyperia khyperia commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

View all comments

fixes rust-lang/project-const-generics#101

required for rust-lang/project-const-generics#108

consider: Struct<{ (some, stuff, const { hi }) }>. The following is very pseudocode-y, the important parts are whether it says AnonConst or InlineConst, not the Tuple stuff

  • On stable, we represent this with: AnonConst(Tuple(some, stuff, InlineConst(hi)))
  • Under mGCA, with "direct" arguments, before this PR, it was Tuple(some, stuff, AnonConst(hi)). The inner InlineConst got intercepted in the def_collector with hacks (ConstArgContext) and converted into an AnonConst, even though it has inline const syntax.

It would be nice to keep it as an InlineConst under mGCA, i.e. Tuple(some, stuff, InlineConst(hi)), and have the type system support passing around InlineConsts in ConstKind::Unevaluated (soon to be renamed ConstKind::Alias). This would allow the def collector to not need to know if we are in a "direct" or "regular/anon" context, which it turns out is extremely useful for implementing rust-lang/project-const-generics#108. Supporting InlineConsts in the type system are also useful for other things, for example, mentioned in rust-lang/project-const-generics#101 is arg position const generics experiments.

This PR does two things:

  • support InlineConsts in the type system (i.e. in ConstKind::Unevaluated)
  • exercise that support, by no longer intercepting mGCA "direct" argument inline consts to be anon consts

r? @BoxyUwU

@rustbot

rustbot commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

HIR ty lowering was modified

cc @fmease

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@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 Jun 24, 2026

@BoxyUwU BoxyUwU left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

did u look through all of DefKind::InlineConst/DefKind::AnonConst or is this just the stuff that when not updated breaks the test suite?

View changes since this review

Comment thread compiler/rustc_resolve/src/def_collector.rs Outdated
Comment thread compiler/rustc_resolve/src/def_collector.rs Outdated
Comment thread compiler/rustc_ty_utils/src/sig_types.rs
@rust-bors

This comment has been minimized.

@khyperia khyperia force-pushed the inline-consts-in-type-system branch from a238c1d to 013f793 Compare June 27, 2026 08:54
@rustbot

rustbot commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@khyperia

khyperia commented Jun 27, 2026

Copy link
Copy Markdown
Contributor Author

did u look through all of DefKind::InlineConst/DefKind::AnonConst or is this just the stuff that when not updated breaks the test suite?

Looked through them all! Went through them all again just now to be sure. Here's a list of things that might be notable for you (to double check my looking-through-them-all):

  • I missed this one!! Added now. The fact it was missing happened to have exactly the same (and correct) behavior as what I changed it to, but it's nice to be explicit.

    DefKind::AnonConst => AnonConst,

    • It is currently impossible to hit loops.rs visit_inline_const with a type system inline const, that newly written if statement in my change is "dead" code, but it's nice to be explicit IMO.
      edit: wait no, uuh, type system inline consts are always hir::AnonConst, they can't be hir::ConstBlock, so maybe I should delete the if?
  • There's some GCE uses of AnonConst that I have left for now.

  • The alias_term_kind_from_def_id vs. unevaluated_const_kind_from_def_id which we discussed in DMs. Maybe I should just add it...

  • The FCW cannot use constants which depend on generic parameters in types, I don't think it's possible to get here with the current use case and adding an InlineConst case would be impossible-to-test dead code, so I'm not sure how to properly test it. Maybe I should just blindly add a type system InlineConst case here, I don't know.

  • I'm 95% sure this backcompat jank around const fn promotion is fine (the only use of the inline field is that ConstContext::Const allow_const_fn_promotion is later initialized with !inline). I thiiink, because it's only called in MIR stuff, MIR should only see non-type-system InlineConsts.

    DefKind::InlineConst => BodyOwnerKind::Const { inline: true },

@rustbot ready (except you didn't do rustbot author :P)

@khyperia khyperia force-pushed the inline-consts-in-type-system branch from 013f793 to 4a41270 Compare June 27, 2026 09:39
@khyperia

Copy link
Copy Markdown
Contributor Author

Updated with the stuff I was unsure of in the previous comment.

Also moved a comment that was wonkily placed IMO (due to #158360 )

Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs Outdated
@khyperia khyperia force-pushed the inline-consts-in-type-system branch from 4a41270 to f31f522 Compare June 27, 2026 15:50

@Shourya742 Shourya742 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks awesome to me (learnt new stuff) 🚀 Thanks.

View changes since this review

@BoxyUwU

BoxyUwU commented Jun 29, 2026

Copy link
Copy Markdown
Member

@bors r+

thx ashley and thx shourya for the reviews, much appreciated :3

@rust-bors

rust-bors Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

📌 Commit f31f522 has been approved by BoxyUwU

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 Jun 29, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 29, 2026
…tem, r=BoxyUwU

Support `DefKind::InlineConst` in `ConstKind::Unevaluated`

fixes rust-lang/project-const-generics#101

required for rust-lang/project-const-generics#108

consider: `Struct<{ (some, stuff, const { hi }) }>`. The following is very pseudocode-y, the important parts are whether it says AnonConst or InlineConst, not the Tuple stuff

- On stable, we represent this with: `AnonConst(Tuple(some, stuff, InlineConst(hi)))`
- Under mGCA, with "direct" arguments, before this PR, it was `Tuple(some, stuff, AnonConst(hi))`. The inner InlineConst got intercepted in the def_collector with hacks (`ConstArgContext`) and converted into an AnonConst, even though it has inline const syntax.

It would be nice to keep it as an InlineConst under mGCA, i.e. `Tuple(some, stuff, InlineConst(hi))`, and have the type system support passing around InlineConsts in `ConstKind::Unevaluated` (soon to be renamed `ConstKind::Alias`). This would allow the def collector to not need to know if we are in a "direct" or "regular/anon" context, which it turns out is extremely useful for implementing rust-lang/project-const-generics#108. Supporting InlineConsts in the type system are also useful for other things, for example, mentioned in rust-lang/project-const-generics#101 is arg position const generics experiments.

This PR does two things:

- support InlineConsts in the type system (i.e. in `ConstKind::Unevaluated`)
- exercise that support, by no longer intercepting mGCA "direct" argument inline consts to be anon consts

r? @BoxyUwU
rust-bors Bot pushed a commit that referenced this pull request Jun 29, 2026
Rollup of 12 pull requests

Successful merges:

 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158169 (Fix debuginfo compression in bootstrap)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158375 (Support `DefKind::InlineConst` in `ConstKind::Unevaluated`)
 - #158417 (Avoid ICE when cfg_eval recovers no item from derive input)
 - #158556 (delegation: store child segment flag in `PathSegment`)
 - #158561 (Avoid building rustdoc for tests without doctests)
 - #158562 (Improve tracing of steps in bootstrap)
 - #157445 (Allow section override when using patchable-function-entries)
 - #158081 (trait-system: Recover deferred closure calls after errors)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158468 (Include default-stability info in rustdoc JSON.)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 29, 2026
…tem, r=BoxyUwU

Support `DefKind::InlineConst` in `ConstKind::Unevaluated`

fixes rust-lang/project-const-generics#101

required for rust-lang/project-const-generics#108

consider: `Struct<{ (some, stuff, const { hi }) }>`. The following is very pseudocode-y, the important parts are whether it says AnonConst or InlineConst, not the Tuple stuff

- On stable, we represent this with: `AnonConst(Tuple(some, stuff, InlineConst(hi)))`
- Under mGCA, with "direct" arguments, before this PR, it was `Tuple(some, stuff, AnonConst(hi))`. The inner InlineConst got intercepted in the def_collector with hacks (`ConstArgContext`) and converted into an AnonConst, even though it has inline const syntax.

It would be nice to keep it as an InlineConst under mGCA, i.e. `Tuple(some, stuff, InlineConst(hi))`, and have the type system support passing around InlineConsts in `ConstKind::Unevaluated` (soon to be renamed `ConstKind::Alias`). This would allow the def collector to not need to know if we are in a "direct" or "regular/anon" context, which it turns out is extremely useful for implementing rust-lang/project-const-generics#108. Supporting InlineConsts in the type system are also useful for other things, for example, mentioned in rust-lang/project-const-generics#101 is arg position const generics experiments.

This PR does two things:

- support InlineConsts in the type system (i.e. in `ConstKind::Unevaluated`)
- exercise that support, by no longer intercepting mGCA "direct" argument inline consts to be anon consts

r? @BoxyUwU
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 29, 2026
…tem, r=BoxyUwU

Support `DefKind::InlineConst` in `ConstKind::Unevaluated`

fixes rust-lang/project-const-generics#101

required for rust-lang/project-const-generics#108

consider: `Struct<{ (some, stuff, const { hi }) }>`. The following is very pseudocode-y, the important parts are whether it says AnonConst or InlineConst, not the Tuple stuff

- On stable, we represent this with: `AnonConst(Tuple(some, stuff, InlineConst(hi)))`
- Under mGCA, with "direct" arguments, before this PR, it was `Tuple(some, stuff, AnonConst(hi))`. The inner InlineConst got intercepted in the def_collector with hacks (`ConstArgContext`) and converted into an AnonConst, even though it has inline const syntax.

It would be nice to keep it as an InlineConst under mGCA, i.e. `Tuple(some, stuff, InlineConst(hi))`, and have the type system support passing around InlineConsts in `ConstKind::Unevaluated` (soon to be renamed `ConstKind::Alias`). This would allow the def collector to not need to know if we are in a "direct" or "regular/anon" context, which it turns out is extremely useful for implementing rust-lang/project-const-generics#108. Supporting InlineConsts in the type system are also useful for other things, for example, mentioned in rust-lang/project-const-generics#101 is arg position const generics experiments.

This PR does two things:

- support InlineConsts in the type system (i.e. in `ConstKind::Unevaluated`)
- exercise that support, by no longer intercepting mGCA "direct" argument inline consts to be anon consts

r? @BoxyUwU
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 29, 2026
…tem, r=BoxyUwU

Support `DefKind::InlineConst` in `ConstKind::Unevaluated`

fixes rust-lang/project-const-generics#101

required for rust-lang/project-const-generics#108

consider: `Struct<{ (some, stuff, const { hi }) }>`. The following is very pseudocode-y, the important parts are whether it says AnonConst or InlineConst, not the Tuple stuff

- On stable, we represent this with: `AnonConst(Tuple(some, stuff, InlineConst(hi)))`
- Under mGCA, with "direct" arguments, before this PR, it was `Tuple(some, stuff, AnonConst(hi))`. The inner InlineConst got intercepted in the def_collector with hacks (`ConstArgContext`) and converted into an AnonConst, even though it has inline const syntax.

It would be nice to keep it as an InlineConst under mGCA, i.e. `Tuple(some, stuff, InlineConst(hi))`, and have the type system support passing around InlineConsts in `ConstKind::Unevaluated` (soon to be renamed `ConstKind::Alias`). This would allow the def collector to not need to know if we are in a "direct" or "regular/anon" context, which it turns out is extremely useful for implementing rust-lang/project-const-generics#108. Supporting InlineConsts in the type system are also useful for other things, for example, mentioned in rust-lang/project-const-generics#101 is arg position const generics experiments.

This PR does two things:

- support InlineConsts in the type system (i.e. in `ConstKind::Unevaluated`)
- exercise that support, by no longer intercepting mGCA "direct" argument inline consts to be anon consts

r? @BoxyUwU
rust-bors Bot pushed a commit that referenced this pull request Jun 29, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - #155722 (Introduce aarch64-unknown-linux-pauthtest target)
 - #156230 (tests: check wasm compiler_builtins object architecture)
 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158169 (Fix debuginfo compression in bootstrap)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158375 (Support `DefKind::InlineConst` in `ConstKind::Unevaluated`)
 - #158556 (delegation: store child segment flag in `PathSegment`)
 - #158561 (Avoid building rustdoc for tests without doctests)
 - #158562 (Improve tracing of steps in bootstrap)
 - #157445 (Allow section override when using patchable-function-entries)
 - #158081 (trait-system: Recover deferred closure calls after errors)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158468 (Include default-stability info in rustdoc JSON.)
 - #158564 (fix `-Z min-recursion-limit` unstable chapter name)
 - #158568 (llvm-wrapper: use accessors for private fields in LLVM 23+)
 - #158582 (Comment on needed RAM in huge-stacks.rs)
rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - #155722 (Introduce aarch64-unknown-linux-pauthtest target)
 - #156230 (tests: check wasm compiler_builtins object architecture)
 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158169 (Fix debuginfo compression in bootstrap)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158375 (Support `DefKind::InlineConst` in `ConstKind::Unevaluated`)
 - #158556 (delegation: store child segment flag in `PathSegment`)
 - #158561 (Avoid building rustdoc for tests without doctests)
 - #158562 (Improve tracing of steps in bootstrap)
 - #157445 (Allow section override when using patchable-function-entries)
 - #158081 (trait-system: Recover deferred closure calls after errors)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158468 (Include default-stability info in rustdoc JSON.)
 - #158564 (fix `-Z min-recursion-limit` unstable chapter name)
 - #158568 (llvm-wrapper: use accessors for private fields in LLVM 23+)
 - #158582 (Comment on needed RAM in huge-stacks.rs)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 30, 2026
…tem, r=BoxyUwU

Support `DefKind::InlineConst` in `ConstKind::Unevaluated`

fixes rust-lang/project-const-generics#101

required for rust-lang/project-const-generics#108

consider: `Struct<{ (some, stuff, const { hi }) }>`. The following is very pseudocode-y, the important parts are whether it says AnonConst or InlineConst, not the Tuple stuff

- On stable, we represent this with: `AnonConst(Tuple(some, stuff, InlineConst(hi)))`
- Under mGCA, with "direct" arguments, before this PR, it was `Tuple(some, stuff, AnonConst(hi))`. The inner InlineConst got intercepted in the def_collector with hacks (`ConstArgContext`) and converted into an AnonConst, even though it has inline const syntax.

It would be nice to keep it as an InlineConst under mGCA, i.e. `Tuple(some, stuff, InlineConst(hi))`, and have the type system support passing around InlineConsts in `ConstKind::Unevaluated` (soon to be renamed `ConstKind::Alias`). This would allow the def collector to not need to know if we are in a "direct" or "regular/anon" context, which it turns out is extremely useful for implementing rust-lang/project-const-generics#108. Supporting InlineConsts in the type system are also useful for other things, for example, mentioned in rust-lang/project-const-generics#101 is arg position const generics experiments.

This PR does two things:

- support InlineConsts in the type system (i.e. in `ConstKind::Unevaluated`)
- exercise that support, by no longer intercepting mGCA "direct" argument inline consts to be anon consts

r? @BoxyUwU
rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #155722 (Introduce aarch64-unknown-linux-pauthtest target)
 - #156230 (tests: check wasm compiler_builtins object architecture)
 - #156295 (Pass the whole `GenericArgs` to `Interner::for_each_relevant_impl()`)
 - #158375 (Support `DefKind::InlineConst` in `ConstKind::Unevaluated`)
 - #158556 (delegation: store child segment flag in `PathSegment`)
 - #158081 (trait-system: Recover deferred closure calls after errors)
 - #158468 (Include default-stability info in rustdoc JSON.)
 - #158543 (Note usage of documentation hard links in `core::io`)
 - #158564 (fix `-Z min-recursion-limit` unstable chapter name)
 - #158568 (llvm-wrapper: use accessors for private fields in LLVM 23+)
 - #158582 (Comment on needed RAM in huge-stacks.rs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Work Item]: Support DefKind::InlineConst as ConstKind::Unevaluated

4 participants