@@ -71,9 +71,9 @@ impl DefPathTable {
71
71
}
72
72
73
73
/// The definition table containing node definitions.
74
- /// It holds the `DefPathTable` for local `DefId `s/`DefPath`s and it also stores a
75
- /// mapping from `NodeId `s to local `DefId `s.
76
- #[ derive( Clone , Default ) ]
74
+ /// It holds the `DefPathTable` for `LocalDefId `s/`DefPath`s.
75
+ /// It also stores mappings to convert `LocalDefId `s to/from `HirId `s.
76
+ #[ derive( Clone ) ]
77
77
pub struct Definitions {
78
78
table : DefPathTable ,
79
79
@@ -328,11 +328,7 @@ impl Definitions {
328
328
}
329
329
330
330
/// Adds a root definition (no parent) and a few other reserved definitions.
331
- pub fn create_root_def (
332
- & mut self ,
333
- crate_name : & str ,
334
- crate_disambiguator : CrateDisambiguator ,
335
- ) -> LocalDefId {
331
+ pub fn new ( crate_name : & str , crate_disambiguator : CrateDisambiguator ) -> Definitions {
336
332
let key = DefKey {
337
333
parent : None ,
338
334
disambiguated_data : DisambiguatedDefPathData {
@@ -344,24 +340,34 @@ impl Definitions {
344
340
let parent_hash = DefKey :: root_parent_stable_hash ( crate_name, crate_disambiguator) ;
345
341
let def_path_hash = key. compute_stable_hash ( parent_hash) ;
346
342
347
- // Create the definition.
348
- let root = LocalDefId { local_def_index : self . table . allocate ( key, def_path_hash) } ;
343
+ // Create the root definition.
344
+ let mut table = DefPathTable :: default ( ) ;
345
+ let root = LocalDefId { local_def_index : table. allocate ( key, def_path_hash) } ;
349
346
assert_eq ! ( root. local_def_index, CRATE_DEF_INDEX ) ;
350
347
351
- root
348
+ Definitions {
349
+ table,
350
+ def_id_to_hir_id : Default :: default ( ) ,
351
+ hir_id_to_def_id : Default :: default ( ) ,
352
+ expansions_that_defined : Default :: default ( ) ,
353
+ next_disambiguator : Default :: default ( ) ,
354
+ parent_modules_of_macro_defs : Default :: default ( ) ,
355
+ }
356
+ }
357
+
358
+ /// Retrieves the root definition.
359
+ pub fn get_root_def ( & self ) -> LocalDefId {
360
+ LocalDefId { local_def_index : CRATE_DEF_INDEX }
352
361
}
353
362
354
363
/// Adds a definition with a parent definition.
355
- pub fn create_def_with_parent (
364
+ pub fn create_def (
356
365
& mut self ,
357
366
parent : LocalDefId ,
358
367
data : DefPathData ,
359
368
expn_id : ExpnId ,
360
369
) -> LocalDefId {
361
- debug ! (
362
- "create_def_with_parent(parent={:?}, data={:?}, expn_id={:?})" ,
363
- parent, data, expn_id
364
- ) ;
370
+ debug ! ( "create_def(parent={:?}, data={:?}, expn_id={:?})" , parent, data, expn_id) ;
365
371
366
372
// The root node must be created with `create_root_def()`.
367
373
assert ! ( data != DefPathData :: CrateRoot ) ;
@@ -382,7 +388,7 @@ impl Definitions {
382
388
let parent_hash = self . table . def_path_hash ( parent. local_def_index ) ;
383
389
let def_path_hash = key. compute_stable_hash ( parent_hash) ;
384
390
385
- debug ! ( "create_def_with_parent : after disambiguation, key = {:?}" , key) ;
391
+ debug ! ( "create_def : after disambiguation, key = {:?}" , key) ;
386
392
387
393
// Create the definition.
388
394
let def_id = LocalDefId { local_def_index : self . table . allocate ( key, def_path_hash) } ;
0 commit comments