Refactor explicitly_linked: bool
-> dep_kind: DepKind
.
This commit is contained in:
parent
c102d7fb68
commit
a1d45d94b0
@ -63,6 +63,16 @@ pub struct CrateSource {
|
||||
pub rlib: Option<(PathBuf, PathKind)>,
|
||||
}
|
||||
|
||||
#[derive(RustcEncodable, RustcDecodable, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug)]
|
||||
pub enum DepKind {
|
||||
/// A dependency that is always injected into the dependency list and so
|
||||
/// doesn't need to be linked to an rlib, e.g. the injected allocator.
|
||||
Implicit,
|
||||
/// A dependency that is required by an rlib version of this crate.
|
||||
/// Ordinary `extern crate`s result in `Explicit` dependencies.
|
||||
Explicit,
|
||||
}
|
||||
|
||||
#[derive(Copy, Debug, PartialEq, Clone, RustcEncodable, RustcDecodable)]
|
||||
pub enum LinkagePreference {
|
||||
RequireDynamic,
|
||||
@ -169,10 +179,10 @@ pub trait CrateStore<'tcx> {
|
||||
// crate metadata
|
||||
fn dylib_dependency_formats(&self, cnum: CrateNum)
|
||||
-> Vec<(CrateNum, LinkagePreference)>;
|
||||
fn dep_kind(&self, cnum: CrateNum) -> DepKind;
|
||||
fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>;
|
||||
fn missing_lang_items(&self, cnum: CrateNum) -> Vec<lang_items::LangItem>;
|
||||
fn is_staged_api(&self, cnum: CrateNum) -> bool;
|
||||
fn is_explicitly_linked(&self, cnum: CrateNum) -> bool;
|
||||
fn is_allocator(&self, cnum: CrateNum) -> bool;
|
||||
fn is_panic_runtime(&self, cnum: CrateNum) -> bool;
|
||||
fn is_compiler_builtins(&self, cnum: CrateNum) -> bool;
|
||||
@ -341,7 +351,7 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
|
||||
fn missing_lang_items(&self, cnum: CrateNum) -> Vec<lang_items::LangItem>
|
||||
{ bug!("missing_lang_items") }
|
||||
fn is_staged_api(&self, cnum: CrateNum) -> bool { bug!("is_staged_api") }
|
||||
fn is_explicitly_linked(&self, cnum: CrateNum) -> bool { bug!("is_explicitly_linked") }
|
||||
fn dep_kind(&self, cnum: CrateNum) -> DepKind { bug!("is_explicitly_linked") }
|
||||
fn is_allocator(&self, cnum: CrateNum) -> bool { bug!("is_allocator") }
|
||||
fn is_panic_runtime(&self, cnum: CrateNum) -> bool { bug!("is_panic_runtime") }
|
||||
fn is_compiler_builtins(&self, cnum: CrateNum) -> bool { bug!("is_compiler_builtins") }
|
||||
|
@ -65,6 +65,7 @@ use hir::def_id::CrateNum;
|
||||
|
||||
use session;
|
||||
use session::config;
|
||||
use middle::cstore::DepKind;
|
||||
use middle::cstore::LinkagePreference::{self, RequireStatic, RequireDynamic};
|
||||
use util::nodemap::FxHashMap;
|
||||
use rustc_back::PanicStrategy;
|
||||
@ -188,7 +189,7 @@ fn calculate_type(sess: &session::Session,
|
||||
let src = sess.cstore.used_crate_source(cnum);
|
||||
if src.dylib.is_none() &&
|
||||
!formats.contains_key(&cnum) &&
|
||||
sess.cstore.is_explicitly_linked(cnum) {
|
||||
sess.cstore.dep_kind(cnum) == DepKind::Explicit {
|
||||
assert!(src.rlib.is_some());
|
||||
info!("adding staticlib: {}", sess.cstore.crate_name(cnum));
|
||||
add_library(sess, cnum, RequireStatic, &mut formats);
|
||||
@ -272,7 +273,7 @@ fn attempt_static(sess: &session::Session) -> Option<DependencyList> {
|
||||
// everything in explicitly so long as it's actually required.
|
||||
let last_crate = sess.cstore.crates().len();
|
||||
let mut ret = (1..last_crate+1).map(|cnum| {
|
||||
if sess.cstore.is_explicitly_linked(CrateNum::new(cnum)) {
|
||||
if sess.cstore.dep_kind(CrateNum::new(cnum)) == DepKind::Explicit {
|
||||
Linkage::Static
|
||||
} else {
|
||||
Linkage::NotLinked
|
||||
|
@ -16,7 +16,7 @@ use schema::CrateRoot;
|
||||
|
||||
use rustc::hir::def_id::{CrateNum, DefIndex};
|
||||
use rustc::hir::svh::Svh;
|
||||
use rustc::middle::cstore::LoadedMacros;
|
||||
use rustc::middle::cstore::{DepKind, LoadedMacros};
|
||||
use rustc::session::{config, Session};
|
||||
use rustc_back::PanicStrategy;
|
||||
use rustc::session::search_paths::PathKind;
|
||||
@ -29,7 +29,7 @@ use std::cell::{RefCell, Cell};
|
||||
use std::ops::Deref;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use std::fs;
|
||||
use std::{cmp, fs};
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::abi::Abi;
|
||||
@ -60,7 +60,7 @@ fn dump_crates(cstore: &CStore) {
|
||||
info!(" name: {}", data.name());
|
||||
info!(" cnum: {}", data.cnum);
|
||||
info!(" hash: {}", data.hash());
|
||||
info!(" reqd: {}", data.explicitly_linked.get());
|
||||
info!(" reqd: {:?}", data.dep_kind.get());
|
||||
let CrateSource { dylib, rlib } = data.source.clone();
|
||||
dylib.map(|dl| info!(" dylib: {}", dl.0.display()));
|
||||
rlib.map(|rl| info!(" rlib: {}", rl.0.display()));
|
||||
@ -258,7 +258,7 @@ impl<'a> CrateLoader<'a> {
|
||||
name: &str,
|
||||
span: Span,
|
||||
lib: Library,
|
||||
explicitly_linked: bool)
|
||||
dep_kind: DepKind)
|
||||
-> (CrateNum, Rc<cstore::CrateMetadata>) {
|
||||
info!("register crate `extern crate {} as {}`", name, ident);
|
||||
let crate_root = lib.metadata.get_root();
|
||||
@ -299,7 +299,7 @@ impl<'a> CrateLoader<'a> {
|
||||
cnum_map: RefCell::new(cnum_map),
|
||||
cnum: cnum,
|
||||
codemap_import_info: RefCell::new(vec![]),
|
||||
explicitly_linked: Cell::new(explicitly_linked),
|
||||
dep_kind: Cell::new(dep_kind),
|
||||
source: cstore::CrateSource {
|
||||
dylib: dylib,
|
||||
rlib: rlib,
|
||||
@ -317,7 +317,7 @@ impl<'a> CrateLoader<'a> {
|
||||
hash: Option<&Svh>,
|
||||
span: Span,
|
||||
kind: PathKind,
|
||||
explicitly_linked: bool)
|
||||
dep_kind: DepKind)
|
||||
-> (CrateNum, Rc<cstore::CrateMetadata>) {
|
||||
info!("resolving crate `extern crate {} as {}`", name, ident);
|
||||
let result = match self.existing_match(name, hash, kind) {
|
||||
@ -350,12 +350,11 @@ impl<'a> CrateLoader<'a> {
|
||||
match result {
|
||||
LoadResult::Previous(cnum) => {
|
||||
let data = self.cstore.get_crate_data(cnum);
|
||||
data.explicitly_linked.set(explicitly_linked || data.explicitly_linked.get());
|
||||
data.dep_kind.set(cmp::max(data.dep_kind.get(), dep_kind));
|
||||
(cnum, data)
|
||||
}
|
||||
LoadResult::Loaded(library) => {
|
||||
self.register_crate(root, ident, name, span, library,
|
||||
explicitly_linked)
|
||||
self.register_crate(root, ident, name, span, library, dep_kind)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -442,7 +441,7 @@ impl<'a> CrateLoader<'a> {
|
||||
Some(&dep.hash),
|
||||
span,
|
||||
PathKind::Dependency,
|
||||
dep.explicitly_linked);
|
||||
dep.kind);
|
||||
(CrateNum::new(crate_num + 1), local_cnum)
|
||||
}).collect();
|
||||
|
||||
@ -716,7 +715,7 @@ impl<'a> CrateLoader<'a> {
|
||||
// #![panic_runtime] crate.
|
||||
self.inject_dependency_if(cnum, "a panic runtime",
|
||||
&|data| data.needs_panic_runtime());
|
||||
runtime_found = runtime_found || data.explicitly_linked.get();
|
||||
runtime_found = runtime_found || data.dep_kind.get() == DepKind::Explicit;
|
||||
}
|
||||
});
|
||||
|
||||
@ -745,8 +744,9 @@ impl<'a> CrateLoader<'a> {
|
||||
};
|
||||
info!("panic runtime not found -- loading {}", name);
|
||||
|
||||
let dep_kind = DepKind::Implicit;
|
||||
let (cnum, data) =
|
||||
self.resolve_crate(&None, name, name, None, DUMMY_SP, PathKind::Crate, false);
|
||||
self.resolve_crate(&None, name, name, None, DUMMY_SP, PathKind::Crate, dep_kind);
|
||||
|
||||
// Sanity check the loaded crate to ensure it is indeed a panic runtime
|
||||
// and the panic strategy is indeed what we thought it was.
|
||||
@ -780,7 +780,7 @@ impl<'a> CrateLoader<'a> {
|
||||
self.inject_dependency_if(cnum, "an allocator",
|
||||
&|data| data.needs_allocator());
|
||||
found_required_allocator = found_required_allocator ||
|
||||
data.explicitly_linked.get();
|
||||
data.dep_kind.get() == DepKind::Explicit;
|
||||
}
|
||||
});
|
||||
if !needs_allocator || found_required_allocator { return }
|
||||
@ -826,8 +826,9 @@ impl<'a> CrateLoader<'a> {
|
||||
} else {
|
||||
&self.sess.target.target.options.exe_allocation_crate
|
||||
};
|
||||
let dep_kind = DepKind::Implicit;
|
||||
let (cnum, data) =
|
||||
self.resolve_crate(&None, name, name, None, DUMMY_SP, PathKind::Crate, false);
|
||||
self.resolve_crate(&None, name, name, None, DUMMY_SP, PathKind::Crate, dep_kind);
|
||||
|
||||
// Sanity check the crate we loaded to ensure that it is indeed an
|
||||
// allocator.
|
||||
@ -993,7 +994,7 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
|
||||
if let PMDSource::Owned(lib) = ekrate.metadata {
|
||||
if ekrate.target_only || config::host_triple() == self.sess.opts.target_triple {
|
||||
let ExternCrateInfo { ref ident, ref name, .. } = info;
|
||||
self.register_crate(&None, ident, name, item.span, lib, true);
|
||||
self.register_crate(&None, ident, name, item.span, lib, DepKind::Explicit);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1006,7 +1007,7 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
|
||||
};
|
||||
|
||||
let (cnum, ..) = self.resolve_crate(
|
||||
&None, &info.ident, &info.name, None, item.span, PathKind::Crate, true,
|
||||
&None, &info.ident, &info.name, None, item.span, PathKind::Crate, DepKind::Explicit,
|
||||
);
|
||||
|
||||
let def_id = definitions.opt_local_def_id(item.id).unwrap();
|
||||
|
@ -18,7 +18,7 @@ use rustc::dep_graph::DepGraph;
|
||||
use rustc::hir::def_id::{CRATE_DEF_INDEX, CrateNum, DefIndex, DefId};
|
||||
use rustc::hir::map::DefKey;
|
||||
use rustc::hir::svh::Svh;
|
||||
use rustc::middle::cstore::ExternCrate;
|
||||
use rustc::middle::cstore::{DepKind, ExternCrate};
|
||||
use rustc_back::PanicStrategy;
|
||||
use rustc_data_structures::indexed_vec::IndexVec;
|
||||
use rustc::util::nodemap::{FxHashMap, NodeMap, NodeSet, DefIdMap};
|
||||
@ -78,12 +78,7 @@ pub struct CrateMetadata {
|
||||
/// compilation support.
|
||||
pub key_map: FxHashMap<DefKey, DefIndex>,
|
||||
|
||||
/// Flag if this crate is required by an rlib version of this crate, or in
|
||||
/// other words whether it was explicitly linked to. An example of a crate
|
||||
/// where this is false is when an allocator crate is injected into the
|
||||
/// dependency list, and therefore isn't actually needed to link an rlib.
|
||||
pub explicitly_linked: Cell<bool>,
|
||||
|
||||
pub dep_kind: Cell<DepKind>,
|
||||
pub source: CrateSource,
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ use encoder;
|
||||
use locator;
|
||||
use schema;
|
||||
|
||||
use rustc::middle::cstore::{InlinedItem, CrateStore, CrateSource, ExternCrate};
|
||||
use rustc::middle::cstore::{InlinedItem, CrateStore, CrateSource, DepKind, ExternCrate};
|
||||
use rustc::middle::cstore::{NativeLibraryKind, LinkMeta, LinkagePreference};
|
||||
use rustc::hir::def::{self, Def};
|
||||
use rustc::middle::lang_items;
|
||||
@ -221,6 +221,11 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
||||
self.get_crate_data(cnum).get_dylib_dependency_formats()
|
||||
}
|
||||
|
||||
fn dep_kind(&self, cnum: CrateNum) -> DepKind
|
||||
{
|
||||
self.get_crate_data(cnum).dep_kind.get()
|
||||
}
|
||||
|
||||
fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>
|
||||
{
|
||||
self.get_crate_data(cnum).get_lang_items()
|
||||
@ -237,11 +242,6 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
||||
self.get_crate_data(cnum).is_staged_api()
|
||||
}
|
||||
|
||||
fn is_explicitly_linked(&self, cnum: CrateNum) -> bool
|
||||
{
|
||||
self.get_crate_data(cnum).explicitly_linked.get()
|
||||
}
|
||||
|
||||
fn is_allocator(&self, cnum: CrateNum) -> bool
|
||||
{
|
||||
self.get_crate_data(cnum).is_allocator()
|
||||
|
@ -1080,7 +1080,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
CrateDep {
|
||||
name: syntax::parse::token::intern(dep.name()),
|
||||
hash: dep.hash(),
|
||||
explicitly_linked: dep.explicitly_linked.get(),
|
||||
kind: dep.dep_kind.get(),
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ use index;
|
||||
use rustc::hir;
|
||||
use rustc::hir::def::{self, CtorKind};
|
||||
use rustc::hir::def_id::{DefIndex, DefId};
|
||||
use rustc::middle::cstore::{LinkagePreference, NativeLibraryKind};
|
||||
use rustc::middle::cstore::{DepKind, LinkagePreference, NativeLibraryKind};
|
||||
use rustc::middle::lang_items;
|
||||
use rustc::mir;
|
||||
use rustc::ty::{self, Ty};
|
||||
@ -187,7 +187,7 @@ pub struct CrateRoot {
|
||||
pub struct CrateDep {
|
||||
pub name: ast::Name,
|
||||
pub hash: hir::svh::Svh,
|
||||
pub explicitly_linked: bool,
|
||||
pub kind: DepKind,
|
||||
}
|
||||
|
||||
#[derive(RustcEncodable, RustcDecodable)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user