2019-11-24 01:10:12 +03:00
|
|
|
use crate::creader::{CStore, LoadedMacro};
|
2019-12-22 17:42:04 -05:00
|
|
|
use crate::foreign_modules;
|
2019-02-08 20:50:17 +09:00
|
|
|
use crate::link_args;
|
|
|
|
use crate::native_libs;
|
2019-11-04 11:57:17 +03:00
|
|
|
use crate::rmeta::{self, encoder};
|
2015-11-25 00:00:26 +02:00
|
|
|
|
2020-01-02 04:53:12 +01:00
|
|
|
use rustc::hir::exports::Export;
|
2019-12-22 17:42:04 -05:00
|
|
|
use rustc::hir::map::definitions::DefPathTable;
|
|
|
|
use rustc::hir::map::{DefKey, DefPath, DefPathHash};
|
2020-02-24 18:03:00 +03:00
|
|
|
use rustc::middle::cstore::{CrateSource, CrateStore, EncodedMetadata, NativeLibraryKind};
|
2018-02-27 19:28:21 +01:00
|
|
|
use rustc::middle::exported_symbols::ExportedSymbol;
|
2017-08-31 15:08:34 -07:00
|
|
|
use rustc::middle::stability::DeprecationEntry;
|
2017-10-24 17:49:58 +02:00
|
|
|
use rustc::session::{CrateDisambiguator, Session};
|
2018-06-13 16:44:43 +03:00
|
|
|
use rustc::ty::query::Providers;
|
2019-12-22 17:42:04 -05:00
|
|
|
use rustc::ty::query::QueryConfig;
|
|
|
|
use rustc::ty::{self, TyCtxt};
|
2019-11-13 13:01:43 +01:00
|
|
|
use rustc_ast::ast;
|
|
|
|
use rustc_ast::attr;
|
|
|
|
use rustc_ast::expand::allocator::AllocatorKind;
|
|
|
|
use rustc_ast::ptr::P;
|
|
|
|
use rustc_ast::tokenstream::DelimSpan;
|
2018-08-03 12:22:22 -06:00
|
|
|
use rustc_data_structures::svh::Svh;
|
2020-01-05 02:37:57 +01:00
|
|
|
use rustc_hir as hir;
|
|
|
|
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
|
2019-11-13 13:01:43 +01:00
|
|
|
use rustc_span::source_map::{self, Span, Spanned};
|
|
|
|
use rustc_span::symbol::Symbol;
|
2015-11-25 00:00:26 +02:00
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
use rustc_data_structures::sync::Lrc;
|
2018-11-30 15:06:42 +01:00
|
|
|
use smallvec::SmallVec;
|
2016-09-29 02:30:53 +03:00
|
|
|
use std::any::Any;
|
2018-02-27 19:28:21 +01:00
|
|
|
use std::sync::Arc;
|
2016-09-29 02:30:53 +03:00
|
|
|
|
|
|
|
macro_rules! provide {
|
2017-08-30 11:40:02 -07:00
|
|
|
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident,
|
|
|
|
$($name:ident => $compute:block)*) => {
|
2017-11-12 18:00:18 +02:00
|
|
|
pub fn provide_extern<$lt>(providers: &mut Providers<$lt>) {
|
2019-06-14 00:48:52 +03:00
|
|
|
// HACK(eddyb) `$lt: $lt` forces `$lt` to be early-bound, which
|
|
|
|
// allows the associated type in the return type to be normalized.
|
|
|
|
$(fn $name<$lt: $lt, T: IntoArgs>(
|
|
|
|
$tcx: TyCtxt<$lt>,
|
|
|
|
def_id_arg: T,
|
|
|
|
) -> <ty::queries::$name<$lt> as QueryConfig<$lt>>::Value {
|
2019-10-09 16:43:47 +02:00
|
|
|
let _prof_timer =
|
|
|
|
$tcx.prof.generic_activity("metadata_decode_entry");
|
|
|
|
|
2017-08-30 11:40:02 -07:00
|
|
|
#[allow(unused_variables)]
|
|
|
|
let ($def_id, $other) = def_id_arg.into_args();
|
2016-09-29 02:30:53 +03:00
|
|
|
assert!(!$def_id.is_local());
|
|
|
|
|
2019-11-24 18:12:02 +03:00
|
|
|
let $cdata = CStore::from_tcx($tcx).get_crate_data($def_id.krate);
|
2019-10-09 16:41:24 +02:00
|
|
|
|
|
|
|
if $tcx.dep_graph.is_fully_enabled() {
|
|
|
|
let crate_dep_node_index = $cdata.get_crate_dep_node_index($tcx);
|
|
|
|
$tcx.dep_graph.read_index(crate_dep_node_index);
|
|
|
|
}
|
|
|
|
|
2016-09-29 02:30:53 +03:00
|
|
|
$compute
|
|
|
|
})*
|
|
|
|
|
|
|
|
*providers = Providers {
|
|
|
|
$($name,)*
|
|
|
|
..*providers
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-30 11:40:02 -07:00
|
|
|
// small trait to work around different signature queries all being defined via
|
|
|
|
// the macro above.
|
|
|
|
trait IntoArgs {
|
|
|
|
fn into_args(self) -> (DefId, DefId);
|
2017-08-28 15:55:32 -07:00
|
|
|
}
|
|
|
|
|
2017-08-30 11:40:02 -07:00
|
|
|
impl IntoArgs for DefId {
|
2019-12-22 17:42:04 -05:00
|
|
|
fn into_args(self) -> (DefId, DefId) {
|
|
|
|
(self, self)
|
|
|
|
}
|
2017-08-28 15:55:32 -07:00
|
|
|
}
|
|
|
|
|
2017-08-30 11:40:02 -07:00
|
|
|
impl IntoArgs for CrateNum {
|
2019-12-22 17:42:04 -05:00
|
|
|
fn into_args(self) -> (DefId, DefId) {
|
|
|
|
(self.as_def_id(), self.as_def_id())
|
|
|
|
}
|
2017-08-28 15:55:32 -07:00
|
|
|
}
|
|
|
|
|
2017-08-30 11:40:02 -07:00
|
|
|
impl IntoArgs for (CrateNum, DefId) {
|
2019-12-22 17:42:04 -05:00
|
|
|
fn into_args(self) -> (DefId, DefId) {
|
|
|
|
(self.0.as_def_id(), self.1)
|
|
|
|
}
|
2017-08-30 11:40:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
provide! { <'tcx> tcx, def_id, other, cdata,
|
2017-04-24 15:20:46 +03:00
|
|
|
type_of => { cdata.get_type(def_id.index, tcx) }
|
2017-11-07 15:14:32 +01:00
|
|
|
generics_of => {
|
2019-05-31 09:25:34 +02:00
|
|
|
tcx.arena.alloc(cdata.get_generics(def_id.index, tcx.sess))
|
2017-11-07 15:14:32 +01:00
|
|
|
}
|
2019-04-09 23:17:56 +03:00
|
|
|
explicit_predicates_of => { cdata.get_explicit_predicates(def_id.index, tcx) }
|
|
|
|
inferred_outlives_of => { cdata.get_inferred_outlives(def_id.index, tcx) }
|
2019-10-18 03:14:57 +03:00
|
|
|
super_predicates_of => { cdata.get_super_predicates(def_id.index, tcx) }
|
2016-09-29 02:30:53 +03:00
|
|
|
trait_def => {
|
2019-05-31 09:25:34 +02:00
|
|
|
tcx.arena.alloc(cdata.get_trait_def(def_id.index, tcx.sess))
|
2016-09-29 02:30:53 +03:00
|
|
|
}
|
|
|
|
adt_def => { cdata.get_adt_def(def_id.index, tcx) }
|
2017-03-01 18:42:26 +02:00
|
|
|
adt_destructor => {
|
|
|
|
let _ = cdata;
|
|
|
|
tcx.calculate_dtor(def_id, &mut |_,_| Ok(()))
|
|
|
|
}
|
2018-11-30 15:12:41 +01:00
|
|
|
variances_of => { tcx.arena.alloc_from_iter(cdata.get_item_variances(def_id.index)) }
|
2016-09-29 02:30:53 +03:00
|
|
|
associated_item_def_ids => {
|
2018-11-30 15:06:42 +01:00
|
|
|
let mut result = SmallVec::<[_; 8]>::new();
|
2017-06-14 22:49:07 -07:00
|
|
|
cdata.each_child_of_item(def_id.index,
|
2019-04-20 19:36:05 +03:00
|
|
|
|child| result.push(child.res.def_id()), tcx.sess);
|
2018-11-30 15:06:42 +01:00
|
|
|
tcx.arena.alloc_slice(&result)
|
2016-09-29 02:30:53 +03:00
|
|
|
}
|
|
|
|
associated_item => { cdata.get_associated_item(def_id.index) }
|
|
|
|
impl_trait_ref => { cdata.get_impl_trait(def_id.index, tcx) }
|
2017-04-20 20:37:02 +03:00
|
|
|
impl_polarity => { cdata.get_impl_polarity(def_id.index) }
|
2017-03-17 16:17:45 -04: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-29 02:30:53 +03:00
|
|
|
})
|
|
|
|
}
|
2019-08-26 21:58:16 -04:00
|
|
|
optimized_mir => { tcx.arena.alloc(cdata.get_optimized_mir(tcx, def_id.index)) }
|
|
|
|
promoted_mir => { tcx.arena.alloc(cdata.get_promoted_mir(tcx, def_id.index)) }
|
2019-10-28 12:17:36 -07:00
|
|
|
mir_const_qualif => { cdata.mir_const_qualif(def_id.index) }
|
2017-05-13 13:12:29 +03:00
|
|
|
fn_sig => { cdata.fn_sig(def_id.index, tcx) }
|
2018-11-30 15:19:12 +01:00
|
|
|
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
|
2018-08-31 13:50:14 +02:00
|
|
|
is_const_fn_raw => { cdata.is_const_fn_raw(def_id.index) }
|
2019-09-21 03:17:57 +00:00
|
|
|
asyncness => { cdata.asyncness(def_id.index) }
|
2017-04-14 10:51:22 -04:00
|
|
|
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
|
2019-04-19 23:32:26 +03:00
|
|
|
static_mutability => { cdata.static_mutability(def_id.index) }
|
2020-01-25 19:09:23 -06:00
|
|
|
generator_kind => { cdata.generator_kind(def_id.index) }
|
2019-04-20 19:46:19 +03:00
|
|
|
def_kind => { cdata.def_kind(def_id.index) }
|
2017-04-28 10:59:57 -05:00
|
|
|
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
|
2017-08-31 15:08:34 -07:00
|
|
|
lookup_stability => {
|
|
|
|
cdata.get_stability(def_id.index).map(|s| tcx.intern_stability(s))
|
2019-12-08 01:43:10 +01:00
|
|
|
}
|
|
|
|
lookup_const_stability => {
|
|
|
|
cdata.get_const_stability(def_id.index).map(|s| tcx.intern_const_stability(s))
|
2017-08-31 15:08:34 -07:00
|
|
|
}
|
|
|
|
lookup_deprecation_entry => {
|
|
|
|
cdata.get_deprecation(def_id.index).map(DeprecationEntry::external)
|
|
|
|
}
|
2017-11-07 15:14:32 +01:00
|
|
|
item_attrs => { cdata.get_item_attrs(def_id.index, tcx.sess) }
|
2017-05-03 09:01:49 -05: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.
|
2019-08-27 13:24:32 +02:00
|
|
|
fn_arg_names => { cdata.get_fn_param_names(def_id.index) }
|
2018-04-15 19:41:33 -04:00
|
|
|
rendered_const => { cdata.get_rendered_const(def_id.index) }
|
2017-05-04 09:37:34 -05:00
|
|
|
impl_parent => { cdata.get_parent_impl(def_id.index) }
|
2017-05-04 08:27:48 -05:00
|
|
|
trait_of_item => { cdata.get_trait_of_item(def_id.index) }
|
2017-05-04 12:45:56 -05:00
|
|
|
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
|
2017-06-14 22:49:07 -07:00
|
|
|
|
2018-12-01 17:27:12 +01:00
|
|
|
dylib_dependency_formats => { cdata.get_dylib_dependency_formats(tcx) }
|
2018-05-12 16:36:53 -07:00
|
|
|
is_panic_runtime => { cdata.root.panic_runtime }
|
|
|
|
is_compiler_builtins => { cdata.root.compiler_builtins }
|
|
|
|
has_global_allocator => { cdata.root.has_global_allocator }
|
2018-09-06 21:24:33 +02:00
|
|
|
has_panic_handler => { cdata.root.has_panic_handler }
|
2018-05-12 16:36:53 -07:00
|
|
|
is_profiler_runtime => { cdata.root.profiler_runtime }
|
|
|
|
panic_strategy => { cdata.root.panic_strategy }
|
2018-02-15 10:52:26 +01:00
|
|
|
extern_crate => {
|
2018-12-01 17:27:12 +01:00
|
|
|
let r = *cdata.extern_crate.lock();
|
|
|
|
r.map(|c| &*tcx.arena.alloc(c))
|
2018-02-15 10:52:26 +01:00
|
|
|
}
|
2018-05-12 16:36:53 -07:00
|
|
|
is_no_builtins => { cdata.root.no_builtins }
|
2019-01-29 07:24:32 +02:00
|
|
|
symbol_mangling_version => { cdata.root.symbol_mangling_version }
|
2017-08-28 16:50:25 -07:00
|
|
|
impl_defaultness => { cdata.get_impl_defaultness(def_id.index) }
|
2018-02-27 19:28:21 +01:00
|
|
|
reachable_non_generics => {
|
|
|
|
let reachable_non_generics = tcx
|
|
|
|
.exported_symbols(cdata.cnum)
|
|
|
|
.iter()
|
2018-03-06 10:33:42 +01:00
|
|
|
.filter_map(|&(exported_symbol, export_level)| {
|
2018-02-27 19:28:21 +01:00
|
|
|
if let ExportedSymbol::NonGeneric(def_id) = exported_symbol {
|
2018-03-06 10:33:42 +01:00
|
|
|
return Some((def_id, export_level))
|
2018-02-27 19:28:21 +01:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
2018-12-01 17:27:12 +01:00
|
|
|
tcx.arena.alloc(reachable_non_generics)
|
2018-02-27 19:28:21 +01:00
|
|
|
}
|
2018-02-27 17:11:14 +01:00
|
|
|
native_libraries => { Lrc::new(cdata.get_native_libraries(tcx.sess)) }
|
2018-12-01 17:14:40 +01:00
|
|
|
foreign_modules => { cdata.get_foreign_modules(tcx) }
|
2017-08-28 17:30:27 -07:00
|
|
|
plugin_registrar_fn => {
|
|
|
|
cdata.root.plugin_registrar_fn.map(|index| {
|
|
|
|
DefId { krate: def_id.krate, index }
|
|
|
|
})
|
|
|
|
}
|
2018-03-16 01:09:22 +02:00
|
|
|
proc_macro_decls_static => {
|
|
|
|
cdata.root.proc_macro_decls_static.map(|index| {
|
2017-08-28 17:30:27 -07:00
|
|
|
DefId { krate: def_id.krate, index }
|
|
|
|
})
|
|
|
|
}
|
2018-05-12 16:36:53 -07:00
|
|
|
crate_disambiguator => { cdata.root.disambiguator }
|
|
|
|
crate_hash => { cdata.root.hash }
|
2019-11-24 18:12:02 +03:00
|
|
|
crate_host_hash => { cdata.host_hash }
|
2018-05-12 16:36:53 -07:00
|
|
|
original_crate_name => { cdata.root.name }
|
2017-08-30 11:40:02 -07:00
|
|
|
|
2018-03-13 11:58:53 -07:00
|
|
|
extra_filename => { cdata.root.extra_filename.clone() }
|
|
|
|
|
2017-08-30 11:40:02 -07:00
|
|
|
implementations_of_trait => {
|
2018-11-30 21:23:01 +01:00
|
|
|
cdata.get_implementations_for_trait(tcx, Some(other))
|
2017-08-30 11:40:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
all_trait_implementations => {
|
2018-11-30 21:23:01 +01:00
|
|
|
cdata.get_implementations_for_trait(tcx, None)
|
2017-08-30 11:40:02 -07:00
|
|
|
}
|
2017-08-30 14:48:57 -07:00
|
|
|
|
2017-08-31 08:07:39 -07:00
|
|
|
visibility => { cdata.get_visibility(def_id.index) }
|
2018-02-15 10:52:26 +01:00
|
|
|
dep_kind => {
|
|
|
|
let r = *cdata.dep_kind.lock();
|
|
|
|
r
|
|
|
|
}
|
2019-10-02 03:15:38 +03:00
|
|
|
crate_name => { cdata.root.name }
|
2017-08-31 08:07:39 -07:00
|
|
|
item_children => {
|
2018-11-30 22:32:16 +01:00
|
|
|
let mut result = SmallVec::<[_; 8]>::new();
|
2017-08-31 08:07:39 -07:00
|
|
|
cdata.each_child_of_item(def_id.index, |child| result.push(child), tcx.sess);
|
2018-11-30 22:32:16 +01:00
|
|
|
tcx.arena.alloc_slice(&result)
|
2017-08-31 08:07:39 -07:00
|
|
|
}
|
2018-12-01 16:57:29 +01:00
|
|
|
defined_lib_features => { cdata.get_lib_features(tcx) }
|
|
|
|
defined_lang_items => { cdata.get_lang_items(tcx) }
|
2019-05-19 20:16:04 +02:00
|
|
|
diagnostic_items => { cdata.get_diagnostic_items(tcx) }
|
2018-12-01 16:57:29 +01:00
|
|
|
missing_lang_items => { cdata.get_missing_lang_items(tcx) }
|
2017-08-31 11:12:05 -07:00
|
|
|
|
2017-08-31 11:30:22 -07:00
|
|
|
missing_extern_crate_item => {
|
2018-02-15 10:52:26 +01:00
|
|
|
let r = match *cdata.extern_crate.borrow() {
|
2019-09-27 21:32:04 +08:00
|
|
|
Some(extern_crate) if !extern_crate.is_direct() => true,
|
2017-08-31 11:30:22 -07:00
|
|
|
_ => false,
|
2018-02-15 10:52:26 +01:00
|
|
|
};
|
|
|
|
r
|
2017-08-31 11:30:22 -07:00
|
|
|
}
|
2017-08-31 12:08:29 -07:00
|
|
|
|
2018-02-27 17:11:14 +01:00
|
|
|
used_crate_source => { Lrc::new(cdata.source.clone()) }
|
2017-09-20 20:42:49 +02:00
|
|
|
|
rustc: Fix mixing crates with different `share_generics`
This commit addresses #64319 by removing the `dylib` crate type from the
list of crate type that exports generic symbols. The bug in #64319
arises because a `dylib` crate type was trying to export a symbol in an
uptream crate but it miscalculated the symbol name of the uptream
symbol. This isn't really necessary, though, since `dylib` crates aren't
that heavily used, so we can just conservatively say that the `dylib`
crate type never exports generic symbols, forcibly removing them from
the exported symbol lists if were to otherwise find them.
The fix here happens in two places:
* First is in the `local_crate_exports_generics` method, indicating that
it's now `false` for the `Dylib` crate type. Only rlibs actually
export generics at this point.
* Next is when we load exported symbols from upstream crate. If, for our
compilation session, the crate may be included from a dynamic library,
then its generic symbols are removed. When the crate was linked into a
dynamic library its symbols weren't exported, so we can't consider
them a candidate to link against.
Overally this should avoid situations where we incorrectly calculate the
upstream symbol names in the face of differnet `share_generics` options,
ultimately...
Closes #64319
2019-09-11 08:08:04 -07:00
|
|
|
exported_symbols => {
|
2019-11-01 13:46:05 +01:00
|
|
|
let syms = cdata.exported_symbols(tcx);
|
rustc: Fix mixing crates with different `share_generics`
This commit addresses #64319 by removing the `dylib` crate type from the
list of crate type that exports generic symbols. The bug in #64319
arises because a `dylib` crate type was trying to export a symbol in an
uptream crate but it miscalculated the symbol name of the uptream
symbol. This isn't really necessary, though, since `dylib` crates aren't
that heavily used, so we can just conservatively say that the `dylib`
crate type never exports generic symbols, forcibly removing them from
the exported symbol lists if were to otherwise find them.
The fix here happens in two places:
* First is in the `local_crate_exports_generics` method, indicating that
it's now `false` for the `Dylib` crate type. Only rlibs actually
export generics at this point.
* Next is when we load exported symbols from upstream crate. If, for our
compilation session, the crate may be included from a dynamic library,
then its generic symbols are removed. When the crate was linked into a
dynamic library its symbols weren't exported, so we can't consider
them a candidate to link against.
Overally this should avoid situations where we incorrectly calculate the
upstream symbol names in the face of differnet `share_generics` options,
ultimately...
Closes #64319
2019-09-11 08:08:04 -07:00
|
|
|
|
2019-11-01 13:46:05 +01:00
|
|
|
// FIXME rust-lang/rust#64319, rust-lang/rust#64872: We want
|
|
|
|
// to block export of generics from dylibs, but we must fix
|
|
|
|
// rust-lang/rust#65890 before we can do that robustly.
|
rustc: Fix mixing crates with different `share_generics`
This commit addresses #64319 by removing the `dylib` crate type from the
list of crate type that exports generic symbols. The bug in #64319
arises because a `dylib` crate type was trying to export a symbol in an
uptream crate but it miscalculated the symbol name of the uptream
symbol. This isn't really necessary, though, since `dylib` crates aren't
that heavily used, so we can just conservatively say that the `dylib`
crate type never exports generic symbols, forcibly removing them from
the exported symbol lists if were to otherwise find them.
The fix here happens in two places:
* First is in the `local_crate_exports_generics` method, indicating that
it's now `false` for the `Dylib` crate type. Only rlibs actually
export generics at this point.
* Next is when we load exported symbols from upstream crate. If, for our
compilation session, the crate may be included from a dynamic library,
then its generic symbols are removed. When the crate was linked into a
dynamic library its symbols weren't exported, so we can't consider
them a candidate to link against.
Overally this should avoid situations where we incorrectly calculate the
upstream symbol names in the face of differnet `share_generics` options,
ultimately...
Closes #64319
2019-09-11 08:08:04 -07:00
|
|
|
|
|
|
|
Arc::new(syms)
|
|
|
|
}
|
2016-09-29 02:30:53 +03:00
|
|
|
}
|
|
|
|
|
2019-06-21 20:27:44 +02:00
|
|
|
pub fn provide(providers: &mut Providers<'_>) {
|
2017-08-31 15:08:34 -07:00
|
|
|
// FIXME(#44234) - almost all of these queries have no sub-queries and
|
|
|
|
// therefore no actual inputs, they're just reading tables calculated in
|
|
|
|
// resolve! Does this work? Unsure! That's what the issue is about
|
2017-06-11 21:16:26 -07:00
|
|
|
*providers = Providers {
|
2019-12-22 17:42:04 -05:00
|
|
|
is_dllimport_foreign_item: |tcx, id| match tcx.native_library_kind(id) {
|
|
|
|
Some(NativeLibraryKind::NativeUnknown) | Some(NativeLibraryKind::NativeRawDylib) => {
|
|
|
|
true
|
2019-08-27 22:42:44 +08:00
|
|
|
}
|
2019-12-22 17:42:04 -05:00
|
|
|
_ => false,
|
2017-08-30 14:48:57 -07:00
|
|
|
},
|
2019-12-22 17:42:04 -05:00
|
|
|
is_statically_included_foreign_item: |tcx, id| match tcx.native_library_kind(id) {
|
|
|
|
Some(NativeLibraryKind::NativeStatic)
|
|
|
|
| Some(NativeLibraryKind::NativeStaticNobundle) => true,
|
|
|
|
_ => false,
|
2017-08-30 14:48:57 -07:00
|
|
|
},
|
|
|
|
native_library_kind: |tcx, id| {
|
|
|
|
tcx.native_libraries(id.krate)
|
|
|
|
.iter()
|
|
|
|
.filter(|lib| native_libs::relevant_lib(&tcx.sess, lib))
|
2018-02-10 14:28:17 -08:00
|
|
|
.find(|lib| {
|
|
|
|
let fm_id = match lib.foreign_module {
|
|
|
|
Some(id) => id,
|
|
|
|
None => return false,
|
|
|
|
};
|
|
|
|
tcx.foreign_modules(id.krate)
|
|
|
|
.iter()
|
|
|
|
.find(|m| m.def_id == fm_id)
|
|
|
|
.expect("failed to find foreign module")
|
|
|
|
.foreign_items
|
|
|
|
.contains(&id)
|
|
|
|
})
|
2017-08-30 14:48:57 -07:00
|
|
|
.map(|l| l.kind)
|
|
|
|
},
|
|
|
|
native_libraries: |tcx, cnum| {
|
|
|
|
assert_eq!(cnum, LOCAL_CRATE);
|
2018-02-27 17:11:14 +01:00
|
|
|
Lrc::new(native_libs::collect(tcx))
|
2017-08-30 14:48:57 -07:00
|
|
|
},
|
2018-02-10 14:28:17 -08:00
|
|
|
foreign_modules: |tcx, cnum| {
|
|
|
|
assert_eq!(cnum, LOCAL_CRATE);
|
2018-12-01 17:14:40 +01:00
|
|
|
&tcx.arena.alloc(foreign_modules::collect(tcx))[..]
|
2018-02-10 14:28:17 -08:00
|
|
|
},
|
2017-08-30 14:48:57 -07:00
|
|
|
link_args: |tcx, cnum| {
|
|
|
|
assert_eq!(cnum, LOCAL_CRATE);
|
2018-02-27 17:11:14 +01:00
|
|
|
Lrc::new(link_args::collect(tcx))
|
2017-08-30 14:48:57 -07:00
|
|
|
},
|
2017-09-07 08:13:41 -07:00
|
|
|
|
2018-11-27 02:59:49 +00:00
|
|
|
// Returns a map from a sufficiently visible external item (i.e., an
|
2017-08-31 11:30:22 -07:00
|
|
|
// 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).
|
|
|
|
visible_parent_map: |tcx, cnum| {
|
|
|
|
use std::collections::hash_map::Entry;
|
2019-12-22 17:42:04 -05:00
|
|
|
use std::collections::vec_deque::VecDeque;
|
2017-08-31 11:30:22 -07:00
|
|
|
|
|
|
|
assert_eq!(cnum, LOCAL_CRATE);
|
2018-07-21 22:15:11 +03:00
|
|
|
let mut visible_parent_map: DefIdMap<DefId> = Default::default();
|
2017-08-31 11:30:22 -07:00
|
|
|
|
2017-12-12 19:05:12 -06:00
|
|
|
// Issue 46112: We want the map to prefer the shortest
|
|
|
|
// paths when reporting the path to an item. Therefore we
|
|
|
|
// build up the map via a breadth-first search (BFS),
|
|
|
|
// which naturally yields minimal-length paths.
|
|
|
|
//
|
|
|
|
// Note that it needs to be a BFS over the whole forest of
|
|
|
|
// crates, not just each individual crate; otherwise you
|
|
|
|
// only get paths that are locally minimal with respect to
|
|
|
|
// whatever crate we happened to encounter first in this
|
|
|
|
// traversal, but not globally minimal across all crates.
|
|
|
|
let bfs_queue = &mut VecDeque::new();
|
2017-12-19 15:04:02 +01:00
|
|
|
|
|
|
|
// Preferring shortest paths alone does not guarantee a
|
|
|
|
// deterministic result; so sort by crate num to avoid
|
|
|
|
// hashtable iteration non-determinism. This only makes
|
|
|
|
// things as deterministic as crate-nums assignment is,
|
|
|
|
// which is to say, its not deterministic in general. But
|
|
|
|
// we believe that libstd is consistently assigned crate
|
|
|
|
// num 1, so it should be enough to resolve #46112.
|
2018-11-30 22:45:46 +01:00
|
|
|
let mut crates: Vec<CrateNum> = (*tcx.crates()).to_owned();
|
2017-12-19 15:04:02 +01:00
|
|
|
crates.sort();
|
|
|
|
|
|
|
|
for &cnum in crates.iter() {
|
2017-08-31 11:30:22 -07:00
|
|
|
// Ignore crates without a corresponding local `extern crate` item.
|
|
|
|
if tcx.missing_extern_crate_item(cnum) {
|
2019-12-22 17:42:04 -05:00
|
|
|
continue;
|
2017-08-31 11:30:22 -07:00
|
|
|
}
|
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
bfs_queue.push_back(DefId { krate: cnum, index: CRATE_DEF_INDEX });
|
2017-12-12 19:05:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// (restrict scope of mutable-borrow of `visible_parent_map`)
|
|
|
|
{
|
2017-08-31 11:30:22 -07:00
|
|
|
let visible_parent_map = &mut visible_parent_map;
|
2020-01-02 04:53:12 +01:00
|
|
|
let mut add_child =
|
|
|
|
|bfs_queue: &mut VecDeque<_>, child: &Export<hir::HirId>, parent: DefId| {
|
|
|
|
if child.vis != ty::Visibility::Public {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-31 11:30:22 -07:00
|
|
|
|
2020-01-02 04:53:12 +01:00
|
|
|
if let Some(child) = child.res.opt_def_id() {
|
|
|
|
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) => {
|
2019-05-20 11:46:44 -07:00
|
|
|
entry.insert(parent);
|
2020-01-02 04:53:12 +01:00
|
|
|
bfs_queue.push_back(child);
|
2019-05-20 11:46:44 -07:00
|
|
|
}
|
|
|
|
}
|
2017-08-31 11:30:22 -07:00
|
|
|
}
|
2020-01-02 04:53:12 +01:00
|
|
|
};
|
2017-08-31 11:30:22 -07:00
|
|
|
|
|
|
|
while let Some(def) = bfs_queue.pop_front() {
|
|
|
|
for child in tcx.item_children(def).iter() {
|
|
|
|
add_child(bfs_queue, child, def);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-01 17:02:51 +01:00
|
|
|
tcx.arena.alloc(visible_parent_map)
|
2017-08-31 11:30:22 -07:00
|
|
|
},
|
|
|
|
|
2019-09-16 13:34:57 -07:00
|
|
|
dependency_formats: |tcx, cnum| {
|
|
|
|
assert_eq!(cnum, LOCAL_CRATE);
|
|
|
|
Lrc::new(crate::dependency_format::calculate(tcx))
|
|
|
|
},
|
2019-11-24 18:12:02 +03:00
|
|
|
has_global_allocator: |tcx, cnum| {
|
|
|
|
assert_eq!(cnum, LOCAL_CRATE);
|
|
|
|
CStore::from_tcx(tcx).has_global_allocator()
|
|
|
|
},
|
|
|
|
postorder_cnums: |tcx, cnum| {
|
|
|
|
assert_eq!(cnum, LOCAL_CRATE);
|
|
|
|
tcx.arena.alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(cnum))
|
|
|
|
},
|
2019-09-16 13:34:57 -07:00
|
|
|
|
2017-06-11 21:16:26 -07:00
|
|
|
..*providers
|
|
|
|
};
|
2016-09-29 02:30:53 +03:00
|
|
|
}
|
|
|
|
|
2019-11-24 01:10:12 +03:00
|
|
|
impl CStore {
|
2019-10-09 17:37:28 +03:00
|
|
|
pub fn struct_field_names_untracked(&self, def: DefId, sess: &Session) -> Vec<Spanned<Symbol>> {
|
|
|
|
self.get_crate_data(def.krate).get_struct_field_names(def.index, sess)
|
2015-11-20 17:46:39 +02:00
|
|
|
}
|
|
|
|
|
2019-04-03 09:07:45 +02:00
|
|
|
pub fn item_children_untracked(
|
|
|
|
&self,
|
|
|
|
def_id: DefId,
|
2019-12-22 17:42:04 -05:00
|
|
|
sess: &Session,
|
2020-01-02 04:53:12 +01:00
|
|
|
) -> Vec<Export<hir::HirId>> {
|
2015-11-20 17:46:39 +02:00
|
|
|
let mut result = vec![];
|
2019-12-22 17:42:04 -05:00
|
|
|
self.get_crate_data(def_id.krate).each_child_of_item(
|
|
|
|
def_id.index,
|
|
|
|
|child| result.push(child),
|
|
|
|
sess,
|
|
|
|
);
|
2015-11-20 17:46:39 +02:00
|
|
|
result
|
|
|
|
}
|
|
|
|
|
2018-07-31 17:23:29 -06:00
|
|
|
pub fn load_macro_untracked(&self, id: DefId, sess: &Session) -> LoadedMacro {
|
2019-10-09 16:43:47 +02:00
|
|
|
let _prof_timer = sess.prof.generic_activity("metadata_load_macro");
|
|
|
|
|
2016-11-05 20:30:40 +00:00
|
|
|
let data = self.get_crate_data(id.krate);
|
2019-11-17 18:54:22 +03:00
|
|
|
if data.root.is_proc_macro_crate() {
|
2019-08-20 23:18:55 +03:00
|
|
|
return LoadedMacro::ProcMacro(data.load_proc_macro(id.index, sess));
|
2016-11-05 20:30:40 +00:00
|
|
|
}
|
|
|
|
|
2019-11-13 13:01:43 +01:00
|
|
|
let span = data.get_span(id.index, sess);
|
|
|
|
let dspan = DelimSpan::from_single(span);
|
|
|
|
let rmeta::MacroDef { body, legacy } = data.get_macro(id.index, sess);
|
2016-10-28 06:52:45 +00:00
|
|
|
|
|
|
|
// Mark the attrs as used
|
2017-11-07 15:14:32 +01:00
|
|
|
let attrs = data.get_item_attrs(id.index, sess);
|
2017-04-20 15:08:41 +03:00
|
|
|
for attr in attrs.iter() {
|
2016-10-28 06:52:45 +00:00
|
|
|
attr::mark_used(attr);
|
|
|
|
}
|
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
let name = data
|
|
|
|
.def_key(id.index)
|
|
|
|
.disambiguated_data
|
|
|
|
.data
|
|
|
|
.get_opt_name()
|
|
|
|
.expect("no name in load_macro");
|
2019-11-13 13:01:43 +01:00
|
|
|
sess.imported_macro_spans.borrow_mut().insert(span, (name.to_string(), span));
|
2016-10-28 06:52:45 +00:00
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
LoadedMacro::MacroDef(
|
|
|
|
ast::Item {
|
|
|
|
// FIXME: cross-crate hygiene
|
|
|
|
ident: ast::Ident::with_dummy_span(name),
|
|
|
|
id: ast::DUMMY_NODE_ID,
|
2019-11-13 13:01:43 +01:00
|
|
|
span,
|
2019-12-22 17:42:04 -05:00
|
|
|
attrs: attrs.iter().cloned().collect(),
|
|
|
|
kind: ast::ItemKind::MacroDef(ast::MacroDef {
|
|
|
|
body: P(ast::MacArgs::Delimited(dspan, ast::MacDelimiter::Brace, body)),
|
2019-11-13 13:01:43 +01:00
|
|
|
legacy,
|
2019-12-22 17:42:04 -05:00
|
|
|
}),
|
2019-11-13 13:01:43 +01:00
|
|
|
vis: source_map::respan(span.shrink_to_lo(), ast::VisibilityKind::Inherited),
|
2019-12-22 17:42:04 -05:00
|
|
|
tokens: None,
|
|
|
|
},
|
|
|
|
data.root.edition,
|
|
|
|
)
|
2016-10-28 06:52:45 +00:00
|
|
|
}
|
|
|
|
|
2019-05-19 16:26:08 +08:00
|
|
|
pub fn associated_item_cloned_untracked(&self, def: DefId) -> ty::AssocItem {
|
2018-07-31 17:23:29 -06:00
|
|
|
self.get_crate_data(def.krate).get_associated_item(def.index)
|
|
|
|
}
|
2019-10-06 14:30:46 +03:00
|
|
|
|
|
|
|
pub fn crate_source_untracked(&self, cnum: CrateNum) -> CrateSource {
|
|
|
|
self.get_crate_data(cnum).source.clone()
|
|
|
|
}
|
2020-01-09 09:23:44 +01:00
|
|
|
|
2019-10-14 17:20:50 -07:00
|
|
|
pub fn get_span_untracked(&self, def_id: DefId, sess: &Session) -> Span {
|
|
|
|
self.get_crate_data(def_id.krate).get_span(def_id.index, sess)
|
|
|
|
}
|
|
|
|
|
2020-01-09 09:23:44 +01:00
|
|
|
pub fn item_generics_num_lifetimes(&self, def_id: DefId, sess: &Session) -> usize {
|
|
|
|
self.get_crate_data(def_id.krate).get_generics(def_id.index, sess).own_counts().lifetimes
|
|
|
|
}
|
2018-07-31 17:23:29 -06:00
|
|
|
}
|
|
|
|
|
2019-11-24 01:10:12 +03:00
|
|
|
impl CrateStore for CStore {
|
2019-11-24 18:12:02 +03:00
|
|
|
fn as_any(&self) -> &dyn Any {
|
|
|
|
self
|
2018-07-31 17:23:29 -06:00
|
|
|
}
|
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
fn crate_name_untracked(&self, cnum: CrateNum) -> Symbol {
|
2019-10-02 03:15:38 +03:00
|
|
|
self.get_crate_data(cnum).root.name
|
2018-07-31 17:23:29 -06:00
|
|
|
}
|
|
|
|
|
2019-03-20 23:27:08 -04:00
|
|
|
fn crate_is_private_dep_untracked(&self, cnum: CrateNum) -> bool {
|
|
|
|
self.get_crate_data(cnum).private_dep
|
|
|
|
}
|
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> CrateDisambiguator {
|
2018-07-31 17:23:29 -06:00
|
|
|
self.get_crate_data(cnum).root.disambiguator
|
|
|
|
}
|
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
fn crate_hash_untracked(&self, cnum: CrateNum) -> Svh {
|
2018-07-31 17:23:29 -06:00
|
|
|
self.get_crate_data(cnum).root.hash
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
fn def_key(&self, def: DefId) -> DefKey {
|
|
|
|
self.get_crate_data(def.krate).def_key(def.index)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn def_path(&self, def: DefId) -> DefPath {
|
|
|
|
self.get_crate_data(def.krate).def_path(def.index)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn def_path_hash(&self, def: DefId) -> DefPathHash {
|
|
|
|
self.get_crate_data(def.krate).def_path_hash(def.index)
|
|
|
|
}
|
|
|
|
|
2019-10-20 14:06:48 +03:00
|
|
|
fn def_path_table(&self, cnum: CrateNum) -> &DefPathTable {
|
2020-03-03 01:06:07 +03:00
|
|
|
&self.get_crate_data(cnum).cdata.def_path_table
|
2018-07-31 17:23:29 -06:00
|
|
|
}
|
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
fn crates_untracked(&self) -> Vec<CrateNum> {
|
2015-11-21 21:39:05 +02:00
|
|
|
let mut result = vec![];
|
|
|
|
self.iter_crate_data(|cnum, _| result.push(cnum));
|
|
|
|
result
|
|
|
|
}
|
|
|
|
|
2019-06-21 20:27:44 +02:00
|
|
|
fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata {
|
2019-11-03 18:27:24 +03:00
|
|
|
encoder::encode_metadata(tcx)
|
2015-11-21 01:08:09 +02:00
|
|
|
}
|
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
fn metadata_encoding_version(&self) -> &[u8] {
|
2019-11-04 11:57:17 +03:00
|
|
|
rmeta::METADATA_HEADER
|
2015-11-21 01:08:09 +02:00
|
|
|
}
|
2019-11-11 14:50:26 -05:00
|
|
|
|
2019-11-11 14:57:34 -05:00
|
|
|
fn allocator_kind(&self) -> Option<AllocatorKind> {
|
2019-11-24 01:25:22 +03:00
|
|
|
self.allocator_kind()
|
2019-11-11 14:57:34 -05:00
|
|
|
}
|
2017-05-18 20:56:25 +03:00
|
|
|
}
|