@@ -15,50 +15,33 @@ use rustc_hir::def_id::DefId;
1515use rustc_hir:: RangeEnd ;
1616use rustc_index:: newtype_index;
1717use rustc_index:: vec:: IndexVec ;
18- use rustc_middle:: infer:: canonical:: Canonical ;
1918use rustc_middle:: middle:: region;
2019use rustc_middle:: mir:: interpret:: AllocId ;
2120use rustc_middle:: mir:: { self , BinOp , BorrowKind , FakeReadCause , Field , Mutability , UnOp } ;
2221use rustc_middle:: ty:: adjustment:: PointerCast ;
2322use rustc_middle:: ty:: subst:: SubstsRef ;
24- use rustc_middle:: ty:: CanonicalUserTypeAnnotation ;
25- use rustc_middle:: ty:: { self , AdtDef , Ty , UpvarSubsts , UserType } ;
23+ use rustc_middle:: ty:: { self , AdtDef , Ty , UpvarSubsts } ;
24+ use rustc_middle:: ty:: { CanonicalUserType , CanonicalUserTypeAnnotation } ;
25+ use rustc_span:: def_id:: LocalDefId ;
2626use rustc_span:: { Span , Symbol , DUMMY_SP } ;
2727use rustc_target:: abi:: VariantIdx ;
2828use rustc_target:: asm:: InlineAsmRegOrRegClass ;
29-
30- use rustc_span:: def_id:: LocalDefId ;
3129use std:: fmt;
3230use std:: ops:: Index ;
3331
3432pub mod visit;
3533
36- newtype_index ! {
37- /// An index to an [`Arm`] stored in [`Thir::arms`]
38- #[ derive( HashStable ) ]
39- pub struct ArmId {
40- DEBUG_FORMAT = "a{}"
41- }
42- }
43-
44- newtype_index ! {
45- /// An index to an [`Expr`] stored in [`Thir::exprs`]
46- #[ derive( HashStable ) ]
47- pub struct ExprId {
48- DEBUG_FORMAT = "e{}"
49- }
50- }
51-
52- newtype_index ! {
53- #[ derive( HashStable ) ]
54- /// An index to a [`Stmt`] stored in [`Thir::stmts`]
55- pub struct StmtId {
56- DEBUG_FORMAT = "s{}"
57- }
58- }
59-
6034macro_rules! thir_with_elements {
61- ( $( $name: ident: $id: ty => $value: ty, ) * ) => {
35+ ( $( $name: ident: $id: ty => $value: ty => $format: literal, ) * ) => {
36+ $(
37+ newtype_index! {
38+ #[ derive( HashStable ) ]
39+ pub struct $id {
40+ DEBUG_FORMAT = $format
41+ }
42+ }
43+ ) *
44+
6245 /// A container for a THIR body.
6346 ///
6447 /// This can be indexed directly by any THIR index (e.g. [`ExprId`]).
@@ -91,9 +74,10 @@ macro_rules! thir_with_elements {
9174}
9275
9376thir_with_elements ! {
94- arms: ArmId => Arm <' tcx>,
95- exprs: ExprId => Expr <' tcx>,
96- stmts: StmtId => Stmt <' tcx>,
77+ arms: ArmId => Arm <' tcx> => "a{}" ,
78+ blocks: BlockId => Block => "b{}" ,
79+ exprs: ExprId => Expr <' tcx> => "e{}" ,
80+ stmts: StmtId => Stmt <' tcx> => "s{}" ,
9781}
9882
9983#[ derive( Copy , Clone , Debug , HashStable ) ]
@@ -121,8 +105,10 @@ pub struct Block {
121105 pub safety_mode : BlockSafety ,
122106}
123107
108+ type UserTy < ' tcx > = Option < Box < CanonicalUserType < ' tcx > > > ;
109+
124110#[ derive( Clone , Debug , HashStable ) ]
125- pub struct Adt < ' tcx > {
111+ pub struct AdtExpr < ' tcx > {
126112 /// The ADT we're constructing.
127113 pub adt_def : AdtDef < ' tcx > ,
128114 /// The variant of the ADT.
@@ -131,13 +117,30 @@ pub struct Adt<'tcx> {
131117
132118 /// Optional user-given substs: for something like `let x =
133119 /// Bar::<T> { ... }`.
134- pub user_ty : Option < Canonical < ' tcx , UserType < ' tcx > > > ,
120+ pub user_ty : UserTy < ' tcx > ,
135121
136122 pub fields : Box < [ FieldExpr ] > ,
137123 /// The base, e.g. `Foo {x: 1, .. base}`.
138124 pub base : Option < FruInfo < ' tcx > > ,
139125}
140126
127+ #[ derive( Clone , Debug , HashStable ) ]
128+ pub struct ClosureExpr < ' tcx > {
129+ pub closure_id : LocalDefId ,
130+ pub substs : UpvarSubsts < ' tcx > ,
131+ pub upvars : Box < [ ExprId ] > ,
132+ pub movability : Option < hir:: Movability > ,
133+ pub fake_reads : Vec < ( ExprId , FakeReadCause , hir:: HirId ) > ,
134+ }
135+
136+ #[ derive( Clone , Debug , HashStable ) ]
137+ pub struct InlineAsmExpr < ' tcx > {
138+ pub template : & ' tcx [ InlineAsmTemplatePiece ] ,
139+ pub operands : Box < [ InlineAsmOperand < ' tcx > ] > ,
140+ pub options : InlineAsmOptions ,
141+ pub line_spans : & ' tcx [ Span ] ,
142+ }
143+
141144#[ derive( Copy , Clone , Debug , HashStable ) ]
142145pub enum BlockSafety {
143146 Safe ,
@@ -183,7 +186,7 @@ pub enum StmtKind<'tcx> {
183186 initializer : Option < ExprId > ,
184187
185188 /// `let pat: ty = <INIT> else { <ELSE> }
186- else_block : Option < Block > ,
189+ else_block : Option < BlockId > ,
187190
188191 /// The lint level for this `let` statement.
189192 lint_level : LintLevel ,
@@ -307,7 +310,7 @@ pub enum ExprKind<'tcx> {
307310 } ,
308311 /// A block.
309312 Block {
310- body : Block ,
313+ block : BlockId ,
311314 } ,
312315 /// An assignment: `lhs = rhs`.
313316 Assign {
@@ -387,27 +390,21 @@ pub enum ExprKind<'tcx> {
387390 fields : Box < [ ExprId ] > ,
388391 } ,
389392 /// An ADT constructor, e.g. `Foo {x: 1, y: 2}`.
390- Adt ( Box < Adt < ' tcx > > ) ,
393+ Adt ( Box < AdtExpr < ' tcx > > ) ,
391394 /// A type ascription on a place.
392395 PlaceTypeAscription {
393396 source : ExprId ,
394397 /// Type that the user gave to this expression
395- user_ty : Option < Canonical < ' tcx , UserType < ' tcx > > > ,
398+ user_ty : UserTy < ' tcx > ,
396399 } ,
397400 /// A type ascription on a value, e.g. `42: i32`.
398401 ValueTypeAscription {
399402 source : ExprId ,
400403 /// Type that the user gave to this expression
401- user_ty : Option < Canonical < ' tcx , UserType < ' tcx > > > ,
404+ user_ty : UserTy < ' tcx > ,
402405 } ,
403406 /// A closure definition.
404- Closure {
405- closure_id : LocalDefId ,
406- substs : UpvarSubsts < ' tcx > ,
407- upvars : Box < [ ExprId ] > ,
408- movability : Option < hir:: Movability > ,
409- fake_reads : Vec < ( ExprId , FakeReadCause , hir:: HirId ) > ,
410- } ,
407+ Closure ( Box < ClosureExpr < ' tcx > > ) ,
411408 /// A literal.
412409 Literal {
413410 lit : & ' tcx hir:: Lit ,
@@ -416,17 +413,17 @@ pub enum ExprKind<'tcx> {
416413 /// For literals that don't correspond to anything in the HIR
417414 NonHirLiteral {
418415 lit : ty:: ScalarInt ,
419- user_ty : Option < Canonical < ' tcx , UserType < ' tcx > > > ,
416+ user_ty : UserTy < ' tcx > ,
420417 } ,
421418 /// A literal of a ZST type.
422419 ZstLiteral {
423- user_ty : Option < Canonical < ' tcx , UserType < ' tcx > > > ,
420+ user_ty : UserTy < ' tcx > ,
424421 } ,
425422 /// Associated constants and named constants
426423 NamedConst {
427424 def_id : DefId ,
428425 substs : SubstsRef < ' tcx > ,
429- user_ty : Option < Canonical < ' tcx , UserType < ' tcx > > > ,
426+ user_ty : UserTy < ' tcx > ,
430427 } ,
431428 ConstParam {
432429 param : ty:: ParamConst ,
@@ -443,12 +440,7 @@ pub enum ExprKind<'tcx> {
443440 def_id : DefId ,
444441 } ,
445442 /// Inline assembly, i.e. `asm!()`.
446- InlineAsm {
447- template : & ' tcx [ InlineAsmTemplatePiece ] ,
448- operands : Box < [ InlineAsmOperand < ' tcx > ] > ,
449- options : InlineAsmOptions ,
450- line_spans : & ' tcx [ Span ] ,
451- } ,
443+ InlineAsm ( Box < InlineAsmExpr < ' tcx > > ) ,
452444 /// An expression taking a reference to a thread local.
453445 ThreadLocalRef ( DefId ) ,
454446 /// A `yield` expression.
@@ -815,7 +807,10 @@ mod size_asserts {
815807 use super :: * ;
816808 // These are in alphabetical order, which is easy to maintain.
817809 static_assert_size ! ( Block , 56 ) ;
818- static_assert_size ! ( Expr <' _>, 104 ) ;
810+ static_assert_size ! ( Expr <' _>, 64 ) ;
811+ static_assert_size ! ( ExprKind <' _>, 40 ) ;
819812 static_assert_size ! ( Pat <' _>, 24 ) ;
820- static_assert_size ! ( Stmt <' _>, 120 ) ;
813+ static_assert_size ! ( PatKind <' _>, 112 ) ;
814+ static_assert_size ! ( Stmt <' _>, 72 ) ;
815+ static_assert_size ! ( StmtKind <' _>, 64 ) ;
821816}
0 commit comments