2015-11-20 06:51:18 -06:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2015-11-24 16:00:26 -06:00
|
|
|
use cstore;
|
|
|
|
use encoder;
|
2016-10-19 23:31:14 -05:00
|
|
|
use locator;
|
2016-09-16 09:25:54 -05:00
|
|
|
use schema;
|
2015-11-24 16:00:26 -06:00
|
|
|
|
2016-09-28 18:30:53 -05:00
|
|
|
use rustc::dep_graph::DepTrackingMapConfig;
|
2017-04-05 16:39:02 -05:00
|
|
|
use rustc::middle::cstore::{CrateStore, CrateSource, LibSource, DepKind,
|
|
|
|
ExternCrate, NativeLibrary, LinkMeta,
|
|
|
|
LinkagePreference, LoadedMacro, EncodedMetadata};
|
2016-09-15 03:05:45 -05:00
|
|
|
use rustc::hir::def::{self, Def};
|
2016-09-08 11:05:50 -05:00
|
|
|
use rustc::middle::lang_items;
|
2016-10-28 01:52:45 -05:00
|
|
|
use rustc::session::Session;
|
2016-09-28 18:30:53 -05:00
|
|
|
use rustc::ty::{self, TyCtxt};
|
|
|
|
use rustc::ty::maps::Providers;
|
2016-11-23 18:09:51 -06:00
|
|
|
use rustc::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
|
2015-11-20 06:51:18 -06:00
|
|
|
|
2016-04-22 14:47:14 -05:00
|
|
|
use rustc::dep_graph::DepNode;
|
2016-12-16 16:24:27 -06:00
|
|
|
use rustc::hir::map::{DefKey, DefPath, DisambiguatedDefPathData};
|
2016-09-19 15:49:01 -05:00
|
|
|
use rustc::util::nodemap::{NodeSet, DefIdMap};
|
2016-09-27 21:26:08 -05:00
|
|
|
use rustc_back::PanicStrategy;
|
2015-11-24 16:00:26 -06:00
|
|
|
|
2016-09-28 18:30:53 -05:00
|
|
|
use std::any::Any;
|
|
|
|
use std::mem;
|
|
|
|
use std::rc::Rc;
|
|
|
|
|
2015-11-20 06:51:18 -06:00
|
|
|
use syntax::ast;
|
|
|
|
use syntax::attr;
|
2017-02-20 23:05:59 -06:00
|
|
|
use syntax::parse::filemap_to_stream;
|
2016-11-16 04:52:37 -06:00
|
|
|
use syntax::symbol::Symbol;
|
2017-03-14 19:22:48 -05:00
|
|
|
use syntax_pos::{Span, NO_EXPANSION};
|
2016-03-29 00:50:44 -05:00
|
|
|
use rustc::hir::svh::Svh;
|
2015-11-20 17:08:09 -06:00
|
|
|
use rustc_back::target::Target;
|
2016-03-29 00:50:44 -05:00
|
|
|
use rustc::hir;
|
2015-11-20 06:51:18 -06:00
|
|
|
|
2016-12-27 03:15:26 -06:00
|
|
|
use std::collections::BTreeMap;
|
|
|
|
|
2016-09-28 18:30:53 -05:00
|
|
|
macro_rules! provide {
|
|
|
|
(<$lt:tt> $tcx:ident, $def_id:ident, $cdata:ident $($name:ident => $compute:block)*) => {
|
|
|
|
pub fn provide<$lt>(providers: &mut Providers<$lt>) {
|
|
|
|
$(fn $name<'a, $lt:$lt>($tcx: TyCtxt<'a, $lt, $lt>, $def_id: DefId)
|
2017-02-19 06:37:50 -06:00
|
|
|
-> <ty::queries::$name<$lt> as
|
2016-09-28 18:30:53 -05:00
|
|
|
DepTrackingMapConfig>::Value {
|
|
|
|
assert!(!$def_id.is_local());
|
|
|
|
|
|
|
|
$tcx.dep_graph.read(DepNode::MetaData($def_id));
|
|
|
|
|
|
|
|
let $cdata = $tcx.sess.cstore.crate_data_as_rc_any($def_id.krate);
|
|
|
|
let $cdata = $cdata.downcast_ref::<cstore::CrateMetadata>()
|
|
|
|
.expect("CrateStore crated ata is not a CrateMetadata");
|
|
|
|
$compute
|
|
|
|
})*
|
|
|
|
|
|
|
|
*providers = Providers {
|
|
|
|
$($name,)*
|
|
|
|
..*providers
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
provide! { <'tcx> tcx, def_id, cdata
|
|
|
|
ty => { cdata.get_type(def_id.index, tcx) }
|
|
|
|
generics => { tcx.alloc_generics(cdata.get_generics(def_id.index)) }
|
|
|
|
predicates => { cdata.get_predicates(def_id.index, tcx) }
|
|
|
|
super_predicates => { cdata.get_super_predicates(def_id.index, tcx) }
|
|
|
|
trait_def => {
|
2017-04-03 12:20:26 -05:00
|
|
|
tcx.alloc_trait_def(cdata.get_trait_def(def_id.index))
|
2016-09-28 18:30:53 -05:00
|
|
|
}
|
|
|
|
adt_def => { cdata.get_adt_def(def_id.index, tcx) }
|
2017-03-01 10:42:26 -06:00
|
|
|
adt_destructor => {
|
|
|
|
let _ = cdata;
|
|
|
|
tcx.calculate_dtor(def_id, &mut |_,_| Ok(()))
|
|
|
|
}
|
2016-09-28 18:30:53 -05:00
|
|
|
variances => { Rc::new(cdata.get_item_variances(def_id.index)) }
|
|
|
|
associated_item_def_ids => {
|
|
|
|
let mut result = vec![];
|
|
|
|
cdata.each_child_of_item(def_id.index, |child| result.push(child.def.def_id()));
|
|
|
|
Rc::new(result)
|
|
|
|
}
|
|
|
|
associated_item => { cdata.get_associated_item(def_id.index) }
|
|
|
|
impl_trait_ref => { cdata.get_impl_trait(def_id.index, tcx) }
|
2017-04-20 12:37:02 -05:00
|
|
|
impl_polarity => { cdata.get_impl_polarity(def_id.index) }
|
2017-03-17 15:17:45 -05:00
|
|
|
coerce_unsized_info => {
|
|
|
|
cdata.get_coerce_unsized_info(def_id.index).unwrap_or_else(|| {
|
|
|
|
bug!("coerce_unsized_info: `{:?}` is missing its info", def_id);
|
2016-09-28 18:30:53 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
mir => {
|
|
|
|
let mir = cdata.maybe_get_item_mir(tcx, def_id.index).unwrap_or_else(|| {
|
|
|
|
bug!("get_item_mir: missing MIR for `{:?}`", def_id)
|
|
|
|
});
|
|
|
|
|
|
|
|
let mir = tcx.alloc_mir(mir);
|
|
|
|
|
|
|
|
// Perma-borrow MIR from extern crates to prevent mutation.
|
|
|
|
mem::forget(mir.borrow());
|
|
|
|
|
|
|
|
mir
|
|
|
|
}
|
2017-02-19 19:55:28 -06:00
|
|
|
mir_const_qualif => { cdata.mir_const_qualif(def_id.index) }
|
2017-02-14 03:32:00 -06:00
|
|
|
typeck_tables => { cdata.item_body_tables(def_id.index, tcx) }
|
2016-09-28 18:30:53 -05:00
|
|
|
closure_kind => { cdata.closure_kind(def_id.index) }
|
|
|
|
closure_type => { cdata.closure_ty(def_id.index, tcx) }
|
2017-03-20 17:35:16 -05:00
|
|
|
inherent_impls => { Rc::new(cdata.get_inherent_implementations_for_type(def_id.index)) }
|
2017-04-14 09:51:22 -05:00
|
|
|
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
|
2016-09-28 18:30:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl CrateStore for cstore::CStore {
|
|
|
|
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc<Any> {
|
|
|
|
self.get_crate_data(krate)
|
|
|
|
}
|
|
|
|
|
2016-09-15 03:05:45 -05:00
|
|
|
fn describe_def(&self, def: DefId) -> Option<Def> {
|
|
|
|
self.dep_graph.read(DepNode::MetaData(def));
|
|
|
|
self.get_crate_data(def.krate).get_def(def.index)
|
|
|
|
}
|
|
|
|
|
2016-11-23 17:39:13 -06:00
|
|
|
fn def_span(&self, sess: &Session, def: DefId) -> Span {
|
|
|
|
self.dep_graph.read(DepNode::MetaData(def));
|
|
|
|
self.get_crate_data(def.krate).get_span(def.index, sess)
|
|
|
|
}
|
|
|
|
|
2016-04-22 14:47:14 -05:00
|
|
|
fn stability(&self, def: DefId) -> Option<attr::Stability> {
|
|
|
|
self.dep_graph.read(DepNode::MetaData(def));
|
2016-09-15 03:04:00 -05:00
|
|
|
self.get_crate_data(def.krate).get_stability(def.index)
|
2015-11-20 06:51:18 -06:00
|
|
|
}
|
|
|
|
|
2016-04-22 14:47:14 -05:00
|
|
|
fn deprecation(&self, def: DefId) -> Option<attr::Deprecation> {
|
|
|
|
self.dep_graph.read(DepNode::MetaData(def));
|
2016-09-15 03:04:00 -05:00
|
|
|
self.get_crate_data(def.krate).get_deprecation(def.index)
|
2015-12-04 10:34:28 -06:00
|
|
|
}
|
|
|
|
|
2016-03-25 01:08:11 -05:00
|
|
|
fn visibility(&self, def: DefId) -> ty::Visibility {
|
2016-04-22 14:47:14 -05:00
|
|
|
self.dep_graph.read(DepNode::MetaData(def));
|
2016-09-15 03:04:00 -05:00
|
|
|
self.get_crate_data(def.krate).get_visibility(def.index)
|
2016-03-05 16:22:44 -06:00
|
|
|
}
|
|
|
|
|
2016-09-28 18:30:53 -05:00
|
|
|
fn item_generics_cloned(&self, def: DefId) -> ty::Generics {
|
2017-01-25 09:32:44 -06:00
|
|
|
self.dep_graph.read(DepNode::MetaData(def));
|
2017-01-25 14:01:11 -06:00
|
|
|
self.get_crate_data(def.krate).get_generics(def.index)
|
2017-01-25 09:32:44 -06:00
|
|
|
}
|
|
|
|
|
2017-04-20 07:08:41 -05:00
|
|
|
fn item_attrs(&self, def_id: DefId) -> Rc<[ast::Attribute]>
|
2015-11-20 06:51:18 -06:00
|
|
|
{
|
2016-04-22 14:47:14 -05:00
|
|
|
self.dep_graph.read(DepNode::MetaData(def_id));
|
2016-09-15 03:04:00 -05:00
|
|
|
self.get_crate_data(def_id.krate).get_item_attrs(def_id.index)
|
2015-11-20 06:51:18 -06:00
|
|
|
}
|
|
|
|
|
2016-09-16 09:25:54 -05:00
|
|
|
fn fn_arg_names(&self, did: DefId) -> Vec<ast::Name>
|
2015-11-22 13:02:04 -06:00
|
|
|
{
|
2016-12-20 14:46:11 -06:00
|
|
|
// FIXME(#38501) We've skipped a `read` on the `HirBody` of
|
|
|
|
// a `fn` when encoding, so the dep-tracking wouldn't work.
|
|
|
|
// This is only used by rustdoc anyway, which shouldn't have
|
|
|
|
// incremental recompilation ever enabled.
|
|
|
|
assert!(!self.dep_graph.is_fully_enabled());
|
2016-09-15 03:04:00 -05:00
|
|
|
self.get_crate_data(did.krate).get_fn_arg_names(did.index)
|
2015-11-20 06:51:18 -06:00
|
|
|
}
|
|
|
|
|
2016-09-19 15:49:01 -05:00
|
|
|
fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId>
|
2015-11-20 06:51:18 -06:00
|
|
|
{
|
2016-09-19 15:49:01 -05:00
|
|
|
if let Some(def_id) = filter {
|
|
|
|
self.dep_graph.read(DepNode::MetaData(def_id));
|
|
|
|
}
|
2015-11-20 06:51:18 -06:00
|
|
|
let mut result = vec![];
|
|
|
|
self.iter_crate_data(|_, cdata| {
|
2016-09-16 09:25:54 -05:00
|
|
|
cdata.get_implementations_for_trait(filter, &mut result)
|
2015-11-20 06:51:18 -06:00
|
|
|
});
|
|
|
|
result
|
|
|
|
}
|
|
|
|
|
2015-12-22 12:20:47 -06:00
|
|
|
fn impl_parent(&self, impl_def: DefId) -> Option<DefId> {
|
2016-04-22 14:47:14 -05:00
|
|
|
self.dep_graph.read(DepNode::MetaData(impl_def));
|
2016-09-15 03:04:00 -05:00
|
|
|
self.get_crate_data(impl_def.krate).get_parent_impl(impl_def.index)
|
2015-12-22 12:20:47 -06:00
|
|
|
}
|
|
|
|
|
2016-08-08 15:39:49 -05:00
|
|
|
fn trait_of_item(&self, def_id: DefId) -> Option<DefId> {
|
2016-04-22 14:47:14 -05:00
|
|
|
self.dep_graph.read(DepNode::MetaData(def_id));
|
2016-09-15 03:04:00 -05:00
|
|
|
self.get_crate_data(def_id.krate).get_trait_of_item(def_id.index)
|
2015-11-20 06:51:18 -06:00
|
|
|
}
|
|
|
|
|
2016-09-28 18:30:53 -05:00
|
|
|
fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem
|
2015-11-20 06:51:18 -06:00
|
|
|
{
|
2016-04-22 14:47:14 -05:00
|
|
|
self.dep_graph.read(DepNode::MetaData(def));
|
2016-11-09 18:06:34 -06:00
|
|
|
self.get_crate_data(def.krate).get_associated_item(def.index)
|
2015-11-20 06:51:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn is_const_fn(&self, did: DefId) -> bool
|
|
|
|
{
|
2016-04-22 14:47:14 -05:00
|
|
|
self.dep_graph.read(DepNode::MetaData(did));
|
2016-09-15 03:04:00 -05:00
|
|
|
self.get_crate_data(did.krate).is_const_fn(did.index)
|
2015-11-20 06:51:18 -06:00
|
|
|
}
|
|
|
|
|
2015-11-22 13:02:04 -06:00
|
|
|
fn is_default_impl(&self, impl_did: DefId) -> bool {
|
2016-04-22 14:47:14 -05:00
|
|
|
self.dep_graph.read(DepNode::MetaData(impl_did));
|
2016-09-15 03:04:00 -05:00
|
|
|
self.get_crate_data(impl_did.krate).is_default_impl(impl_did.index)
|
2015-11-20 09:46:39 -06:00
|
|
|
}
|
|
|
|
|
2016-05-12 11:52:38 -05:00
|
|
|
fn is_foreign_item(&self, did: DefId) -> bool {
|
2016-09-15 03:04:00 -05:00
|
|
|
self.get_crate_data(did.krate).is_foreign_item(did.index)
|
2016-05-12 11:52:38 -05:00
|
|
|
}
|
|
|
|
|
2016-11-23 18:09:51 -06:00
|
|
|
fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool
|
2015-11-21 13:39:05 -06:00
|
|
|
{
|
2016-11-23 18:09:51 -06:00
|
|
|
self.do_is_statically_included_foreign_item(def_id)
|
|
|
|
}
|
|
|
|
|
2017-01-09 08:46:24 -06:00
|
|
|
fn is_exported_symbol(&self, def_id: DefId) -> bool {
|
|
|
|
self.get_crate_data(def_id.krate).exported_symbols.contains(&def_id.index)
|
|
|
|
}
|
|
|
|
|
2016-11-23 18:09:51 -06:00
|
|
|
fn is_dllimport_foreign_item(&self, def_id: DefId) -> bool {
|
|
|
|
if def_id.krate == LOCAL_CRATE {
|
|
|
|
self.dllimport_foreign_items.borrow().contains(&def_id.index)
|
|
|
|
} else {
|
|
|
|
self.get_crate_data(def_id.krate).is_dllimport_foreign_item(def_id.index)
|
|
|
|
}
|
2015-11-21 13:39:05 -06:00
|
|
|
}
|
|
|
|
|
2016-08-31 06:00:29 -05:00
|
|
|
fn dylib_dependency_formats(&self, cnum: CrateNum)
|
|
|
|
-> Vec<(CrateNum, LinkagePreference)>
|
2015-11-20 06:51:18 -06:00
|
|
|
{
|
2016-09-15 03:04:00 -05:00
|
|
|
self.get_crate_data(cnum).get_dylib_dependency_formats()
|
2015-11-20 06:51:18 -06:00
|
|
|
}
|
|
|
|
|
2016-10-27 04:18:45 -05:00
|
|
|
fn dep_kind(&self, cnum: CrateNum) -> DepKind
|
|
|
|
{
|
|
|
|
self.get_crate_data(cnum).dep_kind.get()
|
|
|
|
}
|
|
|
|
|
2016-11-26 20:57:15 -06:00
|
|
|
fn export_macros(&self, cnum: CrateNum) {
|
|
|
|
if self.get_crate_data(cnum).dep_kind.get() == DepKind::UnexportedMacrosOnly {
|
|
|
|
self.get_crate_data(cnum).dep_kind.set(DepKind::MacrosOnly)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-31 06:00:29 -05:00
|
|
|
fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>
|
2015-11-20 06:51:18 -06:00
|
|
|
{
|
2016-09-15 03:04:00 -05:00
|
|
|
self.get_crate_data(cnum).get_lang_items()
|
2015-11-20 06:51:18 -06:00
|
|
|
}
|
|
|
|
|
2016-08-31 06:00:29 -05:00
|
|
|
fn missing_lang_items(&self, cnum: CrateNum)
|
2015-11-20 06:51:18 -06:00
|
|
|
-> Vec<lang_items::LangItem>
|
|
|
|
{
|
2016-09-15 03:04:00 -05:00
|
|
|
self.get_crate_data(cnum).get_missing_lang_items()
|
2015-11-20 06:51:18 -06:00
|
|
|
}
|
|
|
|
|
2016-08-31 06:00:29 -05:00
|
|
|
fn is_staged_api(&self, cnum: CrateNum) -> bool
|
2015-11-20 06:51:18 -06:00
|
|
|
{
|
2016-09-19 15:49:01 -05:00
|
|
|
self.get_crate_data(cnum).is_staged_api()
|
2015-11-20 06:51:18 -06:00
|
|
|
}
|
|
|
|
|
2016-08-31 06:00:29 -05:00
|
|
|
fn is_allocator(&self, cnum: CrateNum) -> bool
|
2015-11-20 17:08:09 -06:00
|
|
|
{
|
|
|
|
self.get_crate_data(cnum).is_allocator()
|
|
|
|
}
|
|
|
|
|
2016-08-31 06:00:29 -05:00
|
|
|
fn is_panic_runtime(&self, cnum: CrateNum) -> bool
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-08 18:18:40 -05:00
|
|
|
{
|
|
|
|
self.get_crate_data(cnum).is_panic_runtime()
|
|
|
|
}
|
|
|
|
|
2016-08-31 06:00:29 -05:00
|
|
|
fn is_compiler_builtins(&self, cnum: CrateNum) -> bool {
|
2016-07-24 21:42:11 -05:00
|
|
|
self.get_crate_data(cnum).is_compiler_builtins()
|
|
|
|
}
|
|
|
|
|
2016-12-29 22:28:11 -06:00
|
|
|
fn is_sanitizer_runtime(&self, cnum: CrateNum) -> bool {
|
|
|
|
self.get_crate_data(cnum).is_sanitizer_runtime()
|
|
|
|
}
|
|
|
|
|
2016-08-31 06:00:29 -05:00
|
|
|
fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy {
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-08 18:18:40 -05:00
|
|
|
self.get_crate_data(cnum).panic_strategy()
|
|
|
|
}
|
|
|
|
|
2016-11-16 04:52:37 -06:00
|
|
|
fn crate_name(&self, cnum: CrateNum) -> Symbol
|
2015-11-20 17:08:09 -06:00
|
|
|
{
|
2016-11-16 04:52:37 -06:00
|
|
|
self.get_crate_data(cnum).name
|
2015-11-20 17:08:09 -06:00
|
|
|
}
|
|
|
|
|
2016-11-16 04:52:37 -06:00
|
|
|
fn original_crate_name(&self, cnum: CrateNum) -> Symbol
|
2016-03-01 07:19:00 -06:00
|
|
|
{
|
2016-11-16 04:52:37 -06:00
|
|
|
self.get_crate_data(cnum).name()
|
2016-03-01 07:19:00 -06:00
|
|
|
}
|
|
|
|
|
2016-08-31 06:00:29 -05:00
|
|
|
fn extern_crate(&self, cnum: CrateNum) -> Option<ExternCrate>
|
2016-03-16 04:50:38 -05:00
|
|
|
{
|
|
|
|
self.get_crate_data(cnum).extern_crate.get()
|
|
|
|
}
|
|
|
|
|
2016-08-31 06:00:29 -05:00
|
|
|
fn crate_hash(&self, cnum: CrateNum) -> Svh
|
2015-11-21 13:39:05 -06:00
|
|
|
{
|
2016-09-08 11:05:50 -05:00
|
|
|
self.get_crate_hash(cnum)
|
2015-11-21 13:39:05 -06:00
|
|
|
}
|
|
|
|
|
2016-11-16 04:52:37 -06:00
|
|
|
fn crate_disambiguator(&self, cnum: CrateNum) -> Symbol
|
2016-02-12 07:41:30 -06:00
|
|
|
{
|
2016-11-16 04:52:37 -06:00
|
|
|
self.get_crate_data(cnum).disambiguator()
|
2015-11-22 13:02:04 -06:00
|
|
|
}
|
|
|
|
|
2016-08-31 06:00:29 -05:00
|
|
|
fn plugin_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>
|
2015-11-20 09:46:39 -06:00
|
|
|
{
|
2016-09-16 09:25:54 -05:00
|
|
|
self.get_crate_data(cnum).root.plugin_registrar_fn.map(|index| DefId {
|
2015-11-20 09:46:39 -06:00
|
|
|
krate: cnum,
|
|
|
|
index: index
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-11-30 09:03:42 -06:00
|
|
|
fn derive_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>
|
|
|
|
{
|
|
|
|
self.get_crate_data(cnum).root.macro_derive_registrar.map(|index| DefId {
|
|
|
|
krate: cnum,
|
|
|
|
index: index
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
rustc: Implement #[link(cfg(..))] and crt-static
This commit is an implementation of [RFC 1721] which adds a new target feature
to the compiler, `crt-static`, which can be used to select how the C runtime for
a target is linked. Most targets dynamically linke the C runtime by default with
the notable exception of some of the musl targets.
[RFC 1721]: https://github.com/rust-lang/rfcs/blob/master/text/1721-crt-static.md
This commit first adds the new target-feature, `crt-static`. If enabled, then
the `cfg(target_feature = "crt-static")` will be available. Targets like musl
will have this enabled by default. This feature can be controlled through the
standard target-feature interface, `-C target-feature=+crt-static` or
`-C target-feature=-crt-static`.
Next this adds an gated and unstable `#[link(cfg(..))]` feature to enable the
`crt-static` semantics we want with libc. The exact behavior of this attribute
is a little squishy, but it's intended to be a forever-unstable
implementation detail of the liblibc crate.
Specifically the `#[link(cfg(..))]` annotation means that the `#[link]`
directive is only active in a compilation unit if that `cfg` value is satisfied.
For example when compiling an rlib, these directives are just encoded and
ignored for dylibs, and all staticlibs are continued to be put into the rlib as
usual. When placing that rlib into a staticlib, executable, or dylib, however,
the `cfg` is evaluated *as if it were defined in the final artifact* and the
library is decided to be linked or not.
Essentially, what'll happen is:
* On MSVC with `-C target-feature=-crt-static`, the `msvcrt.lib` library will be
linked to.
* On MSVC with `-C target-feature=+crt-static`, the `libcmt.lib` library will be
linked to.
* On musl with `-C target-feature=-crt-static`, the object files in liblibc.rlib
are removed and `-lc` is passed instead.
* On musl with `-C target-feature=+crt-static`, the object files in liblibc.rlib
are used and `-lc` is not passed.
This commit does **not** include an update to the liblibc module to implement
these changes. I plan to do that just after the 1.14.0 beta release is cut to
ensure we get ample time to test this feature.
cc #37406
2016-10-31 18:40:13 -05:00
|
|
|
fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>
|
2015-11-20 17:08:09 -06:00
|
|
|
{
|
2016-09-15 03:04:00 -05:00
|
|
|
self.get_crate_data(cnum).get_native_libraries()
|
2015-11-20 17:08:09 -06:00
|
|
|
}
|
|
|
|
|
2016-11-28 17:05:53 -06:00
|
|
|
fn exported_symbols(&self, cnum: CrateNum) -> Vec<DefId>
|
2015-11-20 17:08:09 -06:00
|
|
|
{
|
2016-11-28 17:05:53 -06:00
|
|
|
self.get_crate_data(cnum).get_exported_symbols()
|
2015-11-20 17:08:09 -06:00
|
|
|
}
|
|
|
|
|
2016-08-31 06:00:29 -05:00
|
|
|
fn is_no_builtins(&self, cnum: CrateNum) -> bool {
|
2016-09-15 03:04:00 -05:00
|
|
|
self.get_crate_data(cnum).is_no_builtins()
|
2016-08-14 21:56:26 -05:00
|
|
|
}
|
|
|
|
|
2016-12-16 16:24:27 -06:00
|
|
|
fn retrace_path(&self,
|
|
|
|
cnum: CrateNum,
|
|
|
|
path: &[DisambiguatedDefPathData])
|
|
|
|
-> Option<DefId> {
|
2016-05-06 13:52:57 -05:00
|
|
|
let cdata = self.get_crate_data(cnum);
|
2016-12-16 16:24:27 -06:00
|
|
|
cdata.def_path_table
|
|
|
|
.retrace_path(&path)
|
|
|
|
.map(|index| DefId { krate: cnum, index: index })
|
2016-05-06 13:52:57 -05:00
|
|
|
}
|
|
|
|
|
2016-03-16 04:50:38 -05:00
|
|
|
/// Returns the `DefKey` for a given `DefId`. This indicates the
|
|
|
|
/// parent `DefId` as well as some idea of what kind of data the
|
|
|
|
/// `DefId` refers to.
|
2016-12-16 16:24:27 -06:00
|
|
|
fn def_key(&self, def: DefId) -> DefKey {
|
2016-09-02 07:26:36 -05:00
|
|
|
// Note: loading the def-key (or def-path) for a def-id is not
|
|
|
|
// a *read* of its metadata. This is because the def-id is
|
|
|
|
// really just an interned shorthand for a def-path, which is the
|
|
|
|
// canonical name for an item.
|
|
|
|
//
|
|
|
|
// self.dep_graph.read(DepNode::MetaData(def));
|
2016-09-15 03:04:00 -05:00
|
|
|
self.get_crate_data(def.krate).def_key(def.index)
|
2016-03-16 04:50:38 -05:00
|
|
|
}
|
|
|
|
|
2016-12-16 17:52:47 -06:00
|
|
|
fn def_path(&self, def: DefId) -> DefPath {
|
2016-09-02 07:26:36 -05:00
|
|
|
// See `Note` above in `def_key()` for why this read is
|
|
|
|
// commented out:
|
|
|
|
//
|
|
|
|
// self.dep_graph.read(DepNode::MetaData(def));
|
2016-09-15 03:04:00 -05:00
|
|
|
self.get_crate_data(def.krate).def_path(def.index)
|
2015-11-20 06:51:18 -06:00
|
|
|
}
|
|
|
|
|
2017-04-03 12:20:26 -05:00
|
|
|
fn def_path_hash(&self, def: DefId) -> u64 {
|
|
|
|
self.get_crate_data(def.krate).def_path_hash(def.index)
|
|
|
|
}
|
|
|
|
|
2015-11-20 09:46:39 -06:00
|
|
|
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name>
|
|
|
|
{
|
2016-04-22 14:47:14 -05:00
|
|
|
self.dep_graph.read(DepNode::MetaData(def));
|
2016-09-15 03:04:00 -05:00
|
|
|
self.get_crate_data(def.krate).get_struct_field_names(def.index)
|
2015-11-20 09:46:39 -06:00
|
|
|
}
|
|
|
|
|
2016-09-15 03:05:45 -05:00
|
|
|
fn item_children(&self, def_id: DefId) -> Vec<def::Export>
|
2015-11-20 09:46:39 -06:00
|
|
|
{
|
2016-04-22 14:47:14 -05:00
|
|
|
self.dep_graph.read(DepNode::MetaData(def_id));
|
2015-11-20 09:46:39 -06:00
|
|
|
let mut result = vec![];
|
2016-09-15 03:04:00 -05:00
|
|
|
self.get_crate_data(def_id.krate)
|
2016-09-15 03:05:45 -05:00
|
|
|
.each_child_of_item(def_id.index, |child| result.push(child));
|
2015-11-20 09:46:39 -06:00
|
|
|
result
|
|
|
|
}
|
|
|
|
|
2016-11-05 15:30:40 -05:00
|
|
|
fn load_macro(&self, id: DefId, sess: &Session) -> LoadedMacro {
|
|
|
|
let data = self.get_crate_data(id.krate);
|
|
|
|
if let Some(ref proc_macros) = data.proc_macros {
|
2016-11-16 00:10:34 -06:00
|
|
|
return LoadedMacro::ProcMacro(proc_macros[id.index.as_usize() - 1].1.clone());
|
2016-11-05 15:30:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let (name, def) = data.get_macro(id.index);
|
2016-10-28 01:52:45 -05:00
|
|
|
let source_name = format!("<{} macros>", name);
|
|
|
|
|
2017-01-12 22:49:20 -06:00
|
|
|
let filemap = sess.parse_sess.codemap().new_filemap(source_name, None, def.body);
|
2017-03-14 19:22:48 -05:00
|
|
|
let local_span = Span { lo: filemap.start_pos, hi: filemap.end_pos, ctxt: NO_EXPANSION };
|
2017-02-20 23:05:59 -06:00
|
|
|
let body = filemap_to_stream(&sess.parse_sess, filemap);
|
2016-10-28 01:52:45 -05:00
|
|
|
|
|
|
|
// Mark the attrs as used
|
2016-11-23 17:39:13 -06:00
|
|
|
let attrs = data.get_item_attrs(id.index);
|
2017-04-20 07:08:41 -05:00
|
|
|
for attr in attrs.iter() {
|
2016-10-28 01:52:45 -05:00
|
|
|
attr::mark_used(attr);
|
|
|
|
}
|
|
|
|
|
2016-11-23 17:39:13 -06:00
|
|
|
let name = data.def_key(id.index).disambiguated_data.data
|
|
|
|
.get_opt_name().expect("no name in load_macro");
|
2016-10-28 01:52:45 -05:00
|
|
|
sess.imported_macro_spans.borrow_mut()
|
2016-11-23 17:39:13 -06:00
|
|
|
.insert(local_span, (name.to_string(), data.get_span(id.index, sess)));
|
2016-10-28 01:52:45 -05:00
|
|
|
|
2017-03-04 23:15:58 -06:00
|
|
|
LoadedMacro::MacroDef(ast::Item {
|
2016-11-23 17:39:13 -06:00
|
|
|
ident: ast::Ident::with_empty_ctxt(name),
|
2016-10-28 01:52:45 -05:00
|
|
|
id: ast::DUMMY_NODE_ID,
|
|
|
|
span: local_span,
|
2017-04-20 07:08:41 -05:00
|
|
|
attrs: attrs.iter().cloned().collect(),
|
2017-03-01 17:48:16 -06:00
|
|
|
node: ast::ItemKind::MacroDef(body.into()),
|
2017-03-04 23:15:58 -06:00
|
|
|
vis: ast::Visibility::Inherited,
|
2016-11-05 15:30:40 -05:00
|
|
|
})
|
2016-10-28 01:52:45 -05:00
|
|
|
}
|
|
|
|
|
2016-09-28 18:30:53 -05:00
|
|
|
fn maybe_get_item_body<'a, 'tcx>(&self,
|
|
|
|
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|
|
|
def_id: DefId)
|
|
|
|
-> Option<&'tcx hir::Body>
|
2015-11-20 06:51:18 -06:00
|
|
|
{
|
2017-01-25 18:41:06 -06:00
|
|
|
if let Some(cached) = tcx.hir.get_inlined_body(def_id) {
|
2017-01-03 20:01:58 -06:00
|
|
|
return Some(cached);
|
2016-07-26 09:58:35 -05:00
|
|
|
}
|
|
|
|
|
2017-01-03 20:01:58 -06:00
|
|
|
self.dep_graph.read(DepNode::MetaData(def_id));
|
2016-12-20 15:05:21 -06:00
|
|
|
debug!("maybe_get_item_body({}): inlining item", tcx.item_path_str(def_id));
|
2016-07-26 09:58:35 -05:00
|
|
|
|
2017-01-03 20:01:58 -06:00
|
|
|
self.get_crate_data(def_id.krate).maybe_get_item_body(tcx, def_id.index)
|
2016-07-26 09:58:35 -05:00
|
|
|
}
|
|
|
|
|
2016-12-27 03:15:26 -06:00
|
|
|
fn item_body_nested_bodies(&self, def: DefId) -> BTreeMap<hir::BodyId, hir::Body> {
|
|
|
|
self.dep_graph.read(DepNode::MetaData(def));
|
|
|
|
self.get_crate_data(def.krate).item_body_nested_bodies(def.index)
|
|
|
|
}
|
|
|
|
|
2016-12-20 15:05:21 -06:00
|
|
|
fn const_is_rvalue_promotable_to_static(&self, def: DefId) -> bool {
|
|
|
|
self.dep_graph.read(DepNode::MetaData(def));
|
|
|
|
self.get_crate_data(def.krate).const_is_rvalue_promotable_to_static(def.index)
|
2015-11-20 06:51:18 -06:00
|
|
|
}
|
2015-11-20 17:08:09 -06:00
|
|
|
|
2015-11-02 07:46:39 -06:00
|
|
|
fn is_item_mir_available(&self, def: DefId) -> bool {
|
2016-04-22 14:47:14 -05:00
|
|
|
self.dep_graph.read(DepNode::MetaData(def));
|
2016-09-15 03:04:00 -05:00
|
|
|
self.get_crate_data(def.krate).is_item_mir_available(def.index)
|
2015-11-02 07:46:39 -06:00
|
|
|
}
|
|
|
|
|
2016-08-31 06:00:29 -05:00
|
|
|
fn crates(&self) -> Vec<CrateNum>
|
2015-11-21 13:39:05 -06:00
|
|
|
{
|
|
|
|
let mut result = vec![];
|
|
|
|
self.iter_crate_data(|cnum, _| result.push(cnum));
|
|
|
|
result
|
|
|
|
}
|
|
|
|
|
rustc: Implement #[link(cfg(..))] and crt-static
This commit is an implementation of [RFC 1721] which adds a new target feature
to the compiler, `crt-static`, which can be used to select how the C runtime for
a target is linked. Most targets dynamically linke the C runtime by default with
the notable exception of some of the musl targets.
[RFC 1721]: https://github.com/rust-lang/rfcs/blob/master/text/1721-crt-static.md
This commit first adds the new target-feature, `crt-static`. If enabled, then
the `cfg(target_feature = "crt-static")` will be available. Targets like musl
will have this enabled by default. This feature can be controlled through the
standard target-feature interface, `-C target-feature=+crt-static` or
`-C target-feature=-crt-static`.
Next this adds an gated and unstable `#[link(cfg(..))]` feature to enable the
`crt-static` semantics we want with libc. The exact behavior of this attribute
is a little squishy, but it's intended to be a forever-unstable
implementation detail of the liblibc crate.
Specifically the `#[link(cfg(..))]` annotation means that the `#[link]`
directive is only active in a compilation unit if that `cfg` value is satisfied.
For example when compiling an rlib, these directives are just encoded and
ignored for dylibs, and all staticlibs are continued to be put into the rlib as
usual. When placing that rlib into a staticlib, executable, or dylib, however,
the `cfg` is evaluated *as if it were defined in the final artifact* and the
library is decided to be linked or not.
Essentially, what'll happen is:
* On MSVC with `-C target-feature=-crt-static`, the `msvcrt.lib` library will be
linked to.
* On MSVC with `-C target-feature=+crt-static`, the `libcmt.lib` library will be
linked to.
* On musl with `-C target-feature=-crt-static`, the object files in liblibc.rlib
are removed and `-lc` is passed instead.
* On musl with `-C target-feature=+crt-static`, the object files in liblibc.rlib
are used and `-lc` is not passed.
This commit does **not** include an update to the liblibc module to implement
these changes. I plan to do that just after the 1.14.0 beta release is cut to
ensure we get ample time to test this feature.
cc #37406
2016-10-31 18:40:13 -05:00
|
|
|
fn used_libraries(&self) -> Vec<NativeLibrary>
|
2015-11-21 13:39:05 -06:00
|
|
|
{
|
|
|
|
self.get_used_libraries().borrow().clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn used_link_args(&self) -> Vec<String>
|
|
|
|
{
|
|
|
|
self.get_used_link_args().borrow().clone()
|
|
|
|
}
|
|
|
|
|
2015-11-20 17:08:09 -06:00
|
|
|
fn metadata_filename(&self) -> &str
|
|
|
|
{
|
2016-10-19 23:31:14 -05:00
|
|
|
locator::METADATA_FILENAME
|
2015-11-20 17:08:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn metadata_section_name(&self, target: &Target) -> &str
|
|
|
|
{
|
2016-10-19 23:31:14 -05:00
|
|
|
locator::meta_section_name(target)
|
2015-11-20 17:08:09 -06:00
|
|
|
}
|
|
|
|
|
2016-11-09 20:57:30 -06:00
|
|
|
fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)>
|
2015-11-20 17:08:09 -06:00
|
|
|
{
|
|
|
|
self.do_get_used_crates(prefer)
|
|
|
|
}
|
|
|
|
|
2016-08-31 06:00:29 -05:00
|
|
|
fn used_crate_source(&self, cnum: CrateNum) -> CrateSource
|
2015-11-20 17:08:09 -06:00
|
|
|
{
|
2016-10-27 00:03:11 -05:00
|
|
|
self.get_crate_data(cnum).source.clone()
|
2015-11-20 17:08:09 -06:00
|
|
|
}
|
|
|
|
|
2016-08-31 06:00:29 -05:00
|
|
|
fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum>
|
2015-11-21 13:39:05 -06:00
|
|
|
{
|
2015-11-25 09:02:59 -06:00
|
|
|
self.do_extern_mod_stmt_cnum(emod_id)
|
2015-11-21 13:39:05 -06:00
|
|
|
}
|
|
|
|
|
2017-03-23 13:18:25 -05:00
|
|
|
fn encode_metadata<'a, 'tcx>(&self,
|
|
|
|
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
2016-09-28 18:30:53 -05:00
|
|
|
link_meta: &LinkMeta,
|
2017-04-05 16:39:02 -05:00
|
|
|
reachable: &NodeSet)
|
|
|
|
-> EncodedMetadata
|
2016-09-01 08:55:33 -05:00
|
|
|
{
|
2017-03-23 13:18:25 -05:00
|
|
|
encoder::encode_metadata(tcx, self, link_meta, reachable)
|
2015-11-20 17:08:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn metadata_encoding_version(&self) -> &[u8]
|
|
|
|
{
|
2016-09-16 09:25:54 -05:00
|
|
|
schema::METADATA_HEADER
|
2015-11-20 17:08:09 -06:00
|
|
|
}
|
2016-03-19 04:01:29 -05:00
|
|
|
|
|
|
|
/// Returns a map from a sufficiently visible external item (i.e. an external item that is
|
|
|
|
/// visible from at least one local module) to a sufficiently visible parent (considering
|
|
|
|
/// modules that re-export the external item to be parents).
|
2017-04-04 10:11:03 -05:00
|
|
|
fn visible_parent_map<'a>(&'a self) -> ::std::cell::Ref<'a, DefIdMap<DefId>> {
|
|
|
|
{
|
|
|
|
let visible_parent_map = self.visible_parent_map.borrow();
|
|
|
|
if !visible_parent_map.is_empty() {
|
|
|
|
return visible_parent_map;
|
|
|
|
}
|
|
|
|
}
|
2016-03-19 04:01:29 -05:00
|
|
|
|
|
|
|
use std::collections::vec_deque::VecDeque;
|
|
|
|
use std::collections::hash_map::Entry;
|
2017-04-04 10:11:03 -05:00
|
|
|
|
|
|
|
let mut visible_parent_map = self.visible_parent_map.borrow_mut();
|
|
|
|
|
2016-08-31 06:00:29 -05:00
|
|
|
for cnum in (1 .. self.next_crate_num().as_usize()).map(CrateNum::new) {
|
2016-03-19 04:01:29 -05:00
|
|
|
let cdata = self.get_crate_data(cnum);
|
|
|
|
|
|
|
|
match cdata.extern_crate.get() {
|
|
|
|
// Ignore crates without a corresponding local `extern crate` item.
|
|
|
|
Some(extern_crate) if !extern_crate.direct => continue,
|
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut bfs_queue = &mut VecDeque::new();
|
2016-09-15 03:05:45 -05:00
|
|
|
let mut add_child = |bfs_queue: &mut VecDeque<_>, child: def::Export, parent: DefId| {
|
2016-09-14 16:51:46 -05:00
|
|
|
let child = child.def.def_id();
|
2016-09-15 03:05:45 -05:00
|
|
|
|
|
|
|
if self.visibility(child) != ty::Visibility::Public {
|
2016-09-19 15:49:01 -05:00
|
|
|
return;
|
2016-09-15 03:05:45 -05:00
|
|
|
}
|
2016-03-19 04:01:29 -05:00
|
|
|
|
|
|
|
match visible_parent_map.entry(child) {
|
|
|
|
Entry::Occupied(mut entry) => {
|
|
|
|
// If `child` is defined in crate `cnum`, ensure
|
|
|
|
// that it is mapped to a parent in `cnum`.
|
|
|
|
if child.krate == cnum && entry.get().krate != cnum {
|
|
|
|
entry.insert(parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Entry::Vacant(entry) => {
|
|
|
|
entry.insert(parent);
|
|
|
|
bfs_queue.push_back(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-09-19 15:49:01 -05:00
|
|
|
bfs_queue.push_back(DefId {
|
|
|
|
krate: cnum,
|
|
|
|
index: CRATE_DEF_INDEX
|
|
|
|
});
|
2016-03-19 04:01:29 -05:00
|
|
|
while let Some(def) = bfs_queue.pop_front() {
|
|
|
|
for child in self.item_children(def) {
|
|
|
|
add_child(bfs_queue, child, def);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-04 10:11:03 -05:00
|
|
|
drop(visible_parent_map);
|
|
|
|
self.visible_parent_map.borrow()
|
2016-03-19 04:01:29 -05:00
|
|
|
}
|
2015-11-20 06:51:18 -06:00
|
|
|
}
|