Skip to content

Commit

Permalink
rustc_metadata: Crate loader is immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Oct 14, 2019
1 parent 2805553 commit e843d86
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ pub fn configure_and_expand(
let crate_name = crate_name.to_string();
let (result, resolver) = BoxedResolver::new(static move || {
let sess = &*sess;
let mut crate_loader = CrateLoader::new(sess, &*cstore, &crate_name);
let crate_loader = CrateLoader::new(sess, &*cstore, &crate_name);
let resolver_arenas = Resolver::arenas();
let res = configure_and_expand_inner(
sess,
&*cstore,
krate,
&crate_name,
&resolver_arenas,
&mut crate_loader,
&crate_loader,
plugin_info,
);
let mut resolver = match res {
Expand Down Expand Up @@ -319,7 +319,7 @@ fn configure_and_expand_inner<'a>(
mut krate: ast::Crate,
crate_name: &str,
resolver_arenas: &'a ResolverArenas<'a>,
crate_loader: &'a mut CrateLoader<'a>,
crate_loader: &'a CrateLoader<'a>,
plugin_info: PluginInfo,
) -> Result<(ast::Crate, Resolver<'a>)> {
time(sess, "pre-AST-expansion lint checks", || {
Expand Down
44 changes: 17 additions & 27 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl<'a> CrateLoader<'a> {
}

fn register_crate(
&mut self,
&self,
host_lib: Option<Library>,
root: Option<&CratePaths>,
span: Span,
Expand Down Expand Up @@ -272,7 +272,7 @@ impl<'a> CrateLoader<'a> {
}

fn load_proc_macro<'b>(
&mut self,
&self,
locate_ctxt: &mut locator::Context<'b>,
path_kind: PathKind,
) -> Option<(LoadResult, Option<Library>)>
Expand Down Expand Up @@ -327,7 +327,7 @@ impl<'a> CrateLoader<'a> {
}

fn resolve_crate<'b>(
&'b mut self,
&'b self,
name: Symbol,
span: Span,
dep_kind: DepKind,
Expand All @@ -337,7 +337,7 @@ impl<'a> CrateLoader<'a> {
}

fn maybe_resolve_crate<'b>(
&'b mut self,
&'b self,
name: Symbol,
span: Span,
mut dep_kind: DepKind,
Expand Down Expand Up @@ -397,7 +397,7 @@ impl<'a> CrateLoader<'a> {
}
}

fn load(&mut self, locate_ctxt: &mut locator::Context<'_>) -> Option<LoadResult> {
fn load(&self, locate_ctxt: &mut locator::Context<'_>) -> Option<LoadResult> {
let library = locate_ctxt.maybe_load_library_crate()?;

// In the case that we're loading a crate, but not matching
Expand All @@ -424,7 +424,7 @@ impl<'a> CrateLoader<'a> {
}
}

fn update_extern_crate(&mut self,
fn update_extern_crate(&self,
cnum: CrateNum,
mut extern_crate: ExternCrate,
visited: &mut FxHashSet<(CrateNum, bool)>)
Expand Down Expand Up @@ -466,7 +466,7 @@ impl<'a> CrateLoader<'a> {
}

// Go through the crate metadata and load any crates that it references
fn resolve_crate_deps(&mut self,
fn resolve_crate_deps(&self,
root: &CratePaths,
crate_root: &CrateRoot<'_>,
metadata: &MetadataBlob,
Expand Down Expand Up @@ -496,7 +496,7 @@ impl<'a> CrateLoader<'a> {
})).collect()
}

fn read_extension_crate(&mut self, name: Symbol, span: Span) -> ExtensionCrate {
fn read_extension_crate(&self, name: Symbol, span: Span) -> ExtensionCrate {
info!("read extension crate `{}`", name);
let target_triple = self.sess.opts.target_triple.clone();
let host_triple = TargetTriple::from_triple(config::host_triple());
Expand Down Expand Up @@ -592,7 +592,7 @@ impl<'a> CrateLoader<'a> {

/// Look for a plugin registrar. Returns library path, crate
/// SVH and DefIndex of the registrar function.
pub fn find_plugin_registrar(&mut self,
pub fn find_plugin_registrar(&self,
span: Span,
name: Symbol)
-> Option<(PathBuf, CrateDisambiguator)> {
Expand Down Expand Up @@ -625,7 +625,7 @@ impl<'a> CrateLoader<'a> {
}
}

fn inject_panic_runtime(&mut self, krate: &ast::Crate) {
fn inject_panic_runtime(&self, krate: &ast::Crate) {
// If we're only compiling an rlib, then there's no need to select a
// panic runtime, so we just skip this section entirely.
let any_non_rlib = self.sess.crate_types.borrow().iter().any(|ct| {
Expand Down Expand Up @@ -706,7 +706,7 @@ impl<'a> CrateLoader<'a> {
&|data| data.root.needs_panic_runtime);
}

fn inject_sanitizer_runtime(&mut self) {
fn inject_sanitizer_runtime(&self) {
if let Some(ref sanitizer) = self.sess.opts.debugging_opts.sanitizer {
// Sanitizers can only be used on some tested platforms with
// executables linked to `std`
Expand Down Expand Up @@ -804,7 +804,7 @@ impl<'a> CrateLoader<'a> {
}
}

fn inject_profiler_runtime(&mut self) {
fn inject_profiler_runtime(&self) {
if self.sess.opts.debugging_opts.profile ||
self.sess.opts.cg.profile_generate.enabled()
{
Expand All @@ -821,7 +821,7 @@ impl<'a> CrateLoader<'a> {
}
}

fn inject_allocator_crate(&mut self, krate: &ast::Crate) {
fn inject_allocator_crate(&self, krate: &ast::Crate) {
let has_global_allocator = match &*global_allocator_spans(krate) {
[span1, span2, ..] => {
self.sess.struct_span_err(*span2, "cannot define multiple global allocators")
Expand Down Expand Up @@ -960,7 +960,7 @@ impl<'a> CrateLoader<'a> {
}

impl<'a> CrateLoader<'a> {
pub fn postprocess(&mut self, krate: &ast::Crate) {
pub fn postprocess(&self, krate: &ast::Crate) {
self.inject_sanitizer_runtime();
self.inject_profiler_runtime();
self.inject_allocator_crate(krate);
Expand All @@ -971,9 +971,7 @@ impl<'a> CrateLoader<'a> {
}
}

pub fn process_extern_crate(
&mut self, item: &ast::Item, definitions: &Definitions,
) -> CrateNum {
pub fn process_extern_crate(&self, item: &ast::Item, definitions: &Definitions) -> CrateNum {
match item.kind {
ast::ItemKind::ExternCrate(orig_name) => {
debug!("resolving extern crate stmt. ident: {} orig_name: {:?}",
Expand Down Expand Up @@ -1013,11 +1011,7 @@ impl<'a> CrateLoader<'a> {
}
}

pub fn process_path_extern(
&mut self,
name: Symbol,
span: Span,
) -> CrateNum {
pub fn process_path_extern(&self, name: Symbol, span: Span) -> CrateNum {
let cnum = self.resolve_crate(name, span, DepKind::Explicit, None).0;

self.update_extern_crate(
Expand All @@ -1035,11 +1029,7 @@ impl<'a> CrateLoader<'a> {
cnum
}

pub fn maybe_process_path_extern(
&mut self,
name: Symbol,
span: Span,
) -> Option<CrateNum> {
pub fn maybe_process_path_extern(&self, name: Symbol, span: Span) -> Option<CrateNum> {
let cnum = self.maybe_resolve_crate(name, span, DepKind::Explicit, None).ok()?.0;

self.update_extern_crate(
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ pub struct Resolver<'a> {
arenas: &'a ResolverArenas<'a>,
dummy_binding: &'a NameBinding<'a>,

crate_loader: &'a mut CrateLoader<'a>,
crate_loader: &'a CrateLoader<'a>,
macro_names: FxHashSet<Ident>,
builtin_macros: FxHashMap<Name, SyntaxExtension>,
macro_use_prelude: FxHashMap<Name, &'a NameBinding<'a>>,
Expand Down Expand Up @@ -1070,7 +1070,7 @@ impl<'a> Resolver<'a> {
cstore: &'a CStore,
krate: &Crate,
crate_name: &str,
crate_loader: &'a mut CrateLoader<'a>,
crate_loader: &'a CrateLoader<'a>,
arenas: &'a ResolverArenas<'a>)
-> Resolver<'a> {
let root_def_id = DefId::local(CRATE_DEF_INDEX);
Expand Down

0 comments on commit e843d86

Please sign in to comment.