about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2017-04-13 12:46:37 -0400
committerNiko Matsakis <niko@alum.mit.edu>2017-04-13 18:33:09 -0400
commitbc79f01a581c9340cd869ba36579ee80d9606298 (patch)
tree6d2d9fbeea6d824f3097a63a2cd982d698533f2a
parent6cb516ad7b6e058be547e7ee5dc78762cc9b809b (diff)
downloadrust-bc79f01a581c9340cd869ba36579ee80d9606298.tar.gz
rust-bc79f01a581c9340cd869ba36579ee80d9606298.zip
create `ModuleTranslation` all in one big loop
-rw-r--r--src/librustc_trans/base.rs59
1 files changed, 31 insertions, 28 deletions
diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs
index ce136a7883c..c822cc5f4b9 100644
--- a/src/librustc_trans/base.rs
+++ b/src/librustc_trans/base.rs
@@ -1120,41 +1120,31 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                                                    codegen_units,
                                                    previous_work_products,
                                                    symbol_map.clone());
-    let modules: Vec<_> = crate_context_list.iter_all()
-        .map(|ccx| {
-            let source = match ccx.previous_work_product() {
-                Some(buf) => ModuleSource::Preexisting(buf.clone()),
-                None => ModuleSource::Translated(ModuleLlvm {
-                    llcx: ccx.llcx(),
-                    llmod: ccx.llmod(),
-                }),
-            };
 
-            ModuleTranslation {
-                name: String::from(ccx.codegen_unit().name()),
-                symbol_name_hash: ccx.codegen_unit()
-                                     .compute_symbol_name_hash(&shared_ccx,
-                                                               &symbol_map),
-                source: source,
-            }
+    let modules: Vec<ModuleTranslation> = crate_context_list
+        .iter_all()
+        .map(|ccx| {
+            let dep_node = ccx.codegen_unit().work_product_dep_node();
+            tcx.dep_graph.with_task(dep_node,
+                                    ccx,
+                                    AssertDepGraphSafe(symbol_map.clone()),
+                                    module_translation)
         })
         .collect();
 
-    for ccx in crate_context_list.iter_need_trans() {
-        let dep_node = ccx.codegen_unit().work_product_dep_node();
-        tcx.dep_graph.with_task(dep_node,
-                                ccx,
-                                AssertDepGraphSafe(symbol_map.clone()),
-                                trans_decl_task);
-
+    fn module_translation<'a, 'tcx>(ccx: CrateContext<'a, 'tcx>,
+                                    symbol_map: AssertDepGraphSafe<Rc<SymbolMap<'tcx>>>)
+                                    -> ModuleTranslation {
+        // FIXME(#40304): Instead of this, the symbol-map should be an
+        // on-demand thing that we compute.
+        let AssertDepGraphSafe(symbol_map) = symbol_map;
 
-        fn trans_decl_task<'a, 'tcx>(ccx: CrateContext<'a, 'tcx>,
-                                     symbol_map: AssertDepGraphSafe<Rc<SymbolMap<'tcx>>>) {
+        let source = if let Some(buf) = ccx.previous_work_product() {
+            // Don't need to translate this module.
+            ModuleSource::Preexisting(buf.clone())
+        } else {
             // Instantiate translation items without filling out definitions yet...
 
-            // FIXME(#40304): Instead of this, the symbol-map should be an
-            // on-demand thing that we compute.
-            let AssertDepGraphSafe(symbol_map) = symbol_map;
             let cgu = ccx.codegen_unit();
             let trans_items = cgu.items_in_deterministic_order(ccx.tcx(), &symbol_map);
             for &(trans_item, linkage) in &trans_items {
@@ -1200,6 +1190,19 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
             if ccx.sess().opts.debuginfo != NoDebugInfo {
                 debuginfo::finalize(&ccx);
             }
+
+            ModuleSource::Translated(ModuleLlvm {
+                llcx: ccx.llcx(),
+                llmod: ccx.llmod(),
+            })
+        };
+
+        ModuleTranslation {
+            name: String::from(ccx.codegen_unit().name()),
+            symbol_name_hash: ccx.codegen_unit()
+                                 .compute_symbol_name_hash(ccx.shared(),
+                                                           &symbol_map),
+            source: source,
         }
     }