Skip to content

Commit 0a82177

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 68fe518 commit 0a82177

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
@@ -416,7 +414,6 @@ impl<'a> CompileController<'a> {
416414
after_hir_lowering: PhaseController::basic(),
417415
after_analysis: PhaseController::basic(),
418416
compilation_done: PhaseController::basic(),
419-
make_glob_map: MakeGlobMap::No,
420417
keep_ast: false,
421418
continue_parse_after_error: false,
422419
provide: box |_| {},
@@ -738,7 +735,6 @@ pub fn phase_2_configure_and_expand<F>(
738735
registry: Option<Registry>,
739736
crate_name: &str,
740737
addl_plugins: Option<Vec<String>>,
741-
make_glob_map: MakeGlobMap,
742738
after_expand: F,
743739
) -> Result<ExpansionResult, CompileIncomplete>
744740
where
@@ -758,7 +754,6 @@ where
758754
registry,
759755
crate_name,
760756
addl_plugins,
761-
make_glob_map,
762757
&resolver_arenas,
763758
&mut crate_loader,
764759
after_expand,
@@ -784,11 +779,7 @@ where
784779
},
785780

786781
analysis: ty::CrateAnalysis {
787-
glob_map: if resolver.make_glob_map {
788-
Some(resolver.glob_map)
789-
} else {
790-
None
791-
},
782+
glob_map: resolver.glob_map
792783
},
793784
}),
794785
Err(x) => Err(x),
@@ -804,7 +795,6 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(
804795
registry: Option<Registry>,
805796
crate_name: &str,
806797
addl_plugins: Option<Vec<String>>,
807-
make_glob_map: MakeGlobMap,
808798
resolver_arenas: &'a ResolverArenas<'a>,
809799
crate_loader: &'a mut CrateLoader<'a>,
810800
after_expand: F,
@@ -936,7 +926,6 @@ where
936926
cstore,
937927
&krate,
938928
crate_name,
939-
make_glob_map,
940929
crate_loader,
941930
&resolver_arenas,
942931
);

src/librustc_driver/lib.rs

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

59-
use rustc_resolve as resolve;
6059
use rustc_save_analysis as save;
6160
use rustc_save_analysis::DumpHandler;
6261
use rustc_data_structures::sync::{self, Lrc};
@@ -954,7 +953,6 @@ pub fn enable_save_analysis(control: &mut CompileController) {
954953
});
955954
};
956955
control.after_analysis.run_callback_on_error = true;
957-
control.make_glob_map = resolve::MakeGlobMap::Yes;
958956
}
959957

960958
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

@@ -4528,7 +4525,7 @@ impl<'a> Resolver<'a> {
45284525
let import_id = match binding.kind {
45294526
NameBindingKind::Import { directive, .. } => {
45304527
self.maybe_unused_trait_imports.insert(directive.id);
4531-
self.add_to_glob_map(directive.id, trait_name);
4528+
self.add_to_glob_map(&directive, trait_name);
45324529
Some(directive.id)
45334530
}
45344531
_ => None,
@@ -5232,12 +5229,6 @@ fn err_path_resolution() -> PathResolution {
52325229
PathResolution::new(Def::Err)
52335230
}
52345231

5235-
#[derive(PartialEq,Copy, Clone)]
5236-
pub enum MakeGlobMap {
5237-
Yes,
5238-
No,
5239-
}
5240-
52415232
#[derive(Copy, Clone, Debug)]
52425233
enum CrateLint {
52435234
/// 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)