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

Miscellneous refactorings of trans #41287

Merged
merged 14 commits into from
Apr 14, 2017
Merged
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
1 change: 0 additions & 1 deletion src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ pub use self::NativeLibraryKind::*;

#[derive(Clone, Debug)]
pub struct LinkMeta {
pub crate_name: Symbol,
pub crate_hash: Svh,
}
Copy link
Member

Choose a reason for hiding this comment

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

This is one of the weirder structures in the whole compiler and it'd be nice if it'd just die already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh yeah I meant to kill it altogether; it's just a newtype'd svh at this point

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do that in a follow-up though


Expand Down
12 changes: 5 additions & 7 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub use self::code_stats::{SizeKind, TypeSizeInfo, VariantInfo};

use dep_graph::DepGraph;
use hir::def_id::{CrateNum, DefIndex};
use hir::svh::Svh;
use lint;
use middle::cstore::CrateStore;
use middle::dependency_format;
Expand Down Expand Up @@ -402,15 +401,14 @@ impl Session {

/// Returns the symbol name for the registrar function,
/// given the crate Svh and the function DefIndex.
pub fn generate_plugin_registrar_symbol(&self, svh: &Svh, index: DefIndex)
pub fn generate_plugin_registrar_symbol(&self, disambiguator: Symbol, index: DefIndex)
-> String {
format!("__rustc_plugin_registrar__{}_{}", svh, index.as_usize())
format!("__rustc_plugin_registrar__{}_{}", disambiguator, index.as_usize())
}

pub fn generate_derive_registrar_symbol(&self,
svh: &Svh,
index: DefIndex) -> String {
format!("__rustc_derive_registrar__{}_{}", svh, index.as_usize())
pub fn generate_derive_registrar_symbol(&self, disambiguator: Symbol, index: DefIndex)
-> String {
format!("__rustc_derive_registrar__{}_{}", disambiguator, index.as_usize())
}

pub fn sysroot<'a>(&'a self) -> &'a Path {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ pub fn phase_6_link_output(sess: &Session,
outputs: &OutputFilenames) {
time(sess.time_passes(),
"linking",
|| link::link_binary(sess, trans, outputs, &trans.link.crate_name.as_str()));
|| link::link_binary(sess, trans, outputs, &trans.crate_name.as_str()));
}

