Skip to content

introduce UnevaluatedConstKind#157094

Open
khyperia wants to merge 1 commit into
rust-lang:mainfrom
khyperia:UnevaluatedConstKind
Open

introduce UnevaluatedConstKind#157094
khyperia wants to merge 1 commit into
rust-lang:mainfrom
khyperia:UnevaluatedConstKind

Conversation

@khyperia
Copy link
Copy Markdown
Contributor

(no rush on this, boxy, if you get this notif, I know you're on break after rustweek)

Partially fixes rust-lang/project-const-generics#98

  • does not unify GCE ConstKind::Expr into Unevaluated, which is part of that issue
  • does not do more advanced refactoring to take advantage of the new kind repr, only refactoring when things are very obviously able to take advantage
  • does not change MIR's UnevaluatedConst to use UnevaluatedConstKind, as there's currently no benefit, and doing so instead overcomplicates many places. Possibly could be done in a followup, or I can do it here if desired.
  • more advanced potentially behavior-changing changes can be done in a followup, as this diff is big enough as it is, IMO. same with merging GCE Exprs into Unevaluated.
    • (... but if this takes a while to get reviewed, I might plop some more stuff into this PR)
  • I think it would be cute to rename UnevaluatedConst to AliasConst or something, to better reflect the parallels to AliasTy, but shrug, haha

r? @BoxyUwU

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 29, 2026

changes to the core type system

cc @lcnr

Some changes occurred in rustc_ty_utils::consts.rs

cc @BoxyUwU

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

Some changes occurred in match checking

cc @Nadrieril

This PR changes rustc_public

cc @oli-obk, @celinval, @ouz-a, @makai410

changes to the core type system

cc @lcnr

Some changes occurred in const_evaluatable.rs

cc @BoxyUwU

Some changes occurred in abstract_const.rs

cc @BoxyUwU

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

HIR ty lowering was modified

cc @fmease

@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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels May 29, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 29, 2026

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

Copy link
Copy Markdown
Contributor Author

@khyperia khyperia left a comment

Choose a reason for hiding this comment

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


#[inline]
pub fn new_unevaluated(tcx: TyCtxt<'tcx>, uv: ty::UnevaluatedConst<'tcx>) -> Const<'tcx> {
tcx.debug_assert_args_compatible(uv.def, uv.args);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this assert has moved to the UnevaluatedConstKind constructor, which is what AliasTyKind does

&& self.tcx.def_kind(trait_def_id) == DefKind::Trait =>
{
AllowSelfProjections::Yes => {
let trait_def_id = self.tcx.parent(proj.kind.def_id());
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this rework seems real wonky, but it's changing the shape of the code to look the same as visit_ty above

}
}
DefKind::Const { .. } => ty::UnevaluatedConstKind::Free { def_id },
DefKind::AnonConst | DefKind::InlineConst | DefKind::Ctor(_, CtorKind::Const) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am unsure about DefKind::InlineConst. alias_term_kind_from_def_id does not include it. Removing it causes MIR stuff to panic: rustc_codegen_ssa immediate_const_vector -> eval_unevaluated_mir_constant_to_valtree -> MIR::UnevaluatedConst::shrink -> unevaluated_const_kind_from_def_id -> unexpected DefKind in UnevaluatedConst: InlineConst


#[cfg(target_pointer_width = "64")]
rustc_data_structures::static_assert_size!(ConstKind<'_>, 24);
rustc_data_structures::static_assert_size!(ConstKind<'_>, 32);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

N.B.

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

Labels

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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Goal]: unify representations of ConstKind::Unevaluated and TyKind::Alias and allow non defid/subst pairs

3 participants