@@ -44,51 +44,28 @@ type Res = def::Res<NodeId>;
44
44
45
45
pub ( crate ) struct ImportResolver < ' r , ' ra , ' tcx > {
46
46
r : CmResolver < ' r , ' ra , ' tcx > , // always immutable
47
- batch : Vec < Import < ' ra > > , // a.k.a. indeterminate_imports, also treated as output
48
-
49
- // outputs
50
- prelude : Option < Module < ' ra > > ,
51
- determined_imports : Vec < Import < ' ra > > ,
52
- module_glob_importers : FxIndexMap < Module < ' ra > , Vec < Import < ' ra > > > ,
53
- glob_import_bindings : Vec < ( Module < ' ra > , BindingKey , NameBinding < ' ra > , bool ) > ,
54
- glob_res_outputs : Vec < ( NodeId , PartialRes ) > ,
55
- import_bindings : PerNS < Vec < ( Module < ' ra > , Import < ' ra > , PendingBinding < ' ra > ) > > ,
47
+ outputs : ImportResolutionOutputs < ' ra > ,
56
48
}
57
49
50
+ #[ derive( Default ) ]
58
51
struct ImportResolutionOutputs < ' ra > {
59
52
prelude : Option < Module < ' ra > > ,
60
53
indeterminate_imports : Vec < Import < ' ra > > ,
61
54
determined_imports : Vec < Import < ' ra > > ,
62
55
module_glob_importers : FxIndexMap < Module < ' ra > , Vec < Import < ' ra > > > ,
63
- glob_import_bindings : Vec < ( Module < ' ra > , BindingKey , NameBinding < ' ra > , bool ) > ,
64
- glob_res_outputs : Vec < ( NodeId , PartialRes ) > ,
65
- import_bindings : PerNS < Vec < ( Module < ' ra > , Import < ' ra > , PendingBinding < ' ra > ) > > ,
56
+ glob_import_bindings :
57
+ Vec < ( Module < ' ra > , BindingKey , NameBinding < ' ra > , bool /* warn_ambiguity */ ) > ,
58
+ glob_path_res : Vec < ( NodeId , PartialRes ) > ,
59
+ single_import_bindings : PerNS < Vec < ( Module < ' ra > , Import < ' ra > , PendingBinding < ' ra > ) > > ,
66
60
}
67
61
68
62
impl < ' r , ' ra , ' tcx > ImportResolver < ' r , ' ra , ' tcx > {
69
- pub ( crate ) fn new ( cmr : CmResolver < ' r , ' ra , ' tcx > , batch : Vec < Import < ' ra > > ) -> Self {
70
- ImportResolver {
71
- r : cmr,
72
- batch,
73
- prelude : None ,
74
- determined_imports : Default :: default ( ) ,
75
- module_glob_importers : Default :: default ( ) ,
76
- glob_import_bindings : Default :: default ( ) ,
77
- glob_res_outputs : Default :: default ( ) ,
78
- import_bindings : Default :: default ( ) ,
79
- }
63
+ pub ( crate ) fn new ( cmr : CmResolver < ' r , ' ra , ' tcx > ) -> Self {
64
+ ImportResolver { r : cmr, outputs : Default :: default ( ) }
80
65
}
81
66
82
67
fn into_outputs ( self ) -> ImportResolutionOutputs < ' ra > {
83
- ImportResolutionOutputs {
84
- prelude : self . prelude ,
85
- indeterminate_imports : self . batch ,
86
- determined_imports : self . determined_imports ,
87
- module_glob_importers : self . module_glob_importers ,
88
- glob_import_bindings : self . glob_import_bindings ,
89
- glob_res_outputs : self . glob_res_outputs ,
90
- import_bindings : self . import_bindings ,
91
- }
68
+ self . outputs
92
69
}
93
70
}
94
71
@@ -111,11 +88,11 @@ impl<'ra> ImportResolutionOutputs<'ra> {
111
88
let _ = r. try_define_local ( module, key. ident . 0 , key. ns , binding, warn_ambiguity) ;
112
89
}
113
90
114
- for ( id, res) in self . glob_res_outputs {
91
+ for ( id, res) in self . glob_path_res {
115
92
r. record_partial_res ( id, res) ;
116
93
}
117
94
118
- for ( ns, import_bindings) in self . import_bindings . into_iter_with ( ) {
95
+ for ( ns, import_bindings) in self . single_import_bindings . into_iter_with ( ) {
119
96
for ( parent, import, pending_binding) in import_bindings {
120
97
let ImportKind :: Single { target, ref bindings, .. } = import. kind else {
121
98
unreachable ! ( ) ;
@@ -669,7 +646,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
669
646
prev_indeterminate_count = indeterminate_count;
670
647
let batch = mem:: take ( & mut self . indeterminate_imports ) ;
671
648
self . assert_speculative = true ;
672
- let ( outputs, count) = ImportResolver :: new ( self . cm ( ) , batch ) . resolve_batch ( ) ;
649
+ let ( outputs, count) = ImportResolver :: new ( self . cm ( ) ) . resolve_batch ( batch ) ;
673
650
self . assert_speculative = false ;
674
651
indeterminate_count = count;
675
652
outputs. commit ( self ) ;
@@ -678,14 +655,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
678
655
679
656
fn resolve_batch < ' r > (
680
657
mut self : ImportResolver < ' r , ' ra , ' tcx > ,
658
+ batch : Vec < Import < ' ra > > ,
681
659
) -> ( ImportResolutionOutputs < ' ra > , usize ) {
682
660
let mut indeterminate_count = 0 ;
683
- for import in mem :: take ( & mut self . batch ) {
661
+ for import in batch {
684
662
let import_indeterminate_count = self . resolve_import ( import) ;
685
663
indeterminate_count += import_indeterminate_count;
686
664
match import_indeterminate_count {
687
- 0 => self . determined_imports . push ( import) ,
688
- _ => self . batch . push ( import) ,
665
+ 0 => self . outputs . determined_imports . push ( import) ,
666
+ _ => self . outputs . indeterminate_imports . push ( import) ,
689
667
}
690
668
}
691
669
( self . into_outputs ( ) , indeterminate_count)
@@ -1040,7 +1018,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1040
1018
return ;
1041
1019
}
1042
1020
} ;
1043
- self . import_bindings [ ns] . push ( ( parent, import, pending_binding) ) ;
1021
+ self . outputs . single_import_bindings [ ns] . push ( ( parent, import, pending_binding) ) ;
1044
1022
}
1045
1023
} ) ;
1046
1024
@@ -1607,12 +1585,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1607
1585
if module == import. parent_scope . module {
1608
1586
return ;
1609
1587
} else if is_prelude {
1610
- self . prelude = Some ( module) ;
1588
+ self . outputs . prelude = Some ( module) ;
1611
1589
return ;
1612
1590
}
1613
1591
1614
1592
// Add to module's glob_importers
1615
- self . module_glob_importers . entry ( module) . or_default ( ) . push ( import) ;
1593
+ self . outputs . module_glob_importers . entry ( module) . or_default ( ) . push ( import) ;
1616
1594
1617
1595
// Ensure that `resolutions` isn't borrowed during `try_define`,
1618
1596
// since it might get updated via a glob cycle.
@@ -1636,7 +1614,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1636
1614
. resolution ( import. parent_scope . module , key)
1637
1615
. and_then ( |r| r. binding ( ) )
1638
1616
. is_some_and ( |binding| binding. warn_ambiguity_recursive ( ) ) ;
1639
- self . glob_import_bindings . push ( (
1617
+ self . outputs . glob_import_bindings . push ( (
1640
1618
import. parent_scope . module ,
1641
1619
key,
1642
1620
imported_binding,
@@ -1646,7 +1624,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1646
1624
}
1647
1625
1648
1626
// Record the destination of this import
1649
- self . glob_res_outputs . push ( ( id, PartialRes :: new ( module. res ( ) . unwrap ( ) ) ) ) ;
1627
+ self . outputs . glob_path_res . push ( ( id, PartialRes :: new ( module. res ( ) . unwrap ( ) ) ) ) ;
1650
1628
}
1651
1629
1652
1630
// Miscellaneous post-processing, including recording re-exports,
0 commit comments