Skip to content

Commit 15507bc

Browse files
committed
remove metadata_* from SharedCrateContext
No good reason for them to be in there.
1 parent ea37682 commit 15507bc

File tree

2 files changed

+22
-34
lines changed

2 files changed

+22
-34
lines changed

src/librustc_trans/base.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use assert_module_sources;
3232
use back::link;
3333
use back::linker::LinkerInfo;
3434
use back::symbol_export::{self, ExportedSymbols};
35-
use llvm::{Linkage, ValueRef, Vector, get_param};
35+
use llvm::{ContextRef, Linkage, ModuleRef, ValueRef, Vector, get_param};
3636
use llvm;
3737
use rustc::hir::def_id::LOCAL_CRATE;
3838
use middle::lang_items::StartFnLangItem;
@@ -56,7 +56,7 @@ use common::CrateContext;
5656
use common::{type_is_zero_size, val_ty};
5757
use common;
5858
use consts;
59-
use context::{SharedCrateContext, CrateContextList};
59+
use context::{self, SharedCrateContext, CrateContextList};
6060
use debuginfo;
6161
use declare;
6262
use machine;
@@ -726,9 +726,13 @@ fn contains_null(s: &str) -> bool {
726726

727727
fn write_metadata(cx: &SharedCrateContext,
728728
exported_symbols: &NodeSet)
729-
-> EncodedMetadata {
729+
-> (ContextRef, ModuleRef, EncodedMetadata) {
730730
use flate;
731731

732+
let (metadata_llcx, metadata_llmod) = unsafe {
733+
context::create_context_and_module(cx.sess(), "metadata")
734+
};
735+
732736
#[derive(PartialEq, Eq, PartialOrd, Ord)]
733737
enum MetadataKind {
734738
None,
@@ -750,30 +754,30 @@ fn write_metadata(cx: &SharedCrateContext,
750754
}).max().unwrap();
751755

752756
if kind == MetadataKind::None {
753-
return EncodedMetadata {
757+
return (metadata_llcx, metadata_llmod, EncodedMetadata {
754758
raw_data: vec![],
755759
hashes: vec![],
756-
};
760+
});
757761
}
758762

759763
let cstore = &cx.tcx().sess.cstore;
760764
let metadata = cstore.encode_metadata(cx.tcx(),
761765
cx.link_meta(),
762766
exported_symbols);
763767
if kind == MetadataKind::Uncompressed {
764-
return metadata;
768+
return (metadata_llcx, metadata_llmod, metadata);
765769
}
766770

767771
assert!(kind == MetadataKind::Compressed);
768772
let mut compressed = cstore.metadata_encoding_version().to_vec();
769773
compressed.extend_from_slice(&flate::deflate_bytes(&metadata.raw_data));
770774

771-
let llmeta = C_bytes_in_context(cx.metadata_llcx(), &compressed);
772-
let llconst = C_struct_in_context(cx.metadata_llcx(), &[llmeta], false);
775+
let llmeta = C_bytes_in_context(metadata_llcx, &compressed);
776+
let llconst = C_struct_in_context(metadata_llcx, &[llmeta], false);
773777
let name = cx.metadata_symbol_name();
774778
let buf = CString::new(name).unwrap();
775779
let llglobal = unsafe {
776-
llvm::LLVMAddGlobal(cx.metadata_llmod(), val_ty(llconst).to_ref(), buf.as_ptr())
780+
llvm::LLVMAddGlobal(metadata_llmod, val_ty(llconst).to_ref(), buf.as_ptr())
777781
};
778782
unsafe {
779783
llvm::LLVMSetInitializer(llglobal, llconst);
@@ -787,9 +791,9 @@ fn write_metadata(cx: &SharedCrateContext,
787791
// metadata doesn't get loaded into memory.
788792
let directive = format!(".section {}", section_name);
789793
let directive = CString::new(directive).unwrap();
790-
llvm::LLVMSetModuleInlineAsm(cx.metadata_llmod(), directive.as_ptr())
794+
llvm::LLVMSetModuleInlineAsm(metadata_llmod, directive.as_ptr())
791795
}
792-
return metadata;
796+
return (metadata_llcx, metadata_llmod, metadata);
793797
}
794798

795799
/// Find any symbols that are defined in one compilation unit, but not declared
@@ -1070,16 +1074,17 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10701074
exported_symbols,
10711075
check_overflow);
10721076
// Translate the metadata.
1073-
let metadata = time(tcx.sess.time_passes(), "write metadata", || {
1074-
write_metadata(&shared_ccx, shared_ccx.exported_symbols())
1075-
});
1077+
let (metadata_llcx, metadata_llmod, metadata) =
1078+
time(tcx.sess.time_passes(), "write metadata", || {
1079+
write_metadata(&shared_ccx, shared_ccx.exported_symbols())
1080+
});
10761081

10771082
let metadata_module = ModuleTranslation {
10781083
name: link::METADATA_MODULE_NAME.to_string(),
10791084
symbol_name_hash: 0, // we always rebuild metadata, at least for now
10801085
source: ModuleSource::Translated(ModuleLlvm {
1081-
llcx: shared_ccx.metadata_llcx(),
1082-
llmod: shared_ccx.metadata_llmod(),
1086+
llcx: metadata_llcx,
1087+
llmod: metadata_llmod,
10831088
}),
10841089
};
10851090
let no_builtins = attr::contains_name(&krate.attrs, "no_builtins");

src/librustc_trans/context.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ pub struct Stats {
6565
/// crate, so it must not contain references to any LLVM data structures
6666
/// (aside from metadata-related ones).
6767
pub struct SharedCrateContext<'a, 'tcx: 'a> {
68-
metadata_llmod: ModuleRef,
69-
metadata_llcx: ContextRef,
70-
7168
exported_symbols: NodeSet,
7269
link_meta: LinkMeta,
7370
tcx: TyCtxt<'a, 'tcx, 'tcx>,
@@ -347,7 +344,7 @@ pub fn is_pie_binary(sess: &Session) -> bool {
347344
!is_any_library(sess) && get_reloc_model(sess) == llvm::RelocMode::PIC
348345
}
349346

350-
unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextRef, ModuleRef) {
347+
pub unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextRef, ModuleRef) {
351348
let llcx = llvm::LLVMContextCreate();
352349
let mod_name = CString::new(mod_name).unwrap();
353350
let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx);
@@ -409,10 +406,6 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
409406
exported_symbols: NodeSet,
410407
check_overflow: bool)
411408
-> SharedCrateContext<'b, 'tcx> {
412-
let (metadata_llcx, metadata_llmod) = unsafe {
413-
create_context_and_module(&tcx.sess, "metadata")
414-
};
415-
416409
// An interesting part of Windows which MSVC forces our hand on (and
417410
// apparently MinGW didn't) is the usage of `dllimport` and `dllexport`
418411
// attributes in LLVM IR as well as native dependencies (in C these
@@ -459,8 +452,6 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
459452
let use_dll_storage_attrs = tcx.sess.target.target.options.is_like_msvc;
460453

461454
SharedCrateContext {
462-
metadata_llmod: metadata_llmod,
463-
metadata_llcx: metadata_llcx,
464455
exported_symbols: exported_symbols,
465456
link_meta: link_meta,
466457
empty_param_env: tcx.empty_parameter_environment(),
@@ -492,14 +483,6 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
492483
ty.is_sized(self.tcx, &self.empty_param_env, DUMMY_SP)
493484
}
494485

495-
pub fn metadata_llmod(&self) -> ModuleRef {
496-
self.metadata_llmod
497-
}
498-
499-
pub fn metadata_llcx(&self) -> ContextRef {
500-
self.metadata_llcx
501-
}
502-
503486
pub fn exported_symbols<'a>(&'a self) -> &'a NodeSet {
504487
&self.exported_symbols
505488
}

0 commit comments

Comments
 (0)