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

[experimental] Allow for RLIBs to only contain metadata. #48373

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
5 changes: 5 additions & 0 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ fn main() {
if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
cmd.arg("-Z").arg("force-unstable-if-unmarked");
}

// Don't use MIR only RLIBs for the compiler yet
if stage != "0" {
cmd.arg("-Zmir-only-rlibs=no");
}
} else {
// Override linker if necessary.
if let Ok(host_linker) = env::var("RUSTC_HOST_LINKER") {
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ define_dep_nodes!( <'tcx>
[eval_always] CollectAndPartitionTranslationItems,
[] ExportName(DefId),
[] ContainsExternIndicator(DefId),
[] IsTranslatedFunction(DefId),
[] IsTranslatedItem(DefId),
[] CodegenUnit(InternedString),
[] CompileCodegenUnit(InternedString),
[input] OutputFilenames,
Expand All @@ -642,6 +642,7 @@ define_dep_nodes!( <'tcx>

[] GetSymbolExportLevel(DefId),

[input] IsMirOnlyRlib(CrateNum),
);

trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
Expand Down
98 changes: 98 additions & 0 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use hir::def_id::{CRATE_DEF_INDEX, DefId, LocalDefId, DefIndexAddressSpace};
use syntax::abi::Abi;
use syntax::ast::{self, Name, NodeId, CRATE_NODE_ID};
use syntax::codemap::Spanned;
use syntax::ext::base::MacroKind;
use syntax_pos::Span;

use hir::*;
Expand All @@ -32,13 +33,15 @@ use util::nodemap::{DefIdMap, FxHashMap};
use arena::TypedArena;
use std::cell::RefCell;
use std::io;
use ty::TyCtxt;

pub mod blocks;
mod collector;
mod def_collector;
pub mod definitions;
mod hir_id_validator;


pub const ITEM_LIKE_SPACE: DefIndexAddressSpace = DefIndexAddressSpace::Low;
pub const REGULAR_SPACE: DefIndexAddressSpace = DefIndexAddressSpace::High;

Expand Down Expand Up @@ -373,6 +376,92 @@ impl<'hir> Map<'hir> {
self.definitions.as_local_node_id(def_id.to_def_id()).unwrap()
}

pub fn describe_def(&self, node_id: NodeId) -> Option<Def> {
let node = if let Some(node) = self.find(node_id) {
node
} else {
return None
};

match node {
NodeItem(item) => {
let def_id = || {
self.local_def_id(item.id)
};

match item.node {
ItemStatic(_, m, _) => Some(Def::Static(def_id(),
m == MutMutable)),
ItemConst(..) => Some(Def::Const(def_id())),
ItemFn(..) => Some(Def::Fn(def_id())),
ItemMod(..) => Some(Def::Mod(def_id())),
ItemGlobalAsm(..) => Some(Def::GlobalAsm(def_id())),
ItemTy(..) => Some(Def::TyAlias(def_id())),
ItemEnum(..) => Some(Def::Enum(def_id())),
ItemStruct(..) => Some(Def::Struct(def_id())),
ItemUnion(..) => Some(Def::Union(def_id())),
ItemTrait(..) => Some(Def::Trait(def_id())),
ItemTraitAlias(..) => {
bug!("trait aliases are not yet implemented (see issue #41517)")
},
ItemExternCrate(_) |
ItemUse(..) |
ItemForeignMod(..) |
ItemImpl(..) => None,
}
}
NodeForeignItem(item) => {
let def_id = self.local_def_id(item.id);
match item.node {
ForeignItemFn(..) => Some(Def::Fn(def_id)),
ForeignItemStatic(_, m) => Some(Def::Static(def_id, m)),
ForeignItemType => Some(Def::TyForeign(def_id)),
}
}
NodeTraitItem(item) => {
let def_id = self.local_def_id(item.id);
match item.node {
TraitItemKind::Const(..) => Some(Def::AssociatedConst(def_id)),
TraitItemKind::Method(..) => Some(Def::Method(def_id)),
TraitItemKind::Type(..) => Some(Def::AssociatedTy(def_id)),
}
}
NodeImplItem(item) => {
let def_id = self.local_def_id(item.id);
match item.node {
ImplItemKind::Const(..) => Some(Def::AssociatedConst(def_id)),
ImplItemKind::Method(..) => Some(Def::Method(def_id)),
ImplItemKind::Type(..) => Some(Def::AssociatedTy(def_id)),
}
}
NodeVariant(variant) => {
let def_id = self.local_def_id(variant.node.data.id());
Some(Def::Variant(def_id))
}
NodeField(_) |
NodeExpr(_) |
NodeStmt(_) |
NodeTy(_) |
NodeTraitRef(_) |
NodePat(_) |
NodeBinding(_) |
NodeStructCtor(_) |
NodeLifetime(_) |
NodeVisibility(_) |
NodeBlock(_) => None,
NodeLocal(local) => {
Some(Def::Local(local.id))
}
NodeMacroDef(macro_def) => {
Some(Def::Macro(self.local_def_id(macro_def.id),
MacroKind::Bang))
}
NodeTyParam(param) => {
Some(Def::TyParam(self.local_def_id(param.id)))
}
}
}

fn entry_count(&self) -> usize {
self.map.len()
}
Expand Down Expand Up @@ -1275,3 +1364,12 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
}
}
}

