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

use NonHirLiteral instead of ScalarLiteral, move pattern related code to...

use NonHirLiteral instead of ScalarLiteral, move pattern related code to pat_is_poly in IsThirPolymorphic
上级 5e7f1380
......@@ -413,7 +413,7 @@ pub enum ExprKind<'tcx> {
neg: bool,
},
/// For literals that don't correspond to anything in the HIR
ScalarLiteral {
NonHirLiteral {
lit: ty::ScalarInt,
user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
},
......@@ -454,7 +454,7 @@ pub enum ExprKind<'tcx> {
impl<'tcx> ExprKind<'tcx> {
pub fn zero_sized_literal(user_ty: Option<Canonical<'tcx, UserType<'tcx>>>) -> Self {
ExprKind::ScalarLiteral { lit: ty::ScalarInt::ZST, user_ty }
ExprKind::NonHirLiteral { lit: ty::ScalarInt::ZST, user_ty }
}
}
......
......@@ -119,7 +119,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
}
Closure { closure_id: _, substs: _, upvars: _, movability: _, fake_reads: _ } => {}
Literal { lit: _, neg: _ } => {}
ScalarLiteral { lit: _, user_ty: _ } => {}
NonHirLiteral { lit: _, user_ty: _ } => {}
NamedConst { def_id: _, substs: _, user_ty: _ } => {}
ConstParam { param: _, def_id: _ } => {}
StaticRef { alloc_id: _, ty: _, def_id: _ } => {}
......
......@@ -45,7 +45,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Constant { span, user_ty: None, literal: literal.into() }
}
ExprKind::ScalarLiteral { lit, user_ty } => {
ExprKind::NonHirLiteral { lit, user_ty } => {
let user_ty = user_ty.map(|user_ty| {
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
span,
......
......@@ -567,7 +567,7 @@ fn expr_as_place(
| ExprKind::Return { .. }
| ExprKind::Literal { .. }
| ExprKind::NamedConst { .. }
| ExprKind::ScalarLiteral { .. }
| ExprKind::NonHirLiteral { .. }
| ExprKind::ConstParam { .. }
| ExprKind::ConstBlock { .. }
| ExprKind::StaticRef { .. }
......
......@@ -328,7 +328,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
ExprKind::Yield { .. }
| ExprKind::Literal { .. }
| ExprKind::NamedConst { .. }
| ExprKind::ScalarLiteral { .. }
| ExprKind::NonHirLiteral { .. }
| ExprKind::ConstParam { .. }
| ExprKind::ConstBlock { .. }
| ExprKind::StaticRef { .. }
......
......@@ -70,8 +70,7 @@ fn as_temp_inner(
local_decl.local_info =
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, .. } | ExprKind::ConstParam { def_id, .. } => {
local_decl.local_info = Some(Box::new(LocalInfo::ConstRef { def_id }));
}
_ => {}
......
......@@ -71,7 +71,7 @@ impl Category {
ExprKind::ConstBlock { .. }
| ExprKind::Literal { .. }
| ExprKind::ScalarLiteral { .. }
| ExprKind::NonHirLiteral { .. }
| ExprKind::ConstParam { .. }
| ExprKind::StaticRef { .. }
| ExprKind::NamedConst { .. } => Some(Category::Constant),
......
......@@ -534,7 +534,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
| ExprKind::ConstBlock { .. }
| ExprKind::Literal { .. }
| ExprKind::NamedConst { .. }
| ExprKind::ScalarLiteral { .. }
| ExprKind::NonHirLiteral { .. }
| ExprKind::ConstParam { .. }
| ExprKind::ThreadLocalRef(_)
| ExprKind::StaticRef { .. } => {
......
......@@ -304,7 +304,7 @@ fn visit_expr(&mut self, expr: &Expr<'tcx>) {
| ExprKind::Borrow { .. }
| ExprKind::Literal { .. }
| ExprKind::NamedConst { .. }
| ExprKind::ScalarLiteral { .. }
| ExprKind::NonHirLiteral { .. }
| ExprKind::ConstParam { .. }
| ExprKind::ConstBlock { .. }
| ExprKind::Deref { .. }
......
......@@ -695,7 +695,7 @@ fn make_mirror_unadjusted(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Expr<'tcx>
})
.size;
let lit = ScalarInt::try_from_uint(offset as u128, size).unwrap();
let kind = ExprKind::ScalarLiteral { lit, user_ty: None };
let kind = ExprKind::NonHirLiteral { lit, user_ty: None };
let offset = self.thir.exprs.push(Expr {
temp_lifetime,
ty: var_ty,
......
......@@ -337,6 +337,20 @@ fn expr_is_poly(&mut self, expr: &thir::Expr<'tcx>) -> bool {
_ => false,
}
}
fn pat_is_poly(&mut self, pat: &thir::Pat<'tcx>) -> bool {
if pat.ty.has_param_types_or_consts() {
return true;
}
match pat.kind.as_ref() {
thir::PatKind::Constant { value } => value.has_param_types_or_consts(),
thir::PatKind::Range(thir::PatRange { lo, hi, .. }) => {
lo.has_param_types_or_consts() || hi.has_param_types_or_consts()
}
_ => false,
}
}
}
impl<'a, 'tcx> visit::Visitor<'a, 'tcx> for IsThirPolymorphic<'a, 'tcx> {
......@@ -354,18 +368,9 @@ fn visit_expr(&mut self, expr: &thir::Expr<'tcx>) {
#[instrument(skip(self), level = "debug")]
fn visit_pat(&mut self, pat: &thir::Pat<'tcx>) {
self.is_poly |= pat.ty.has_param_types_or_consts();
self.is_poly |= self.pat_is_poly(pat);
if !self.is_poly {
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),
}
visit::walk_pat(self, pat);
}
}
}
......@@ -443,7 +448,7 @@ fn recurse_build(&mut self, node: thir::ExprId) -> Result<NodeId, ErrorGuarantee
self.nodes.push(Node::Leaf(constant))
}
&ExprKind::ScalarLiteral { lit , user_ty: _} => {
&ExprKind::NonHirLiteral { lit , user_ty: _} => {
// FIXME Construct a Valtree from this ScalarInt when introducing Valtrees
let const_value = ConstValue::Scalar(Scalar::Int(lit));
self.nodes.push(Node::Leaf(ty::Const::from_value(self.tcx, const_value, node.ty)))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册