Skip to content

Commit 424f6bd

Browse files
Store concrete crate stores where possible
1 parent d148b41 commit 424f6bd

File tree

19 files changed

+101
-105
lines changed

19 files changed

+101
-105
lines changed

src/Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,6 +2338,7 @@ dependencies = [
23382338
"rustc 0.0.0",
23392339
"rustc_data_structures 0.0.0",
23402340
"rustc_errors 0.0.0",
2341+
"rustc_metadata 0.0.0",
23412342
"syntax 0.0.0",
23422343
"syntax_pos 0.0.0",
23432344
]

src/librustc/middle/cstore.rs

Lines changed: 1 addition & 21 deletions
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

Lines changed: 7 additions & 8 deletions
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;
@@ -475,7 +474,7 @@ impl<'a> ::CompilerCalls<'a> for CompileController<'a> {
475474
codegen_backend: &dyn (::CodegenBackend),
476475
matches: &::getopts::Matches,
477476
sess: &Session,
478-
cstore: &dyn (::CrateStore),
477+
cstore: &CStore,
479478
input: &Input,
480479
odir: &Option<PathBuf>,
481480
ofile: &Option<PathBuf>,
@@ -717,9 +716,9 @@ pub struct ExpansionResult {
717716
pub hir_forest: hir_map::Forest,
718717
}
719718

720-
pub struct InnerExpansionResult<'a> {
719+
pub struct InnerExpansionResult<'a, 'b: 'a> {
721720
pub expanded_crate: ast::Crate,
722-
pub resolver: Resolver<'a>,
721+
pub resolver: Resolver<'a, 'b>,
723722
pub hir_forest: hir_map::Forest,
724723
}
725724

@@ -795,7 +794,7 @@ where
795794

796795
/// Same as phase_2_configure_and_expand, but doesn't let you keep the resolver
797796
/// around
798-
pub fn phase_2_configure_and_expand_inner<'a, F>(
797+
pub fn phase_2_configure_and_expand_inner<'a, 'b: 'a, F>(
799798
sess: &'a Session,
800799
cstore: &'a CStore,
801800
mut krate: ast::Crate,
@@ -804,9 +803,9 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(
804803
addl_plugins: Option<Vec<String>>,
805804
make_glob_map: MakeGlobMap,
806805
resolver_arenas: &'a ResolverArenas<'a>,
807-
crate_loader: &'a mut CrateLoader,
806+
crate_loader: &'a mut CrateLoader<'b>,
808807
after_expand: F,
809-
) -> Result<InnerExpansionResult<'a>, CompileIncomplete>
808+
) -> Result<InnerExpansionResult<'a, 'b>, CompileIncomplete>
810809
where
811810
F: FnOnce(&ast::Crate) -> CompileResult,
812811
{
@@ -1196,7 +1195,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(
11961195
codegen_backend: &dyn CodegenBackend,
11971196
control: &CompileController,
11981197
sess: &'tcx Session,
1199-
cstore: &'tcx CrateStoreDyn,
1198+
cstore: &'tcx CStore,
12001199
hir_map: hir_map::Map<'tcx>,
12011200
mut analysis: ty::CrateAnalysis,
12021201
resolutions: Resolutions,

src/librustc_driver/lib.rs

Lines changed: 3 additions & 3 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 7 additions & 6 deletions
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;
@@ -1056,8 +1055,8 @@ impl<'a> CrateLoader<'a> {
10561055
}
10571056
}
10581057

1059-
impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
1060-
fn postprocess(&mut self, krate: &ast::Crate) {
1058+
impl<'a> CrateLoader<'a> {
1059+
pub fn postprocess(&mut self, krate: &ast::Crate) {
10611060
// inject the sanitizer runtime before the allocator runtime because all
10621061
// sanitizers force the use of the `alloc_system` allocator
10631062
self.inject_sanitizer_runtime();
@@ -1070,7 +1069,9 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
10701069
}
10711070
}
10721071

1073-
fn process_extern_crate(&mut self, item: &ast::Item, definitions: &Definitions) -> CrateNum {
1072+
pub fn process_extern_crate(
1073+
&mut self, item: &ast::Item, definitions: &Definitions,
1074+
) -> CrateNum {
10741075
match item.node {
10751076
ast::ItemKind::ExternCrate(orig_name) => {
10761077
debug!("resolving extern crate stmt. ident: {} orig_name: {:?}",
@@ -1113,7 +1114,7 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
11131114
}
11141115
}
11151116

1116-
fn process_path_extern(
1117+
pub fn process_path_extern(
11171118
&mut self,
11181119
name: Symbol,
11191120
span: Span,
@@ -1137,7 +1138,7 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
11371138
cnum
11381139
}
11391140

1140-
fn process_use_extern(
1141+
pub fn process_use_extern(
11411142
&mut self,
11421143
name: Symbol,
11431144
span: Span,

src/librustc_resolve/Cargo.toml

Lines changed: 1 addition & 0 deletions
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

Lines changed: 6 additions & 5 deletions
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;
@@ -73,7 +74,7 @@ struct LegacyMacroImports {
7374
imports: Vec<(Name, Span)>,
7475
}
7576

76-
impl<'a> Resolver<'a> {
77+
impl<'a, 'cl> Resolver<'a, 'cl> {
7778
/// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined;
7879
/// otherwise, reports an error.
7980
pub fn define<T>(&mut self, parent: Module<'a>, ident: Ident, ns: Namespace, def: T)
@@ -762,13 +763,13 @@ impl<'a> Resolver<'a> {
762763
}
763764
}
764765

765-
pub struct BuildReducedGraphVisitor<'a, 'b: 'a> {
766-
pub resolver: &'a mut Resolver<'b>,
766+
pub struct BuildReducedGraphVisitor<'a, 'b: 'a, 'c: 'b> {
767+
pub resolver: &'a mut Resolver<'b, 'c>,
767768
pub legacy_scope: LegacyScope<'b>,
768769
pub expansion: Mark,
769770
}
770771

771-
impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
772+
impl<'a, 'b, 'cl> BuildReducedGraphVisitor<'a, 'b, 'cl> {
772773
fn visit_invoc(&mut self, id: ast::NodeId) -> &'b InvocationData<'b> {
773774
let mark = id.placeholder_to_mark();
774775
self.resolver.current_module.unresolved_invocations.borrow_mut().insert(mark);
@@ -791,7 +792,7 @@ macro_rules! method {
791792
}
792793
}
793794

794-
impl<'a, 'b> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b> {
795+
impl<'a, 'b, 'cl> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b, 'cl> {
795796
method!(visit_impl_item: ast::ImplItem, ast::ImplItemKind::Macro, walk_impl_item);
796797
method!(visit_expr: ast::Expr, ast::ExprKind::Mac, walk_expr);
797798
method!(visit_pat: ast::Pat, ast::PatKind::Mac, walk_pat);

src/librustc_resolve/check_unused.rs

Lines changed: 9 additions & 9 deletions
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)