1
Fork 0

Box user_ty fields in thir::ExprKind.

This shrinks several large variants of `ExprKind`.
This commit is contained in:
Nicholas Nethercote 2022-08-24 10:37:41 +10:00
parent c9429b1cec
commit e7c25c3a97
5 changed files with 47 additions and 43 deletions

View file

@ -41,11 +41,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Constant { span, user_ty: None, literal }
}
ExprKind::NonHirLiteral { lit, user_ty } => {
let user_ty = user_ty.map(|user_ty| {
ExprKind::NonHirLiteral { lit, ref user_ty } => {
let user_ty = user_ty.as_ref().map(|box user_ty| {
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
span,
user_ty,
user_ty: *user_ty,
inferred_ty: ty,
})
});
@ -53,11 +53,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Constant { span, user_ty: user_ty, literal }
}
ExprKind::ZstLiteral { user_ty } => {
let user_ty = user_ty.map(|user_ty| {
ExprKind::ZstLiteral { ref user_ty } => {
let user_ty = user_ty.as_ref().map(|box user_ty| {
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
span,
user_ty,
user_ty: *user_ty,
inferred_ty: ty,
})
});
@ -65,11 +65,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Constant { span, user_ty: user_ty, literal }
}
ExprKind::NamedConst { def_id, substs, user_ty } => {
let user_ty = user_ty.map(|user_ty| {
ExprKind::NamedConst { def_id, substs, ref user_ty } => {
let user_ty = user_ty.as_ref().map(|box user_ty| {
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
span,
user_ty,
user_ty: *user_ty,
inferred_ty: ty,
})
});

View file

@ -513,7 +513,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block.and(place_builder)
}
ExprKind::PlaceTypeAscription { source, user_ty } => {
ExprKind::PlaceTypeAscription { source, ref user_ty } => {
let place_builder = unpack!(
block = this.expr_as_place(
block,
@ -522,11 +522,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fake_borrow_temps,
)
);
if let Some(user_ty) = user_ty {
if let Some(box user_ty) = user_ty {
let annotation_index =
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
span: source_info.span,
user_ty,
user_ty: *user_ty,
inferred_ty: expr.ty,
});
@ -547,15 +547,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
block.and(place_builder)
}
ExprKind::ValueTypeAscription { source, user_ty } => {
ExprKind::ValueTypeAscription { source, ref user_ty } => {
let source = &this.thir[source];
let temp =
unpack!(block = this.as_temp(block, source.temp_lifetime, source, mutability));
if let Some(user_ty) = user_ty {
if let Some(box user_ty) = user_ty {
let annotation_index =
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
span: source_info.span,
user_ty,
user_ty: *user_ty,
inferred_ty: expr.ty,
});
this.cfg.push(

View file

@ -318,7 +318,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
adt_def,
variant_index,
substs,
user_ty,
ref user_ty,
ref fields,
ref base,
}) => {
@ -378,10 +378,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
};
let inferred_ty = expr.ty;
let user_ty = user_ty.map(|ty| {
let user_ty = user_ty.as_ref().map(|box user_ty| {
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
span: source_info.span,
user_ty: ty,
user_ty: *user_ty,
inferred_ty,
})
});

View file

@ -329,7 +329,7 @@ impl<'tcx> Cx<'tcx> {
if let UserType::TypeOf(ref mut did, _) = &mut u_ty.value {
*did = adt_def.did();
}
u_ty
Box::new(u_ty)
});
debug!("make_mirror_unadjusted: (call) user_ty={:?}", user_ty);
@ -464,7 +464,7 @@ impl<'tcx> Cx<'tcx> {
ty::Adt(adt, substs) => match adt.adt_kind() {
AdtKind::Struct | AdtKind::Union => {
let user_provided_types = self.typeck_results().user_provided_types();
let user_ty = user_provided_types.get(expr.hir_id).copied();
let user_ty = user_provided_types.get(expr.hir_id).copied().map(Box::new);
debug!("make_mirror_unadjusted: (struct/union) user_ty={:?}", user_ty);
ExprKind::Adt(Box::new(Adt {
adt_def: *adt,
@ -490,7 +490,8 @@ impl<'tcx> Cx<'tcx> {
let index = adt.variant_index_with_id(variant_id);
let user_provided_types =
self.typeck_results().user_provided_types();
let user_ty = user_provided_types.get(expr.hir_id).copied();
let user_ty =
user_provided_types.get(expr.hir_id).copied().map(Box::new);
debug!("make_mirror_unadjusted: (variant) user_ty={:?}", user_ty);
ExprKind::Adt(Box::new(Adt {
adt_def: *adt,
@ -712,14 +713,17 @@ impl<'tcx> Cx<'tcx> {
});
debug!("make_mirror_unadjusted: (cast) user_ty={:?}", user_ty);
ExprKind::ValueTypeAscription { source: cast_expr, user_ty: Some(*user_ty) }
ExprKind::ValueTypeAscription {
source: cast_expr,
user_ty: Some(Box::new(*user_ty)),
}
} else {
cast
}
}
hir::ExprKind::Type(ref source, ref ty) => {
let user_provided_types = self.typeck_results.user_provided_types();
let user_ty = user_provided_types.get(ty.hir_id).copied();
let user_ty = user_provided_types.get(ty.hir_id).copied().map(Box::new);
debug!("make_mirror_unadjusted: (type) user_ty={:?}", user_ty);
let mirrored = self.mirror_expr(source);
if source.is_syntactic_place_expr() {
@ -748,7 +752,7 @@ impl<'tcx> Cx<'tcx> {
&mut self,
hir_id: hir::HirId,
res: Res,
) -> Option<ty::CanonicalUserType<'tcx>> {
) -> Option<Box<ty::CanonicalUserType<'tcx>>> {
debug!("user_substs_applied_to_res: res={:?}", res);
let user_provided_type = match res {
// A reference to something callable -- e.g., a fn, method, or
@ -759,7 +763,7 @@ impl<'tcx> Cx<'tcx> {
| Res::Def(DefKind::Ctor(_, CtorKind::Fn), _)
| Res::Def(DefKind::Const, _)
| Res::Def(DefKind::AssocConst, _) => {
self.typeck_results().user_provided_types().get(hir_id).copied()
self.typeck_results().user_provided_types().get(hir_id).copied().map(Box::new)
}
// A unit struct/variant which is used as a value (e.g.,
@ -767,11 +771,11 @@ impl<'tcx> Cx<'tcx> {
// this variant -- but with the substitutions given by the
// user.
Res::Def(DefKind::Ctor(_, CtorKind::Const), _) => {
self.user_substs_applied_to_ty_of_hir_id(hir_id)
self.user_substs_applied_to_ty_of_hir_id(hir_id).map(Box::new)
}
// `Self` is used in expression as a tuple struct constructor or a unit struct constructor
Res::SelfCtor(_) => self.user_substs_applied_to_ty_of_hir_id(hir_id),
Res::SelfCtor(_) => self.user_substs_applied_to_ty_of_hir_id(hir_id).map(Box::new),
_ => bug!("user_substs_applied_to_res: unexpected res {:?} at {:?}", res, hir_id),
};
@ -846,13 +850,13 @@ impl<'tcx> Cx<'tcx> {
Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => {
let user_ty = self.user_substs_applied_to_res(expr.hir_id, res);
ExprKind::NamedConst { def_id, substs, user_ty: user_ty }
ExprKind::NamedConst { def_id, substs, user_ty }
}
Res::Def(DefKind::Ctor(_, CtorKind::Const), def_id) => {
let user_provided_types = self.typeck_results.user_provided_types();
let user_provided_type = user_provided_types.get(expr.hir_id).copied();
debug!("convert_path_expr: user_provided_type={:?}", user_provided_type);
let user_ty = user_provided_types.get(expr.hir_id).copied().map(Box::new);
debug!("convert_path_expr: user_ty={:?}", user_ty);
let ty = self.typeck_results().node_type(expr.hir_id);
match ty.kind() {
// A unit struct/variant which is used as a value.
@ -861,7 +865,7 @@ impl<'tcx> Cx<'tcx> {
adt_def: *adt_def,
variant_index: adt_def.variant_index_with_ctor_id(def_id),
substs,
user_ty: user_provided_type,
user_ty,
fields: Box::new([]),
base: None,
})),