Skip to content

Move Const from rustc_middle to rustc_type_ir - #162628

Open
Jamesbarford wants to merge 6 commits into
rust-lang:mainfrom
Jamesbarford:chore/move-const-pt1
Open

Move Const from rustc_middle to rustc_type_ir#162628
Jamesbarford wants to merge 6 commits into
rust-lang:mainfrom
Jamesbarford:chore/move-const-pt1

Conversation

@Jamesbarford

Copy link
Copy Markdown
Contributor

Split by commit;

  • Firstly move the type and methods
  • From I::Const -> Const<I>
  • Import ConstExt in all places that require the extension trait methods in compiler
  • Import ConstExt in all places that require the extension trait methods in clippy

r? @lcnr

@rustbot

rustbot commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred in compiler/rustc_sanitizers

cc @rcvalle

Some changes occurred in match lowering

cc @Nadrieril

Some changes occurred in match checking

cc @Nadrieril

clippy is developed in its own repository. If possible, consider making this change to rust-lang/rust-clippy instead.

cc @rust-lang/clippy

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred in rustc_ty_utils::consts.rs

cc @BoxyUwU

Some changes occurred in exhaustiveness checking

cc @Nadrieril

changes to the core type system

cc @lcnr

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

HIR ty lowering was modified

cc @fmease

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Sep 11, 2026
// its pointee is valid for the entire lifetime of the target `TyCtxt`.
unsafe { mem::transmute(self) }
}
}

@lcnr lcnr Sep 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do we need manual impls instead of the macro here again?

View changes since the review

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.

nop_lift does;

 assert!(tcx.interners.$set.contains_pointer_to(&InternedInSet(&*self.0.0)));

Whereas we need;

assert!(tcx.interners.const_.contains_pointer_to(&InternedInSet(&*self.0)));

Comment thread compiler/rustc_middle/src/ty/mod.rs Outdated
Comment thread compiler/rustc_type_ir/src/interner.rs Outdated

// Things stored inside of tys
type ErrorGuaranteed: Copy + Debug + Hash + Eq;
type ErrorGuaranteed: Copy + Debug + Hash + Eq + TypeVisitable<Self>;

@lcnr lcnr Sep 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

instead mark with type_visitable(ignored) 🤔

View changes since the review

Comment thread compiler/rustc_type_ir/src/interner.rs Outdated
type Consts: Copy + Debug + Hash + Eq + SliceLike<Item = Const<Self>> + Default;
type ParamConst: Copy + Debug + Hash + Eq + ParamLike;
type ValueConst: ValueConst<Self>;
type ValueConst: ValueConst<Self> + TypeVisitable<Self> + TypeFoldable<Self> + Display;

@lcnr lcnr Sep 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@rust-log-analyzer

This comment has been minimized.

/// cache the type flags and debruijn index on creation and not recompute it
/// whenever the information is needed.
#[derive(Copy, Clone, GenericTypeVisitable)]
#[derive(Copy, Clone, Debug, GenericTypeVisitable)]

@lcnr lcnr Sep 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

when do we want to Debug that 🤔 does this PR change the debug output for some types?

View changes since the review

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.

In impl_interner.rs we have;

impl<'tcx> Interner for TyCtxt<'tcx> {
    // lots of `type <name> = <concrete>;`
    type InternedConstKind = Interned<'tcx, WithCachedTypeInfo<ty::ConstKind<'tcx>>>;

And then later in the file have;

impl<'tcx, T: std::fmt::Debug + Clone + Copy> rustc_type_ir::intern::Interned<TyCtxt<'tcx>>
    for Interned<'tcx, T>
{
    type Value = T;
    fn get(self) -> T {
        *self.0
    }
}

Interned has the trait bound Debug. This is because as the InternedConstKind and InternedRegionKind implement Lift which has the trait bound Debug.

As InternedConstKind is different to InternedRegionKind I had to add Debug to WithCachedTypeInfo

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why does that impl have a Debug bound?

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.

We can get rid of it for trait Interned but trait Lift: std::fmt::Debug and we implement Lift for WithCachedTypeInfo<ConstKind>

@lcnr lcnr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nits, otherwise this is looking good

View changes since this review

@rust-log-analyzer

This comment has been minimized.

@rustbot

rustbot commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

rustc_codegen_cranelift is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_cranelift instead.

cc @bjorn3

rustc_codegen_gcc is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_gcc instead.

cc @antoyo, @GuillaumeGomez

@rust-bors

rust-bors Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #162640) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

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

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler 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.

4 participants