use NonHirLiteral instead of ScalarLiteral, move pattern related code to pat_is_poly in IsThirPolymorphic
This commit is contained in:
parent
5e7f1380f6
commit
5fcccd1739
@ -413,7 +413,7 @@ pub enum ExprKind<'tcx> {
|
|||||||
neg: bool,
|
neg: bool,
|
||||||
},
|
},
|
||||||
/// For literals that don't correspond to anything in the HIR
|
/// For literals that don't correspond to anything in the HIR
|
||||||
ScalarLiteral {
|
NonHirLiteral {
|
||||||
lit: ty::ScalarInt,
|
lit: ty::ScalarInt,
|
||||||
user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
|
user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
|
||||||
},
|
},
|
||||||
@ -454,7 +454,7 @@ pub enum ExprKind<'tcx> {
|
|||||||
|
|
||||||
impl<'tcx> ExprKind<'tcx> {
|
impl<'tcx> ExprKind<'tcx> {
|
||||||
pub fn zero_sized_literal(user_ty: Option<Canonical<'tcx, UserType<'tcx>>>) -> Self {
|
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: _ } => {}
|
Closure { closure_id: _, substs: _, upvars: _, movability: _, fake_reads: _ } => {}
|
||||||
Literal { lit: _, neg: _ } => {}
|
Literal { lit: _, neg: _ } => {}
|
||||||
ScalarLiteral { lit: _, user_ty: _ } => {}
|
NonHirLiteral { lit: _, user_ty: _ } => {}
|
||||||
NamedConst { def_id: _, substs: _, user_ty: _ } => {}
|
NamedConst { def_id: _, substs: _, user_ty: _ } => {}
|
||||||
ConstParam { param: _, def_id: _ } => {}
|
ConstParam { param: _, def_id: _ } => {}
|
||||||
StaticRef { alloc_id: _, ty: _, 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() }
|
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| {
|
let user_ty = user_ty.map(|user_ty| {
|
||||||
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
|
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
|
||||||
span,
|
span,
|
||||||
|
@ -567,7 +567,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
| ExprKind::Return { .. }
|
| ExprKind::Return { .. }
|
||||||
| ExprKind::Literal { .. }
|
| ExprKind::Literal { .. }
|
||||||
| ExprKind::NamedConst { .. }
|
| ExprKind::NamedConst { .. }
|
||||||
| ExprKind::ScalarLiteral { .. }
|
| ExprKind::NonHirLiteral { .. }
|
||||||
| ExprKind::ConstParam { .. }
|
| ExprKind::ConstParam { .. }
|
||||||
| ExprKind::ConstBlock { .. }
|
| ExprKind::ConstBlock { .. }
|
||||||
| ExprKind::StaticRef { .. }
|
| ExprKind::StaticRef { .. }
|
||||||
|
@ -328,7 +328,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
ExprKind::Yield { .. }
|
ExprKind::Yield { .. }
|
||||||
| ExprKind::Literal { .. }
|
| ExprKind::Literal { .. }
|
||||||
| ExprKind::NamedConst { .. }
|
| ExprKind::NamedConst { .. }
|
||||||
| ExprKind::ScalarLiteral { .. }
|
| ExprKind::NonHirLiteral { .. }
|
||||||
| ExprKind::ConstParam { .. }
|
| ExprKind::ConstParam { .. }
|
||||||
| ExprKind::ConstBlock { .. }
|
| ExprKind::ConstBlock { .. }
|
||||||
| ExprKind::StaticRef { .. }
|
| ExprKind::StaticRef { .. }
|
||||||
|
@ -70,8 +70,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
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::ConstParam { 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 }));
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -71,7 +71,7 @@ impl Category {
|
|||||||
|
|
||||||
ExprKind::ConstBlock { .. }
|
ExprKind::ConstBlock { .. }
|
||||||
| ExprKind::Literal { .. }
|
| ExprKind::Literal { .. }
|
||||||
| ExprKind::ScalarLiteral { .. }
|
| ExprKind::NonHirLiteral { .. }
|
||||||
| ExprKind::ConstParam { .. }
|
| ExprKind::ConstParam { .. }
|
||||||
| ExprKind::StaticRef { .. }
|
| ExprKind::StaticRef { .. }
|
||||||
| ExprKind::NamedConst { .. } => Some(Category::Constant),
|
| ExprKind::NamedConst { .. } => Some(Category::Constant),
|
||||||
|
@ -534,7 +534,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
| ExprKind::ConstBlock { .. }
|
| ExprKind::ConstBlock { .. }
|
||||||
| ExprKind::Literal { .. }
|
| ExprKind::Literal { .. }
|
||||||
| ExprKind::NamedConst { .. }
|
| ExprKind::NamedConst { .. }
|
||||||
| ExprKind::ScalarLiteral { .. }
|
| ExprKind::NonHirLiteral { .. }
|
||||||
| ExprKind::ConstParam { .. }
|
| ExprKind::ConstParam { .. }
|
||||||
| ExprKind::ThreadLocalRef(_)
|
| ExprKind::ThreadLocalRef(_)
|
||||||
| ExprKind::StaticRef { .. } => {
|
| ExprKind::StaticRef { .. } => {
|
||||||
|
@ -304,7 +304,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
|
|||||||
| ExprKind::Borrow { .. }
|
| ExprKind::Borrow { .. }
|
||||||
| ExprKind::Literal { .. }
|
| ExprKind::Literal { .. }
|
||||||
| ExprKind::NamedConst { .. }
|
| ExprKind::NamedConst { .. }
|
||||||
| ExprKind::ScalarLiteral { .. }
|
| ExprKind::NonHirLiteral { .. }
|
||||||
| ExprKind::ConstParam { .. }
|
| ExprKind::ConstParam { .. }
|
||||||
| ExprKind::ConstBlock { .. }
|
| ExprKind::ConstBlock { .. }
|
||||||
| ExprKind::Deref { .. }
|
| ExprKind::Deref { .. }
|
||||||
|
@ -695,7 +695,7 @@ impl<'tcx> Cx<'tcx> {
|
|||||||
})
|
})
|
||||||
.size;
|
.size;
|
||||||
let lit = ScalarInt::try_from_uint(offset as u128, size).unwrap();
|
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 {
|
let offset = self.thir.exprs.push(Expr {
|
||||||
temp_lifetime,
|
temp_lifetime,
|
||||||
ty: var_ty,
|
ty: var_ty,
|
||||||
|
@ -337,6 +337,20 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
|
|||||||
_ => false,
|
_ => 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> {
|
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")]
|
#[instrument(skip(self), level = "debug")]
|
||||||
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 |= self.pat_is_poly(pat);
|
||||||
if !self.is_poly {
|
if !self.is_poly {
|
||||||
match pat.kind.as_ref() {
|
visit::walk_pat(self, pat);
|
||||||
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),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -443,7 +448,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
|
|||||||
|
|
||||||
self.nodes.push(Node::Leaf(constant))
|
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
|
// FIXME Construct a Valtree from this ScalarInt when introducing Valtrees
|
||||||
let const_value = ConstValue::Scalar(Scalar::Int(lit));
|
let const_value = ConstValue::Scalar(Scalar::Int(lit));
|
||||||
self.nodes.push(Node::Leaf(ty::Const::from_value(self.tcx, const_value, node.ty)))
|
self.nodes.push(Node::Leaf(ty::Const::from_value(self.tcx, const_value, node.ty)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user