Add a new normalization query just for mir constants
This commit is contained in:
parent
c7c39ce6d0
commit
dbacfbc368
19 changed files with 128 additions and 34 deletions
|
@ -2410,7 +2410,8 @@ pub struct Constant<'tcx> {
|
|||
pub literal: ConstantKind<'tcx>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, PartialOrd, TyEncodable, TyDecodable, Hash, HashStable, Debug)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, TyEncodable, TyDecodable, Hash, HashStable, Debug)]
|
||||
#[derive(Lift)]
|
||||
pub enum ConstantKind<'tcx> {
|
||||
/// This constant came from the type system
|
||||
Ty(&'tcx ty::Const<'tcx>),
|
||||
|
@ -2709,7 +2710,13 @@ impl<'tcx> Display for Constant<'tcx> {
|
|||
ty::FnDef(..) => {}
|
||||
_ => write!(fmt, "const ")?,
|
||||
}
|
||||
match self.literal {
|
||||
Display::fmt(&self.literal, fmt)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Display for ConstantKind<'tcx> {
|
||||
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
ConstantKind::Ty(c) => pretty_print_const(c, fmt, true),
|
||||
ConstantKind::Val(val, ty) => pretty_print_const_value(val, ty, fmt, true),
|
||||
}
|
||||
|
|
|
@ -348,6 +348,10 @@ impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> {
|
|||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ConstantKind<'tcx> {
|
||||
fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
folder.fold_mir_const(self)
|
||||
}
|
||||
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
match self {
|
||||
ConstantKind::Ty(c) => ConstantKind::Ty(c.fold_with(folder)),
|
||||
|
|
|
@ -1482,6 +1482,13 @@ rustc_queries! {
|
|||
desc { "normalizing `{}`", goal.value }
|
||||
}
|
||||
|
||||
/// Do not call this query directly: invoke `normalize_erasing_regions` instead.
|
||||
query normalize_mir_const_after_erasing_regions(
|
||||
goal: ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
|
||||
) -> mir::ConstantKind<'tcx> {
|
||||
desc { "normalizing `{}`", goal.value }
|
||||
}
|
||||
|
||||
query implied_outlives_bounds(
|
||||
goal: CanonicalTyGoal<'tcx>
|
||||
) -> Result<
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::mir;
|
||||
use crate::ty::fold::{TypeFoldable, TypeFolder};
|
||||
use crate::ty::{self, Ty, TyCtxt, TypeFlags};
|
||||
|
||||
|
@ -65,4 +66,8 @@ impl TypeFolder<'tcx> for RegionEraserVisitor<'tcx> {
|
|||
_ => self.tcx.lifetimes.re_erased,
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> mir::ConstantKind<'tcx> {
|
||||
c.super_fold_with(self)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
//!
|
||||
//! These methods return true to indicate that the visitor has found what it is
|
||||
//! looking for, and does not need to visit anything else.
|
||||
use crate::mir;
|
||||
use crate::ty::{self, flags::FlagComputation, Binder, Ty, TyCtxt, TypeFlags};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
|
@ -179,6 +180,10 @@ pub trait TypeFolder<'tcx>: Sized {
|
|||
fn fold_const(&mut self, c: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
|
||||
c.super_fold_with(self)
|
||||
}
|
||||
|
||||
fn fold_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> mir::ConstantKind<'tcx> {
|
||||
bug!("most type folders should not be folding MIR datastructures: {:?}", c)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TypeVisitor<'tcx>: Sized {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
//! `normalize_generic_arg_after_erasing_regions` query for each type
|
||||
//! or constant found within. (This underlying query is what is cached.)
|
||||
|
||||
use crate::mir;
|
||||
use crate::ty::fold::{TypeFoldable, TypeFolder};
|
||||
use crate::ty::subst::{Subst, SubstsRef};
|
||||
use crate::ty::{self, Ty, TyCtxt};
|
||||
|
@ -101,4 +102,9 @@ impl TypeFolder<'tcx> for NormalizeAfterErasingRegionsFolder<'tcx> {
|
|||
let arg = self.param_env.and(c.into());
|
||||
self.tcx.normalize_generic_arg_after_erasing_regions(arg).expect_const()
|
||||
}
|
||||
|
||||
fn fold_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> mir::ConstantKind<'tcx> {
|
||||
let arg = self.param_env.and(c);
|
||||
self.tcx.normalize_mir_const_after_erasing_regions(arg)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// Type substitutions.
|
||||
|
||||
use crate::mir;
|
||||
use crate::ty::codec::{TyDecoder, TyEncoder};
|
||||
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
||||
use crate::ty::sty::{ClosureSubsts, GeneratorSubsts};
|
||||
|
@ -503,6 +504,10 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
|
|||
c.super_fold_with(self)
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> mir::ConstantKind<'tcx> {
|
||||
c.super_fold_with(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue