Skip to content

Commit df9df19

Browse files
committed
Always calculate glob map but only for glob uses
Previously calculating glob map was *opt-in*, however it did record node id -> ident use for every use directive. This aims to see if we can unconditionally calculate the glob map and not regress performance.
1 parent 75a369c commit df9df19

File tree

9 files changed

+11
-41
lines changed

9 files changed

+11
-41
lines changed

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ mod sty;
122122
/// *on-demand* infrastructure.
123123
#[derive(Clone)]
124124
pub struct CrateAnalysis {
125-
pub glob_map: Option<hir::GlobMap>,
125+
pub glob_map: hir::GlobMap,
126126
}
127127

128128
#[derive(Clone)]

src/librustc_driver/driver.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_passes::{self, ast_validation, hir_stats, loops, rvalue_promotion};
2626
use rustc_plugin as plugin;
2727
use rustc_plugin::registry::Registry;
2828
use rustc_privacy;
29-
use rustc_resolve::{MakeGlobMap, Resolver, ResolverArenas};
29+
use rustc_resolve::{Resolver, ResolverArenas};
3030
use rustc_traits;
3131
use rustc_typeck as typeck;
3232
use syntax::{self, ast, attr, diagnostics, visit};
@@ -179,7 +179,6 @@ pub fn compile_input(
179179
registry,
180180
&crate_name,
181181
addl_plugins,
182-
control.make_glob_map,
183182
|expanded_crate| {
184183
let mut state = CompileState::state_after_expand(
185184
input,
@@ -394,7 +393,6 @@ pub struct CompileController<'a> {
394393

395394
// FIXME we probably want to group the below options together and offer a
396395
// better API, rather than this ad-hoc approach.
397-
pub make_glob_map: MakeGlobMap,
398396
// Whether the compiler should keep the ast beyond parsing.
399397
pub keep_ast: bool,
400398
// -Zcontinue-parse-after-error
@@ -417,7 +415,6 @@ impl<'a> CompileController<'a> {
417415
after_hir_lowering: PhaseController::basic(),
418416
after_analysis: PhaseController::basic(),
419417
compilation_done: PhaseController::basic(),
420-
make_glob_map: MakeGlobMap::No,
421418
keep_ast: false,
422419
continue_parse_after_error: false,
423420
provide: box |_| {},
@@ -739,7 +736,6 @@ pub fn phase_2_configure_and_expand<F>(
739736
registry: Option<Registry>,
740737
crate_name: &str,
741738
addl_plugins: Option<Vec<String>>,
742-
make_glob_map: MakeGlobMap,
743739
after_expand: F,
744740
) -> Result<ExpansionResult, CompileIncomplete>
745741
where
@@ -759,7 +755,6 @@ where
759755
registry,
760756
crate_name,
761757
addl_plugins,
762-
make_glob_map,
763758
&resolver_arenas,
764759
&mut crate_loader,
765760
after_expand,
@@ -785,11 +780,7 @@ where
785780
},
786781

787782
analysis: ty::CrateAnalysis {
788-
glob_map: if resolver.make_glob_map {
789-
Some(resolver.glob_map)
790-
} else {
791-
None
792-
},
783+
glob_map: resolver.glob_map
793784
},
794785
}),
795786
Err(x) => Err(x),
@@ -805,7 +796,6 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(
805796
registry: Option<Registry>,
806797
crate_name: &str,
807798
addl_plugins: Option<Vec<String>>,
808-
make_glob_map: MakeGlobMap,
809799
resolver_arenas: &'a ResolverArenas<'a>,
810800
crate_loader: &'a mut CrateLoader<'a>,
811801
after_expand: F,
@@ -937,7 +927,6 @@ where
937927
cstore,
938928
&krate,
939929
crate_name,
940-
make_glob_map,
941930
crate_loader,
942931
&resolver_arenas,
943932
);

src/librustc_driver/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ extern crate syntax_pos;
5757
use driver::CompileController;
5858
use pretty::{PpMode, UserIdentifiedItem};
5959

60-
use rustc_resolve as resolve;
6160
use rustc_save_analysis as save;
6261
use rustc_save_analysis::DumpHandler;
6362
use rustc_data_structures::sync::{self, Lrc, Ordering::SeqCst};
@@ -950,7 +949,6 @@ pub fn enable_save_analysis(control: &mut CompileController) {
950949
});
951950
};
952951
control.after_analysis.run_callback_on_error = true;
953-
control.make_glob_map = resolve::MakeGlobMap::Yes;
954952
}
955953

956954
impl RustcDefaultCalls {

src/librustc_driver/test.rs

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
1818
use rustc_data_structures::sync::{self, Lrc};
1919
use rustc_lint;
2020
use rustc_metadata::cstore::CStore;
21-
use rustc_resolve::MakeGlobMap;
2221
use rustc_target::spec::abi::Abi;
2322
use syntax;
2423
use syntax::ast;
@@ -134,7 +133,6 @@ fn test_env_with_pool<F>(
134133
None,
135134
"test",
136135
None,
137-
MakeGlobMap::No,
138136
|_| Ok(()),
139137
).expect("phase 2 aborted")
140138
};

src/librustc_resolve/lib.rs

+7-16
Original file line numberDiff line numberDiff line change
@@ -1536,9 +1536,7 @@ pub struct Resolver<'a> {
15361536
extern_module_map: FxHashMap<(DefId, bool /* MacrosOnly? */), Module<'a>>,
15371537
binding_parent_modules: FxHashMap<PtrKey<'a, NameBinding<'a>>, Module<'a>>,
15381538

1539-
pub make_glob_map: bool,
1540-
/// Maps imports to the names of items actually imported (this actually maps
1541-
/// all imports, but only glob imports are actually interesting).
1539+
/// Maps glob imports to the names of items actually imported.
15421540
pub glob_map: GlobMap,
15431541

15441542
used_imports: FxHashSet<(NodeId, Namespace)>,
@@ -1785,7 +1783,6 @@ impl<'a> Resolver<'a> {
17851783
cstore: &'a CStore,
17861784
krate: &Crate,
17871785
crate_name: &str,
1788-
make_glob_map: MakeGlobMap,
17891786
crate_loader: &'a mut CrateLoader<'a>,
17901787
arenas: &'a ResolverArenas<'a>)
17911788
-> Resolver<'a> {
@@ -1869,7 +1866,6 @@ impl<'a> Resolver<'a> {
18691866
extern_module_map: FxHashMap::default(),
18701867
binding_parent_modules: FxHashMap::default(),
18711868

1872-
make_glob_map: make_glob_map == MakeGlobMap::Yes,
18731869
glob_map: Default::default(),
18741870

18751871
used_imports: FxHashSet::default(),
@@ -1979,14 +1975,15 @@ impl<'a> Resolver<'a> {
19791975
used.set(true);
19801976
directive.used.set(true);
19811977
self.used_imports.insert((directive.id, ns));
1982-
self.add_to_glob_map(directive.id, ident);
1978+
self.add_to_glob_map(&directive, ident);
19831979
self.record_use(ident, ns, binding, false);
19841980
}
19851981
}
19861982

1987-
fn add_to_glob_map(&mut self, id: NodeId, ident: Ident) {
1988-
if self.make_glob_map {
1989-
self.glob_map.entry(id).or_default().insert(ident.name);
1983+
#[inline]
1984+
fn add_to_glob_map(&mut self, directive: &ImportDirective<'_>, ident: Ident) {
1985+
if directive.is_glob() {
1986+
self.glob_map.entry(directive.id).or_default().insert(ident.name);
19901987
}
19911988
}
19921989

@@ -4551,7 +4548,7 @@ impl<'a> Resolver<'a> {
45514548
let import_id = match binding.kind {
45524549
NameBindingKind::Import { directive, .. } => {
45534550
self.maybe_unused_trait_imports.insert(directive.id);
4554-
self.add_to_glob_map(directive.id, trait_name);
4551+
self.add_to_glob_map(&directive, trait_name);
45554552
Some(directive.id)
45564553
}
45574554
_ => None,
@@ -5255,12 +5252,6 @@ fn err_path_resolution() -> PathResolution {
52555252
PathResolution::new(Def::Err)
52565253
}
52575254

5258-
#[derive(PartialEq,Copy, Clone)]
5259-
pub enum MakeGlobMap {
5260-
Yes,
5261-
No,
5262-
}
5263-
52645255
#[derive(Copy, Clone, Debug)]
52655256
enum CrateLint {
52665257
/// Do not issue the lint

src/librustc_save_analysis/dump_visitor.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,6 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
12391239

12401240
// Make a comma-separated list of names of imported modules.
12411241
let glob_map = &self.save_ctxt.analysis.glob_map;
1242-
let glob_map = glob_map.as_ref().unwrap();
12431242
let names = if glob_map.contains_key(&id) {
12441243
glob_map.get(&id).unwrap().iter().map(|n| n.to_string()).collect()
12451244
} else {

src/librustc_save_analysis/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1122,8 +1122,6 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
11221122
mut handler: H,
11231123
) {
11241124
tcx.dep_graph.with_ignore(|| {
1125-
assert!(analysis.glob_map.is_some());
1126-
11271125
info!("Dumping crate {}", cratename);
11281126

11291127
let save_ctxt = SaveContext {

src/librustdoc/core.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,6 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
451451
None,
452452
&name,
453453
None,
454-
resolve::MakeGlobMap::No,
455454
&resolver_arenas,
456455
&mut crate_loader,
457456
|_| Ok(()));
@@ -476,7 +475,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
476475
}).collect(),
477476
};
478477
let analysis = ty::CrateAnalysis {
479-
glob_map: if resolver.make_glob_map { Some(resolver.glob_map.clone()) } else { None },
478+
glob_map: resolver.glob_map.clone(),
480479
};
481480

482481
let mut arenas = AllArenas::new();

src/librustdoc/test.rs

-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc_driver::{self, driver, target_features, Compilation};
66
use rustc_driver::driver::phase_2_configure_and_expand;
77
use rustc_metadata::cstore::CStore;
88
use rustc_metadata::dynamic_lib::DynamicLibrary;
9-
use rustc_resolve::MakeGlobMap;
109
use rustc::hir;
1110
use rustc::hir::intravisit;
1211
use rustc::session::{self, CompileIncomplete, config};
@@ -100,7 +99,6 @@ pub fn run(mut options: Options) -> isize {
10099
None,
101100
"rustdoc-test",
102101
None,
103-
MakeGlobMap::No,
104102
|_| Ok(()),
105103
).expect("phase_2_configure_and_expand aborted in rustdoc!")
106104
};

0 commit comments

Comments
 (0)