提交 e2496b3c 编写于 作者: B b-naber

remove thir::Visitor::visit_const

上级 f713b501
...@@ -426,7 +426,6 @@ pub enum ExprKind<'tcx> { ...@@ -426,7 +426,6 @@ pub enum ExprKind<'tcx> {
ConstParam { ConstParam {
literal: ty::Const<'tcx>, literal: ty::Const<'tcx>,
def_id: DefId, def_id: DefId,
user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
}, },
// FIXME improve docs for `StaticRef` by distinguishing it from `NamedConst` // FIXME improve docs for `StaticRef` by distinguishing it from `NamedConst`
/// A literal containing the address of a `static`. /// A literal containing the address of a `static`.
......
use super::{ use super::{
Arm, Block, Expr, ExprKind, Guard, InlineAsmOperand, Pat, PatKind, Stmt, StmtKind, Thir, Arm, Block, Expr, ExprKind, Guard, InlineAsmOperand, Pat, PatKind, Stmt, StmtKind, Thir,
}; };
use rustc_middle::ty::Const;
pub trait Visitor<'a, 'tcx: 'a>: Sized { pub trait Visitor<'a, 'tcx: 'a>: Sized {
fn thir(&self) -> &'a Thir<'tcx>; fn thir(&self) -> &'a Thir<'tcx>;
...@@ -25,8 +24,6 @@ fn visit_arm(&mut self, arm: &Arm<'tcx>) { ...@@ -25,8 +24,6 @@ fn visit_arm(&mut self, arm: &Arm<'tcx>) {
fn visit_pat(&mut self, pat: &Pat<'tcx>) { fn visit_pat(&mut self, pat: &Pat<'tcx>) {
walk_pat(self, pat); walk_pat(self, pat);
} }
fn visit_const(&mut self, _cnst: Const<'tcx>) {}
} }
pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Expr<'tcx>) { pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Expr<'tcx>) {
...@@ -94,9 +91,8 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp ...@@ -94,9 +91,8 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
} }
} }
ConstBlock { did: _, substs: _ } => {} ConstBlock { did: _, substs: _ } => {}
Repeat { value, count } => { Repeat { value, count: _ } => {
visitor.visit_expr(&visitor.thir()[value]); visitor.visit_expr(&visitor.thir()[value]);
visitor.visit_const(count);
} }
Array { ref fields } | Tuple { ref fields } => { Array { ref fields } | Tuple { ref fields } => {
for &field in &**fields { for &field in &**fields {
...@@ -125,7 +121,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp ...@@ -125,7 +121,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
Literal { lit: _, neg: _ } => {} Literal { lit: _, neg: _ } => {}
ScalarLiteral { lit: _, user_ty: _ } => {} ScalarLiteral { lit: _, user_ty: _ } => {}
NamedConst { def_id: _, substs: _, user_ty: _ } => {} NamedConst { def_id: _, substs: _, user_ty: _ } => {}
ConstParam { literal: _, def_id: _, user_ty: _ } => {} ConstParam { literal: _, def_id: _ } => {}
StaticRef { alloc_id: _, ty: _, def_id: _ } => {} StaticRef { alloc_id: _, ty: _, def_id: _ } => {}
InlineAsm { ref operands, template: _, options: _, line_spans: _ } => { InlineAsm { ref operands, template: _, options: _, line_spans: _ } => {
for op in &**operands { for op in &**operands {
...@@ -212,11 +208,8 @@ pub fn walk_pat<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, pat: &Pat<' ...@@ -212,11 +208,8 @@ pub fn walk_pat<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, pat: &Pat<'
visitor.visit_pat(&subpattern.pattern); visitor.visit_pat(&subpattern.pattern);
} }
} }
Constant { value } => visitor.visit_const(*value), Constant { value: _ } => {}
Range(range) => { Range(_) => {}
visitor.visit_const(range.lo);
visitor.visit_const(range.hi);
}
Slice { prefix, slice, suffix } | Array { prefix, slice, suffix } => { Slice { prefix, slice, suffix } | Array { prefix, slice, suffix } => {
for subpattern in prefix { for subpattern in prefix {
visitor.visit_pat(&subpattern); visitor.visit_pat(&subpattern);
......
...@@ -17,10 +17,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ...@@ -17,10 +17,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// Compile `expr`, yielding a compile-time constant. Assumes that /// Compile `expr`, yielding a compile-time constant. Assumes that
/// `expr` is a valid compile-time constant! /// `expr` is a valid compile-time constant!
crate fn as_constant(&mut self, expr: &Expr<'tcx>) -> Constant<'tcx> { crate fn as_constant(&mut self, expr: &Expr<'tcx>) -> Constant<'tcx> {
debug!("expr: {:#?}", expr);
// FIXME: Maybe we should try to evaluate here and only create an `Unevaluated`
// constant in case the evaluation fails. Need some evaluation function that
// allows normalization to fail.
let create_uneval_from_def_id = let create_uneval_from_def_id =
|tcx: TyCtxt<'tcx>, def_id: DefId, ty: Ty<'tcx>, substs: SubstsRef<'tcx>| { |tcx: TyCtxt<'tcx>, def_id: DefId, ty: Ty<'tcx>, substs: SubstsRef<'tcx>| {
let uneval = ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs); let uneval = ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs);
...@@ -74,17 +70,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ...@@ -74,17 +70,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Constant { user_ty, span, literal } Constant { user_ty, span, literal }
} }
ExprKind::ConstParam { literal, def_id: _, user_ty } => { ExprKind::ConstParam { literal, def_id: _ } => {
let user_ty = user_ty.map(|user_ty| {
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
span,
user_ty,
inferred_ty: ty,
})
});
let literal = ConstantKind::Ty(literal); let literal = ConstantKind::Ty(literal);
Constant { user_ty: user_ty, span, literal } Constant { user_ty: None, span, literal }
} }
ExprKind::ConstBlock { did: def_id, substs } => { ExprKind::ConstBlock { did: def_id, substs } => {
let literal = ConstantKind::Ty(create_uneval_from_def_id(tcx, def_id, ty, substs)); let literal = ConstantKind::Ty(create_uneval_from_def_id(tcx, def_id, ty, substs));
......
...@@ -70,6 +70,7 @@ fn as_temp_inner( ...@@ -70,6 +70,7 @@ fn as_temp_inner(
local_decl.local_info = local_decl.local_info =
Some(Box::new(LocalInfo::StaticRef { def_id, is_thread_local: true })); Some(Box::new(LocalInfo::StaticRef { def_id, is_thread_local: true }));
} }
// FIXME Might have to include `ExprKind::ConstParam` here as well
ExprKind::NamedConst { def_id, .. } => { ExprKind::NamedConst { def_id, .. } => {
local_decl.local_info = Some(Box::new(LocalInfo::ConstRef { def_id })); local_decl.local_info = Some(Box::new(LocalInfo::ConstRef { def_id }));
} }
......
...@@ -876,7 +876,6 @@ fn convert_path_expr(&mut self, expr: &'tcx hir::Expr<'tcx>, res: Res) -> ExprKi ...@@ -876,7 +876,6 @@ fn convert_path_expr(&mut self, expr: &'tcx hir::Expr<'tcx>, res: Res) -> ExprKi
val, val,
ty: self.typeck_results().node_type(expr.hir_id), ty: self.typeck_results().node_type(expr.hir_id),
}), }),
user_ty: None,
def_id, def_id,
} }
} }
......
...@@ -39,7 +39,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>( ...@@ -39,7 +39,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
) -> Result<(), NotConstEvaluatable> { ) -> Result<(), NotConstEvaluatable> {
let tcx = infcx.tcx; let tcx = infcx.tcx;
if infcx.tcx.features().generic_const_exprs { if tcx.features().generic_const_exprs {
match AbstractConst::new(tcx, uv)? { match AbstractConst::new(tcx, uv)? {
// We are looking at a generic abstract constant. // We are looking at a generic abstract constant.
Some(ct) => { Some(ct) => {
...@@ -342,7 +342,13 @@ fn thir(&self) -> &'a thir::Thir<'tcx> { ...@@ -342,7 +342,13 @@ fn thir(&self) -> &'a thir::Thir<'tcx> {
fn visit_expr(&mut self, expr: &thir::Expr<'tcx>) { fn visit_expr(&mut self, expr: &thir::Expr<'tcx>) {
self.is_poly |= self.expr_is_poly(expr); self.is_poly |= self.expr_is_poly(expr);
if !self.is_poly { if !self.is_poly {
visit::walk_expr(self, expr) match expr.kind {
thir::ExprKind::Repeat { value, count } => {
self.visit_expr(&self.thir()[value]);
self.is_poly |= count.has_param_types_or_consts();
}
_ => visit::walk_expr(self, expr),
}
} }
} }
...@@ -350,14 +356,18 @@ fn visit_expr(&mut self, expr: &thir::Expr<'tcx>) { ...@@ -350,14 +356,18 @@ fn visit_expr(&mut self, expr: &thir::Expr<'tcx>) {
fn visit_pat(&mut self, pat: &thir::Pat<'tcx>) { fn visit_pat(&mut self, pat: &thir::Pat<'tcx>) {
self.is_poly |= pat.ty.has_param_types_or_consts(); self.is_poly |= pat.ty.has_param_types_or_consts();
if !self.is_poly { if !self.is_poly {
visit::walk_pat(self, pat); match pat.kind.as_ref() {
thir::PatKind::Constant { value } => {
self.is_poly |= value.has_param_types_or_consts();
}
thir::PatKind::Range(thir::PatRange { lo, hi, .. }) => {
self.is_poly |=
lo.has_param_types_or_consts() | hi.has_param_types_or_consts();
}
_ => visit::walk_pat(self, pat),
}
} }
} }
#[instrument(skip(self), level = "debug")]
fn visit_const(&mut self, ct: ty::Const<'tcx>) {
self.is_poly |= ct.has_param_types_or_consts();
}
} }
let mut is_poly_vis = IsThirPolymorphic { is_poly: false, thir: body }; let mut is_poly_vis = IsThirPolymorphic { is_poly: false, thir: body };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册