Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crate metadata nondefid args #41780

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub enum DepNode<D: Clone + Debug> {
// Represents the metadata for a given HIR node, typically found
// in an extern crate.
MetaData(D),
MetaDataByCrateNum(CrateNum),

// Represents some artifact that we save to disk. Note that these
// do not have a def-id as part of their identifier.
Expand Down Expand Up @@ -208,6 +209,7 @@ impl<D: Clone + Debug> DepNode<D> {
MirKeys => Some(MirKeys),
LateLintCheck => Some(LateLintCheck),
TransWriteMetadata => Some(TransWriteMetadata),
MetaDataByCrateNum(c) => Some(MetaDataByCrateNum(c)),

// work product names do not need to be mapped, because
// they are always absolute.
Expand Down
16 changes: 0 additions & 16 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,7 @@ pub trait CrateStore {
fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem;

// flags
fn is_const_fn(&self, did: DefId) -> bool;
fn is_default_impl(&self, impl_did: DefId) -> bool;
fn is_foreign_item(&self, did: DefId) -> bool;
fn is_dllimport_foreign_item(&self, def: DefId) -> bool;
fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool;
fn is_exported_symbol(&self, def_id: DefId) -> bool;

Expand All @@ -226,10 +223,6 @@ pub trait CrateStore {
fn crate_hash(&self, cnum: CrateNum) -> Svh;
fn crate_disambiguator(&self, cnum: CrateNum) -> Symbol;
fn plugin_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>;
fn derive_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>;
fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>;
fn exported_symbols(&self, cnum: CrateNum) -> Vec<DefId>;
fn is_no_builtins(&self, cnum: CrateNum) -> bool;

// resolve
fn retrace_path(&self,
Expand Down Expand Up @@ -325,10 +318,7 @@ impl CrateStore for DummyCrateStore {
{ bug!("associated_item_cloned") }

// flags
fn is_const_fn(&self, did: DefId) -> bool { bug!("is_const_fn") }
fn is_default_impl(&self, impl_did: DefId) -> bool { bug!("is_default_impl") }
fn is_foreign_item(&self, did: DefId) -> bool { bug!("is_foreign_item") }
fn is_dllimport_foreign_item(&self, id: DefId) -> bool { false }
fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool { false }
fn is_exported_symbol(&self, def_id: DefId) -> bool { false }

Expand Down Expand Up @@ -360,12 +350,6 @@ impl CrateStore for DummyCrateStore {
-> Symbol { bug!("crate_disambiguator") }
fn plugin_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>
{ bug!("plugin_registrar_fn") }
fn derive_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>
{ bug!("derive_registrar_fn") }
fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>
{ bug!("native_libraries") }
fn exported_symbols(&self, cnum: CrateNum) -> Vec<DefId> { bug!("exported_symbols") }
fn is_no_builtins(&self, cnum: CrateNum) -> bool { bug!("is_no_builtins") }

// resolve
fn retrace_path(&self,
Expand Down
53 changes: 49 additions & 4 deletions src/librustc/ty/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use hir::def::Def;
use hir;
use middle::const_val;
use middle::cstore::NativeLibrary;
use middle::privacy::AccessLevels;
use middle::region::RegionMaps;
use mir;
Expand Down Expand Up @@ -347,13 +348,44 @@ impl<'tcx> QueryDescription for queries::const_is_rvalue_promotable_to_static<'t
}
}

impl<'tcx> QueryDescription for queries::is_mir_available<'tcx> {
fn describe(tcx: TyCtxt, def_id: DefId) -> String {
format!("checking if item is mir available: `{}`",
tcx.item_path_str(def_id))
macro_rules! simple_query_description {
($($fn_name:ident, $desc:expr),*,) => {
$(
impl<'tcx> QueryDescription for queries::$fn_name<'tcx> {
fn describe(tcx: TyCtxt, def_id: DefId) -> String {
format!(concat!($desc, "`: {}`"),
tcx.item_path_str(def_id))
}
}
)*
}
}

simple_query_description! {
is_mir_available, "checking if item is mir available",
is_const_fn, "checking if item is const fn",
is_dllimport_foreign_item, "checking if item is dll import foreign item",
}

macro_rules! cratenum_query_description {
($($fn_name:ident, $desc:expr),*,) => {
$(
impl<'tcx> QueryDescription for queries::$fn_name<'tcx> {
fn describe(_tcx: TyCtxt, crate_num: CrateNum) -> String {
format!(concat!($desc, "`: crate {}`"), crate_num)
}
}
)*
}
}

cratenum_query_description! {
derive_registrar_fn, "getting the derive_registrar_fn",
native_libraries, "getting native libraries",
exported_symbols, "getting the exported symbols",
is_no_builtins, "checking if is_no_builtins",
}

macro_rules! define_maps {
(<$tcx:tt>
$($(#[$attr:meta])*
Expand Down Expand Up @@ -786,6 +818,15 @@ define_maps! { <'tcx>
[] item_body_nested_bodies: metadata_dep_node(DefId) -> Rc<BTreeMap<hir::BodyId, hir::Body>>,
[] const_is_rvalue_promotable_to_static: metadata_dep_node(DefId) -> bool,
[] is_mir_available: metadata_dep_node(DefId) -> bool,

[] is_const_fn: metadata_dep_node(DefId) -> bool,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's something in MIR const qualif doing this check, so that could be fully replaced by this (right now users of this query have to take into account the fact that it only works cross-crate).

[] is_default_impl: metadata_dep_node(DefId) -> bool,
[] is_dllimport_foreign_item: metadata_dep_node(DefId) -> bool,

[] derive_registrar_fn: cratenum_metadata_dep_node(CrateNum) -> Option<DefId>,
[] native_libraries: cratenum_metadata_dep_node(CrateNum) -> Vec<NativeLibrary>,
[] exported_symbols: cratenum_metadata_dep_node(CrateNum) -> Vec<DefId>,
[] is_no_builtins: cratenum_metadata_dep_node(CrateNum) -> bool,
}

fn coherent_trait_dep_node((_, def_id): (CrateNum, DefId)) -> DepNode<DefId> {
Expand All @@ -804,6 +845,10 @@ fn metadata_dep_node(def_id: DefId) -> DepNode<DefId> {
DepNode::MetaData(def_id)
}

fn cratenum_metadata_dep_node(crate_num: CrateNum) -> DepNode<DefId> {
DepNode::MetaDataByCrateNum(crate_num)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just use MetaDataByCrateNum above, the functions are used when the variants don't match the key exactly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should have DepNode with a cratenum in it, though, at least not yet, as it won't get remapped properly when being loaded back up.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikomatsakis what would you suggest instead?

}

fn mir_shim_dep_node(instance: ty::InstanceDef) -> DepNode<DefId> {
instance.dep_node()
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_const_eval/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
signal!(e, TypeckError)
}
} else {
if tcx.sess.cstore.is_const_fn(def_id) {
if tcx.is_const_fn(def_id) {
tcx.sess.cstore.item_body(tcx, def_id)
} else {
signal!(e, TypeckError)
Expand Down
15 changes: 9 additions & 6 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,9 +1065,11 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,

/// Run LLVM itself, producing a bitcode file, assembly file or object file
/// as a side effect.
pub fn phase_5_run_llvm_passes(sess: &Session,
pub fn phase_5_run_llvm_passes<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
trans: &trans::CrateTranslation,
outputs: &OutputFilenames) -> CompileResult {
let sess = tcx.sess;
if sess.opts.cg.no_integrated_as ||
(sess.target.target.options.no_integrated_as &&
(outputs.outputs.contains_key(&OutputType::Object) ||
Expand All @@ -1076,7 +1078,7 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
let output_types = OutputTypes::new(&[(OutputType::Assembly, None)]);
time(sess.time_passes(),
"LLVM passes",
|| write::run_passes(sess, trans, &output_types, outputs));
|| write::run_passes(tcx, trans, &output_types, outputs));

write::run_assembler(sess, outputs);

Expand All @@ -1097,7 +1099,7 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
} else {
time(sess.time_passes(),
"LLVM passes",
|| write::run_passes(sess, trans, &sess.opts.output_types, outputs));
|| write::run_passes(tcx, trans, &sess.opts.output_types, outputs));
}

time(sess.time_passes(),
Expand All @@ -1113,12 +1115,13 @@ pub fn phase_5_run_llvm_passes(sess: &Session,

/// Run the linker on any artifacts that resulted from the LLVM run.
/// This should produce either a finished executable or library.
pub fn phase_6_link_output(sess: &Session,
pub fn phase_6_link_output<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
trans: &trans::CrateTranslation,
outputs: &OutputFilenames) {
time(sess.time_passes(),
time(tcx.sess.time_passes(),
"linking",
|| link::link_binary(sess, trans, outputs, &trans.crate_name.as_str()));
|| link::link_binary(tcx, trans, outputs, &trans.crate_name.as_str()));
}

fn escape_dep_filename(filename: &str) -> String {
Expand Down
Loading