]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_trans/context.rs
Auto merge of #43710 - zackmdavis:field_init_shorthand_power_slam, r=Mark-Simulacrum
[rust.git] / src / librustc_trans / context.rs
index 208e994653b585d7e2a8d0f770de4a23399d5457..8c6bd302e4bfdb51fd495938024285a04b8ba25c 100644 (file)
 use rustc::traits;
 use debuginfo;
 use callee;
+use back::symbol_export::ExportedSymbols;
 use base;
 use declare;
 use monomorphize::Instance;
 
 use partitioning::CodegenUnit;
+use trans_item::TransItem;
 use type_::Type;
 use rustc_data_structures::base_n;
 use rustc::session::config::{self, NoDebugInfo, OutputFilenames};
 use rustc::ty::subst::Substs;
 use rustc::ty::{self, Ty, TyCtxt};
 use rustc::ty::layout::{LayoutCx, LayoutError, LayoutTyper, TyLayout};
-use rustc::util::nodemap::{NodeSet, DefIdMap, FxHashMap};
+use rustc::util::nodemap::{DefIdMap, FxHashMap, FxHashSet};
 
 use std::ffi::{CStr, CString};
 use std::cell::{Cell, RefCell};
 use std::ptr;
 use std::iter;
 use std::str;
+use std::sync::Arc;
 use std::marker::PhantomData;
 use syntax::ast;
 use syntax::symbol::InternedString;
@@ -76,7 +79,6 @@ pub fn extend(&mut self, stats: Stats) {
 /// crate, so it must not contain references to any LLVM data structures
 /// (aside from metadata-related ones).
 pub struct SharedCrateContext<'a, 'tcx: 'a> {
-    exported_symbols: NodeSet,
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
     check_overflow: bool,
 
@@ -94,6 +96,13 @@ pub struct LocalCrateContext<'a, 'tcx: 'a> {
     llcx: ContextRef,
     stats: Stats,
     codegen_unit: CodegenUnit<'tcx>,
+
+    /// The translation items of the whole crate.
+    crate_trans_items: Arc<FxHashSet<TransItem<'tcx>>>,
+
+    /// Information about which symbols are exported from the crate.
+    exported_symbols: Arc<ExportedSymbols>,
+
     /// Cache instances of monomorphic and polymorphic items
     instances: RefCell<FxHashMap<Instance<'tcx>, ValueRef>>,
     /// Cache generated vtables
@@ -265,7 +274,6 @@ pub unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (Cont
 
 impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
     pub fn new(tcx: TyCtxt<'b, 'tcx, 'tcx>,
-               exported_symbols: NodeSet,
                check_overflow: bool,
                output_filenames: &'b OutputFilenames)
                -> SharedCrateContext<'b, 'tcx> {
@@ -315,11 +323,10 @@ pub fn new(tcx: TyCtxt<'b, 'tcx, 'tcx>,
         let use_dll_storage_attrs = tcx.sess.target.target.options.is_like_msvc;
 
         SharedCrateContext {
-            exported_symbols: exported_symbols,
-            tcx: tcx,
-            check_overflow: check_overflow,
-            use_dll_storage_attrs: use_dll_storage_attrs,
-            output_filenames: output_filenames,
+            tcx,
+            check_overflow,
+            use_dll_storage_attrs,
+            output_filenames,
         }
     }
 
@@ -335,10 +342,6 @@ pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
         ty.is_freeze(self.tcx, ty::ParamEnv::empty(traits::Reveal::All), DUMMY_SP)
     }
 
-    pub fn exported_symbols<'a>(&'a self) -> &'a NodeSet {
-        &self.exported_symbols
-    }
-
     pub fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> {
         self.tcx
     }
@@ -362,7 +365,9 @@ pub fn output_filenames(&self) -> &OutputFilenames {
 
 impl<'a, 'tcx> LocalCrateContext<'a, 'tcx> {
     pub fn new(shared: &SharedCrateContext<'a, 'tcx>,
-               codegen_unit: CodegenUnit<'tcx>)
+               codegen_unit: CodegenUnit<'tcx>,
+               crate_trans_items: Arc<FxHashSet<TransItem<'tcx>>>,
+               exported_symbols: Arc<ExportedSymbols>,)
                -> LocalCrateContext<'a, 'tcx> {
         unsafe {
             // Append ".rs" to LLVM module identifier.
@@ -390,10 +395,12 @@ pub fn new(shared: &SharedCrateContext<'a, 'tcx>,
             };
 
             let local_ccx = LocalCrateContext {
-                llmod: llmod,
-                llcx: llcx,
+                llmod,
+                llcx,
                 stats: Stats::default(),
-                codegen_unit: codegen_unit,
+                codegen_unit,
+                crate_trans_items,
+                exported_symbols,
                 instances: RefCell::new(FxHashMap()),
                 vtables: RefCell::new(FxHashMap()),
                 const_cstr_cache: RefCell::new(FxHashMap()),
@@ -409,7 +416,7 @@ pub fn new(shared: &SharedCrateContext<'a, 'tcx>,
                 int_type: Type::from_ref(ptr::null_mut()),
                 opaque_vec_type: Type::from_ref(ptr::null_mut()),
                 str_slice_type: Type::from_ref(ptr::null_mut()),
-                dbg_cx: dbg_cx,
+                dbg_cx,
                 eh_personality: Cell::new(None),
                 eh_unwind_resume: Cell::new(None),
                 rust_try_fn: Cell::new(None),
@@ -455,7 +462,7 @@ fn dummy_ccx(shared: &'a SharedCrateContext<'a, 'tcx>,
                  -> CrateContext<'a, 'tcx> {
         assert!(local_ccxs.len() == 1);
         CrateContext {
-            shared: shared,
+            shared,
             local_ccx: &local_ccxs[0]
         }
     }
@@ -504,6 +511,14 @@ pub fn codegen_unit(&self) -> &CodegenUnit<'tcx> {
         &self.local().codegen_unit
     }
 
+    pub fn crate_trans_items(&self) -> &FxHashSet<TransItem<'tcx>> {
+        &self.local().crate_trans_items
+    }
+
+    pub fn exported_symbols(&self) -> &ExportedSymbols {
+        &self.local().exported_symbols
+    }
+
     pub fn td(&self) -> llvm::TargetDataRef {
         unsafe { llvm::LLVMRustGetModuleDataLayout(self.llmod()) }
     }