Skip to content

Commit 5aec365

Browse files
Store concrete crate stores where possible
1 parent eb0bc64 commit 5aec365

File tree

19 files changed

+101
-105
lines changed

19 files changed

+101
-105
lines changed

src/Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -2451,6 +2451,7 @@ dependencies = [
24512451
"rustc 0.0.0",
24522452
"rustc_data_structures 0.0.0",
24532453
"rustc_errors 0.0.0",
2454+
"rustc_metadata 0.0.0",
24542455
"syntax 0.0.0",
24552456
"syntax_pos 0.0.0",
24562457
]

src/librustc/middle/cstore.rs

+1-21
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
use hir::def;
2626
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
2727
use hir::map as hir_map;
28-
use hir::map::definitions::{Definitions, DefKey, DefPathTable};
28+
use hir::map::definitions::{DefKey, DefPathTable};
2929
use hir::svh::Svh;
3030
use ty::{self, TyCtxt};
3131
use session::{Session, CrateDisambiguator};
@@ -259,26 +259,6 @@ pub trait CrateStore {
259259

260260
pub type CrateStoreDyn = dyn CrateStore + sync::Sync;
261261

262-
pub trait CrateLoader {
263-
fn process_extern_crate(&mut self, item: &ast::Item, defs: &Definitions) -> CrateNum;
264-
265-
fn process_path_extern(
266-
&mut self,
267-
name: Symbol,
268-
span: Span,
269-
) -> CrateNum;
270-
271-
fn process_use_extern(
272-
&mut self,
273-
name: Symbol,
274-
span: Span,
275-
id: ast::NodeId,
276-
defs: &Definitions,
277-
) -> CrateNum;
278-
279-
fn postprocess(&mut self, krate: &ast::Crate);
280-
}
281-
282262
// This method is used when generating the command line to pass through to
283263
// system linker. The linker expects undefined symbols on the left of the
284264
// command line to be defined in libraries on the right, not the other way

src/librustc_driver/driver.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use rustc::session::config::{self, Input, OutputFilenames, OutputType};
2020
use rustc::session::search_paths::PathKind;
2121
use rustc::lint;
2222
use rustc::middle::{self, reachable, resolve_lifetime, stability};
23-
use rustc::middle::cstore::CrateStoreDyn;
2423
use rustc::middle::privacy::AccessLevels;
2524
use rustc::ty::{self, AllArenas, Resolutions, TyCtxt};
2625
use rustc::traits;
@@ -484,7 +483,7 @@ impl<'a> ::CompilerCalls<'a> for CompileController<'a> {
484483
codegen_backend: &dyn (::CodegenBackend),
485484
matches: &::getopts::Matches,
486485
sess: &Session,
487-
cstore: &dyn (::CrateStore),
486+
cstore: &CStore,
488487
input: &Input,
489488
odir: &Option<PathBuf>,
490489
ofile: &Option<PathBuf>,
@@ -728,9 +727,9 @@ pub struct ExpansionResult {
728727
pub hir_forest: hir_map::Forest,
729728
}
730729

731-
pub struct InnerExpansionResult<'a> {
730+
pub struct InnerExpansionResult<'a, 'b: 'a> {
732731
pub expanded_crate: ast::Crate,
733-
pub resolver: Resolver<'a>,
732+
pub resolver: Resolver<'a, 'b>,
734733
pub hir_forest: hir_map::Forest,
735734
}
736735

@@ -806,7 +805,7 @@ where
806805

