Repository navigation
Move rustc_middle::ty::Const to rustc_type_ir Part 2 - #163258
Conversation
|
cc @bjorn3 Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred in cc @BoxyUwU Some changes occurred in exhaustiveness checking cc @Nadrieril Some changes occurred in match checking cc @Nadrieril HIR ty lowering was modified cc @fmease Some changes occurred in match lowering cc @Nadrieril Some changes occurred to the CTFE machinery
cc @rust-lang/clippy Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri
Some changes occurred in compiler/rustc_sanitizers cc @rcvalle |
This comment has been minimized.
This comment has been minimized.
This is ty::Const, not mir::Const, right? Would be good to clarify so these PRs are easier to interpret. :) |
Const from rustc_middle to rustc_type_ir Part 2rustc_middle::ty::Const to rustc_type_ir Part 2
| let valtree = | ||
| ty::ValTree::from_scalar_int(tcx, ScalarInt::try_from_uint(bits, size).unwrap()); | ||
| ty::Const::new_value(tcx, valtree, ty) | ||
| } |
There was a problem hiding this comment.
this function is kind of scuffed :< I don't want this in rustc_type_ir if I am honest. More generally TypingEnv is in a weird state and I'd like to keep this out of rustc_type_ir for now 🤔 can we maybe keep this in an extension trait for now?
There was a problem hiding this comment.
Hmm what about on Interner;
fn const_from_bits(self, bits: u128, typing_env: Self::TypingEnv, ty: Self::Ty) -> Const<Self>;Then keep the implementation in the rustc_middle's interner implementation? That way we don't need to resurrect the ConstExt and the scuffed parts stay in rustc_middle? Obviously happy to revert if that's a terrible idea.
There was a problem hiding this comment.
I've given it a go in this commit; 39c689e, doesn't feel too bad as it uses a few interner methods
| } else { | ||
| const_v.try_to_leaf().map(|s| s.to_target_usize(self)) | ||
| } | ||
| } |
There was a problem hiding this comment.
why exactly does this need to be on the interner? I guess the to_target_usize is the actually relevant part? 🤔
There was a problem hiding this comment.
Yes s.to_target_usize() to the relevant part. I've now made to_target_usize a method on ValueConst in inherent.rs. Could be less bad than bolting another helper method on to Interner?
I've done so in; bcc98fa
This comment has been minimized.
This comment has been minimized.
4f1d48f to
828380b
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
39c689e to
2255191
Compare
|
Some changes occurred in compiler/rustc_codegen_llvm/src/debuginfo cc @Walnut356 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| @@ -228,13 +227,21 @@ impl<'tcx> Value<'tcx> { | |||
| } | |||
|
|
|||
| impl<'tcx> rustc_type_ir::inherent::ValueConst<TyCtxt<'tcx>> for Value<'tcx> { | |||
There was a problem hiding this comment.
future work, we should move Value into rustc_type_ir
|
my only question is Why do we need the this is partially out of cache for me unfortunately 🤔 |
|
|
That's inconsistent, is it not. If we need to use Either have all these functions outside of rustc_type_ir or all of them in it I'd say |
Good point, I've made a |
This comment has been minimized.
This comment has been minimized.
|
r=me after rebase |
0bf6c48 to
bbefa03
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. |
|
@bors r=lcnr |
|
@Jamesbarford: 🔑 Insufficient privileges: not in review users |
|
@bors r+ rollup=iffy |
…uwer Rollup of 8 pull requests Successful merges: - #163258 (Move `rustc_middle::ty::Const` to `rustc_type_ir` Part 2) - #164173 (don't drop `AnyOpaqueHasInferAsHidden` when merging with `OpaqueInStorageOrAnyOpaqueHasInferAsHidden`) - #160230 (CFI: Cover each InstanceKind explicitly) - #163713 (codegen Propagate reported errors from ABI checks) - #164205 (cg_llvm: Assorted cleanups to LLVM diagnostic handling) - #164114 (restore the old behavior for `derive(Default)` on fieldless types) - #164127 (core: Ignore explicit_tail_calls doc tests on PowerPC) - #164204 (explicitly mark next-solver ICE in test suite)
Rollup merge of #163258 - Jamesbarford:chore/move-const-pt2, r=lcnr Move `rustc_middle::ty::Const` to `rustc_type_ir` Part 2 Split by commit; - Move all methods from `ConstExt` from `rustc_middle`, creating small helpers to aid this. Subsequently delete `ConstExt`. - Remove `ConstExt` from imports in compiler. - Remove `ConstExt` from imports in clippy. r? lcnr
Upstream rust-lang/rust#163258 moved `try_to_target_usize` from the `ConstExt` extension trait to an inherent method on `Const`, and removed `ConstExt`. Gate `use ty::consts::ConstExt;` behind `#[rustversion::before(2026-10-13)]` so that `cc_bindings_from_rs` compiles both on nightlies that had the temporary `ConstExt` trait (2026-09-22 to 2026-10-12) and on newer nightlies (2026-10-13+) as well as stable toolchains where `try_to_target_usize` is an inherent method. PiperOrigin-RevId: 999083269
Upstream rust-lang/rust#163258 moved `try_to_target_usize` from the `ConstExt` extension trait to an inherent method on `Const`, and removed `ConstExt`. Gate `use ty::consts::ConstExt;` behind `#[rustversion::before(2026-10-13)]` so that `cc_bindings_from_rs` compiles both on nightlies that had the temporary `ConstExt` trait (2026-09-22 to 2026-10-12) and on newer nightlies (2026-10-13+) as well as stable toolchains where `try_to_target_usize` is an inherent method. PiperOrigin-RevId: 999104756
…uwer Rollup of 8 pull requests Successful merges: - rust-lang/rust#163258 (Move `rustc_middle::ty::Const` to `rustc_type_ir` Part 2) - rust-lang/rust#164173 (don't drop `AnyOpaqueHasInferAsHidden` when merging with `OpaqueInStorageOrAnyOpaqueHasInferAsHidden`) - rust-lang/rust#160230 (CFI: Cover each InstanceKind explicitly) - rust-lang/rust#163713 (codegen Propagate reported errors from ABI checks) - rust-lang/rust#164205 (cg_llvm: Assorted cleanups to LLVM diagnostic handling) - rust-lang/rust#164114 (restore the old behavior for `derive(Default)` on fieldless types) - rust-lang/rust#164127 (core: Ignore explicit_tail_calls doc tests on PowerPC) - rust-lang/rust#164204 (explicitly mark next-solver ICE in test suite)
View all comments
Split by commit;
ConstExtfromrustc_middle, creating small helpers to aid this. Subsequently deleteConstExt.ConstExtfrom imports in compiler.ConstExtfrom imports in clippy.r? lcnr