Skip to content

Commit 8b0dd6d

Browse files
committed
Explain the val caching in ty::Const
1 parent 785302d commit 8b0dd6d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/librustc_mir/const_eval.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,14 @@ fn validate_and_turn_into_const<'a, 'tcx>(
538538
)?;
539539
}
540540
// Now that we validated, turn this into a proper constant.
541+
542+
// We also store a simpler version of certain constants in the `val` field of `ty::Const`
543+
// This helps us reduce the effort required to access e.g. the `usize` constant value for
544+
// array lengths. Since array lengths make up a non-insignificant amount of all of the
545+
// constants in the compiler, this caching has a very noticeable effect.
546+
547+
// FIXME(oli-obk): see if creating a query to go from an `Allocation` + offset to a
548+
// `ConstValue` is just as effective as proactively generating the `ConstValue`.
541549
let val = match op.layout.abi {
542550
layout::Abi::Scalar(..) => ConstValue::Scalar(ecx.read_immediate(op)?.to_scalar()?),
543551
layout::Abi::ScalarPair(..) if op.layout.ty.is_slice() => {

0 commit comments

Comments
 (0)