]> git.lizzy.rs Git - rust.git/blob - src/librustc_middle/arena.rs
f2259e5e9f857bece5a479903f03b361cf0ccb45
[rust.git] / src / librustc_middle / arena.rs
1 /// This declares a list of types which can be allocated by `Arena`.
2 ///
3 /// The `few` modifier will cause allocation to use the shared arena and recording the destructor.
4 /// This is faster and more memory efficient if there's only a few allocations of the type.
5 /// Leaving `few` out will cause the type to get its own dedicated `TypedArena` which is
6 /// faster and more memory efficient if there is lots of allocations.
7 ///
8 /// Specifying the `decode` modifier will add decode impls for `&T` and `&[T]` where `T` is the type
9 /// listed. These impls will appear in the implement_ty_decoder! macro.
10 #[macro_export]
11 macro_rules! arena_types {
12     ($macro:path, $args:tt, $tcx:lifetime) => (
13         $macro!($args, [
14             [] layouts: rustc_target::abi::Layout, rustc_target::abi::Layout;
15             // AdtDef are interned and compared by address
16             [] adt_def: rustc_middle::ty::AdtDef, rustc_middle::ty::AdtDef;
17             [] steal_mir:
18                 rustc_middle::ty::steal::Steal<rustc_middle::mir::Body<$tcx>>,
19                 rustc_middle::ty::steal::Steal<rustc_middle::mir::Body<$tcx>>;
20             [decode] mir: rustc_middle::mir::Body<$tcx>, rustc_middle::mir::Body<'_x>;
21             [] steal_promoted:
22                 rustc_middle::ty::steal::Steal<
23                     rustc_index::vec::IndexVec<
24                         rustc_middle::mir::Promoted,
25                         rustc_middle::mir::Body<$tcx>
26                     >
27                 >,
28                 rustc_middle::ty::steal::Steal<
29                     rustc_index::vec::IndexVec<
30                         rustc_middle::mir::Promoted,
31                         rustc_middle::mir::Body<$tcx>
32                     >
33                 >;
34             [decode] promoted:
35                 rustc_index::vec::IndexVec<
36                     rustc_middle::mir::Promoted,
37                     rustc_middle::mir::Body<$tcx>
38                 >,
39                 rustc_index::vec::IndexVec<
40                     rustc_middle::mir::Promoted,
41                     rustc_middle::mir::Body<'_x>
42                 >;
43             [decode] typeck_results: rustc_middle::ty::TypeckResults<$tcx>, rustc_middle::ty::TypeckResults<'_x>;
44             [decode] borrowck_result:
45                 rustc_middle::mir::BorrowCheckResult<$tcx>,
46                 rustc_middle::mir::BorrowCheckResult<'_x>;
47             [decode] unsafety_check_result: rustc_middle::mir::UnsafetyCheckResult, rustc_middle::mir::UnsafetyCheckResult;
48             [] const_allocs: rustc_middle::mir::interpret::Allocation, rustc_middle::mir::interpret::Allocation;
49             // Required for the incremental on-disk cache
50             [few, decode] mir_keys: rustc_hir::def_id::DefIdSet, rustc_hir::def_id::DefIdSet;
51             [] region_scope_tree: rustc_middle::middle::region::ScopeTree, rustc_middle::middle::region::ScopeTree;
52             [] dropck_outlives:
53                 rustc_middle::infer::canonical::Canonical<'tcx,
54                     rustc_middle::infer::canonical::QueryResponse<'tcx,
55                         rustc_middle::traits::query::DropckOutlivesResult<'tcx>
56                     >
57                 >,
58                 rustc_middle::infer::canonical::Canonical<'_x,
59                     rustc_middle::infer::canonical::QueryResponse<'_y,
60                         rustc_middle::traits::query::DropckOutlivesResult<'_z>
61                     >
62                 >;
63             [] normalize_projection_ty:
64                 rustc_middle::infer::canonical::Canonical<'tcx,
65                     rustc_middle::infer::canonical::QueryResponse<'tcx,
66                         rustc_middle::traits::query::NormalizationResult<'tcx>
67                     >
68                 >,
69                 rustc_middle::infer::canonical::Canonical<'_x,
70                     rustc_middle::infer::canonical::QueryResponse<'_y,
71                         rustc_middle::traits::query::NormalizationResult<'_z>
72                     >
73                 >;
74             [] implied_outlives_bounds:
75                 rustc_middle::infer::canonical::Canonical<'tcx,
76                     rustc_middle::infer::canonical::QueryResponse<'tcx,
77                         Vec<rustc_middle::traits::query::OutlivesBound<'tcx>>
78                     >
79                 >,
80                 rustc_middle::infer::canonical::Canonical<'_x,
81                     rustc_middle::infer::canonical::QueryResponse<'_y,
82                         Vec<rustc_middle::traits::query::OutlivesBound<'_z>>
83                     >
84                 >;
85             [] type_op_subtype:
86                 rustc_middle::infer::canonical::Canonical<'tcx,
87                     rustc_middle::infer::canonical::QueryResponse<'tcx, ()>
88                 >,
89                 rustc_middle::infer::canonical::Canonical<'_x,
90                     rustc_middle::infer::canonical::QueryResponse<'_y, ()>
91                 >;
92             [] type_op_normalize_poly_fn_sig:
93                 rustc_middle::infer::canonical::Canonical<'tcx,
94                     rustc_middle::infer::canonical::QueryResponse<'tcx, rustc_middle::ty::PolyFnSig<'tcx>>
95                 >,
96                 rustc_middle::infer::canonical::Canonical<'_x,
97                     rustc_middle::infer::canonical::QueryResponse<'_y, rustc_middle::ty::PolyFnSig<'_z>>
98                 >;
99             [] type_op_normalize_fn_sig:
100                 rustc_middle::infer::canonical::Canonical<'tcx,
101                     rustc_middle::infer::canonical::QueryResponse<'tcx, rustc_middle::ty::FnSig<'tcx>>
102                 >,
103                 rustc_middle::infer::canonical::Canonical<'_x,
104                     rustc_middle::infer::canonical::QueryResponse<'_y, rustc_middle::ty::FnSig<'_z>>
105                 >;
106             [] type_op_normalize_predicate:
107                 rustc_middle::infer::canonical::Canonical<'tcx,
108                     rustc_middle::infer::canonical::QueryResponse<'tcx, rustc_middle::ty::Predicate<'tcx>>
109                 >,
110                 rustc_middle::infer::canonical::Canonical<'_x,
111                     rustc_middle::infer::canonical::QueryResponse<'_y, rustc_middle::ty::Predicate<'_z>>
112                 >;
113             [] type_op_normalize_ty:
114                 rustc_middle::infer::canonical::Canonical<'tcx,
115                     rustc_middle::infer::canonical::QueryResponse<'tcx, rustc_middle::ty::Ty<'tcx>>
116                 >,
117                 rustc_middle::infer::canonical::Canonical<'_x,
118                     rustc_middle::infer::canonical::QueryResponse<'_y, &'_z rustc_middle::ty::TyS<'_w>>
119                 >;
120             [few] all_traits: Vec<rustc_hir::def_id::DefId>, Vec<rustc_hir::def_id::DefId>;
121             [few] privacy_access_levels: rustc_middle::middle::privacy::AccessLevels, rustc_middle::middle::privacy::AccessLevels;
122             [few] foreign_module: rustc_middle::middle::cstore::ForeignModule, rustc_middle::middle::cstore::ForeignModule;
123             [few] foreign_modules: Vec<rustc_middle::middle::cstore::ForeignModule>, Vec<rustc_middle::middle::cstore::ForeignModule>;
124             [] upvars_mentioned: rustc_data_structures::fx::FxIndexMap<rustc_hir::HirId, rustc_hir::Upvar>, rustc_data_structures::fx::FxIndexMap<rustc_hir::HirId, rustc_hir::Upvar>;
125             [] object_safety_violations: rustc_middle::traits::ObjectSafetyViolation, rustc_middle::traits::ObjectSafetyViolation;
126             [] codegen_unit: rustc_middle::mir::mono::CodegenUnit<$tcx>, rustc_middle::mir::mono::CodegenUnit<'_x>;
127             [] attribute: rustc_ast::ast::Attribute, rustc_ast::ast::Attribute;
128             [] name_set: rustc_data_structures::fx::FxHashSet<rustc_span::symbol::Symbol>, rustc_data_structures::fx::FxHashSet<rustc_span::symbol::Symbol>;
129             [] hir_id_set: rustc_hir::HirIdSet, rustc_hir::HirIdSet;
130
131             // Interned types
132             [] tys: rustc_middle::ty::TyS<$tcx>, rustc_middle::ty::TyS<'_x>;
133             [] predicates: rustc_middle::ty::PredicateInner<$tcx>, rustc_middle::ty::PredicateInner<'_x>;
134
135             // HIR query types
136             [few] indexed_hir: rustc_middle::hir::map::IndexedHir<$tcx>, rustc_middle::hir::map::IndexedHir<'_x>;
137             [few] hir_definitions: rustc_hir::definitions::Definitions, rustc_hir::definitions::Definitions;
138             [] hir_owner: rustc_middle::hir::Owner<$tcx>, rustc_middle::hir::Owner<'_x>;
139             [] hir_owner_nodes: rustc_middle::hir::OwnerNodes<$tcx>, rustc_middle::hir::OwnerNodes<'_x>;
140
141             // Note that this deliberately duplicates items in the `rustc_hir::arena`,
142             // since we need to allocate this type on both the `rustc_hir` arena
143             // (during lowering) and the `librustc_middle` arena (for decoding MIR)
144             [decode] asm_template: rustc_ast::ast::InlineAsmTemplatePiece, rustc_ast::ast::InlineAsmTemplatePiece;
145
146             // This is used to decode the &'tcx [Span] for InlineAsm's line_spans.
147             [decode] span: rustc_span::Span, rustc_span::Span;
148             [decode] used_trait_imports: rustc_data_structures::fx::FxHashSet<rustc_hir::def_id::LocalDefId>, rustc_data_structures::fx::FxHashSet<rustc_hir::def_id::LocalDefId>;
149         ], $tcx);
150     )
151 }
152
153 arena_types!(rustc_arena::declare_arena, [], 'tcx);