From c9429b1cec47ae4d2be8c891a482142e9efd4b24 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 24 Aug 2022 10:46:27 +1000 Subject: [PATCH 1/7] Define index types within `thir_with_elements`. The macro already generates other stuff, might as well generate these index types as well. --- compiler/rustc_middle/src/thir.rs | 41 ++++++++++--------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 5e26a52900eaf..9cb6763b663e5 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -33,32 +33,17 @@ use std::ops::Index; pub mod visit; -newtype_index! { - /// An index to an [`Arm`] stored in [`Thir::arms`] - #[derive(HashStable)] - pub struct ArmId { - DEBUG_FORMAT = "a{}" - } -} - -newtype_index! { - /// An index to an [`Expr`] stored in [`Thir::exprs`] - #[derive(HashStable)] - pub struct ExprId { - DEBUG_FORMAT = "e{}" - } -} - -newtype_index! { - #[derive(HashStable)] - /// An index to a [`Stmt`] stored in [`Thir::stmts`] - pub struct StmtId { - DEBUG_FORMAT = "s{}" - } -} - macro_rules! thir_with_elements { - ($($name:ident: $id:ty => $value:ty,)*) => { + ($($name:ident: $id:ty => $value:ty => $format:literal,)*) => { + $( + newtype_index! { + #[derive(HashStable)] + pub struct $id { + DEBUG_FORMAT = $format + } + } + )* + /// A container for a THIR body. /// /// This can be indexed directly by any THIR index (e.g. [`ExprId`]). @@ -91,9 +76,9 @@ macro_rules! thir_with_elements { } thir_with_elements! { - arms: ArmId => Arm<'tcx>, - exprs: ExprId => Expr<'tcx>, - stmts: StmtId => Stmt<'tcx>, + arms: ArmId => Arm<'tcx> => "a{}", + exprs: ExprId => Expr<'tcx> => "e{}", + stmts: StmtId => Stmt<'tcx> => "s{}", } #[derive(Copy, Clone, Debug, HashStable)] From e7c25c3a97864cd740ea82a6ea40d801cfc3fae0 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 24 Aug 2022 10:37:41 +1000 Subject: [PATCH 2/7] Box `user_ty` fields in `thir::ExprKind`. This shrinks several large variants of `ExprKind`. --- compiler/rustc_middle/src/thir.rs | 24 +++++++-------- .../src/build/expr/as_constant.rs | 18 +++++------ .../src/build/expr/as_place.rs | 12 ++++---- .../rustc_mir_build/src/build/expr/into.rs | 6 ++-- compiler/rustc_mir_build/src/thir/cx/expr.rs | 30 +++++++++++-------- 5 files changed, 47 insertions(+), 43 deletions(-) diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 9cb6763b663e5..9064ac3f07f7a 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -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>>; + #[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:: { ... }`. - pub user_ty: Option>>, + 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>>, + 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>>, + 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>>, + user_ty: UserTy<'tcx>, }, /// A literal of a ZST type. ZstLiteral { - user_ty: Option>>, + user_ty: UserTy<'tcx>, }, /// Associated constants and named constants NamedConst { def_id: DefId, substs: SubstsRef<'tcx>, - user_ty: Option>>, + 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); } diff --git a/compiler/rustc_mir_build/src/build/expr/as_constant.rs b/compiler/rustc_mir_build/src/build/expr/as_constant.rs index 19d420f154d5c..b316a6eeac1ca 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_constant.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_constant.rs @@ -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, }) }); diff --git a/compiler/rustc_mir_build/src/build/expr/as_place.rs b/compiler/rustc_mir_build/src/build/expr/as_place.rs index 0c06aad4e44d5..b8277f28cdc43 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_place.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_place.rs @@ -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( diff --git a/compiler/rustc_mir_build/src/build/expr/into.rs b/compiler/rustc_mir_build/src/build/expr/into.rs index 017d43d10a9a9..7ebcc53693ffc 100644 --- a/compiler/rustc_mir_build/src/build/expr/into.rs +++ b/compiler/rustc_mir_build/src/build/expr/into.rs @@ -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, }) }); diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 985601712c4f0..0db8748cb25dc 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -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> { + ) -> Option>> { 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, })), From 2df805fc7a98b5bea7022901ea7f837a13a51186 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 24 Aug 2022 12:02:17 +1000 Subject: [PATCH 3/7] Store blocks in `Thir`. Like expressions, statements, and match arms. This shrinks `thir::Stmt` and is a precursor to further shrinking `thir::Expr`. --- compiler/rustc_middle/src/thir.rs | 7 +++--- compiler/rustc_middle/src/thir/visit.rs | 4 ++-- compiler/rustc_mir_build/src/build/block.rs | 6 ++--- .../rustc_mir_build/src/build/expr/as_temp.rs | 5 +++-- .../rustc_mir_build/src/build/expr/into.rs | 2 +- .../rustc_mir_build/src/build/expr/stmt.rs | 22 +++++++++++++------ .../rustc_mir_build/src/build/matches/mod.rs | 13 ++++++----- compiler/rustc_mir_build/src/thir/cx/block.rs | 8 ++++--- compiler/rustc_mir_build/src/thir/cx/expr.rs | 10 ++++----- compiler/rustc_ty_utils/src/consts.rs | 15 ++++++++----- src/test/ui/thir-tree.stdout | 21 ++++++++++-------- 11 files changed, 66 insertions(+), 47 deletions(-) diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 9064ac3f07f7a..b55268d07526f 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -75,6 +75,7 @@ macro_rules! thir_with_elements { thir_with_elements! { arms: ArmId => Arm<'tcx> => "a{}", + blocks: BlockId => Block => "b{}", exprs: ExprId => Expr<'tcx> => "e{}", stmts: StmtId => Stmt<'tcx> => "s{}", } @@ -168,7 +169,7 @@ pub enum StmtKind<'tcx> { initializer: Option, /// `let pat: ty = else { } - else_block: Option, + else_block: Option, /// The lint level for this `let` statement. lint_level: LintLevel, @@ -292,7 +293,7 @@ pub enum ExprKind<'tcx> { }, /// A block. Block { - body: Block, + block: BlockId, }, /// An assignment: `lhs = rhs`. Assign { @@ -802,5 +803,5 @@ mod size_asserts { static_assert_size!(Block, 56); static_assert_size!(Expr<'_>, 88); static_assert_size!(Pat<'_>, 24); - static_assert_size!(Stmt<'_>, 120); + static_assert_size!(Stmt<'_>, 72); } diff --git a/compiler/rustc_middle/src/thir/visit.rs b/compiler/rustc_middle/src/thir/visit.rs index 97249fdd17563..758a42ea320f8 100644 --- a/compiler/rustc_middle/src/thir/visit.rs +++ b/compiler/rustc_middle/src/thir/visit.rs @@ -75,7 +75,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp visitor.visit_arm(&visitor.thir()[arm]); } } - Block { ref body } => visitor.visit_block(body), + Block { block } => visitor.visit_block(&visitor.thir()[block]), Assign { lhs, rhs } | AssignOp { lhs, rhs, op: _ } => { visitor.visit_expr(&visitor.thir()[lhs]); visitor.visit_expr(&visitor.thir()[rhs]); @@ -174,7 +174,7 @@ pub fn walk_stmt<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, stmt: &Stm } visitor.visit_pat(pattern); if let Some(block) = else_block { - visitor.visit_block(block) + visitor.visit_block(&visitor.thir()[*block]) } } } diff --git a/compiler/rustc_mir_build/src/build/block.rs b/compiler/rustc_mir_build/src/build/block.rs index 6875600129a8f..09045ef63a12b 100644 --- a/compiler/rustc_mir_build/src/build/block.rs +++ b/compiler/rustc_mir_build/src/build/block.rs @@ -10,7 +10,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { &mut self, destination: Place<'tcx>, block: BasicBlock, - ast_block: &Block, + ast_block: BlockId, source_info: SourceInfo, ) -> BlockAnd<()> { let Block { @@ -21,7 +21,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { expr, targeted_by_break, safety_mode, - } = *ast_block; + } = self.thir[ast_block]; let expr = expr.map(|expr| &self.thir[expr]); self.in_opt_scope(opt_destruction_scope.map(|de| (de, source_info)), move |this| { this.in_scope((region_scope, source_info), LintLevel::Inherited, move |this| { @@ -130,7 +130,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block, init, initializer_span, - else_block, + *else_block, visibility_scope, *remainder_scope, remainder_span, diff --git a/compiler/rustc_mir_build/src/build/expr/as_temp.rs b/compiler/rustc_mir_build/src/build/expr/as_temp.rs index 724b72f8769b8..e5dafb820bf8d 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_temp.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_temp.rs @@ -83,8 +83,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // Don't bother with StorageLive and Dead for these temporaries, // they are never assigned. ExprKind::Break { .. } | ExprKind::Continue { .. } | ExprKind::Return { .. } => (), - ExprKind::Block { body: Block { expr: None, targeted_by_break: false, .. } } - if expr_ty.is_never() => {} + ExprKind::Block { block } + if let Block { expr: None, targeted_by_break: false, .. } = this.thir[block] + && expr_ty.is_never() => {} _ => { this.cfg .push(block, Statement { source_info, kind: StatementKind::StorageLive(temp) }); diff --git a/compiler/rustc_mir_build/src/build/expr/into.rs b/compiler/rustc_mir_build/src/build/expr/into.rs index 7ebcc53693ffc..1e35167fce279 100644 --- a/compiler/rustc_mir_build/src/build/expr/into.rs +++ b/compiler/rustc_mir_build/src/build/expr/into.rs @@ -46,7 +46,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { }) }) } - ExprKind::Block { body: ref ast_block } => { + ExprKind::Block { block: ast_block } => { this.ast_block(destination, block, ast_block, source_info) } ExprKind::Match { scrutinee, ref arms } => { diff --git a/compiler/rustc_mir_build/src/build/expr/stmt.rs b/compiler/rustc_mir_build/src/build/expr/stmt.rs index a7e1331aabca3..00dbcaeb0c96f 100644 --- a/compiler/rustc_mir_build/src/build/expr/stmt.rs +++ b/compiler/rustc_mir_build/src/build/expr/stmt.rs @@ -116,14 +116,22 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // it is usually better to focus on `the_value` rather // than the entirety of block(s) surrounding it. let adjusted_span = (|| { - if let ExprKind::Block { body } = &expr.kind && let Some(tail_ex) = body.expr { + if let ExprKind::Block { block } = expr.kind + && let Some(tail_ex) = this.thir[block].expr + { let mut expr = &this.thir[tail_ex]; - while let ExprKind::Block { - body: Block { expr: Some(nested_expr), .. }, - } - | ExprKind::Scope { value: nested_expr, .. } = expr.kind - { - expr = &this.thir[nested_expr]; + loop { + match expr.kind { + ExprKind::Block { block } + if let Some(nested_expr) = this.thir[block].expr => + { + expr = &this.thir[nested_expr]; + } + ExprKind::Scope { value: nested_expr, .. } => { + expr = &this.thir[nested_expr]; + } + _ => break, + } } this.block_context.push(BlockFrame::TailExpr { tail_result_is_ignored: true, diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index ce38283724dac..080dab0303166 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -2280,15 +2280,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { mut block: BasicBlock, init: &Expr<'tcx>, initializer_span: Span, - else_block: &Block, + else_block: BlockId, visibility_scope: Option, remainder_scope: region::Scope, remainder_span: Span, pattern: &Pat<'tcx>, ) -> BlockAnd<()> { + let else_block_span = self.thir[else_block].span; let (matching, failure) = self.in_if_then_scope(remainder_scope, |this| { let scrutinee = unpack!(block = this.lower_scrutinee(block, init, initializer_span)); - let pat = Pat { ty: init.ty, span: else_block.span, kind: Box::new(PatKind::Wild) }; + let pat = Pat { ty: init.ty, span: else_block_span, kind: Box::new(PatKind::Wild) }; let mut wildcard = Candidate::new(scrutinee.clone(), &pat, false); this.declare_bindings( visibility_scope, @@ -2318,7 +2319,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ); // This block is for the failure case let failure = this.bind_pattern( - this.source_info(else_block.span), + this.source_info(else_block_span), wildcard, None, &fake_borrow_temps, @@ -2334,19 +2335,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // This place is not really used because this destination place // should never be used to take values at the end of the failure // block. - let dummy_place = self.temp(self.tcx.types.never, else_block.span); + let dummy_place = self.temp(self.tcx.types.never, else_block_span); let failure_block; unpack!( failure_block = self.ast_block( dummy_place, failure, else_block, - self.source_info(else_block.span), + self.source_info(else_block_span), ) ); self.cfg.terminate( failure_block, - self.source_info(else_block.span), + self.source_info(else_block_span), TerminatorKind::Unreachable, ); matching.unit() diff --git a/compiler/rustc_mir_build/src/thir/cx/block.rs b/compiler/rustc_mir_build/src/thir/cx/block.rs index dccaa61ed89d4..54c4b9eda70dc 100644 --- a/compiler/rustc_mir_build/src/thir/cx/block.rs +++ b/compiler/rustc_mir_build/src/thir/cx/block.rs @@ -9,13 +9,13 @@ use rustc_index::vec::Idx; use rustc_middle::ty::CanonicalUserTypeAnnotation; impl<'tcx> Cx<'tcx> { - pub(crate) fn mirror_block(&mut self, block: &'tcx hir::Block<'tcx>) -> Block { + pub(crate) fn mirror_block(&mut self, block: &'tcx hir::Block<'tcx>) -> BlockId { // We have to eagerly lower the "spine" of the statements // in order to get the lexical scoping correctly. let stmts = self.mirror_stmts(block.hir_id.local_id, block.stmts); let opt_destruction_scope = self.region_scope_tree.opt_destruction_scope(block.hir_id.local_id); - Block { + let block = Block { targeted_by_break: block.targeted_by_break, region_scope: region::Scope { id: block.hir_id.local_id, @@ -34,7 +34,9 @@ impl<'tcx> Cx<'tcx> { BlockSafety::ExplicitUnsafe(block.hir_id) } }, - } + }; + + self.thir.blocks.push(block) } fn mirror_stmts( diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 0db8748cb25dc..5e1f1c8e84e81 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -108,8 +108,8 @@ impl<'tcx> Cx<'tcx> { // // ^ error message points at this expression. // } let mut adjust_span = |expr: &mut Expr<'tcx>| { - if let ExprKind::Block { body } = &expr.kind { - if let Some(last_expr) = body.expr { + if let ExprKind::Block { block } = expr.kind { + if let Some(last_expr) = self.thir[block].expr { span = self.thir[last_expr].span; expr.span = span; } @@ -369,7 +369,7 @@ impl<'tcx> Cx<'tcx> { ExprKind::AddressOf { mutability, arg: self.mirror_expr(arg) } } - hir::ExprKind::Block(ref blk, _) => ExprKind::Block { body: self.mirror_block(blk) }, + hir::ExprKind::Block(ref blk, _) => ExprKind::Block { block: self.mirror_block(blk) }, hir::ExprKind::Assign(ref lhs, ref rhs, _) => { ExprKind::Assign { lhs: self.mirror_expr(lhs), rhs: self.mirror_expr(rhs) } @@ -680,8 +680,8 @@ impl<'tcx> Cx<'tcx> { let body = self.thir.exprs.push(Expr { ty: block_ty, temp_lifetime, - span: block.span, - kind: ExprKind::Block { body: block }, + span: self.thir[block].span, + kind: ExprKind::Block { block }, }); ExprKind::Loop { body } } diff --git a/compiler/rustc_ty_utils/src/consts.rs b/compiler/rustc_ty_utils/src/consts.rs index 7c2f4db94ff72..e8ce8e6f23ec9 100644 --- a/compiler/rustc_ty_utils/src/consts.rs +++ b/compiler/rustc_ty_utils/src/consts.rs @@ -311,8 +311,15 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> { // bar::<{ N + 1 }>(); // } // ``` - ExprKind::Block { body: thir::Block { stmts: box [], expr: Some(e), .. } } => { - self.recurse_build(*e)? + ExprKind::Block { block } => { + if let thir::Block { stmts: box [], expr: Some(e), .. } = &self.body.blocks[*block] { + self.recurse_build(*e)? + } else { + self.maybe_supported_error( + node.span, + "blocks are not supported in generic constant", + )? + } } // `ExprKind::Use` happens when a `hir::ExprKind::Cast` is a // "coercion cast" i.e. using a coercion or is a no-op. @@ -349,10 +356,6 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> { node.span, "array construction is not supported in generic constants", )?, - ExprKind::Block { .. } => self.maybe_supported_error( - node.span, - "blocks are not supported in generic constant", - )?, ExprKind::NeverToAny { .. } => self.maybe_supported_error( node.span, "converting nevers to any is not supported in generic constant", diff --git a/src/test/ui/thir-tree.stdout b/src/test/ui/thir-tree.stdout index 3c84be8e8f8d8..960b7f7f4ddea 100644 --- a/src/test/ui/thir-tree.stdout +++ b/src/test/ui/thir-tree.stdout @@ -1,6 +1,17 @@ DefId(0:3 ~ thir_tree[8f1d]::main): Thir { arms: [], + blocks: [ + Block { + targeted_by_break: false, + region_scope: Node(1), + opt_destruction_scope: None, + span: $DIR/thir-tree.rs:4:15: 4:17 (#0), + stmts: [], + expr: None, + safety_mode: Safe, + }, + ], exprs: [ Expr { ty: (), @@ -9,15 +20,7 @@ Thir { ), span: $DIR/thir-tree.rs:4:15: 4:17 (#0), kind: Block { - body: Block { - targeted_by_break: false, - region_scope: Node(1), - opt_destruction_scope: None, - span: $DIR/thir-tree.rs:4:15: 4:17 (#0), - stmts: [], - expr: None, - safety_mode: Safe, - }, + block: b0, }, }, Expr { From b3245a8dffc1460db7a8e5fbc748156a68327fcf Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 24 Aug 2022 11:28:05 +1000 Subject: [PATCH 4/7] Box `thir::ExprKind::Closure`. This shrinks `thir::Expr`. --- compiler/rustc_middle/src/thir.rs | 19 +++++++++++-------- compiler/rustc_middle/src/thir/visit.rs | 11 +++++++++-- .../src/build/expr/as_rvalue.rs | 8 +++++++- .../rustc_mir_build/src/check_unsafety.rs | 4 ++-- compiler/rustc_mir_build/src/thir/cx/expr.rs | 8 +++++++- 5 files changed, 36 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index b55268d07526f..73449cc179a1a 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -124,6 +124,15 @@ pub struct Adt<'tcx> { pub base: Option>, } +#[derive(Clone, Debug, HashStable)] +pub struct ClosureExpr<'tcx> { + pub closure_id: LocalDefId, + pub substs: UpvarSubsts<'tcx>, + pub upvars: Box<[ExprId]>, + pub movability: Option, + pub fake_reads: Vec<(ExprId, FakeReadCause, hir::HirId)>, +} + #[derive(Copy, Clone, Debug, HashStable)] pub enum BlockSafety { Safe, @@ -387,13 +396,7 @@ pub enum ExprKind<'tcx> { user_ty: UserTy<'tcx>, }, /// A closure definition. - Closure { - closure_id: LocalDefId, - substs: UpvarSubsts<'tcx>, - upvars: Box<[ExprId]>, - movability: Option, - fake_reads: Vec<(ExprId, FakeReadCause, hir::HirId)>, - }, + Closure(Box>), /// A literal. Literal { lit: &'tcx hir::Lit, @@ -801,7 +804,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<'_>, 88); + static_assert_size!(Expr<'_>, 80); static_assert_size!(Pat<'_>, 24); static_assert_size!(Stmt<'_>, 72); } diff --git a/compiler/rustc_middle/src/thir/visit.rs b/compiler/rustc_middle/src/thir/visit.rs index 758a42ea320f8..baa07d8ef0aa3 100644 --- a/compiler/rustc_middle/src/thir/visit.rs +++ b/compiler/rustc_middle/src/thir/visit.rs @@ -1,5 +1,6 @@ use super::{ - Arm, Block, Expr, ExprKind, Guard, InlineAsmOperand, Pat, PatKind, Stmt, StmtKind, Thir, + Arm, Block, ClosureExpr, Expr, ExprKind, Guard, InlineAsmOperand, Pat, PatKind, Stmt, StmtKind, + Thir, }; pub trait Visitor<'a, 'tcx: 'a>: Sized { @@ -126,7 +127,13 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp PlaceTypeAscription { source, user_ty: _ } | ValueTypeAscription { source, user_ty: _ } => { visitor.visit_expr(&visitor.thir()[source]) } - Closure { closure_id: _, substs: _, upvars: _, movability: _, fake_reads: _ } => {} + Closure(box ClosureExpr { + closure_id: _, + substs: _, + upvars: _, + movability: _, + fake_reads: _, + }) => {} Literal { lit: _, neg: _ } => {} NonHirLiteral { lit: _, user_ty: _ } => {} ZstLiteral { user_ty: _ } => {} diff --git a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs index 15f2d17c4e08b..4b232a1b51530 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs @@ -302,7 +302,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block.and(Rvalue::Aggregate(Box::new(AggregateKind::Tuple), fields)) } - ExprKind::Closure { closure_id, substs, ref upvars, movability, ref fake_reads } => { + ExprKind::Closure(box ClosureExpr { + closure_id, + substs, + ref upvars, + movability, + ref fake_reads, + }) => { // Convert the closure fake reads, if any, from `ExprRef` to mir `Place` // and push the fake reads. // This must come before creating the operands. This is required in case diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index f0b0456c4b961..6564c526c5be4 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -402,13 +402,13 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { (Bound::Unbounded, Bound::Unbounded) => {} _ => self.requires_unsafe(expr.span, InitializingTypeWith), }, - ExprKind::Closure { + ExprKind::Closure(box ClosureExpr { closure_id, substs: _, upvars: _, movability: _, fake_reads: _, - } => { + }) => { let closure_def = if let Some((did, const_param_id)) = ty::WithOptConstParam::try_lookup(closure_id, self.tcx) { diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 5e1f1c8e84e81..a742e2f264774 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -548,7 +548,13 @@ impl<'tcx> Cx<'tcx> { None => Vec::new(), }; - ExprKind::Closure { closure_id: def_id, substs, upvars, movability, fake_reads } + ExprKind::Closure(Box::new(ClosureExpr { + closure_id: def_id, + substs, + upvars, + movability, + fake_reads, + })) } hir::ExprKind::Path(ref qpath) => { From e57ac764b80e1f0ddb06bb49cb1eb12c699022bb Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 24 Aug 2022 12:16:01 +1000 Subject: [PATCH 5/7] Box `thir::ExprKind::InlineAsm`. This shrinks `thir::Expr`. --- compiler/rustc_middle/src/thir.rs | 17 ++++++++++------- compiler/rustc_middle/src/thir/visit.rs | 4 ++-- compiler/rustc_mir_build/src/build/expr/into.rs | 2 +- compiler/rustc_mir_build/src/thir/cx/expr.rs | 4 ++-- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 73449cc179a1a..17dadecfae0b4 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -133,6 +133,14 @@ pub struct ClosureExpr<'tcx> { pub fake_reads: Vec<(ExprId, FakeReadCause, hir::HirId)>, } +#[derive(Clone, Debug, HashStable)] +pub struct InlineAsmExpr<'tcx> { + pub template: &'tcx [InlineAsmTemplatePiece], + pub operands: Box<[InlineAsmOperand<'tcx>]>, + pub options: InlineAsmOptions, + pub line_spans: &'tcx [Span], +} + #[derive(Copy, Clone, Debug, HashStable)] pub enum BlockSafety { Safe, @@ -432,12 +440,7 @@ pub enum ExprKind<'tcx> { def_id: DefId, }, /// Inline assembly, i.e. `asm!()`. - InlineAsm { - template: &'tcx [InlineAsmTemplatePiece], - operands: Box<[InlineAsmOperand<'tcx>]>, - options: InlineAsmOptions, - line_spans: &'tcx [Span], - }, + InlineAsm(Box>), /// An expression taking a reference to a thread local. ThreadLocalRef(DefId), /// A `yield` expression. @@ -804,7 +807,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<'_>, 80); + static_assert_size!(Expr<'_>, 64); static_assert_size!(Pat<'_>, 24); static_assert_size!(Stmt<'_>, 72); } diff --git a/compiler/rustc_middle/src/thir/visit.rs b/compiler/rustc_middle/src/thir/visit.rs index baa07d8ef0aa3..68100f037d936 100644 --- a/compiler/rustc_middle/src/thir/visit.rs +++ b/compiler/rustc_middle/src/thir/visit.rs @@ -1,5 +1,5 @@ use super::{ - Arm, Block, ClosureExpr, Expr, ExprKind, Guard, InlineAsmOperand, Pat, PatKind, Stmt, StmtKind, + Arm, Block, ClosureExpr, Expr, ExprKind, Guard, InlineAsmExpr, InlineAsmOperand, Pat, PatKind, Stmt, StmtKind, Thir, }; @@ -140,7 +140,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp NamedConst { def_id: _, substs: _, user_ty: _ } => {} ConstParam { param: _, def_id: _ } => {} StaticRef { alloc_id: _, ty: _, def_id: _ } => {} - InlineAsm { ref operands, template: _, options: _, line_spans: _ } => { + InlineAsm(box InlineAsmExpr { ref operands, template: _, options: _, line_spans: _ }) => { for op in &**operands { use InlineAsmOperand::*; match op { diff --git a/compiler/rustc_mir_build/src/build/expr/into.rs b/compiler/rustc_mir_build/src/build/expr/into.rs index 1e35167fce279..dd6162300c34c 100644 --- a/compiler/rustc_mir_build/src/build/expr/into.rs +++ b/compiler/rustc_mir_build/src/build/expr/into.rs @@ -400,7 +400,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ); block.unit() } - ExprKind::InlineAsm { template, ref operands, options, line_spans } => { + ExprKind::InlineAsm(box InlineAsmExpr { template, ref operands, options, line_spans }) => { use rustc_middle::{mir, thir}; let operands = operands .into_iter() diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index a742e2f264774..0012de45b9e9e 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -562,7 +562,7 @@ impl<'tcx> Cx<'tcx> { self.convert_path_expr(expr, res) } - hir::ExprKind::InlineAsm(ref asm) => ExprKind::InlineAsm { + hir::ExprKind::InlineAsm(ref asm) => ExprKind::InlineAsm(Box::new(InlineAsmExpr { template: asm.template, operands: asm .operands @@ -621,7 +621,7 @@ impl<'tcx> Cx<'tcx> { .collect(), options: asm.options, line_spans: asm.line_spans, - }, + })), hir::ExprKind::ConstBlock(ref anon_const) => { let ty = self.typeck_results().node_type(anon_const.hir_id); From e3755c1d543a507e67daa6f4c67f50e85a85387f Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 24 Aug 2022 12:59:06 +1000 Subject: [PATCH 6/7] Rename `thir::Adt` as `thir::AdtExpr`. This matches the naming scheme used elsewhere, e.g. in the AST, and avoids name clashes with the `ExprKind::Closure` variant. --- compiler/rustc_middle/src/thir.rs | 4 ++-- compiler/rustc_middle/src/thir/visit.rs | 6 +++--- compiler/rustc_mir_build/src/build/expr/into.rs | 9 +++++++-- compiler/rustc_mir_build/src/check_unsafety.rs | 2 +- compiler/rustc_mir_build/src/thir/cx/expr.rs | 8 ++++---- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 17dadecfae0b4..c5d0892dde910 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -108,7 +108,7 @@ pub struct Block { type UserTy<'tcx> = Option>>; #[derive(Clone, Debug, HashStable)] -pub struct Adt<'tcx> { +pub struct AdtExpr<'tcx> { /// The ADT we're constructing. pub adt_def: AdtDef<'tcx>, /// The variant of the ADT. @@ -390,7 +390,7 @@ pub enum ExprKind<'tcx> { fields: Box<[ExprId]>, }, /// An ADT constructor, e.g. `Foo {x: 1, y: 2}`. - Adt(Box>), + Adt(Box>), /// A type ascription on a place. PlaceTypeAscription { source: ExprId, diff --git a/compiler/rustc_middle/src/thir/visit.rs b/compiler/rustc_middle/src/thir/visit.rs index 68100f037d936..c5c48a6360925 100644 --- a/compiler/rustc_middle/src/thir/visit.rs +++ b/compiler/rustc_middle/src/thir/visit.rs @@ -1,6 +1,6 @@ use super::{ - Arm, Block, ClosureExpr, Expr, ExprKind, Guard, InlineAsmExpr, InlineAsmOperand, Pat, PatKind, Stmt, StmtKind, - Thir, + AdtExpr, Arm, Block, ClosureExpr, Expr, ExprKind, Guard, InlineAsmExpr, InlineAsmOperand, Pat, + PatKind, Stmt, StmtKind, Thir, }; pub trait Visitor<'a, 'tcx: 'a>: Sized { @@ -109,7 +109,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp visitor.visit_expr(&visitor.thir()[field]); } } - Adt(box crate::thir::Adt { + Adt(box AdtExpr { ref fields, ref base, adt_def: _, diff --git a/compiler/rustc_mir_build/src/build/expr/into.rs b/compiler/rustc_mir_build/src/build/expr/into.rs index dd6162300c34c..48ec7a06724a1 100644 --- a/compiler/rustc_mir_build/src/build/expr/into.rs +++ b/compiler/rustc_mir_build/src/build/expr/into.rs @@ -314,7 +314,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { this.cfg.push_assign(block, source_info, destination, address_of); block.unit() } - ExprKind::Adt(box Adt { + ExprKind::Adt(box AdtExpr { adt_def, variant_index, substs, @@ -400,7 +400,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ); block.unit() } - ExprKind::InlineAsm(box InlineAsmExpr { template, ref operands, options, line_spans }) => { + ExprKind::InlineAsm(box InlineAsmExpr { + template, + ref operands, + options, + line_spans, + }) => { use rustc_middle::{mir, thir}; let operands = operands .into_iter() diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 6564c526c5be4..bf5a2e7c73fab 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -391,7 +391,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { ExprKind::InlineAsm { .. } => { self.requires_unsafe(expr.span, UseOfInlineAssembly); } - ExprKind::Adt(box Adt { + ExprKind::Adt(box AdtExpr { adt_def, variant_index: _, substs: _, diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 0012de45b9e9e..0c2b117453fe9 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -341,7 +341,7 @@ impl<'tcx> Cx<'tcx> { expr: self.mirror_expr(e), }) .collect(); - ExprKind::Adt(Box::new(Adt { + ExprKind::Adt(Box::new(AdtExpr { adt_def, substs, variant_index: index, @@ -466,7 +466,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().map(Box::new); debug!("make_mirror_unadjusted: (struct/union) user_ty={:?}", user_ty); - ExprKind::Adt(Box::new(Adt { + ExprKind::Adt(Box::new(AdtExpr { adt_def: *adt, variant_index: VariantIdx::new(0), substs, @@ -493,7 +493,7 @@ impl<'tcx> Cx<'tcx> { 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 { + ExprKind::Adt(Box::new(AdtExpr { adt_def: *adt, variant_index: index, substs, @@ -867,7 +867,7 @@ 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(Box::new(Adt { + ty::Adt(adt_def, substs) => ExprKind::Adt(Box::new(AdtExpr { adt_def: *adt_def, variant_index: adt_def.variant_index_with_ctor_id(def_id), substs, From 5a41eb81cabaa074072eb5f76a3ba771c7e68899 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 24 Aug 2022 15:06:11 +1000 Subject: [PATCH 7/7] Add some more THIR size assertions. --- compiler/rustc_middle/src/thir.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index c5d0892dde910..0f2504e3d9afe 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -808,6 +808,9 @@ mod size_asserts { // These are in alphabetical order, which is easy to maintain. static_assert_size!(Block, 56); static_assert_size!(Expr<'_>, 64); + static_assert_size!(ExprKind<'_>, 40); static_assert_size!(Pat<'_>, 24); + static_assert_size!(PatKind<'_>, 112); static_assert_size!(Stmt<'_>, 72); + static_assert_size!(StmtKind<'_>, 64); }