rustc_resolve: move extern_prelude from Resolver to Session.
This commit is contained in:
parent
80e6e3e582
commit
e90985acde
4 changed files with 25 additions and 22 deletions
|
@ -38,7 +38,7 @@ use syntax::parse;
|
||||||
use syntax::parse::ParseSess;
|
use syntax::parse::ParseSess;
|
||||||
use syntax::{ast, source_map};
|
use syntax::{ast, source_map};
|
||||||
use syntax::feature_gate::AttributeType;
|
use syntax::feature_gate::AttributeType;
|
||||||
use syntax_pos::{MultiSpan, Span};
|
use syntax_pos::{MultiSpan, Span, symbol::Symbol};
|
||||||
use util::profiling::SelfProfiler;
|
use util::profiling::SelfProfiler;
|
||||||
|
|
||||||
use rustc_target::spec::PanicStrategy;
|
use rustc_target::spec::PanicStrategy;
|
||||||
|
@ -168,6 +168,10 @@ pub struct Session {
|
||||||
|
|
||||||
/// Cap lint level specified by a driver specifically.
|
/// Cap lint level specified by a driver specifically.
|
||||||
pub driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
|
pub driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
|
||||||
|
|
||||||
|
/// All the crate names specified with `--extern`, and the builtin ones.
|
||||||
|
/// Starting with the Rust 2018 edition, absolute paths resolve in this set.
|
||||||
|
pub extern_prelude: FxHashSet<Symbol>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PerfStats {
|
pub struct PerfStats {
|
||||||
|
@ -1126,6 +1130,18 @@ pub fn build_session_(
|
||||||
CguReuseTracker::new_disabled()
|
CguReuseTracker::new_disabled()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
let mut extern_prelude: FxHashSet<Symbol> =
|
||||||
|
sopts.externs.iter().map(|kv| Symbol::intern(kv.0)).collect();
|
||||||
|
|
||||||
|
// HACK(eddyb) this ignores the `no_{core,std}` attributes.
|
||||||
|
// FIXME(eddyb) warn (somewhere) if core/std is used with `no_{core,std}`.
|
||||||
|
// if !attr::contains_name(&krate.attrs, "no_core") {
|
||||||
|
// if !attr::contains_name(&krate.attrs, "no_std") {
|
||||||
|
extern_prelude.insert(Symbol::intern("core"));
|
||||||
|
extern_prelude.insert(Symbol::intern("std"));
|
||||||
|
extern_prelude.insert(Symbol::intern("meta"));
|
||||||
|
|
||||||
let sess = Session {
|
let sess = Session {
|
||||||
target: target_cfg,
|
target: target_cfg,
|
||||||
host,
|
host,
|
||||||
|
@ -1201,6 +1217,7 @@ pub fn build_session_(
|
||||||
has_global_allocator: Once::new(),
|
has_global_allocator: Once::new(),
|
||||||
has_panic_handler: Once::new(),
|
has_panic_handler: Once::new(),
|
||||||
driver_lint_caps: FxHashMap(),
|
driver_lint_caps: FxHashMap(),
|
||||||
|
extern_prelude,
|
||||||
};
|
};
|
||||||
|
|
||||||
validate_commandline_args_with_session_available(&sess);
|
validate_commandline_args_with_session_available(&sess);
|
||||||
|
|
|
@ -1350,7 +1350,6 @@ pub struct Resolver<'a, 'b: 'a> {
|
||||||
graph_root: Module<'a>,
|
graph_root: Module<'a>,
|
||||||
|
|
||||||
prelude: Option<Module<'a>>,
|
prelude: Option<Module<'a>>,
|
||||||
extern_prelude: FxHashSet<Name>,
|
|
||||||
|
|
||||||
/// n.b. This is used only for better diagnostics, not name resolution itself.
|
/// n.b. This is used only for better diagnostics, not name resolution itself.
|
||||||
has_self: FxHashSet<DefId>,
|
has_self: FxHashSet<DefId>,
|
||||||
|
@ -1663,17 +1662,6 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
||||||
DefCollector::new(&mut definitions, Mark::root())
|
DefCollector::new(&mut definitions, Mark::root())
|
||||||
.collect_root(crate_name, session.local_crate_disambiguator());
|
.collect_root(crate_name, session.local_crate_disambiguator());
|
||||||
|
|
||||||
let mut extern_prelude: FxHashSet<Name> =
|
|
||||||
session.opts.externs.iter().map(|kv| Symbol::intern(kv.0)).collect();
|
|
||||||
|
|
||||||
// HACK(eddyb) this ignore the `no_{core,std}` attributes.
|
|
||||||
// FIXME(eddyb) warn (elsewhere) if core/std is used with `no_{core,std}`.
|
|
||||||
// if !attr::contains_name(&krate.attrs, "no_core") {
|
|
||||||
// if !attr::contains_name(&krate.attrs, "no_std") {
|
|
||||||
extern_prelude.insert(Symbol::intern("core"));
|
|
||||||
extern_prelude.insert(Symbol::intern("std"));
|
|
||||||
extern_prelude.insert(Symbol::intern("meta"));
|
|
||||||
|
|
||||||
let mut invocations = FxHashMap();
|
let mut invocations = FxHashMap();
|
||||||
invocations.insert(Mark::root(),
|
invocations.insert(Mark::root(),
|
||||||
arenas.alloc_invocation_data(InvocationData::root(graph_root)));
|
arenas.alloc_invocation_data(InvocationData::root(graph_root)));
|
||||||
|
@ -1692,7 +1680,6 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
||||||
// AST.
|
// AST.
|
||||||
graph_root,
|
graph_root,
|
||||||
prelude: None,
|
prelude: None,
|
||||||
extern_prelude,
|
|
||||||
|
|
||||||
has_self: FxHashSet(),
|
has_self: FxHashSet(),
|
||||||
field_names: FxHashMap(),
|
field_names: FxHashMap(),
|
||||||
|
@ -1963,7 +1950,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
||||||
|
|
||||||
if !module.no_implicit_prelude {
|
if !module.no_implicit_prelude {
|
||||||
// `record_used` means that we don't try to load crates during speculative resolution
|
// `record_used` means that we don't try to load crates during speculative resolution
|
||||||
if record_used && ns == TypeNS && self.extern_prelude.contains(&ident.name) {
|
if record_used && ns == TypeNS && self.session.extern_prelude.contains(&ident.name) {
|
||||||
let crate_id = self.crate_loader.process_path_extern(ident.name, ident.span);
|
let crate_id = self.crate_loader.process_path_extern(ident.name, ident.span);
|
||||||
let crate_root = self.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX });
|
let crate_root = self.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX });
|
||||||
self.populate_module_if_necessary(&crate_root);
|
self.populate_module_if_necessary(&crate_root);
|
||||||
|
@ -3955,7 +3942,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
||||||
} else {
|
} else {
|
||||||
// Items from the prelude
|
// Items from the prelude
|
||||||
if !module.no_implicit_prelude {
|
if !module.no_implicit_prelude {
|
||||||
names.extend(self.extern_prelude.iter().cloned());
|
names.extend(self.session.extern_prelude.iter().cloned());
|
||||||
if let Some(prelude) = self.prelude {
|
if let Some(prelude) = self.prelude {
|
||||||
add_module_candidates(prelude, &mut names);
|
add_module_candidates(prelude, &mut names);
|
||||||
}
|
}
|
||||||
|
@ -4401,8 +4388,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
|
||||||
);
|
);
|
||||||
|
|
||||||
if self.session.rust_2018() {
|
if self.session.rust_2018() {
|
||||||
let extern_prelude_names = self.extern_prelude.clone();
|
for &name in &self.session.extern_prelude {
|
||||||
for &name in extern_prelude_names.iter() {
|
|
||||||
let ident = Ident::with_empty_ctxt(name);
|
let ident = Ident::with_empty_ctxt(name);
|
||||||
match self.crate_loader.maybe_process_path_extern(name, ident.span) {
|
match self.crate_loader.maybe_process_path_extern(name, ident.span) {
|
||||||
Some(crate_id) => {
|
Some(crate_id) => {
|
||||||
|
|
|
@ -682,7 +682,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
WhereToResolve::ExternPrelude => {
|
WhereToResolve::ExternPrelude => {
|
||||||
if use_prelude && self.extern_prelude.contains(&ident.name) {
|
if use_prelude && self.session.extern_prelude.contains(&ident.name) {
|
||||||
let crate_id =
|
let crate_id =
|
||||||
self.crate_loader.process_path_extern(ident.name, ident.span);
|
self.crate_loader.process_path_extern(ident.name, ident.span);
|
||||||
let crate_root =
|
let crate_root =
|
||||||
|
|
|
@ -199,7 +199,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
|
||||||
if !(
|
if !(
|
||||||
ns == TypeNS &&
|
ns == TypeNS &&
|
||||||
!ident.is_path_segment_keyword() &&
|
!ident.is_path_segment_keyword() &&
|
||||||
self.extern_prelude.contains(&ident.name)
|
self.session.extern_prelude.contains(&ident.name)
|
||||||
) {
|
) {
|
||||||
// ... unless the crate name is not in the `extern_prelude`.
|
// ... unless the crate name is not in the `extern_prelude`.
|
||||||
return binding;
|
return binding;
|
||||||
|
@ -218,7 +218,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
|
||||||
} else if
|
} else if
|
||||||
ns == TypeNS &&
|
ns == TypeNS &&
|
||||||
!ident.is_path_segment_keyword() &&
|
!ident.is_path_segment_keyword() &&
|
||||||
self.extern_prelude.contains(&ident.name)
|
self.session.extern_prelude.contains(&ident.name)
|
||||||
{
|
{
|
||||||
let crate_id =
|
let crate_id =
|
||||||
self.crate_loader.process_path_extern(ident.name, ident.span);
|
self.crate_loader.process_path_extern(ident.name, ident.span);
|
||||||
|
@ -735,7 +735,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
|
||||||
let uniform_paths_feature = self.session.features_untracked().uniform_paths;
|
let uniform_paths_feature = self.session.features_untracked().uniform_paths;
|
||||||
for ((span, _, ns), results) in uniform_paths_canaries {
|
for ((span, _, ns), results) in uniform_paths_canaries {
|
||||||
let name = results.name;
|
let name = results.name;
|
||||||
let external_crate = if ns == TypeNS && self.extern_prelude.contains(&name) {
|
let external_crate = if ns == TypeNS && self.session.extern_prelude.contains(&name) {
|
||||||
let crate_id =
|
let crate_id =
|
||||||
self.crate_loader.process_path_extern(name, span);
|
self.crate_loader.process_path_extern(name, span);
|
||||||
Some(Def::Mod(DefId { krate: crate_id, index: CRATE_DEF_INDEX }))
|
Some(Def::Mod(DefId { krate: crate_id, index: CRATE_DEF_INDEX }))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue