Move Const from rustc_middle to rustc_type_ir - #162628
Conversation
|
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
cc @rust-lang/clippy Some changes occurred to the CTFE machinery Some changes occurred in 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 |
| // its pointee is valid for the entire lifetime of the target `TyCtxt`. | ||
| unsafe { mem::transmute(self) } | ||
| } | ||
| } |
There was a problem hiding this comment.
why do we need manual impls instead of the macro here again?
There was a problem hiding this comment.
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)));There was a problem hiding this comment.
hmm, why does moving Const change this access pattern from .0.0 to just .0 🤔 that's not immediately obvious to me.
Please add that as a comment if it can't be avoided
There was a problem hiding this comment.
I'm not sure why;
nop_lift! { const_; Const<'a> => Const<'tcx> }Given the following definitions
// rustc_type_ir/src/sty/consts.rs
pub struct Const<I: Interner>(pub I::InternedConstKind);
// rustc_middle/rustc_middle/src/ty/context/impl_interner.rs
type InternedConstKind = Interned<'tcx, WithCachedTypeInfo<ty::ConstKind<'tcx>>>;
// rustc_middle/src/ty/consts.rs
pub type Const<'tcx> = ir::Const<TyCtxt<'tcx>>;Walking through how I think the above would work, which could be wrong, I'd have thought the following code snippet would be true;
pub type Const<'tcx> = struct Const<TyCtxt<'tcx>>(pub TyCtxt<'tcx>::InternedConst);
// which in turn becomes
pub type Const<'tcx> = struct Const<TyCtxt<'tcx>>(pub Interned<'tcx, WithCachedTypeInfo<ty::ConstKind<'tcx>>>);Which is the same as what we have before all be it the definition is composed from different modules and associated types. The rust-analyser LSP I have setup agrees with with me that my intuition is correct.
However I get a bunch of cascading errors. Of which this one seems the most likely culprit. So I did what the compiler error told me to do; implement Lift for WithCachedTypeInfo<...>.
error[E0277]: the trait bound `Interned<'tcx, _>: Lift<TyCtxt<'tcx>>` is not satisfied
--> compiler/rustc_middle/src/ty/context.rs:1894:54
|
1894 | struct InternedInSet<'tcx, T: ?Sized + PointeeSized>(&'tcx T);
| ^^^^^^^ unsatisfied trait bound
|
help: the trait `Lift<TyCtxt<'tcx>>` is not implemented for `Interned<'tcx, rustc_type_ir::WithCachedTypeInfo<rustc_type_ir::ConstKind<context::TyCtxt<'tcx>>>>`
but trait `Lift<TyCtxt<'_>>` is implemented for `Interned<'_, rustc_type_ir::RegionKind<context::TyCtxt<'_>>>`
--> compiler/rustc_middle/src/ty/context.rs:1721:1
|
|
||
| // Things stored inside of tys | ||
| type ErrorGuaranteed: Copy + Debug + Hash + Eq; | ||
| type ErrorGuaranteed: Copy + Debug + Hash + Eq + TypeVisitable<Self>; |
There was a problem hiding this comment.
instead mark with type_visitable(ignored) 🤔
| 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; |
There was a problem hiding this comment.
same here
This comment has been minimized.
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)] |
There was a problem hiding this comment.
when do we want to Debug that 🤔 does this PR change the debug output for some types?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
why does that impl have a Debug bound?
There was a problem hiding this comment.
We can get rid of it for trait Interned but trait Lift: std::fmt::Debug and we implement Lift for WithCachedTypeInfo<ConstKind>
This comment has been minimized.
This comment has been minimized.
|
cc @bjorn3
|
63b89a3 to
0e986ed
Compare
This comment has been minimized.
This comment has been minimized.
0e986ed to
cd5d852
Compare
|
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. |
Split by commit;
I::Const->Const<I>ConstExtin all places that require the extension trait methods in compilerConstExtin all places that require the extension trait methods in clippyr? @lcnr