pub fn describe_def(tcx: TyCtxt, def_id: DefId) -> Option<Def> {
if let Some(node_id) = tcx.hir.as_local_node_id(def_id) {
tcx.hir.describe_def(node_id)
} else {
bug!("Calling local describe_def query provider for upstream DefId: {:?}",
def_id)
}
}
6 changes: 6 additions & 0 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use syntax::tokenstream::TokenStream;
use syntax::util::ThinVec;
use syntax::util::parser::ExprPrecedence;
use ty::AdtKind;
use ty::maps::Providers;

use rustc_data_structures::indexed_vec;

Expand Down Expand Up @@ -2204,3 +2205,8 @@ pub type TraitMap = NodeMap<Vec<TraitCandidate>>;
// Map from the NodeId of a glob import to a list of items which are actually
// imported.
pub type GlobMap = NodeMap<FxHashSet<Name>>;


pub fn provide(providers: &mut Providers) {
providers.describe_def = map::describe_def;
}
7 changes: 5 additions & 2 deletions src/librustc/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use hir::def_id::DefId;
use syntax::ast::NodeId;
use syntax::symbol::InternedString;
use ty::{Instance, TyCtxt};
Expand All @@ -21,7 +22,7 @@ use std::hash::Hash;
#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)]
pub enum MonoItem<'tcx> {
Fn(Instance<'tcx>),
Static(NodeId),
Static(DefId),
GlobalAsm(NodeId),
}

Expand Down Expand Up @@ -50,7 +51,9 @@ impl<'tcx> HashStable<StableHashingContext<'tcx>> for MonoItem<'tcx> {
MonoItem::Fn(ref instance) => {
instance.hash_stable(hcx, hasher);
}
MonoItem::Static(node_id) |
MonoItem::Static(def_id) => {
def_id.hash_stable(hcx, hasher);
}
MonoItem::GlobalAsm(node_id) => {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
node_id.hash_stable(hcx, hasher);
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
epoch). Crates compiled with different epochs can be linked together."),
run_dsymutil: Option<bool> = (None, parse_opt_bool, [TRACKED],
"run `dsymutil` and delete intermediate object files"),

mir_only_rlibs: Option<bool> = (Some(true), parse_opt_bool, [TRACKED], "go!"),
}

pub fn default_lib_output() -> CrateType {
Expand Down
7 changes: 7 additions & 0 deletions src/librustc/ty/maps/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ impl<'tcx, M: QueryConfig<Key=DefId>> QueryDescription<'tcx> for M {
}
}


impl<'tcx> QueryDescription<'tcx> for queries::is_mir_only_rlib<'tcx> {
fn describe(_tcx: TyCtxt, cnum: CrateNum) -> String {
format!("computing whether `{}` is a MIR-only RLIB", cnum)
}
}

impl<'tcx> QueryDescription<'tcx> for queries::is_copy_raw<'tcx> {
fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
format!("computing whether `{}` is `Copy`", env.value)
Expand Down
4 changes: 3 additions & 1 deletion src/librustc/ty/maps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ define_maps! { <'tcx>
[] fn export_name: ExportName(DefId) -> Option<Symbol>,
[] fn contains_extern_indicator: ContainsExternIndicator(DefId) -> bool,
[] fn symbol_export_level: GetSymbolExportLevel(DefId) -> SymbolExportLevel,
[] fn is_translated_function: IsTranslatedFunction(DefId) -> bool,
[] fn is_translated_item: IsTranslatedItem(DefId) -> bool,
[] fn codegen_unit: CodegenUnit(InternedString) -> Arc<CodegenUnit<'tcx>>,
[] fn compile_codegen_unit: CompileCodegenUnit(InternedString) -> Stats,
[] fn output_filenames: output_filenames_node(CrateNum)
Expand All @@ -374,6 +374,8 @@ define_maps! { <'tcx>
// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
[] fn instance_def_size_estimate: instance_def_size_estimate_dep_node(ty::InstanceDef<'tcx>)
-> usize,

[] fn is_mir_only_rlib: IsMirOnlyRlib(CrateNum) -> bool,
}

//////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/ty/maps/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,13 +929,14 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
DepKind::ContainsExternIndicator => {
force!(contains_extern_indicator, def_id!());
}
DepKind::IsTranslatedFunction => { force!(is_translated_function, def_id!()); }
DepKind::IsTranslatedItem => { force!(is_translated_item, def_id!()); }
DepKind::OutputFilenames => { force!(output_filenames, LOCAL_CRATE); }

DepKind::TargetFeaturesWhitelist => { force!(target_features_whitelist, LOCAL_CRATE); }
DepKind::TargetFeaturesEnabled => { force!(target_features_enabled, def_id!()); }

DepKind::GetSymbolExportLevel => { force!(symbol_export_level, def_id!()); }
DepKind::IsMirOnlyRlib => { force!(is_mir_only_rlib, krate!()); }
}

true
Expand Down
1 change: 1 addition & 0 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
}

pub fn default_provide(providers: &mut ty::maps::Providers) {
hir::provide(providers);
borrowck::provide(providers);
mir::provide(providers);
reachable::provide(providers);
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ provide! { <'tcx> tcx, def_id, other, cdata,

has_copy_closures => { cdata.has_copy_closures(tcx.sess) }
has_clone_closures => { cdata.has_clone_closures(tcx.sess) }

is_mir_only_rlib => { cdata.root.is_mir_only_rlib }
}

pub fn provide<'tcx>(providers: &mut Providers<'tcx>) {
Expand Down
18 changes: 15 additions & 3 deletions src/librustc_metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,14 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
let has_default_lib_allocator =
attr::contains_name(tcx.hir.krate_attrs(), "default_lib_allocator");
let has_global_allocator = tcx.sess.has_global_allocator.get();

let is_mir_only_rlib = if tcx.sess.opts.debugging_opts.mir_only_rlibs != Some(false) {
let crate_types = tcx.sess.crate_types.borrow();
crate_types.len() == 1 && crate_types[0] == config::CrateTypeRlib
} else {
false
};

let root = self.lazy(&CrateRoot {
name: tcx.crate_name(LOCAL_CRATE),
triple: tcx.sess.opts.target_triple.clone(),
Expand All @@ -423,6 +431,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
panic_strategy: tcx.sess.panic_strategy(),
has_global_allocator: has_global_allocator,
has_default_lib_allocator: has_default_lib_allocator,
is_mir_only_rlib,
plugin_registrar_fn: tcx.sess
.plugin_registrar_fn
.get()
Expand Down Expand Up @@ -833,7 +842,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
let needs_inline = types > 0 || attr::requests_inline(&ast_item.attrs);
let is_const_fn = sig.constness == hir::Constness::Const;
let ast = if is_const_fn { Some(body) } else { None };
let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir;
let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir ||
self.tcx.sess.opts.debugging_opts.mir_only_rlibs != Some(false);
(ast, needs_inline || is_const_fn || always_encode_mir)
} else {
(None, false)
Expand Down Expand Up @@ -1115,14 +1125,16 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
_ => None,
},
mir: match item.node {
hir::ItemStatic(..) if self.tcx.sess.opts.debugging_opts.always_encode_mir => {
hir::ItemStatic(..) if self.tcx.sess.opts.debugging_opts.always_encode_mir ||
self.tcx.sess.opts.debugging_opts.mir_only_rlibs != Some(false) => {
self.encode_optimized_mir(def_id)
}
hir::ItemConst(..) => self.encode_optimized_mir(def_id),
hir::ItemFn(_, _, constness, _, ref generics, _) => {
let has_tps = generics.ty_params().next().is_some();
let needs_inline = has_tps || attr::requests_inline(&item.attrs);
let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir;
let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir ||
self.tcx.sess.opts.debugging_opts.mir_only_rlibs != Some(false);
if needs_inline || constness == hir::Constness::Const || always_encode_mir {
self.encode_optimized_mir(def_id)
} else {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_metadata/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ pub struct CrateRoot {
pub panic_strategy: PanicStrategy,
pub has_global_allocator: bool,
pub has_default_lib_allocator: bool,
pub is_mir_only_rlib: bool,
pub plugin_registrar_fn: Option<DefIndex>,
pub macro_derive_registrar: Option<DefIndex>,

Expand Down
Loading