807806
/// Same as phase_2_configure_and_expand, but doesn't let you keep the resolver
808807
/// around
809-
pub fn phase_2_configure_and_expand_inner<'a, F>(
808+
pub fn phase_2_configure_and_expand_inner<'a, 'b: 'a, F>(
810809
sess: &'a Session,
811810
cstore: &'a CStore,
812811
mut krate: ast::Crate,
@@ -815,9 +814,9 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(
815814
addl_plugins: Option<Vec<String>>,
816815
make_glob_map: MakeGlobMap,
817816
resolver_arenas: &'a ResolverArenas<'a>,
818-
crate_loader: &'a mut CrateLoader,
817+
crate_loader: &'a mut CrateLoader<'b>,
819818
after_expand: F,
820-
) -> Result<InnerExpansionResult<'a>, CompileIncomplete>
819+
) -> Result<InnerExpansionResult<'a, 'b>, CompileIncomplete>
821820
where
822821
F: FnOnce(&ast::Crate) -> CompileResult,
823822
{
@@ -1209,7 +1208,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(
12091208
codegen_backend: &dyn CodegenBackend,
12101209
control: &CompileController,
12111210
sess: &'tcx Session,
1212-
cstore: &'tcx CrateStoreDyn,
1211+
cstore: &'tcx CStore,
12131212
hir_map: hir_map::Map<'tcx>,
12141213
mut analysis: ty::CrateAnalysis,
12151214
resolutions: Resolutions,

src/librustc_driver/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ pub trait CompilerCalls<'a> {
676676
_: &dyn CodegenBackend,
677677
_: &getopts::Matches,
678678
_: &Session,
679-
_: &dyn CrateStore,
679+
_: &CStore,
680680
_: &Input,
681681
_: &Option<PathBuf>,
682682
_: &Option<PathBuf>)
@@ -884,7 +884,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
884884
codegen_backend: &dyn CodegenBackend,
885885
matches: &getopts::Matches,
886886
sess: &Session,
887-
cstore: &dyn CrateStore,
887+
cstore: &CStore,
888888
input: &Input,
889889
odir: &Option<PathBuf>,
890890
ofile: &Option<PathBuf>)
@@ -990,7 +990,7 @@ pub fn enable_save_analysis(control: &mut CompileController) {
990990

991991
impl RustcDefaultCalls {
992992
pub fn list_metadata(sess: &Session,
993-
cstore: &dyn CrateStore,
993+
cstore: &CStore,
994994
matches: &getopts::Matches,
995995
input: &Input)
996996
-> Compilation {

src/librustc_driver/pretty.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ use {abort_on_err, driver};
2020
use rustc::ty::{self, TyCtxt, Resolutions, AllArenas};
2121
use rustc::cfg;
2222
use rustc::cfg::graphviz::LabelledCFG;
23-
use rustc::middle::cstore::CrateStoreDyn;
2423
use rustc::session::Session;
2524
use rustc::session::config::{Input, OutputFilenames};
2625
use rustc_borrowck as borrowck;
2726
use rustc_borrowck::graphviz as borrowck_dot;
27+
use rustc_metadata::cstore::CStore;
2828

2929
use rustc_mir::util::{write_mir_pretty, write_mir_graphviz};
3030

@@ -199,7 +199,7 @@ impl PpSourceMode {
199199
}
200200
fn call_with_pp_support_hir<'tcx, A, F>(&self,
201201
sess: &'tcx Session,
202-
cstore: &'tcx CrateStoreDyn,
202+
cstore: &'tcx CStore,
203203
hir_map: &hir_map::Map<'tcx>,
204204
analysis: &ty::CrateAnalysis,
205205
resolutions: &Resolutions,
@@ -918,7 +918,7 @@ pub fn print_after_parsing(sess: &Session,
918918
}
919919

920920
pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
921-
cstore: &'tcx CrateStoreDyn,
921+
cstore: &'tcx CStore,
922922
hir_map: &hir_map::Map<'tcx>,
923923
analysis: &ty::CrateAnalysis,
924924
resolutions: &Resolutions,
@@ -1074,7 +1074,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
10741074
// with a different callback than the standard driver, so that isn't easy.
10751075
// Instead, we call that function ourselves.
10761076
fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
1077-
cstore: &'a CrateStoreDyn,
1077+
cstore: &'a CStore,
10781078
hir_map: &hir_map::Map<'tcx>,
10791079
analysis: &ty::CrateAnalysis,
10801080
resolutions: &Resolutions,

src/librustc_metadata/creader.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use rustc::session::{Session, CrateDisambiguator};
2424
use rustc::session::config::{Sanitizer, self};
2525
use rustc_target::spec::{PanicStrategy, TargetTriple};
2626
use rustc::session::search_paths::PathKind;
27-
use rustc::middle;
2827
use rustc::middle::cstore::{ExternCrate, ExternCrateSource};
2928
use rustc::util::common::record_time;
3029
use rustc::util::nodemap::FxHashSet;
@@ -1058,8 +1057,8 @@ impl<'a> CrateLoader<'a> {
10581057
}
10591058
}
10601059

1061-
impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
1062-
fn postprocess(&mut self, krate: &ast::Crate) {
1060+
impl<'a> CrateLoader<'a> {
1061+
pub fn postprocess(&mut self, krate: &ast::Crate) {
10631062
// inject the sanitizer runtime before the allocator runtime because all
10641063
// sanitizers force the use of the `alloc_system` allocator
10651064
self.inject_sanitizer_runtime();
@@ -1072,7 +1071,9 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
10721071
}
10731072
}
10741073

1075-
fn process_extern_crate(&mut self, item: &ast::Item, definitions: &Definitions) -> CrateNum {
1074+
pub fn process_extern_crate(
1075+
&mut self, item: &ast::Item, definitions: &Definitions,
1076+
) -> CrateNum {
10761077
match item.node {
10771078
ast::ItemKind::ExternCrate(orig_name) => {
10781079
debug!("resolving extern crate stmt. ident: {} orig_name: {:?}",
@@ -1115,7 +1116,7 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
11151116
}
11161117
}
11171118

1118-
fn process_path_extern(
1119+
pub fn process_path_extern(
11191120
&mut self,
11201121
name: Symbol,
11211122
span: Span,
@@ -1139,7 +1140,7 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
11391140
cnum
11401141
}
11411142

1142-
fn process_use_extern(
1143+
pub fn process_use_extern(
11431144
&mut self,
11441145
name: Symbol,
11451146
span: Span,

src/librustc_resolve/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ arena = { path = "../libarena" }
1717
rustc_errors = { path = "../librustc_errors" }
1818
syntax_pos = { path = "../libsyntax_pos" }
1919
rustc_data_structures = { path = "../librustc_data_structures" }
20+
rustc_metadata = { path = "../librustc_metadata" }

src/librustc_resolve/build_reduced_graph.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use rustc::middle::cstore::LoadedMacro;
2525
use rustc::hir::def::*;
2626
use rustc::hir::def_id::{BUILTIN_MACROS_CRATE, CRATE_DEF_INDEX, LOCAL_CRATE, DefId};
2727
use rustc::ty;
28+
use rustc::middle::cstore::CrateStore;
2829

2930
use std::cell::Cell;
3031
use rustc_data_structures::sync::Lrc;
@@ -86,7 +87,7 @@ struct LegacyMacroImports {
8687
imports: Vec<(Name, Span)>,
8788
}
8889

89-
impl<'a> Resolver<'a> {
90+
impl<'a, 'cl> Resolver<'a, 'cl> {
9091
/// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined;
9192
/// otherwise, reports an error.
9293
pub fn define<T>(&mut self, parent: Module<'a>, ident: Ident, ns: Namespace, def: T)
@@ -776,13 +777,13 @@ impl<'a> Resolver<'a> {
776777
}
777778
}
778779

779-
pub struct BuildReducedGraphVisitor<'a, 'b: 'a> {
780-
pub resolver: &'a mut Resolver<'b>,
780+
pub struct BuildReducedGraphVisitor<'a, 'b: 'a, 'c: 'b> {
781+
pub resolver: &'a mut Resolver<'b, 'c>,
781782
pub legacy_scope: LegacyScope<'b>,
782783
pub expansion: Mark,
783784
}
784785

785-
impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
786+
impl<'a, 'b, 'cl> BuildReducedGraphVisitor<'a, 'b, 'cl> {
786787
fn visit_invoc(&mut self, id: ast::NodeId) -> &'b InvocationData<'b> {
787788
let mark = id.placeholder_to_mark();
788789
self.resolver.current_module.unresolved_invocations.borrow_mut().insert(mark);
@@ -806,7 +807,7 @@ macro_rules! method {
806807
}
807808
}
808809

809-
impl<'a, 'b> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b> {
810+
impl<'a, 'b, 'cl> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b, 'cl> {
810811
method!(visit_impl_item: ast::ImplItem, ast::ImplItemKind::Macro, walk_impl_item);
811812
method!(visit_expr: ast::Expr, ast::ExprKind::Mac, walk_expr);
812813
method!(visit_pat: ast::Pat, ast::PatKind::Mac, walk_pat);

src/librustc_resolve/check_unused.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,30 @@ use syntax::visit::{self, Visitor};
3131
use syntax_pos::{Span, MultiSpan, DUMMY_SP};
3232

3333

34-
struct UnusedImportCheckVisitor<'a, 'b: 'a> {
35-
resolver: &'a mut Resolver<'b>,
34+
struct UnusedImportCheckVisitor<'a, 'b: 'a, 'd: 'b> {
35+
resolver: &'a mut Resolver<'b, 'd>,
3636
/// All the (so far) unused imports, grouped path list
3737
unused_imports: NodeMap<NodeMap<Span>>,
3838
base_id: ast::NodeId,
3939
item_span: Span,
4040
}
4141

4242
// Deref and DerefMut impls allow treating UnusedImportCheckVisitor as Resolver.
43-
impl<'a, 'b> Deref for UnusedImportCheckVisitor<'a, 'b> {
44-
type Target = Resolver<'b>;
43+
impl<'a, 'b, 'd> Deref for UnusedImportCheckVisitor<'a, 'b, 'd> {
44+
type Target = Resolver<'b, 'd>;
4545

46-
fn deref<'c>(&'c self) -> &'c Resolver<'b> {
46+
fn deref<'c>(&'c self) -> &'c Resolver<'b, 'd> {
4747
&*self.resolver
4848
}
4949
}
5050

51-
impl<'a, 'b> DerefMut for UnusedImportCheckVisitor<'a, 'b> {
52-
fn deref_mut<'c>(&'c mut self) -> &'c mut Resolver<'b> {
51+
impl<'a, 'b, 'd> DerefMut for UnusedImportCheckVisitor<'a, 'b, 'd> {
52+
fn deref_mut<'c>(&'c mut self) -> &'c mut Resolver<'b, 'd> {
5353
&mut *self.resolver
5454
}
5555
}
5656

57-
impl<'a, 'b> UnusedImportCheckVisitor<'a, 'b> {
57+
impl<'a, 'b, 'd> UnusedImportCheckVisitor<'a, 'b, 'd> {
5858
// We have information about whether `use` (import) directives are actually
5959
// used now. If an import is not used at all, we signal a lint error.
6060
fn check_import(&mut self, item_id: ast::NodeId, id: ast::NodeId, span: Span) {
@@ -77,7 +77,7 @@ impl<'a, 'b> UnusedImportCheckVisitor<'a, 'b> {
7777
}
7878
}
7979

80-
impl<'a, 'b> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b> {
80+
impl<'a, 'b, 'cl> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b, 'cl> {
8181
fn visit_item(&mut self, item: &'a ast::Item) {
8282
self.item_span = item.span;
8383

0 commit comments

Comments
 (0)