use NonHirLiteral instead of ScalarLiteral, move pattern related code to pat_is_poly in IsThirPolymorphic

This commit is contained in:
b-naber 2022-03-23 08:47:11 +01:00
parent 5e7f1380f6
commit 5fcccd1739
11 changed files with 28 additions and 24 deletions

View File

@ -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 }
}
}

View File

@ -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: _ } => {}

View File

@ -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,

View File

@ -567,7 +567,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
| ExprKind::Return { .. }
| ExprKind::Literal { .. }
| ExprKind::NamedConst { .. }
| ExprKind::ScalarLiteral { .. }
| ExprKind::NonHirLiteral { .. }
| ExprKind::ConstParam { .. }
| ExprKind::ConstBlock { .. }
| ExprKind::StaticRef { .. }

View File

@ -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 { .. }

View File

@ -70,8 +70,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
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 }));
}
_ => {}

View File

@ -71,7 +71,7 @@ impl Category {
ExprKind::ConstBlock { .. }
| ExprKind::Literal { .. }
| ExprKind::ScalarLiteral { .. }
| ExprKind::NonHirLiteral { .. }
| ExprKind::ConstParam { .. }
| ExprKind::StaticRef { .. }
| ExprKind::NamedConst { .. } => Some(Category::Constant),

View File

@ -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 { .. } => {

View File

@ -304,7 +304,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
| ExprKind::Borrow { .. }
| ExprKind::Literal { .. }
| ExprKind::NamedConst { .. }
| ExprKind::ScalarLiteral { .. }
| ExprKind::NonHirLiteral { .. }
| ExprKind::ConstParam { .. }
| ExprKind::ConstBlock { .. }
| ExprKind::Deref { .. }

View File

@ -695,7 +695,7 @@ impl<'tcx> Cx<'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,

View File

@ -337,6 +337,20 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
_ => 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 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, '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 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
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)))