Box ExprKind::Adt
This commit is contained in:
parent
6cc5d5432a
commit
5e802e5e97
5 changed files with 43 additions and 26 deletions
|
@ -97,6 +97,20 @@ pub struct Block {
|
|||
pub safety_mode: BlockSafety,
|
||||
}
|
||||
|
||||
#[derive(Debug, HashStable)]
|
||||
pub struct Adt<'tcx> {
|
||||
pub adt_def: &'tcx AdtDef,
|
||||
pub variant_index: VariantIdx,
|
||||
pub substs: SubstsRef<'tcx>,
|
||||
|
||||
/// Optional user-given substs: for something like `let x =
|
||||
/// Bar::<T> { ... }`.
|
||||
pub user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
|
||||
|
||||
pub fields: Box<[FieldExpr]>,
|
||||
pub base: Option<FruInfo<'tcx>>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, HashStable)]
|
||||
pub enum BlockSafety {
|
||||
Safe,
|
||||
|
@ -145,7 +159,7 @@ pub enum StmtKind<'tcx> {
|
|||
|
||||
// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
|
||||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
||||
rustc_data_structures::static_assert_size!(Expr<'_>, 144);
|
||||
rustc_data_structures::static_assert_size!(Expr<'_>, 104);
|
||||
|
||||
/// The Thir trait implementor lowers their expressions (`&'tcx H::Expr`)
|
||||
/// into instances of this `Expr` enum. This lowering can be done
|
||||
|
@ -304,18 +318,7 @@ pub enum ExprKind<'tcx> {
|
|||
Tuple {
|
||||
fields: Box<[ExprId]>,
|
||||
},
|
||||
Adt {
|
||||
adt_def: &'tcx AdtDef,
|
||||
variant_index: VariantIdx,
|
||||
substs: SubstsRef<'tcx>,
|
||||
|
||||
/// Optional user-given substs: for something like `let x =
|
||||
/// Bar::<T> { ... }`.
|
||||
user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
|
||||
|
||||
fields: Box<[FieldExpr]>,
|
||||
base: Option<FruInfo<'tcx>>,
|
||||
},
|
||||
Adt(Box<Adt<'tcx>>),
|
||||
PlaceTypeAscription {
|
||||
source: ExprId,
|
||||
/// Type that the user gave to this expression
|
||||
|
|
|
@ -264,7 +264,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
this.cfg.push_assign(block, source_info, destination, address_of);
|
||||
block.unit()
|
||||
}
|
||||
ExprKind::Adt { adt_def, variant_index, substs, user_ty, ref fields, ref base } => {
|
||||
ExprKind::Adt(box Adt {
|
||||
adt_def,
|
||||
variant_index,
|
||||
substs,
|
||||
user_ty,
|
||||
ref fields,
|
||||
ref base,
|
||||
}) => {
|
||||
// See the notes for `ExprKind::Array` in `as_rvalue` and for
|
||||
// `ExprKind::Borrow` above.
|
||||
let is_union = adt_def.is_union();
|
||||
|
|
|
@ -195,14 +195,14 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
|
|||
ExprKind::InlineAsm { .. } | ExprKind::LlvmInlineAsm { .. } => {
|
||||
self.requires_unsafe(expr.span, UseOfInlineAssembly);
|
||||
}
|
||||
ExprKind::Adt {
|
||||
ExprKind::Adt(box Adt {
|
||||
adt_def,
|
||||
variant_index: _,
|
||||
substs: _,
|
||||
user_ty: _,
|
||||
fields: _,
|
||||
base: _,
|
||||
} => match self.tcx.layout_scalar_valid_range(adt_def.did) {
|
||||
}) => match self.tcx.layout_scalar_valid_range(adt_def.did) {
|
||||
(Bound::Unbounded, Bound::Unbounded) => {}
|
||||
_ => self.requires_unsafe(expr.span, InitializingTypeWith),
|
||||
},
|
||||
|
|
|
@ -228,14 +228,14 @@ impl<'tcx> Cx<'tcx> {
|
|||
expr: self.mirror_expr(e),
|
||||
})
|
||||
.collect();
|
||||
ExprKind::Adt {
|
||||
ExprKind::Adt(Box::new(Adt {
|
||||
adt_def,
|
||||
substs,
|
||||
variant_index: index,
|
||||
fields: field_refs,
|
||||
user_ty,
|
||||
base: None,
|
||||
}
|
||||
}))
|
||||
} else {
|
||||
ExprKind::Call {
|
||||
ty: self.typeck_results().node_type(fun.hir_id),
|
||||
|
@ -362,7 +362,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
let user_provided_types = self.typeck_results().user_provided_types();
|
||||
let user_ty = user_provided_types.get(expr.hir_id).copied();
|
||||
debug!("make_mirror_unadjusted: (struct/union) user_ty={:?}", user_ty);
|
||||
ExprKind::Adt {
|
||||
ExprKind::Adt(Box::new(Adt {
|
||||
adt_def: adt,
|
||||
variant_index: VariantIdx::new(0),
|
||||
substs,
|
||||
|
@ -375,7 +375,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
.copied()
|
||||
.collect(),
|
||||
}),
|
||||
}
|
||||
}))
|
||||
}
|
||||
AdtKind::Enum => {
|
||||
let res = self.typeck_results().qpath_res(qpath, expr.hir_id);
|
||||
|
@ -388,14 +388,14 @@ impl<'tcx> Cx<'tcx> {
|
|||
self.typeck_results().user_provided_types();
|
||||
let user_ty = user_provided_types.get(expr.hir_id).copied();
|
||||
debug!("make_mirror_unadjusted: (variant) user_ty={:?}", user_ty);
|
||||
ExprKind::Adt {
|
||||
ExprKind::Adt(Box::new(Adt {
|
||||
adt_def: adt,
|
||||
variant_index: index,
|
||||
substs,
|
||||
user_ty,
|
||||
fields: self.field_refs(fields),
|
||||
base: None,
|
||||
}
|
||||
}))
|
||||
}
|
||||
_ => {
|
||||
span_bug!(expr.span, "unexpected res: {:?}", res);
|
||||
|
@ -906,14 +906,14 @@ impl<'tcx> Cx<'tcx> {
|
|||
match ty.kind() {
|
||||
// A unit struct/variant which is used as a value.
|
||||
// We return a completely different ExprKind here to account for this special case.
|
||||
ty::Adt(adt_def, substs) => ExprKind::Adt {
|
||||
ty::Adt(adt_def, substs) => ExprKind::Adt(Box::new(Adt {
|
||||
adt_def,
|
||||
variant_index: adt_def.variant_index_with_ctor_id(def_id),
|
||||
substs,
|
||||
user_ty: user_provided_type,
|
||||
fields: box [],
|
||||
base: None,
|
||||
},
|
||||
})),
|
||||
_ => bug!("unexpected ty: {:?}", ty),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use rustc_middle::thir::*;
|
||||
use rustc_middle::thir::{self, *};
|
||||
use rustc_middle::ty::Const;
|
||||
|
||||
pub trait Visitor<'a, 'tcx: 'a>: Sized {
|
||||
|
@ -94,7 +94,14 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
|
|||
visitor.visit_expr(&visitor.thir()[field]);
|
||||
}
|
||||
}
|
||||
Adt { ref fields, ref base, adt_def: _, variant_index: _, substs: _, user_ty: _ } => {
|
||||
Adt(box thir::Adt {
|
||||
ref fields,
|
||||
ref base,
|
||||
adt_def: _,
|
||||
variant_index: _,
|
||||
substs: _,
|
||||
user_ty: _,
|
||||
}) => {
|
||||
for field in &**fields {
|
||||
visitor.visit_expr(&visitor.thir()[field.expr]);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue