mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-22 03:44:24 +00:00
Box user_ty
fields in thir::ExprKind
.
This shrinks several large variants of `ExprKind`.
This commit is contained in:
parent
c9429b1cec
commit
e7c25c3a97
@ -15,19 +15,17 @@ use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::RangeEnd;
|
||||
use rustc_index::newtype_index;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_middle::infer::canonical::Canonical;
|
||||
use rustc_middle::middle::region;
|
||||
use rustc_middle::mir::interpret::AllocId;
|
||||
use rustc_middle::mir::{self, BinOp, BorrowKind, FakeReadCause, Field, Mutability, UnOp};
|
||||
use rustc_middle::ty::adjustment::PointerCast;
|
||||
use rustc_middle::ty::subst::SubstsRef;
|
||||
use rustc_middle::ty::CanonicalUserTypeAnnotation;
|
||||
use rustc_middle::ty::{self, AdtDef, Ty, UpvarSubsts, UserType};
|
||||
use rustc_middle::ty::{self, AdtDef, Ty, UpvarSubsts};
|
||||
use rustc_middle::ty::{CanonicalUserType, CanonicalUserTypeAnnotation};
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_span::{Span, Symbol, DUMMY_SP};
|
||||
use rustc_target::abi::VariantIdx;
|
||||
use rustc_target::asm::InlineAsmRegOrRegClass;
|
||||
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use std::fmt;
|
||||
use std::ops::Index;
|
||||
|
||||
@ -106,6 +104,8 @@ pub struct Block {
|
||||
pub safety_mode: BlockSafety,
|
||||
}
|
||||
|
||||
type UserTy<'tcx> = Option<Box<CanonicalUserType<'tcx>>>;
|
||||
|
||||
#[derive(Clone, Debug, HashStable)]
|
||||
pub struct Adt<'tcx> {
|
||||
/// The ADT we're constructing.
|
||||
@ -116,7 +116,7 @@ pub struct Adt<'tcx> {
|
||||
|
||||
/// Optional user-given substs: for something like `let x =
|
||||
/// Bar::<T> { ... }`.
|
||||
pub user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
|
||||
pub user_ty: UserTy<'tcx>,
|
||||
|
||||
pub fields: Box<[FieldExpr]>,
|
||||
/// The base, e.g. `Foo {x: 1, .. base}`.
|
||||
@ -377,13 +377,13 @@ pub enum ExprKind<'tcx> {
|
||||
PlaceTypeAscription {
|
||||
source: ExprId,
|
||||
/// Type that the user gave to this expression
|
||||
user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
|
||||
user_ty: UserTy<'tcx>,
|
||||
},
|
||||
/// A type ascription on a value, e.g. `42: i32`.
|
||||
ValueTypeAscription {
|
||||
source: ExprId,
|
||||
/// Type that the user gave to this expression
|
||||
user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
|
||||
user_ty: UserTy<'tcx>,
|
||||
},
|
||||
/// A closure definition.
|
||||
Closure {
|
||||
@ -401,17 +401,17 @@ pub enum ExprKind<'tcx> {
|
||||
/// For literals that don't correspond to anything in the HIR
|
||||
NonHirLiteral {
|
||||
lit: ty::ScalarInt,
|
||||
user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
|
||||
user_ty: UserTy<'tcx>,
|
||||
},
|
||||
/// A literal of a ZST type.
|
||||
ZstLiteral {
|
||||
user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
|
||||
user_ty: UserTy<'tcx>,
|
||||
},
|
||||
/// Associated constants and named constants
|
||||
NamedConst {
|
||||
def_id: DefId,
|
||||
substs: SubstsRef<'tcx>,
|
||||
user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
|
||||
user_ty: UserTy<'tcx>,
|
||||
},
|
||||
ConstParam {
|
||||
param: ty::ParamConst,
|
||||
@ -800,7 +800,7 @@ mod size_asserts {
|
||||
use super::*;
|
||||
// These are in alphabetical order, which is easy to maintain.
|
||||
static_assert_size!(Block, 56);
|
||||
static_assert_size!(Expr<'_>, 104);
|
||||
static_assert_size!(Expr<'_>, 88);
|
||||
static_assert_size!(Pat<'_>, 24);
|
||||
static_assert_size!(Stmt<'_>, 120);
|
||||
}
|
||||
|
@ -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,
|
||||
})
|
||||
});
|
||||
|
@ -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(
|
||||
|
@ -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,
|
||||
})
|
||||
});
|
||||
|
@ -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,
|
||||
})),
|
||||
|
Loading…
Reference in New Issue
Block a user