-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement (but don't use) valtree and refactor in preparation of use #82936
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
compiler/rustc_middle/src/mir/mod.rs
Outdated
@@ -2012,7 +2013,7 @@ impl<'tcx> Operand<'tcx> { | |||
Operand::Constant(box Constant { | |||
span, | |||
user_ty: None, | |||
literal: ty::Const::zero_sized(tcx, ty), | |||
literal: ConstantSource::Ty(ty::Const::zero_sized(tcx, ty)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are you using ConstantSource::Ty
instead of Val
here?
do you prefer ty::Const
values over allocations where possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly in order to change as little as possible. ConstantSource::Val
is essentially dead code in this PR
it's kinda unfortunate that enum ConstantSource {
Param(ParamConst),
Bound(...),
Unevaluated(...),
Value(...),
Err(...),
} would be nice, but it's also a bit annoying because we have to somehow change this for the probably missed/forgot some previous discussion about this |
☔ The latest upstream changes (presumably #82953) made this pull request unmergeable. Please resolve the merge conflicts. |
you mean the two occurrences of
Yea, I have a local branch where I tried making The reason this PR is a better first step is that we have to handle all special cases around |
would be r=me @matthewjasper want to still look over this? |
valtree is a version of constants that is inherently safe to be used within types. This is in contrast to ty::Const which can have different representations of the same value. These representation differences can show up in hashing or equality comparisons, breaking type equality of otherwise equal types. valtrees do not have this problem.
Value trees won't have scalar ptr at all, so we need a scalar int printing method anyway. This way we'll be able to share that method between all const representations.
This is in preparation of the `literal` field becoming an enum that distinguishes between type level constants and runtime constants
It's not necessary yet, but it may become necessary with things like lazy normalization.
Any use of it has been shown to be a bug in the past.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Ralf Jung <[email protected]>
Co-authored-by: Ralf Jung <[email protected]>
Co-authored-by: Ralf Jung <[email protected]>
@bors r=RalfJung,lcnr,matthewjasper |
📌 Commit c4d564c has been approved by |
☀️ Test successful - checks-actions |
@oli-obk @lcnr This seems to have regressed performance slightly in the |
cachegrind diff: +1,933,323,286 ???:rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::const_val_to_op
-1,352,146,900 ???:rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::const_to_op
+452,987,692 ???:rustc_middle::ty::normalize_erasing_regions::<impl rustc_middle::ty::context::TyCtxt>::subst_and_normalize_erasing_regions
+227,857,068 ???:rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::eval_operand
+158,899,167 ???:rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::run
+155,194,634 ???:<rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::query::TyCtxtAt> as rustc_target::abi::LayoutOf>::layout_of
+17,034,883 ???:<core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::try_fold
-14,942,211 ???:<rustc_middle::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder as rustc_middle::ty::fold::TypeFolder>::fold_const
-7,340,200 ???:rustc_middle::mir::interpret::value::ConstValue::try_to_bits
+3,932,250 ???:rustc_middle::mir::interpret::value::ConstValue::try_to_machine_usize |
This PR does not cause any functional change. It refactors various things that are needed to make valtrees possible. This refactoring got big enough that I decided I'd want it reviewed as a PR instead of trying to make one huge PR with all the changes.
cc @rust-lang/wg-const-eval on the following commits:
cc @eddyb on ef04a6d
cc @rust-lang/wg-mir-opt for cf1700c (
mir::Constant
can now represent either aConstValue
or aty::Const
, and it is totally possible to have two different representations for the same value)