fn escape_dep_filename(filename: &str) -> String {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ impl<'a> CrateLoader<'a> {
Err(err) => self.sess.span_fatal(span, &err),
};

let sym = self.sess.generate_derive_registrar_symbol(&root.hash,
let sym = self.sess.generate_derive_registrar_symbol(root.disambiguator,
root.macro_derive_registrar.unwrap());
let registrar = unsafe {
let sym = match lib.symbol(&sym) {
Expand Down Expand Up @@ -654,7 +654,7 @@ impl<'a> CrateLoader<'a> {
/// Look for a plugin registrar. Returns library path, crate
/// SVH and DefIndex of the registrar function.
pub fn find_plugin_registrar(&mut self, span: Span, name: &str)
-> Option<(PathBuf, Svh, DefIndex)> {
-> Option<(PathBuf, Symbol, DefIndex)> {
let ekrate = self.read_extension_crate(span, &ExternCrateInfo {
name: Symbol::intern(name),
ident: Symbol::intern(name),
Expand All @@ -675,7 +675,7 @@ impl<'a> CrateLoader<'a> {
let root = ekrate.metadata.get_root();
match (ekrate.dylib.as_ref(), root.plugin_registrar_fn) {
(Some(dylib), Some(reg)) => {
Some((dylib.to_path_buf(), root.hash, reg))
Some((dylib.to_path_buf(), root.disambiguator, reg))
}
(None, Some(_)) => {
span_err!(self.sess, span, E0457,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use schema::*;

use rustc::middle::cstore::{LinkMeta, LinkagePreference, NativeLibrary,
EncodedMetadata, EncodedMetadataHash};
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefIndex, DefId};
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefIndex, DefId, LOCAL_CRATE};
use rustc::hir::map::definitions::DefPathTable;
use rustc::middle::dependency_format::Linkage;
use rustc::middle::lang_items;
Expand Down Expand Up @@ -1380,7 +1380,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
let link_meta = self.link_meta;
let is_proc_macro = tcx.sess.crate_types.borrow().contains(&CrateTypeProcMacro);
let root = self.lazy(&CrateRoot {
name: link_meta.crate_name,
name: tcx.crate_name(LOCAL_CRATE),
triple: tcx.sess.opts.target_triple.clone(),
hash: link_meta.crate_hash,
disambiguator: tcx.sess.local_crate_disambiguator(),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_plugin/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ impl<'a> PluginLoader<'a> {
fn load_plugin(&mut self, span: Span, name: &str, args: Vec<ast::NestedMetaItem>) {
let registrar = self.reader.find_plugin_registrar(span, name);

if let Some((lib, svh, index)) = registrar {
let symbol = self.sess.generate_plugin_registrar_symbol(&svh, index);
if let Some((lib, disambiguator, index)) = registrar {
let symbol = self.sess.generate_plugin_registrar_symbol(disambiguator, index);
let fun = self.dylink_registrar(span, lib, symbol);
self.plugins.push(PluginRegistrar {
fun: fun,
Expand Down
6 changes: 1 addition & 5 deletions src/librustc_trans/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ use std::str;
use flate;
use syntax::ast;
use syntax::attr;
use syntax::symbol::Symbol;
use syntax_pos::Span;

/// The LLVM module name containing crate-metadata. This includes a `.` on
Expand Down Expand Up @@ -136,11 +135,8 @@ pub fn find_crate_name(sess: Option<&Session>,
"rust_out".to_string()
}

pub fn build_link_meta(incremental_hashes_map: &IncrementalHashesMap,
name: &str)
-> LinkMeta {
pub fn build_link_meta(incremental_hashes_map: &IncrementalHashesMap) -> LinkMeta {
let r = LinkMeta {
crate_name: Symbol::intern(name),
crate_hash: Svh::new(incremental_hashes_map[&DepNode::Krate].to_smaller_hash()),
};
info!("{:?}", r);
Expand Down
13 changes: 10 additions & 3 deletions src/librustc_trans/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use back::symbol_names::symbol_name;
use util::nodemap::FxHashMap;
use rustc::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
use rustc::session::config;
use rustc::ty::TyCtxt;
use syntax::attr;
use trans_item::TransItem;

Expand Down Expand Up @@ -64,15 +65,15 @@ impl ExportedSymbols {
}

if let Some(id) = scx.sess().derive_registrar_fn.get() {
let svh = &scx.link_meta().crate_hash;
let def_id = scx.tcx().hir.local_def_id(id);
let idx = def_id.index;
let registrar = scx.sess().generate_derive_registrar_symbol(svh, idx);
let disambiguator = scx.sess().local_crate_disambiguator();
let registrar = scx.sess().generate_derive_registrar_symbol(disambiguator, idx);
local_crate.push((registrar, SymbolExportLevel::C));
}

if scx.sess().crate_types.borrow().contains(&config::CrateTypeDylib) {
local_crate.push((scx.metadata_symbol_name(),
local_crate.push((metadata_symbol_name(scx.tcx()),
SymbolExportLevel::Rust));
}

Expand Down Expand Up @@ -173,6 +174,12 @@ impl ExportedSymbols {
}
}

pub fn metadata_symbol_name(tcx: TyCtxt) -> String {
format!("rust_metadata_{}_{}",
tcx.crate_name(LOCAL_CRATE),
tcx.crate_disambiguator(LOCAL_CRATE))
}

pub fn crate_export_threshold(crate_type: config::CrateType)
-> SymbolExportLevel {
match crate_type {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_trans/back/symbol_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ pub fn symbol_name<'a, 'tcx>(instance: Instance<'tcx>,

if let Some(id) = node_id {
if scx.sess().plugin_registrar_fn.get() == Some(id) {
let svh = &scx.link_meta().crate_hash;
let idx = def_id.index;
return scx.sess().generate_plugin_registrar_symbol(svh, idx);
let disambiguator = scx.sess().local_crate_disambiguator();
return scx.sess().generate_plugin_registrar_symbol(disambiguator, idx);
}
if scx.sess().derive_registrar_fn.get() == Some(id) {
let svh = &scx.link_meta().crate_hash;
let idx = def_id.index;
return scx.sess().generate_derive_registrar_symbol(svh, idx);
let disambiguator = scx.sess().local_crate_disambiguator();
return scx.sess().generate_derive_registrar_symbol(disambiguator, idx);
}
}

Expand Down
Loading