Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Store concrete crate stores where possible
  • Loading branch information
Mark-Simulacrum committed Aug 3, 2018
commit 5aec365cb9d3df7b6da30393363ea571f2e60368
1 change: 1 addition & 0 deletions src/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2451,6 +2451,7 @@ dependencies = [
"rustc 0.0.0",
"rustc_data_structures 0.0.0",
"rustc_errors 0.0.0",
"rustc_metadata 0.0.0",
"syntax 0.0.0",
"syntax_pos 0.0.0",
]
Expand Down
22 changes: 1 addition & 21 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use hir::def;
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use hir::map as hir_map;
use hir::map::definitions::{Definitions, DefKey, DefPathTable};
use hir::map::definitions::{DefKey, DefPathTable};
use hir::svh::Svh;
use ty::{self, TyCtxt};
use session::{Session, CrateDisambiguator};
Expand Down Expand Up @@ -259,26 +259,6 @@ pub trait CrateStore {

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
// 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
Expand Down
15 changes: 7 additions & 8 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use rustc::session::config::{self, Input, OutputFilenames, OutputType};
use rustc::session::search_paths::PathKind;
use rustc::lint;
use rustc::middle::{self, reachable, resolve_lifetime, stability};
use rustc::middle::cstore::CrateStoreDyn;
use rustc::middle::privacy::AccessLevels;
use rustc::ty::{self, AllArenas, Resolutions, TyCtxt};
use rustc::traits;
Expand Down Expand Up @@ -484,7 +483,7 @@ impl<'a> ::CompilerCalls<'a> for CompileController<'a> {
codegen_backend: &dyn (::CodegenBackend),
matches: &::getopts::Matches,
sess: &Session,
cstore: &dyn (::CrateStore),
cstore: &CStore,
input: &Input,
odir: &Option<PathBuf>,
ofile: &Option<PathBuf>,
Expand Down Expand Up @@ -728,9 +727,9 @@ pub struct ExpansionResult {
pub hir_forest: hir_map::Forest,
}

pub struct InnerExpansionResult<'a> {
pub struct InnerExpansionResult<'a, 'b: 'a> {
pub expanded_crate: ast::Crate,
pub resolver: Resolver<'a>,
pub resolver: Resolver<'a, 'b>,
pub hir_forest: hir_map::Forest,
}

Expand Down Expand Up @@ -806,7 +805,7 @@ where

