rustc_metadata: Crate loader is immutable
This commit is contained in:
parent
2805553dd8
commit
e843d867e6
3 changed files with 22 additions and 32 deletions
|
|
@ -130,7 +130,7 @@ 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,
|
||||
|
|
@ -138,7 +138,7 @@ pub fn configure_and_expand(
|
|||
krate,
|
||||
&crate_name,
|
||||
&resolver_arenas,
|
||||
&mut crate_loader,
|
||||
&crate_loader,
|
||||
plugin_info,
|
||||
);
|
||||
let mut resolver = match res {
|
||||
|
|
@ -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", || {
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ impl<'a> CrateLoader<'a> {
|
|||
}
|
||||
|
||||
fn register_crate(
|
||||
&mut self,
|
||||
&self,
|
||||
host_lib: Option<Library>,
|
||||
root: Option<&CratePaths>,
|
||||
span: Span,
|
||||
|
|
@ -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>)>
|
||||
|
|
@ -327,7 +327,7 @@ impl<'a> CrateLoader<'a> {
|
|||
}
|
||||
|
||||
fn resolve_crate<'b>(
|
||||
&'b mut self,
|
||||
&'b self,
|
||||
name: Symbol,
|
||||
span: Span,
|
||||
dep_kind: DepKind,
|
||||
|
|
@ -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,
|
||||
|
|
@ -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
|
||||
|
|
@ -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)>)
|
||||
|
|
@ -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,
|
||||
|
|
@ -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());
|
||||
|
|
@ -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)> {
|
||||
|
|
@ -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| {
|
||||
|
|
@ -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`
|
||||
|
|
@ -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()
|
||||
{
|
||||
|
|
@ -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")
|
||||
|
|
@ -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);
|
||||
|
|
@ -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: {:?}",
|
||||
|
|
@ -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(
|
||||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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>>,
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue