Store concrete crate stores where possible

This commit is contained in:
Mark Rousskov 2018-07-31 15:23:31 -06:00
parent eb0bc64265
commit 5aec365cb9
19 changed files with 101 additions and 105 deletions

View File

@ -2451,6 +2451,7 @@ dependencies = [
"rustc 0.0.0", "rustc 0.0.0",
"rustc_data_structures 0.0.0", "rustc_data_structures 0.0.0",
"rustc_errors 0.0.0", "rustc_errors 0.0.0",
"rustc_metadata 0.0.0",
"syntax 0.0.0", "syntax 0.0.0",
"syntax_pos 0.0.0", "syntax_pos 0.0.0",
] ]

View File

@ -25,7 +25,7 @@
use hir::def; use hir::def;
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use hir::map as hir_map; use hir::map as hir_map;
use hir::map::definitions::{Definitions, DefKey, DefPathTable}; use hir::map::definitions::{DefKey, DefPathTable};
use hir::svh::Svh; use hir::svh::Svh;
use ty::{self, TyCtxt}; use ty::{self, TyCtxt};
use session::{Session, CrateDisambiguator}; use session::{Session, CrateDisambiguator};
@ -259,26 +259,6 @@ pub trait CrateStore {
pub type CrateStoreDyn = dyn CrateStore + sync::Sync; pub type CrateStoreDyn = dyn CrateStore + sync::Sync;
pub trait CrateLoader {
fn process_extern_crate(&mut self, item: &ast::Item, defs: &Definitions) -> CrateNum;
fn process_path_extern(
&mut self,
name: Symbol,
span: Span,
) -> CrateNum;
fn process_use_extern(
&mut self,
name: Symbol,
span: Span,
id: ast::NodeId,
defs: &Definitions,
) -> CrateNum;
fn postprocess(&mut self, krate: &ast::Crate);
}
// This method is used when generating the command line to pass through to // This method is used when generating the command line to pass through to
// system linker. The linker expects undefined symbols on the left of the // system linker. The linker expects undefined symbols on the left of the
// command line to be defined in libraries on the right, not the other way // command line to be defined in libraries on the right, not the other way

View File

@ -20,7 +20,6 @@ use rustc::session::config::{self, Input, OutputFilenames, OutputType};
use rustc::session::search_paths::PathKind; use rustc::session::search_paths::PathKind;
use rustc::lint; use rustc::lint;
use rustc::middle::{self, reachable, resolve_lifetime, stability}; use rustc::middle::{self, reachable, resolve_lifetime, stability};
use rustc::middle::cstore::CrateStoreDyn;
use rustc::middle::privacy::AccessLevels; use rustc::middle::privacy::AccessLevels;
use rustc::ty::{self, AllArenas, Resolutions, TyCtxt}; use rustc::ty::{self, AllArenas, Resolutions, TyCtxt};
use rustc::traits; use rustc::traits;
@ -484,7 +483,7 @@ impl<'a> ::CompilerCalls<'a> for CompileController<'a> {
codegen_backend: &dyn (::CodegenBackend), codegen_backend: &dyn (::CodegenBackend),
matches: &::getopts::Matches, matches: &::getopts::Matches,
sess: &Session, sess: &Session,
cstore: &dyn (::CrateStore), cstore: &CStore,
input: &Input, input: &Input,
odir: &Option<PathBuf>, odir: &Option<PathBuf>,
ofile: &Option<PathBuf>, ofile: &Option<PathBuf>,
@ -728,9 +727,9 @@ pub struct ExpansionResult {
pub hir_forest: hir_map::Forest, pub hir_forest: hir_map::Forest,
} }
pub struct InnerExpansionResult<'a> { pub struct InnerExpansionResult<'a, 'b: 'a> {
pub expanded_crate: ast::Crate, pub expanded_crate: ast::Crate,
pub resolver: Resolver<'a>, pub resolver: Resolver<'a, 'b>,
pub hir_forest: hir_map::Forest, pub hir_forest: hir_map::Forest,
} }
@ -806,7 +805,7 @@ where
/// Same as phase_2_configure_and_expand, but doesn't let you keep the resolver /// Same as phase_2_configure_and_expand, but doesn't let you keep the resolver
/// around /// around
pub fn phase_2_configure_and_expand_inner<'a, F>( pub fn phase_2_configure_and_expand_inner<'a, 'b: 'a, F>(
sess: &'a Session, sess: &'a Session,
cstore: &'a CStore, cstore: &'a CStore,
mut krate: ast::Crate, mut krate: ast::Crate,
@ -815,9 +814,9 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(
addl_plugins: Option<Vec<String>>, addl_plugins: Option<Vec<String>>,
make_glob_map: MakeGlobMap, make_glob_map: MakeGlobMap,
resolver_arenas: &'a ResolverArenas<'a>, resolver_arenas: &'a ResolverArenas<'a>,
crate_loader: &'a mut CrateLoader, crate_loader: &'a mut CrateLoader<'b>,
after_expand: F, after_expand: F,
) -> Result<InnerExpansionResult<'a>, CompileIncomplete> ) -> Result<InnerExpansionResult<'a, 'b>, CompileIncomplete>
where where
F: FnOnce(&ast::Crate) -> CompileResult, F: FnOnce(&ast::Crate) -> CompileResult,
{ {
@ -1209,7 +1208,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(
codegen_backend: &dyn CodegenBackend, codegen_backend: &dyn CodegenBackend,
control: &CompileController, control: &CompileController,
sess: &'tcx Session, sess: &'tcx Session,
cstore: &'tcx CrateStoreDyn, cstore: &'tcx CStore,
hir_map: hir_map::Map<'tcx>, hir_map: hir_map::Map<'tcx>,
mut analysis: ty::CrateAnalysis, mut analysis: ty::CrateAnalysis,
resolutions: Resolutions, resolutions: Resolutions,

View File

@ -676,7 +676,7 @@ pub trait CompilerCalls<'a> {
_: &dyn CodegenBackend, _: &dyn CodegenBackend,
_: &getopts::Matches, _: &getopts::Matches,
_: &Session, _: &Session,
_: &dyn CrateStore, _: &CStore,
_: &Input, _: &Input,
_: &Option<PathBuf>, _: &Option<PathBuf>,
_: &Option<PathBuf>) _: &Option<PathBuf>)
@ -884,7 +884,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
codegen_backend: &dyn CodegenBackend, codegen_backend: &dyn CodegenBackend,
matches: &getopts::Matches, matches: &getopts::Matches,
sess: &Session, sess: &Session,
cstore: &dyn CrateStore, cstore: &CStore,
input: &Input, input: &Input,
odir: &Option<PathBuf>, odir: &Option<PathBuf>,
ofile: &Option<PathBuf>) ofile: &Option<PathBuf>)
@ -990,7 +990,7 @@ pub fn enable_save_analysis(control: &mut CompileController) {
impl RustcDefaultCalls { impl RustcDefaultCalls {
pub fn list_metadata(sess: &Session, pub fn list_metadata(sess: &Session,
cstore: &dyn CrateStore, cstore: &CStore,
matches: &getopts::Matches, matches: &getopts::Matches,
input: &Input) input: &Input)
-> Compilation { -> Compilation {

View File

@ -20,11 +20,11 @@ use {abort_on_err, driver};
use rustc::ty::{self, TyCtxt, Resolutions, AllArenas}; use rustc::ty::{self, TyCtxt, Resolutions, AllArenas};
use rustc::cfg; use rustc::cfg;
use rustc::cfg::graphviz::LabelledCFG; use rustc::cfg::graphviz::LabelledCFG;
use rustc::middle::cstore::CrateStoreDyn;
use rustc::session::Session; use rustc::session::Session;
use rustc::session::config::{Input, OutputFilenames}; use rustc::session::config::{Input, OutputFilenames};
use rustc_borrowck as borrowck; use rustc_borrowck as borrowck;
use rustc_borrowck::graphviz as borrowck_dot; use rustc_borrowck::graphviz as borrowck_dot;
use rustc_metadata::cstore::CStore;
use rustc_mir::util::{write_mir_pretty, write_mir_graphviz}; use rustc_mir::util::{write_mir_pretty, write_mir_graphviz};
@ -199,7 +199,7 @@ impl PpSourceMode {
} }
fn call_with_pp_support_hir<'tcx, A, F>(&self, fn call_with_pp_support_hir<'tcx, A, F>(&self,
sess: &'tcx Session, sess: &'tcx Session,
cstore: &'tcx CrateStoreDyn, cstore: &'tcx CStore,
hir_map: &hir_map::Map<'tcx>, hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis, analysis: &ty::CrateAnalysis,
resolutions: &Resolutions, resolutions: &Resolutions,
@ -918,7 +918,7 @@ pub fn print_after_parsing(sess: &Session,
} }
pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session, pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
cstore: &'tcx CrateStoreDyn, cstore: &'tcx CStore,
hir_map: &hir_map::Map<'tcx>, hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis, analysis: &ty::CrateAnalysis,
resolutions: &Resolutions, resolutions: &Resolutions,
@ -1074,7 +1074,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
// with a different callback than the standard driver, so that isn't easy. // with a different callback than the standard driver, so that isn't easy.
// Instead, we call that function ourselves. // Instead, we call that function ourselves.
fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session, fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
cstore: &'a CrateStoreDyn, cstore: &'a CStore,
hir_map: &hir_map::Map<'tcx>, hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis, analysis: &ty::CrateAnalysis,
resolutions: &Resolutions, resolutions: &Resolutions,

View File

@ -24,7 +24,6 @@ use rustc::session::{Session, CrateDisambiguator};
use rustc::session::config::{Sanitizer, self}; use rustc::session::config::{Sanitizer, self};
use rustc_target::spec::{PanicStrategy, TargetTriple}; use rustc_target::spec::{PanicStrategy, TargetTriple};
use rustc::session::search_paths::PathKind; use rustc::session::search_paths::PathKind;
use rustc::middle;
use rustc::middle::cstore::{ExternCrate, ExternCrateSource}; use rustc::middle::cstore::{ExternCrate, ExternCrateSource};
use rustc::util::common::record_time; use rustc::util::common::record_time;
use rustc::util::nodemap::FxHashSet; use rustc::util::nodemap::FxHashSet;
@ -1058,8 +1057,8 @@ impl<'a> CrateLoader<'a> {
} }
} }
impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> { impl<'a> CrateLoader<'a> {
fn postprocess(&mut self, krate: &ast::Crate) { pub fn postprocess(&mut self, krate: &ast::Crate) {
// inject the sanitizer runtime before the allocator runtime because all // inject the sanitizer runtime before the allocator runtime because all
// sanitizers force the use of the `alloc_system` allocator // sanitizers force the use of the `alloc_system` allocator
self.inject_sanitizer_runtime(); self.inject_sanitizer_runtime();
@ -1072,7 +1071,9 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
} }
} }
fn process_extern_crate(&mut self, item: &ast::Item, definitions: &Definitions) -> CrateNum { pub fn process_extern_crate(
&mut self, item: &ast::Item, definitions: &Definitions,
) -> CrateNum {
match item.node { match item.node {
ast::ItemKind::ExternCrate(orig_name) => { ast::ItemKind::ExternCrate(orig_name) => {
debug!("resolving extern crate stmt. ident: {} orig_name: {:?}", debug!("resolving extern crate stmt. ident: {} orig_name: {:?}",
@ -1115,7 +1116,7 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
} }
} }
fn process_path_extern( pub fn process_path_extern(
&mut self, &mut self,
name: Symbol, name: Symbol,
span: Span, span: Span,
@ -1139,7 +1140,7 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
cnum cnum
} }
fn process_use_extern( pub fn process_use_extern(
&mut self, &mut self,
name: Symbol, name: Symbol,
span: Span, span: Span,

View File

@ -17,3 +17,4 @@ arena = { path = "../libarena" }
rustc_errors = { path = "../librustc_errors" } rustc_errors = { path = "../librustc_errors" }
syntax_pos = { path = "../libsyntax_pos" } syntax_pos = { path = "../libsyntax_pos" }
rustc_data_structures = { path = "../librustc_data_structures" } rustc_data_structures = { path = "../librustc_data_structures" }
rustc_metadata = { path = "../librustc_metadata" }

View File

@ -25,6 +25,7 @@ use rustc::middle::cstore::LoadedMacro;
use rustc::hir::def::*; use rustc::hir::def::*;
use rustc::hir::def_id::{BUILTIN_MACROS_CRATE, CRATE_DEF_INDEX, LOCAL_CRATE, DefId}; use rustc::hir::def_id::{BUILTIN_MACROS_CRATE, CRATE_DEF_INDEX, LOCAL_CRATE, DefId};
use rustc::ty; use rustc::ty;
use rustc::middle::cstore::CrateStore;
use std::cell::Cell; use std::cell::Cell;
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
@ -86,7 +87,7 @@ struct LegacyMacroImports {
imports: Vec<(Name, Span)>, imports: Vec<(Name, Span)>,
} }
impl<'a> Resolver<'a> { impl<'a, 'cl> Resolver<'a, 'cl> {
/// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined; /// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined;
/// otherwise, reports an error. /// otherwise, reports an error.
pub fn define<T>(&mut self, parent: Module<'a>, ident: Ident, ns: Namespace, def: T) pub fn define<T>(&mut self, parent: Module<'a>, ident: Ident, ns: Namespace, def: T)
@ -776,13 +777,13 @@ impl<'a> Resolver<'a> {
} }
} }
pub struct BuildReducedGraphVisitor<'a, 'b: 'a> { pub struct BuildReducedGraphVisitor<'a, 'b: 'a, 'c: 'b> {
pub resolver: &'a mut Resolver<'b>, pub resolver: &'a mut Resolver<'b, 'c>,
pub legacy_scope: LegacyScope<'b>, pub legacy_scope: LegacyScope<'b>,
pub expansion: Mark, pub expansion: Mark,
} }
impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { impl<'a, 'b, 'cl> BuildReducedGraphVisitor<'a, 'b, 'cl> {
fn visit_invoc(&mut self, id: ast::NodeId) -> &'b InvocationData<'b> { fn visit_invoc(&mut self, id: ast::NodeId) -> &'b InvocationData<'b> {
let mark = id.placeholder_to_mark(); let mark = id.placeholder_to_mark();
self.resolver.current_module.unresolved_invocations.borrow_mut().insert(mark); self.resolver.current_module.unresolved_invocations.borrow_mut().insert(mark);
@ -806,7 +807,7 @@ macro_rules! method {
} }
} }
impl<'a, 'b> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b> { impl<'a, 'b, 'cl> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b, 'cl> {
method!(visit_impl_item: ast::ImplItem, ast::ImplItemKind::Macro, walk_impl_item); method!(visit_impl_item: ast::ImplItem, ast::ImplItemKind::Macro, walk_impl_item);
method!(visit_expr: ast::Expr, ast::ExprKind::Mac, walk_expr); method!(visit_expr: ast::Expr, ast::ExprKind::Mac, walk_expr);
method!(visit_pat: ast::Pat, ast::PatKind::Mac, walk_pat); method!(visit_pat: ast::Pat, ast::PatKind::Mac, walk_pat);

View File

@ -31,8 +31,8 @@ use syntax::visit::{self, Visitor};
use syntax_pos::{Span, MultiSpan, DUMMY_SP}; use syntax_pos::{Span, MultiSpan, DUMMY_SP};
struct UnusedImportCheckVisitor<'a, 'b: 'a> { struct UnusedImportCheckVisitor<'a, 'b: 'a, 'd: 'b> {
resolver: &'a mut Resolver<'b>, resolver: &'a mut Resolver<'b, 'd>,
/// All the (so far) unused imports, grouped path list /// All the (so far) unused imports, grouped path list
unused_imports: NodeMap<NodeMap<Span>>, unused_imports: NodeMap<NodeMap<Span>>,
base_id: ast::NodeId, base_id: ast::NodeId,
@ -40,21 +40,21 @@ struct UnusedImportCheckVisitor<'a, 'b: 'a> {
} }
// Deref and DerefMut impls allow treating UnusedImportCheckVisitor as Resolver. // Deref and DerefMut impls allow treating UnusedImportCheckVisitor as Resolver.
impl<'a, 'b> Deref for UnusedImportCheckVisitor<'a, 'b> { impl<'a, 'b, 'd> Deref for UnusedImportCheckVisitor<'a, 'b, 'd> {
type Target = Resolver<'b>; type Target = Resolver<'b, 'd>;
fn deref<'c>(&'c self) -> &'c Resolver<'b> { fn deref<'c>(&'c self) -> &'c Resolver<'b, 'd> {
&*self.resolver &*self.resolver
} }
} }
impl<'a, 'b> DerefMut for UnusedImportCheckVisitor<'a, 'b> { impl<'a, 'b, 'd> DerefMut for UnusedImportCheckVisitor<'a, 'b, 'd> {
fn deref_mut<'c>(&'c mut self) -> &'c mut Resolver<'b> { fn deref_mut<'c>(&'c mut self) -> &'c mut Resolver<'b, 'd> {
&mut *self.resolver &mut *self.resolver
} }
} }
impl<'a, 'b> UnusedImportCheckVisitor<'a, 'b> { impl<'a, 'b, 'd> UnusedImportCheckVisitor<'a, 'b, 'd> {
// We have information about whether `use` (import) directives are actually // We have information about whether `use` (import) directives are actually
// used now. If an import is not used at all, we signal a lint error. // used now. If an import is not used at all, we signal a lint error.
fn check_import(&mut self, item_id: ast::NodeId, id: ast::NodeId, span: Span) { fn check_import(&mut self, item_id: ast::NodeId, id: ast::NodeId, span: Span) {
@ -77,7 +77,7 @@ impl<'a, 'b> UnusedImportCheckVisitor<'a, 'b> {
} }
} }
impl<'a, 'b> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b> { impl<'a, 'b, 'cl> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b, 'cl> {
fn visit_item(&mut self, item: &'a ast::Item) { fn visit_item(&mut self, item: &'a ast::Item) {
self.item_span = item.span; self.item_span = item.span;

View File

@ -26,6 +26,7 @@ extern crate arena;
#[macro_use] #[macro_use]
extern crate rustc; extern crate rustc;
extern crate rustc_data_structures; extern crate rustc_data_structures;
extern crate rustc_metadata;
pub use rustc::hir::def::{Namespace, PerNS}; pub use rustc::hir::def::{Namespace, PerNS};
@ -34,7 +35,7 @@ use self::RibKind::*;
use rustc::hir::map::{Definitions, DefCollector}; use rustc::hir::map::{Definitions, DefCollector};
use rustc::hir::{self, PrimTy, TyBool, TyChar, TyFloat, TyInt, TyUint, TyStr}; use rustc::hir::{self, PrimTy, TyBool, TyChar, TyFloat, TyInt, TyUint, TyStr};
use rustc::middle::cstore::{CrateStore, CrateLoader}; use rustc::middle::cstore::CrateStore;
use rustc::session::Session; use rustc::session::Session;
use rustc::lint; use rustc::lint;
use rustc::hir::def::*; use rustc::hir::def::*;
@ -44,6 +45,9 @@ use rustc::ty;
use rustc::hir::{Freevar, FreevarMap, TraitCandidate, TraitMap, GlobMap}; use rustc::hir::{Freevar, FreevarMap, TraitCandidate, TraitMap, GlobMap};
use rustc::util::nodemap::{NodeMap, NodeSet, FxHashMap, FxHashSet, DefIdMap}; use rustc::util::nodemap::{NodeMap, NodeSet, FxHashMap, FxHashSet, DefIdMap};
use rustc_metadata::creader::CrateLoader;
use rustc_metadata::cstore::CStore;
use syntax::codemap::CodeMap; use syntax::codemap::CodeMap;
use syntax::ext::hygiene::{Mark, Transparency, SyntaxContext}; use syntax::ext::hygiene::{Mark, Transparency, SyntaxContext};
use syntax::ast::{self, Name, NodeId, Ident, FloatTy, IntTy, UintTy}; use syntax::ast::{self, Name, NodeId, Ident, FloatTy, IntTy, UintTy};
@ -687,7 +691,7 @@ impl<'tcx> Visitor<'tcx> for UsePlacementFinder {
} }
/// This thing walks the whole crate in DFS manner, visiting each item, resolving names as it goes. /// This thing walks the whole crate in DFS manner, visiting each item, resolving names as it goes.
impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> { impl<'a, 'tcx, 'cl> Visitor<'tcx> for Resolver<'a, 'cl> {
fn visit_item(&mut self, item: &'tcx Item) { fn visit_item(&mut self, item: &'tcx Item) {
self.resolve_item(item); self.resolve_item(item);
} }
@ -1176,7 +1180,7 @@ impl<'a> NameBinding<'a> {
} }
} }
fn get_macro(&self, resolver: &mut Resolver<'a>) -> Lrc<SyntaxExtension> { fn get_macro<'b: 'a>(&self, resolver: &mut Resolver<'a, 'b>) -> Lrc<SyntaxExtension> {
resolver.get_macro(self.def_ignoring_ambiguity()) resolver.get_macro(self.def_ignoring_ambiguity())
} }
@ -1291,9 +1295,9 @@ impl PrimitiveTypeTable {
/// The main resolver class. /// The main resolver class.
/// ///
/// This is the visitor that walks the whole crate. /// This is the visitor that walks the whole crate.
pub struct Resolver<'a> { pub struct Resolver<'a, 'b: 'a> {
session: &'a Session, session: &'a Session,
cstore: &'a dyn CrateStore, cstore: &'a CStore,
pub definitions: Definitions, pub definitions: Definitions,
@ -1389,7 +1393,7 @@ pub struct Resolver<'a> {
/// true if `#![feature(use_extern_macros)]` /// true if `#![feature(use_extern_macros)]`
use_extern_macros: bool, use_extern_macros: bool,
crate_loader: &'a mut dyn CrateLoader, crate_loader: &'a mut CrateLoader<'b>,
macro_names: FxHashSet<Ident>, macro_names: FxHashSet<Ident>,
macro_prelude: FxHashMap<Name, &'a NameBinding<'a>>, macro_prelude: FxHashMap<Name, &'a NameBinding<'a>>,
pub all_macros: FxHashMap<Name, Def>, pub all_macros: FxHashMap<Name, Def>,
@ -1473,7 +1477,7 @@ impl<'a> ResolverArenas<'a> {
} }
} }
impl<'a, 'b: 'a> ty::DefIdTree for &'a Resolver<'b> { impl<'a, 'b: 'a, 'cl: 'b> ty::DefIdTree for &'a Resolver<'b, 'cl> {
fn parent(self, id: DefId) -> Option<DefId> { fn parent(self, id: DefId) -> Option<DefId> {
match id.krate { match id.krate {
LOCAL_CRATE => self.definitions.def_key(id.index).parent, LOCAL_CRATE => self.definitions.def_key(id.index).parent,
@ -1484,7 +1488,7 @@ impl<'a, 'b: 'a> ty::DefIdTree for &'a Resolver<'b> {
/// This interface is used through the AST→HIR step, to embed full paths into the HIR. After that /// This interface is used through the AST→HIR step, to embed full paths into the HIR. After that
/// the resolver is no longer needed as all the relevant information is inline. /// the resolver is no longer needed as all the relevant information is inline.
impl<'a> hir::lowering::Resolver for Resolver<'a> { impl<'a, 'cl> hir::lowering::Resolver for Resolver<'a, 'cl> {
fn resolve_hir_path(&mut self, path: &mut hir::Path, is_value: bool) { fn resolve_hir_path(&mut self, path: &mut hir::Path, is_value: bool) {
self.resolve_hir_path_cb(path, is_value, self.resolve_hir_path_cb(path, is_value,
|resolver, span, error| resolve_error(resolver, span, error)) |resolver, span, error| resolve_error(resolver, span, error))
@ -1537,7 +1541,7 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
} }
} }
impl<'a> Resolver<'a> { impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
/// Rustdoc uses this to resolve things in a recoverable way. ResolutionError<'a> /// Rustdoc uses this to resolve things in a recoverable way. ResolutionError<'a>
/// isn't something that can be returned because it can't be made to live that long, /// isn't something that can be returned because it can't be made to live that long,
/// and also it's a private type. Fortunately rustdoc doesn't need to know the error, /// and also it's a private type. Fortunately rustdoc doesn't need to know the error,
@ -1603,15 +1607,15 @@ impl<'a> Resolver<'a> {
} }
} }
impl<'a> Resolver<'a> { impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
pub fn new(session: &'a Session, pub fn new(session: &'a Session,
cstore: &'a dyn CrateStore, cstore: &'a CStore,
krate: &Crate, krate: &Crate,
crate_name: &str, crate_name: &str,
make_glob_map: MakeGlobMap, make_glob_map: MakeGlobMap,
crate_loader: &'a mut dyn CrateLoader, crate_loader: &'a mut CrateLoader<'crateloader>,
arenas: &'a ResolverArenas<'a>) arenas: &'a ResolverArenas<'a>)
-> Resolver<'a> { -> Resolver<'a, 'crateloader> {
let root_def_id = DefId::local(CRATE_DEF_INDEX); let root_def_id = DefId::local(CRATE_DEF_INDEX);
let root_module_kind = ModuleKind::Def(Def::Mod(root_def_id), keywords::Invalid.name()); let root_module_kind = ModuleKind::Def(Def::Mod(root_def_id), keywords::Invalid.name());
let graph_root = arenas.alloc_module(ModuleData { let graph_root = arenas.alloc_module(ModuleData {

View File

@ -18,6 +18,7 @@ use rustc::hir::def_id::{DefId, BUILTIN_MACROS_CRATE, CRATE_DEF_INDEX, DefIndex,
use rustc::hir::def::{Def, Export}; use rustc::hir::def::{Def, Export};
use rustc::hir::map::{self, DefCollector}; use rustc::hir::map::{self, DefCollector};
use rustc::{ty, lint}; use rustc::{ty, lint};
use rustc::middle::cstore::CrateStore;
use syntax::ast::{self, Name, Ident}; use syntax::ast::{self, Name, Ident};
use syntax::attr::{self, HasAttrs}; use syntax::attr::{self, HasAttrs};
use syntax::errors::DiagnosticBuilder; use syntax::errors::DiagnosticBuilder;
@ -117,7 +118,7 @@ impl<'a> MacroBinding<'a> {
} }
} }
impl<'a> base::Resolver for Resolver<'a> { impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
fn next_node_id(&mut self) -> ast::NodeId { fn next_node_id(&mut self) -> ast::NodeId {
self.session.next_node_id() self.session.next_node_id()
} }
@ -135,9 +136,11 @@ impl<'a> base::Resolver for Resolver<'a> {
} }
fn eliminate_crate_var(&mut self, item: P<ast::Item>) -> P<ast::Item> { fn eliminate_crate_var(&mut self, item: P<ast::Item>) -> P<ast::Item> {
struct EliminateCrateVar<'b, 'a: 'b>(&'b mut Resolver<'a>, Span); struct EliminateCrateVar<'b, 'a: 'b, 'crateloader: 'a>(
&'b mut Resolver<'a, 'crateloader>, Span
);
impl<'a, 'b> Folder for EliminateCrateVar<'a, 'b> { impl<'a, 'b, 'crateloader> Folder for EliminateCrateVar<'a, 'b, 'crateloader> {
fn fold_path(&mut self, path: ast::Path) -> ast::Path { fn fold_path(&mut self, path: ast::Path) -> ast::Path {
match self.fold_qpath(None, path) { match self.fold_qpath(None, path) {
(None, path) => path, (None, path) => path,
@ -387,7 +390,7 @@ impl<'a> base::Resolver for Resolver<'a> {
} }
} }
impl<'a> Resolver<'a> { impl<'a, 'cl> Resolver<'a, 'cl> {
fn report_proc_macro_stub(&self, span: Span) { fn report_proc_macro_stub(&self, span: Span) {
self.session.span_err(span, self.session.span_err(span,
"can't use a procedural macro from the same crate that defines it"); "can't use a procedural macro from the same crate that defines it");

View File

@ -25,6 +25,7 @@ use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
use rustc::hir::def::*; use rustc::hir::def::*;
use rustc::session::DiagnosticMessageId; use rustc::session::DiagnosticMessageId;
use rustc::util::nodemap::{FxHashMap, FxHashSet}; use rustc::util::nodemap::{FxHashMap, FxHashSet};
use rustc::middle::cstore::CrateStore;
use syntax::ast::{Ident, Name, NodeId, CRATE_NODE_ID}; use syntax::ast::{Ident, Name, NodeId, CRATE_NODE_ID};
use syntax::ext::base::Determinacy::{self, Determined, Undetermined}; use syntax::ext::base::Determinacy::{self, Determined, Undetermined};
@ -123,7 +124,7 @@ impl<'a> NameResolution<'a> {
} }
} }
impl<'a> Resolver<'a> { impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace) fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace)
-> &'a RefCell<NameResolution<'a>> { -> &'a RefCell<NameResolution<'a>> {
*module.resolutions.borrow_mut().entry((ident.modern(), ns)) *module.resolutions.borrow_mut().entry((ident.modern(), ns))
@ -402,7 +403,7 @@ impl<'a> Resolver<'a> {
// If the resolution becomes a success, define it in the module's glob importers. // If the resolution becomes a success, define it in the module's glob importers.
fn update_resolution<T, F>(&mut self, module: Module<'a>, ident: Ident, ns: Namespace, f: F) fn update_resolution<T, F>(&mut self, module: Module<'a>, ident: Ident, ns: Namespace, f: F)
-> T -> T
where F: FnOnce(&mut Resolver<'a>, &mut NameResolution<'a>) -> T where F: FnOnce(&mut Resolver<'a, 'crateloader>, &mut NameResolution<'a>) -> T
{ {
// Ensure that `resolution` isn't borrowed when defining in the module's glob importers, // Ensure that `resolution` isn't borrowed when defining in the module's glob importers,
// during which the resolution might end up getting re-defined via a glob cycle. // during which the resolution might end up getting re-defined via a glob cycle.
@ -453,30 +454,30 @@ impl<'a> Resolver<'a> {
} }
} }
pub struct ImportResolver<'a, 'b: 'a> { pub struct ImportResolver<'a, 'b: 'a, 'c: 'a + 'b> {
pub resolver: &'a mut Resolver<'b>, pub resolver: &'a mut Resolver<'b, 'c>,
} }
impl<'a, 'b: 'a> ::std::ops::Deref for ImportResolver<'a, 'b> { impl<'a, 'b: 'a, 'c: 'a + 'b> ::std::ops::Deref for ImportResolver<'a, 'b, 'c> {
type Target = Resolver<'b>; type Target = Resolver<'b, 'c>;
fn deref(&self) -> &Resolver<'b> { fn deref(&self) -> &Resolver<'b, 'c> {
self.resolver self.resolver
} }
} }
impl<'a, 'b: 'a> ::std::ops::DerefMut for ImportResolver<'a, 'b> { impl<'a, 'b: 'a, 'c: 'a + 'b> ::std::ops::DerefMut for ImportResolver<'a, 'b, 'c> {
fn deref_mut(&mut self) -> &mut Resolver<'b> { fn deref_mut(&mut self) -> &mut Resolver<'b, 'c> {
self.resolver self.resolver
} }
} }
impl<'a, 'b: 'a> ty::DefIdTree for &'a ImportResolver<'a, 'b> { impl<'a, 'b: 'a, 'c: 'a + 'b> ty::DefIdTree for &'a ImportResolver<'a, 'b, 'c> {
fn parent(self, id: DefId) -> Option<DefId> { fn parent(self, id: DefId) -> Option<DefId> {
self.resolver.parent(id) self.resolver.parent(id)
} }
} }
impl<'a, 'b:'a> ImportResolver<'a, 'b> { impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
// Import resolution // Import resolution
// //
// This is a fixed-point algorithm. We resolve imports until our efforts // This is a fixed-point algorithm. We resolve imports until our efforts

View File

@ -13,6 +13,7 @@ use rustc::traits::{self, auto_trait as auto};
use rustc::ty::{self, ToPredicate, TypeFoldable}; use rustc::ty::{self, ToPredicate, TypeFoldable};
use rustc::ty::subst::Subst; use rustc::ty::subst::Subst;
use rustc::infer::InferOk; use rustc::infer::InferOk;
use rustc::middle::cstore::CrateStore;
use std::fmt::Debug; use std::fmt::Debug;
use syntax_pos::DUMMY_SP; use syntax_pos::DUMMY_SP;
@ -20,13 +21,13 @@ use core::DocAccessLevels;
use super::*; use super::*;
pub struct AutoTraitFinder<'a, 'tcx: 'a, 'rcx: 'a> { pub struct AutoTraitFinder<'a, 'tcx: 'a, 'rcx: 'a, 'cstore: 'rcx> {
pub cx: &'a core::DocContext<'a, 'tcx, 'rcx>, pub cx: &'a core::DocContext<'a, 'tcx, 'rcx, 'cstore>,
pub f: auto::AutoTraitFinder<'a, 'tcx>, pub f: auto::AutoTraitFinder<'a, 'tcx>,
} }
impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> {
pub fn new(cx: &'a core::DocContext<'a, 'tcx, 'rcx>) -> Self { pub fn new(cx: &'a core::DocContext<'a, 'tcx, 'rcx, 'cstore>) -> Self {
let f = auto::AutoTraitFinder::new(&cx.tcx); let f = auto::AutoTraitFinder::new(&cx.tcx);
AutoTraitFinder { cx, f } AutoTraitFinder { cx, f }

View File

@ -19,7 +19,7 @@ use syntax_pos::Span;
use rustc::hir; use rustc::hir;
use rustc::hir::def::{Def, CtorKind}; use rustc::hir::def::{Def, CtorKind};
use rustc::hir::def_id::DefId; use rustc::hir::def_id::DefId;
use rustc::middle::cstore::LoadedMacro; use rustc::middle::cstore::{CrateStore, LoadedMacro};
use rustc::ty; use rustc::ty;
use rustc::util::nodemap::FxHashSet; use rustc::util::nodemap::FxHashSet;

View File

@ -145,7 +145,7 @@ pub struct Crate {
pub masked_crates: FxHashSet<CrateNum>, pub masked_crates: FxHashSet<CrateNum>,
} }
impl<'a, 'tcx, 'rcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx, 'rcx> { impl<'a, 'tcx, 'rcx, 'cstore> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> {
fn clean(&self, cx: &DocContext) -> Crate { fn clean(&self, cx: &DocContext) -> Crate {
use ::visit_lib::LibEmbargoVisitor; use ::visit_lib::LibEmbargoVisitor;

View File

@ -13,7 +13,6 @@ use rustc_driver::{self, driver, target_features, abort_on_err};
use rustc::session::{self, config}; use rustc::session::{self, config};
use rustc::hir::def_id::{DefId, CrateNum, LOCAL_CRATE}; use rustc::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
use rustc::hir::def::Def; use rustc::hir::def::Def;
use rustc::middle::cstore::CrateStore;
use rustc::middle::privacy::AccessLevels; use rustc::middle::privacy::AccessLevels;
use rustc::ty::{self, TyCtxt, AllArenas}; use rustc::ty::{self, TyCtxt, AllArenas};
use rustc::hir::map as hir_map; use rustc::hir::map as hir_map;
@ -49,13 +48,13 @@ pub use rustc::session::search_paths::SearchPaths;
pub type ExternalPaths = FxHashMap<DefId, (Vec<String>, clean::TypeKind)>; pub type ExternalPaths = FxHashMap<DefId, (Vec<String>, clean::TypeKind)>;
pub struct DocContext<'a, 'tcx: 'a, 'rcx: 'a> { pub struct DocContext<'a, 'tcx: 'a, 'rcx: 'a, 'cstore: 'rcx> {
pub tcx: TyCtxt<'a, 'tcx, 'tcx>, pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
pub resolver: &'a RefCell<resolve::Resolver<'rcx>>, pub resolver: &'a RefCell<resolve::Resolver<'rcx, 'cstore>>,
/// The stack of module NodeIds up till this point /// The stack of module NodeIds up till this point
pub mod_ids: RefCell<Vec<NodeId>>, pub mod_ids: RefCell<Vec<NodeId>>,
pub crate_name: Option<String>, pub crate_name: Option<String>,
pub cstore: Rc<dyn CrateStore>, pub cstore: Rc<CStore>,
pub populated_all_crate_impls: Cell<bool>, pub populated_all_crate_impls: Cell<bool>,
// Note that external items for which `doc(hidden)` applies to are shown as // Note that external items for which `doc(hidden)` applies to are shown as
// non-reachable while local items aren't. This is because we're reusing // non-reachable while local items aren't. This is because we're reusing
@ -87,7 +86,7 @@ pub struct DocContext<'a, 'tcx: 'a, 'rcx: 'a> {
pub all_traits: Vec<DefId>, pub all_traits: Vec<DefId>,
} }
impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> { impl<'a, 'tcx, 'rcx, 'cstore> DocContext<'a, 'tcx, 'rcx, 'cstore> {
pub fn sess(&self) -> &session::Session { pub fn sess(&self) -> &session::Session {
&self.tcx.sess &self.tcx.sess
} }

View File

@ -38,10 +38,10 @@ use doctree::*;
// also, is there some reason that this doesn't use the 'visit' // also, is there some reason that this doesn't use the 'visit'
// framework from syntax? // framework from syntax?
pub struct RustdocVisitor<'a, 'tcx: 'a, 'rcx: 'a> { pub struct RustdocVisitor<'a, 'tcx: 'a, 'rcx: 'a, 'cstore: 'rcx> {
pub module: Module, pub module: Module,
pub attrs: hir::HirVec<ast::Attribute>, pub attrs: hir::HirVec<ast::Attribute>,
pub cx: &'a core::DocContext<'a, 'tcx, 'rcx>, pub cx: &'a core::DocContext<'a, 'tcx, 'rcx, 'cstore>,
view_item_stack: FxHashSet<ast::NodeId>, view_item_stack: FxHashSet<ast::NodeId>,
inlining: bool, inlining: bool,
/// Is the current module and all of its parents public? /// Is the current module and all of its parents public?
@ -49,8 +49,10 @@ pub struct RustdocVisitor<'a, 'tcx: 'a, 'rcx: 'a> {
exact_paths: Option<FxHashMap<DefId, Vec<String>>>, exact_paths: Option<FxHashMap<DefId, Vec<String>>>,
} }
impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> {
pub fn new(cx: &'a core::DocContext<'a, 'tcx, 'rcx>) -> RustdocVisitor<'a, 'tcx, 'rcx> { pub fn new(
cx: &'a core::DocContext<'a, 'tcx, 'rcx, 'cstore>
) -> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> {
// If the root is re-exported, terminate all recursion. // If the root is re-exported, terminate all recursion.
let mut stack = FxHashSet(); let mut stack = FxHashSet();
stack.insert(ast::CRATE_NODE_ID); stack.insert(ast::CRATE_NODE_ID);

View File

@ -22,8 +22,8 @@ use clean::{AttributesExt, NestedAttributesExt};
/// Similar to `librustc_privacy::EmbargoVisitor`, but also takes /// Similar to `librustc_privacy::EmbargoVisitor`, but also takes
/// specific rustdoc annotations into account (i.e. `doc(hidden)`) /// specific rustdoc annotations into account (i.e. `doc(hidden)`)
pub struct LibEmbargoVisitor<'a, 'tcx: 'a, 'rcx: 'a> { pub struct LibEmbargoVisitor<'a, 'tcx: 'a, 'rcx: 'a, 'cstore: 'rcx> {
cx: &'a ::core::DocContext<'a, 'tcx, 'rcx>, cx: &'a ::core::DocContext<'a, 'tcx, 'rcx, 'cstore>,
// Accessibility levels for reachable nodes // Accessibility levels for reachable nodes
access_levels: RefMut<'a, AccessLevels<DefId>>, access_levels: RefMut<'a, AccessLevels<DefId>>,
// Previous accessibility level, None means unreachable // Previous accessibility level, None means unreachable
@ -32,8 +32,10 @@ pub struct LibEmbargoVisitor<'a, 'tcx: 'a, 'rcx: 'a> {
visited_mods: FxHashSet<DefId>, visited_mods: FxHashSet<DefId>,
} }
impl<'a, 'tcx, 'rcx> LibEmbargoVisitor<'a, 'tcx, 'rcx> { impl<'a, 'tcx, 'rcx, 'cstore> LibEmbargoVisitor<'a, 'tcx, 'rcx, 'cstore> {
pub fn new(cx: &'a ::core::DocContext<'a, 'tcx, 'rcx>) -> LibEmbargoVisitor<'a, 'tcx, 'rcx> { pub fn new(
cx: &'a ::core::DocContext<'a, 'tcx, 'rcx, 'cstore>
) -> LibEmbargoVisitor<'a, 'tcx, 'rcx, 'cstore> {
LibEmbargoVisitor { LibEmbargoVisitor {
cx, cx,
access_levels: cx.access_levels.borrow_mut(), access_levels: cx.access_levels.borrow_mut(),

View File

@ -21,12 +21,13 @@ extern crate rustc_driver;
extern crate rustc_codegen_utils; extern crate rustc_codegen_utils;
extern crate syntax; extern crate syntax;
extern crate rustc_errors as errors; extern crate rustc_errors as errors;
extern crate rustc_metadata;
use rustc::middle::cstore::CrateStore;
use rustc::session::Session; use rustc::session::Session;
use rustc::session::config::{self, Input}; use rustc::session::config::{self, Input};
use rustc_driver::{driver, CompilerCalls, Compilation}; use rustc_driver::{driver, CompilerCalls, Compilation};
use rustc_codegen_utils::codegen_backend::CodegenBackend; use rustc_codegen_utils::codegen_backend::CodegenBackend;
use rustc_metadata::cstore::CStore;
use syntax::ast; use syntax::ast;
use std::path::PathBuf; use std::path::PathBuf;
@ -51,7 +52,7 @@ impl<'a> CompilerCalls<'a> for TestCalls<'a> {
_: &CodegenBackend, _: &CodegenBackend,
_: &getopts::Matches, _: &getopts::Matches,
_: &Session, _: &Session,
_: &CrateStore, _: &CStore,
_: &Input, _: &Input,
_: &Option<PathBuf>, _: &Option<PathBuf>,
_: &Option<PathBuf>) _: &Option<PathBuf>)