@@ -13,11 +13,12 @@ use cfg::{CfgExpr, CfgOptions};
13
13
use drop_bomb:: DropBomb ;
14
14
use either:: Either ;
15
15
use hir_expand:: {
16
- attrs:: RawAttrs , hygiene:: Hygiene , name:: Name , ExpandError , ExpandResult , HirFileId , InFile ,
17
- MacroCallId ,
16
+ ast_id_map :: AstIdMap , attrs:: RawAttrs , hygiene:: Hygiene , name:: Name , AstId , ExpandError ,
17
+ ExpandResult , HirFileId , InFile , MacroCallId ,
18
18
} ;
19
19
use la_arena:: { Arena , ArenaMap } ;
20
20
use limit:: Limit ;
21
+ use once_cell:: unsync:: OnceCell ;
21
22
use profile:: Count ;
22
23
use rustc_hash:: FxHashMap ;
23
24
use syntax:: { ast, AstPtr , SyntaxNode , SyntaxNodePtr } ;
@@ -37,7 +38,43 @@ use crate::{
37
38
UnresolvedMacro ,
38
39
} ;
39
40
40
- pub use lower:: LowerCtx ;
41
+ pub struct LowerCtx < ' a > {
42
+ pub db : & ' a dyn DefDatabase ,
43
+ hygiene : Hygiene ,
44
+ ast_id_map : Option < ( HirFileId , OnceCell < Arc < AstIdMap > > ) > ,
45
+ }
46
+
47
+ impl < ' a > LowerCtx < ' a > {
48
+ pub fn new ( db : & ' a dyn DefDatabase , hygiene : & Hygiene , file_id : HirFileId ) -> Self {
49
+ LowerCtx { db, hygiene : hygiene. clone ( ) , ast_id_map : Some ( ( file_id, OnceCell :: new ( ) ) ) }
50
+ }
51
+
52
+ pub fn with_file_id ( db : & ' a dyn DefDatabase , file_id : HirFileId ) -> Self {
53
+ LowerCtx {
54
+ db,
55
+ hygiene : Hygiene :: new ( db. upcast ( ) , file_id) ,
56
+ ast_id_map : Some ( ( file_id, OnceCell :: new ( ) ) ) ,
57
+ }
58
+ }
59
+
60
+ pub fn with_hygiene ( db : & ' a dyn DefDatabase , hygiene : & Hygiene ) -> Self {
61
+ LowerCtx { db, hygiene : hygiene. clone ( ) , ast_id_map : None }
62
+ }
63
+
64
+ pub ( crate ) fn hygiene ( & self ) -> & Hygiene {
65
+ & self . hygiene
66
+ }
67
+
68
+ pub ( crate ) fn lower_path ( & self , ast : ast:: Path ) -> Option < Path > {
69
+ Path :: from_src ( ast, self )
70
+ }
71
+
72
+ pub ( crate ) fn ast_id < N : syntax:: AstNode > ( & self , item : & N ) -> Option < AstId < N > > {
73
+ let & ( file_id, ref ast_id_map) = self . ast_id_map . as_ref ( ) ?;
74
+ let ast_id_map = ast_id_map. get_or_init ( || self . db . ast_id_map ( file_id) ) ;
75
+ Some ( InFile :: new ( file_id, ast_id_map. ast_id ( item) ) )
76
+ }
77
+ }
41
78
42
79
/// A subset of Expander that only deals with cfg attributes. We only need it to
43
80
/// avoid cyclic queries in crate def map during enum processing.
@@ -241,7 +278,7 @@ impl Expander {
241
278
// The overflow error should have been reported when it occurred (see the next branch),
242
279
// so don't return overflow error here to avoid diagnostics duplication.
243
280
cov_mark:: hit!( overflow_but_not_me) ;
244
- return ExpandResult :: only_err ( ExpandError :: RecursionOverflowPosioned ) ;
281
+ return ExpandResult :: only_err ( ExpandError :: RecursionOverflowPoisoned ) ;
245
282
} else if self . recursion_limit ( db) . check ( self . recursion_depth + 1 ) . is_err ( ) {
246
283
self . recursion_depth = usize:: MAX ;
247
284
cov_mark:: hit!( your_stack_belongs_to_me) ;
0 commit comments