Description
The ConstValue
type serves different purposes currently. As return value of const_eval
for statics, consts and promoteds, we could instead always return an AllocId
+ offset (i.e., a Pointer
) and avoid even thinking about whether we want the value to be immediate instead. Some places want an immediate (array lengths, pattern matching), they could get a different query returning a different type that "wraps" the main query.
So, I imagine something like: We have one type that serves the current role of ConstValue
enum Const<'tcx> {
Unevaluated(DefId, &'tcx Substs<'tcx>),
Evaluated(Pointer),
}
and a new one
enum ConstValue {
Scalar(Scalar),
ScalarPair(Scalar, Scalar),
}
(I called the latter ConstValue
for symmetry with the Value
type. But maybe it's better to not change too many names, and call the 2nd type ConstImmediate
or so.)
Then we make the const_eval
query return a Pointer
, and we add a new query const_eval_value
returning a ConstValue
.
Overall, this uses the type system to encode that the queries never return Unevaluated
, and it lets most callers handle everything uniformly (no need to deal with immediates unless needed).