Skip to content

Commit 59c1cac

Browse files
committed
Auto merge of #57392 - Xanewok:always-calc-glob-map, r=petrochenkov
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. Main motivation is to get rid of some of the moving pieces and simplify the compilation interface - this would allow us to entirely remove `CrateAnalysis`. Later, we could easily expose a relevant query, similar to the likes of `maybe_unused_trait_import` (so using precomputed data from the resolver, but which could be rewritten to be on-demand). r? @nikomatsakis Local perf run showed mostly noise (except `ctfe-stress-*`) but I'd appreciate if we could do a perf run run here and double-check that this won't regress performance.
2 parents ceb2512 + b1b64bd commit 59c1cac

File tree

11 files changed

+14
-44
lines changed

11 files changed

+14
-44
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
@@ -1546,9 +1546,7 @@ pub struct Resolver<'a> {
15461546
extern_module_map: FxHashMap<(DefId, bool /* MacrosOnly? */), Module<'a>>,
15471547
binding_parent_modules: FxHashMap<PtrKey<'a, NameBinding<'a>>, Module<'a>>,
15481548

1549-
pub make_glob_map: bool,
1550-
/// Maps imports to the names of items actually imported (this actually maps
1551-
/// all imports, but only glob imports are actually interesting).
1549+
/// Maps glob imports to the names of items actually imported.
15521550
pub glob_map: GlobMap,
15531551

15541552
used_imports: FxHashSet<(NodeId, Namespace)>,
@@ -1795,7 +1793,6 @@ impl<'a> Resolver<'a> {
17951793
cstore: &'a CStore,
17961794
krate: &Crate,
17971795
crate_name: &str,
1798-
make_glob_map: MakeGlobMap,
17991796
crate_loader: &'a mut CrateLoader<'a>,
18001797
arenas: &'a ResolverArenas<'a>)
18011798
-> Resolver<'a> {
@@ -1879,7 +1876,6 @@ impl<'a> Resolver<'a> {
18791876
extern_module_map: FxHashMap::default(),
18801877
binding_parent_modules: FxHashMap::default(),
18811878

1882-
make_glob_map: make_glob_map == MakeGlobMap::Yes,
18831879
glob_map: Default::default(),
18841880

18851881
used_imports: FxHashSet::default(),
@@ -1989,14 +1985,15 @@ impl<'a> Resolver<'a> {
19891985
used.set(true);
19901986
directive.used.set(true);
19911987
self.used_imports.insert((directive.id, ns));
1992-
self.add_to_glob_map(directive.id, ident);
1988+
self.add_to_glob_map(&directive, ident);
19931989
self.record_use(ident, ns, binding, false);
19941990
}
19951991
}
19961992

1997-
fn add_to_glob_map(&mut self, id: NodeId, ident: Ident) {
1998-
if self.make_glob_map {
1999-
self.glob_map.entry(id).or_default().insert(ident.name);
1993+
#[inline]
1994+
fn add_to_glob_map(&mut self, directive: &ImportDirective<'_>, ident: Ident) {
1995+
if directive.is_glob() {
1996+
self.glob_map.entry(directive.id).or_default().insert(ident.name);
20001997
}
20011998
}
20021999

@@ -4598,7 +4595,7 @@ impl<'a> Resolver<'a> {
45984595
let import_id = match binding.kind {
45994596
NameBindingKind::Import { directive, .. } => {
46004597
self.maybe_unused_trait_imports.insert(directive.id);
4601-
self.add_to_glob_map(directive.id, trait_name);
4598+
self.add_to_glob_map(&directive, trait_name);
46024599
Some(directive.id)
46034600
}
46044601
_ => None,
@@ -5305,12 +5302,6 @@ fn err_path_resolution() -> PathResolution {
53055302
PathResolution::new(Def::Err)
53065303
}
53075304

5308-
#[derive(PartialEq,Copy, Clone)]
5309-
pub enum MakeGlobMap {
5310-
Yes,
5311-
No,
5312-
}
5313-
53145305
#[derive(Copy, Clone, Debug)]
53155306
enum CrateLint {
53165307
/// 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
@@ -1127,8 +1127,6 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
11271127
mut handler: H,
11281128
) {
11291129
tcx.dep_graph.with_ignore(|| {
1130-
assert!(analysis.glob_map.is_some());
1131-
11321130
info!("Dumping crate {}", cratename);
11331131

11341132
// Privacy checking requires and is done after type checking; use a

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
};

src/test/rustdoc-ui/failed-doctest-output.stdout

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ error[E0425]: cannot find value `no` in this scope
1212
3 | no
1313
| ^^ not found in this scope
1414

15-
thread '$DIR/failed-doctest-output.rs - OtherStruct (line 17)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:321:13
15+
thread '$DIR/failed-doctest-output.rs - OtherStruct (line 17)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:319:13
1616
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
1717

1818
---- $DIR/failed-doctest-output.rs - SomeStruct (line 11) stdout ----
@@ -21,7 +21,7 @@ thread '$DIR/failed-doctest-output.rs - SomeStruct (line 11)' panicked at 'test
2121
thread 'main' panicked at 'oh no', $DIR/failed-doctest-output.rs:3:1
2222
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
2323

24-
', src/librustdoc/test.rs:356:17
24+
', src/librustdoc/test.rs:354:17
2525

2626

2727
failures:

src/tools/rls

Submodule rls updated from 1a6361b to ae0d89a

0 commit comments

Comments
 (0)