Skip to content

Commit bc79f01

Browse files
committed
create ModuleTranslation all in one big loop
1 parent 6cb516a commit bc79f01

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

src/librustc_trans/base.rs

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,41 +1120,31 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11201120
codegen_units,
11211121
previous_work_products,
11221122
symbol_map.clone());
1123-
let modules: Vec<_> = crate_context_list.iter_all()
1124-
.map(|ccx| {
1125-
let source = match ccx.previous_work_product() {
1126-
Some(buf) => ModuleSource::Preexisting(buf.clone()),
1127-
None => ModuleSource::Translated(ModuleLlvm {
1128-
llcx: ccx.llcx(),
1129-
llmod: ccx.llmod(),
1130-
}),
1131-
};
11321123

1133-
ModuleTranslation {
1134-
name: String::from(ccx.codegen_unit().name()),
1135-
symbol_name_hash: ccx.codegen_unit()
1136-
.compute_symbol_name_hash(&shared_ccx,
1137-
&symbol_map),
1138-
source: source,
1139-
}
1124+
let modules: Vec<ModuleTranslation> = crate_context_list
1125+
.iter_all()
1126+
.map(|ccx| {
1127+
let dep_node = ccx.codegen_unit().work_product_dep_node();
1128+
tcx.dep_graph.with_task(dep_node,
1129+
ccx,
1130+
AssertDepGraphSafe(symbol_map.clone()),
1131+
module_translation)
11401132
})
11411133
.collect();
11421134

1143-
for ccx in crate_context_list.iter_need_trans() {
1144-
let dep_node = ccx.codegen_unit().work_product_dep_node();
1145-
tcx.dep_graph.with_task(dep_node,
1146-
ccx,
1147-
AssertDepGraphSafe(symbol_map.clone()),
1148-
trans_decl_task);
1149-
1135+
fn module_translation<'a, 'tcx>(ccx: CrateContext<'a, 'tcx>,
1136+
symbol_map: AssertDepGraphSafe<Rc<SymbolMap<'tcx>>>)
1137+
-> ModuleTranslation {
1138+
// FIXME(#40304): Instead of this, the symbol-map should be an
1139+
// on-demand thing that we compute.
1140+
let AssertDepGraphSafe(symbol_map) = symbol_map;
11501141

1151-
fn trans_decl_task<'a, 'tcx>(ccx: CrateContext<'a, 'tcx>,
1152-
symbol_map: AssertDepGraphSafe<Rc<SymbolMap<'tcx>>>) {
1142+
let source = if let Some(buf) = ccx.previous_work_product() {
1143+
// Don't need to translate this module.
1144+
ModuleSource::Preexisting(buf.clone())
1145+
} else {
11531146
// Instantiate translation items without filling out definitions yet...
11541147

1155-
// FIXME(#40304): Instead of this, the symbol-map should be an
1156-
// on-demand thing that we compute.
1157-
let AssertDepGraphSafe(symbol_map) = symbol_map;
11581148
let cgu = ccx.codegen_unit();
11591149
let trans_items = cgu.items_in_deterministic_order(ccx.tcx(), &symbol_map);
11601150
for &(trans_item, linkage) in &trans_items {
@@ -1200,6 +1190,19 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12001190
if ccx.sess().opts.debuginfo != NoDebugInfo {
12011191
debuginfo::finalize(&ccx);
12021192
}
1193+
1194+
ModuleSource::Translated(ModuleLlvm {
1195+
llcx: ccx.llcx(),
1196+
llmod: ccx.llmod(),
1197+
})
1198+
};
1199+
1200+
ModuleTranslation {
1201+
name: String::from(ccx.codegen_unit().name()),
1202+
symbol_name_hash: ccx.codegen_unit()
1203+
.compute_symbol_name_hash(ccx.shared(),
1204+
&symbol_map),
1205+
source: source,
12031206
}
12041207
}
12051208

0 commit comments

Comments
 (0)