1
Fork 0

implement valtrees as the type-system representation for constant values

This commit is contained in:
b-naber 2022-02-16 10:56:01 +01:00
parent edab34ab2a
commit 705d818bd5
116 changed files with 1606 additions and 1032 deletions

View file

@ -100,7 +100,7 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
}
}
/// Visitor to find the maximum escaping bound var
// Visitor to find the maximum escaping bound var
struct MaxEscapingBoundVarVisitor {
// The index which would count as escaping
outer_index: ty::DebruijnIndex,
@ -336,12 +336,15 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
) -> Result<mir::ConstantKind<'tcx>, Self::Error> {
Ok(match constant {
mir::ConstantKind::Ty(c) => {
let const_folded = c.try_fold_with(self)?;
let const_folded = c.try_super_fold_with(self)?;
match const_folded.kind() {
ty::ConstKind::Value(cv) => {
// FIXME With Valtrees we need to convert `cv: ValTree`
// to a `ConstValue` here.
mir::ConstantKind::Val(cv, const_folded.ty())
ty::ConstKind::Value(valtree) => {
let tcx = self.infcx.tcx;
let ty = const_folded.ty();
let const_val = tcx.valtree_to_const_val((ty, valtree));
debug!(?ty, ?valtree, ?const_val);
mir::ConstantKind::Val(const_val, ty)
}
_ => mir::ConstantKind::Ty(const_folded),
}