@@ -15,50 +15,33 @@ use rustc_hir::def_id::DefId;
15
15
use rustc_hir:: RangeEnd ;
16
16
use rustc_index:: newtype_index;
17
17
use rustc_index:: vec:: IndexVec ;
18
- use rustc_middle:: infer:: canonical:: Canonical ;
19
18
use rustc_middle:: middle:: region;
20
19
use rustc_middle:: mir:: interpret:: AllocId ;
21
20
use rustc_middle:: mir:: { self , BinOp , BorrowKind , FakeReadCause , Field , Mutability , UnOp } ;
22
21
use rustc_middle:: ty:: adjustment:: PointerCast ;
23
22
use 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 ;
26
26
use rustc_span:: { Span , Symbol , DUMMY_SP } ;
27
27
use rustc_target:: abi:: VariantIdx ;
28
28
use rustc_target:: asm:: InlineAsmRegOrRegClass ;
29
-
30
- use rustc_span:: def_id:: LocalDefId ;
31
29
use std:: fmt;
32
30
use std:: ops:: Index ;
33
31
34
32
pub mod visit;
35
33
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
-
60
34
macro_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
+
62
45
/// A container for a THIR body.
63
46
///
64
47
/// This can be indexed directly by any THIR index (e.g. [`ExprId`]).
@@ -91,9 +74,10 @@ macro_rules! thir_with_elements {
91
74
}
92
75
93
76
thir_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{}" ,
97
81
}
98
82
99
83
#[ derive( Copy , Clone , Debug , HashStable ) ]
@@ -121,8 +105,10 @@ pub struct Block {
121
105
pub safety_mode : BlockSafety ,
122
106
}
123
107
108
+ type UserTy < ' tcx > = Option < Box < CanonicalUserType < ' tcx > > > ;
109
+
124
110
#[ derive( Clone , Debug , HashStable ) ]
125
- pub struct Adt < ' tcx > {
111
+ pub struct AdtExpr < ' tcx > {
126
112
/// The ADT we're constructing.
127
113
pub adt_def : AdtDef < ' tcx > ,
128
114
/// The variant of the ADT.
@@ -131,13 +117,30 @@ pub struct Adt<'tcx> {
131
117
132
118
/// Optional user-given substs: for something like `let x =
133
119
/// Bar::<T> { ... }`.
134
- pub user_ty : Option < Canonical < ' tcx , UserType < ' tcx > > > ,
120
+ pub user_ty : UserTy < ' tcx > ,
135
121
136
122
pub fields : Box < [ FieldExpr ] > ,
137
123
/// The base, e.g. `Foo {x: 1, .. base}`.
138
124
pub base : Option < FruInfo < ' tcx > > ,
139
125
}
140
126
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
+
141
144
#[ derive( Copy , Clone , Debug , HashStable ) ]
142
145
pub enum BlockSafety {
143
146
Safe ,
@@ -183,7 +186,7 @@ pub enum StmtKind<'tcx> {
183
186
initializer : Option < ExprId > ,
184
187
185
188
/// `let pat: ty = <INIT> else { <ELSE> }
186
- else_block : Option < Block > ,
189
+ else_block : Option < BlockId > ,
187
190
188
191
/// The lint level for this `let` statement.
189
192
lint_level : LintLevel ,
@@ -307,7 +310,7 @@ pub enum ExprKind<'tcx> {
307
310
} ,
308
311
/// A block.
309
312
Block {
310
- body : Block ,
313
+ block : BlockId ,
311
314
} ,
312
315
/// An assignment: `lhs = rhs`.
313
316
Assign {
@@ -387,27 +390,21 @@ pub enum ExprKind<'tcx> {
387
390
fields : Box < [ ExprId ] > ,
388
391
} ,
389
392
/// An ADT constructor, e.g. `Foo {x: 1, y: 2}`.
390
- Adt ( Box < Adt < ' tcx > > ) ,
393
+ Adt ( Box < AdtExpr < ' tcx > > ) ,
391
394
/// A type ascription on a place.
392
395
PlaceTypeAscription {
393
396
source : ExprId ,
394
397
/// Type that the user gave to this expression
395
- user_ty : Option < Canonical < ' tcx , UserType < ' tcx > > > ,
398
+ user_ty : UserTy < ' tcx > ,
396
399
} ,
397
400
/// A type ascription on a value, e.g. `42: i32`.
398
401
ValueTypeAscription {
399
402
source : ExprId ,
400
403
/// Type that the user gave to this expression
401
- user_ty : Option < Canonical < ' tcx , UserType < ' tcx > > > ,
404
+ user_ty : UserTy < ' tcx > ,
402
405
} ,
403
406
/// 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 > > ) ,
411
408
/// A literal.
412
409
Literal {
413
410
lit : & ' tcx hir:: Lit ,
@@ -416,17 +413,17 @@ pub enum ExprKind<'tcx> {
416
413
/// For literals that don't correspond to anything in the HIR
417
414
NonHirLiteral {
418
415
lit : ty:: ScalarInt ,
419
- user_ty : Option < Canonical < ' tcx , UserType < ' tcx > > > ,
416
+ user_ty : UserTy < ' tcx > ,
420
417
} ,
421
418
/// A literal of a ZST type.
422
419
ZstLiteral {
423
- user_ty : Option < Canonical < ' tcx , UserType < ' tcx > > > ,
420
+ user_ty : UserTy < ' tcx > ,
424
421
} ,
425
422
/// Associated constants and named constants
426
423
NamedConst {
427
424
def_id : DefId ,
428
425
substs : SubstsRef < ' tcx > ,
429
- user_ty : Option < Canonical < ' tcx , UserType < ' tcx > > > ,
426
+ user_ty : UserTy < ' tcx > ,
430
427
} ,
431
428
ConstParam {
432
429
param : ty:: ParamConst ,
@@ -443,12 +440,7 @@ pub enum ExprKind<'tcx> {
443
440
def_id : DefId ,
444
441
} ,
445
442
/// 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 > > ) ,
452
444
/// An expression taking a reference to a thread local.
453
445
ThreadLocalRef ( DefId ) ,
454
446
/// A `yield` expression.
@@ -815,7 +807,10 @@ mod size_asserts {
815
807
use super :: * ;
816
808
// These are in alphabetical order, which is easy to maintain.
817
809
static_assert_size ! ( Block , 56 ) ;
818
- static_assert_size ! ( Expr <' _>, 104 ) ;
810
+ static_assert_size ! ( Expr <' _>, 64 ) ;
811
+ static_assert_size ! ( ExprKind <' _>, 40 ) ;
819
812
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 ) ;
821
816
}
0 commit comments