/// Same as phase_2_configure_and_expand, but doesn't let you keep the resolver
/// 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,
cstore: &'a CStore,
mut krate: ast::Crate,
Expand All @@ -815,9 +814,9 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(
addl_plugins: Option<Vec<String>>,
make_glob_map: MakeGlobMap,
resolver_arenas: &'a ResolverArenas<'a>,
crate_loader: &'a mut CrateLoader,
crate_loader: &'a mut CrateLoader<'b>,
after_expand: F,
) -> Result<InnerExpansionResult<'a>, CompileIncomplete>
) -> Result<InnerExpansionResult<'a, 'b>, CompileIncomplete>
where
F: FnOnce(&ast::Crate) -> CompileResult,
{
Expand Down Expand Up @@ -1209,7 +1208,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(
codegen_backend: &dyn CodegenBackend,
control: &CompileController,
sess: &'tcx Session,
cstore: &'tcx CrateStoreDyn,
cstore: &'tcx CStore,
hir_map: hir_map::Map<'tcx>,
mut analysis: ty::CrateAnalysis,
resolutions: Resolutions,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ pub trait CompilerCalls<'a> {
_: &dyn CodegenBackend,
_: &getopts::Matches,
_: &Session,
_: &dyn CrateStore,
_: &CStore,
_: &Input,
_: &Option<PathBuf>,
_: &Option<PathBuf>)
Expand Down Expand Up @@ -884,7 +884,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
codegen_backend: &dyn CodegenBackend,
matches: &getopts::Matches,
sess: &Session,
cstore: &dyn CrateStore,
cstore: &CStore,
input: &Input,
odir: &Option<PathBuf>,
ofile: &Option<PathBuf>)
Expand Down Expand Up @@ -990,7 +990,7 @@ pub fn enable_save_analysis(control: &mut CompileController) {

impl RustcDefaultCalls {
pub fn list_metadata(sess: &Session,
cstore: &dyn CrateStore,
cstore: &CStore,
matches: &getopts::Matches,
input: &Input)
-> Compilation {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ use {abort_on_err, driver};
use rustc::ty::{self, TyCtxt, Resolutions, AllArenas};
use rustc::cfg;
use rustc::cfg::graphviz::LabelledCFG;
use rustc::middle::cstore::CrateStoreDyn;
use rustc::session::Session;
use rustc::session::config::{Input, OutputFilenames};
use rustc_borrowck as borrowck;
use rustc_borrowck::graphviz as borrowck_dot;
use rustc_metadata::cstore::CStore;

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

Expand Down Expand Up @@ -199,7 +199,7 @@ impl PpSourceMode {
}
fn call_with_pp_support_hir<'tcx, A, F>(&self,
sess: &'tcx Session,
cstore: &'tcx CrateStoreDyn,
cstore: &'tcx CStore,
hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis,
resolutions: &Resolutions,
Expand Down Expand Up @@ -918,7 +918,7 @@ pub fn print_after_parsing(sess: &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>,
analysis: &ty::CrateAnalysis,
resolutions: &Resolutions,
Expand Down Expand Up @@ -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.
// Instead, we call that function ourselves.
fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
cstore: &'a CrateStoreDyn,
cstore: &'a CStore,
hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis,
resolutions: &Resolutions,
Expand Down
13 changes: 7 additions & 6 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use rustc::session::{Session, CrateDisambiguator};
use rustc::session::config::{Sanitizer, self};
use rustc_target::spec::{PanicStrategy, TargetTriple};
use rustc::session::search_paths::PathKind;
use rustc::middle;
use rustc::middle::cstore::{ExternCrate, ExternCrateSource};
use rustc::util::common::record_time;
use rustc::util::nodemap::FxHashSet;
Expand Down Expand Up @@ -1058,8 +1057,8 @@ impl<'a> CrateLoader<'a> {
}
}

impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
fn postprocess(&mut self, krate: &ast::Crate) {
impl<'a> CrateLoader<'a> {
pub fn postprocess(&mut self, krate: &ast::Crate) {
// inject the sanitizer runtime before the allocator runtime because all
// sanitizers force the use of the `alloc_system` allocator
self.inject_sanitizer_runtime();
Expand All @@ -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 {
ast::ItemKind::ExternCrate(orig_name) => {
debug!("resolving extern crate stmt. ident: {} orig_name: {:?}",
Expand Down Expand Up @@ -1115,7 +1116,7 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
}
}

fn process_path_extern(
pub fn process_path_extern(
&mut self,
name: Symbol,
span: Span,
Expand All @@ -1139,7 +1140,7 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
cnum
}

fn process_use_extern(
pub fn process_use_extern(
&mut self,
name: Symbol,
span: Span,
Expand Down
1 change: 1 addition & 0 deletions src/librustc_resolve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ arena = { path = "../libarena" }
rustc_errors = { path = "../librustc_errors" }
syntax_pos = { path = "../libsyntax_pos" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_metadata = { path = "../librustc_metadata" }
11 changes: 6 additions & 5 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use rustc::middle::cstore::LoadedMacro;
use rustc::hir::def::*;
use rustc::hir::def_id::{BUILTIN_MACROS_CRATE, CRATE_DEF_INDEX, LOCAL_CRATE, DefId};
use rustc::ty;
use rustc::middle::cstore::CrateStore;

use std::cell::Cell;
use rustc_data_structures::sync::Lrc;
Expand Down Expand Up @@ -86,7 +87,7 @@ struct LegacyMacroImports {
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;
/// otherwise, reports an error.
pub fn define<T>(&mut self, parent: Module<'a>, ident: Ident, ns: Namespace, def: T)
Expand Down Expand Up @@ -776,13 +777,13 @@ impl<'a> Resolver<'a> {
}
}

pub struct BuildReducedGraphVisitor<'a, 'b: 'a> {
pub resolver: &'a mut Resolver<'b>,
pub struct BuildReducedGraphVisitor<'a, 'b: 'a, 'c: 'b> {
pub resolver: &'a mut Resolver<'b, 'c>,
pub legacy_scope: LegacyScope<'b>,
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> {
let mark = id.placeholder_to_mark();
self.resolver.current_module.unresolved_invocations.borrow_mut().insert(mark);
Expand All @@ -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_expr: ast::Expr, ast::ExprKind::Mac, walk_expr);
method!(visit_pat: ast::Pat, ast::PatKind::Mac, walk_pat);
Expand Down
18 changes: 9 additions & 9 deletions src/librustc_resolve/check_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,30 @@ use syntax::visit::{self, Visitor};
use syntax_pos::{Span, MultiSpan, DUMMY_SP};


struct UnusedImportCheckVisitor<'a, 'b: 'a> {
resolver: &'a mut Resolver<'b>,
struct UnusedImportCheckVisitor<'a, 'b: 'a, 'd: 'b> {
resolver: &'a mut Resolver<'b, 'd>,
/// All the (so far) unused imports, grouped path list
unused_imports: NodeMap<NodeMap<Span>>,
base_id: ast::NodeId,
item_span: Span,
}

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

fn deref<'c>(&'c self) -> &'c Resolver<'b> {
fn deref<'c>(&'c self) -> &'c Resolver<'b, 'd> {
&*self.resolver
}
}

impl<'a, 'b> DerefMut for UnusedImportCheckVisitor<'a, 'b> {
fn deref_mut<'c>(&'c mut self) -> &'c mut Resolver<'b> {
impl<'a, 'b, 'd> DerefMut for UnusedImportCheckVisitor<'a, 'b, 'd> {
fn deref_mut<'c>(&'c mut self) -> &'c mut Resolver<'b, 'd> {
&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
// 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) {
Expand All @@ -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) {
self.item_span = item.span;

Expand Down
Loading