Skip to content

Commit 394f684

Browse files
committed
Rewrite WorkItem not to use proc().
1 parent d8e51ea commit 394f684

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/librustc_trans/back/write.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -842,18 +842,31 @@ pub fn run_passes(sess: &Session,
842842
//if sess.time_llvm_passes() { llvm::LLVMRustPrintPassTimings(); }
843843
}
844844

845-
type WorkItem = proc(&CodegenContext):Send;
845+
struct WorkItem {
846+
mtrans: ModuleTranslation,
847+
config: ModuleConfig,
848+
output_names: OutputFilenames,
849+
name_extra: String
850+
}
846851

847852
fn build_work_item(sess: &Session,
848853
mtrans: ModuleTranslation,
849854
config: ModuleConfig,
850855
output_names: OutputFilenames,
851-
name_extra: String) -> WorkItem {
856+
name_extra: String)
857+
-> WorkItem
858+
{
852859
let mut config = config;
853860
config.tm = create_target_machine(sess);
861+
WorkItem { mtrans: mtrans, config: config, output_names: output_names,
862+
name_extra: name_extra }
863+
}
854864

855-
proc(cgcx) unsafe {
856-
optimize_and_codegen(cgcx, mtrans, config, name_extra, output_names);
865+
fn execute_work_item(cgcx: &CodegenContext,
866+
work_item: WorkItem) {
867+
unsafe {
868+
optimize_and_codegen(cgcx, work_item.mtrans, work_item.config,
869+
work_item.name_extra, work_item.output_names);
857870
}
858871
}
859872

@@ -866,7 +879,7 @@ fn run_work_singlethreaded(sess: &Session,
866879
// Since we're running single-threaded, we can pass the session to
867880
// the proc, allowing `optimize_and_codegen` to perform LTO.
868881
for work in Unfold::new((), |_| work_items.pop()) {
869-
work(&cgcx);
882+
execute_work_item(&cgcx, work);
870883
}
871884
}
872885

@@ -883,7 +896,7 @@ fn run_work_multithreaded(sess: &Session,
883896
let diag_emitter = diag_emitter.clone();
884897
let remark = sess.opts.cg.remark.clone();
885898

886-
let future = TaskBuilder::new().named(format!("codegen-{}", i)).try_future(proc() {
899+
let future = TaskBuilder::new().named(format!("codegen-{}", i)).try_future(move |:| {
887900
let diag_handler = mk_handler(box diag_emitter);
888901

889902
// Must construct cgcx inside the proc because it has non-Send
@@ -899,7 +912,7 @@ fn run_work_multithreaded(sess: &Session,
899912
let maybe_work = work_items_arc.lock().pop();
900913
match maybe_work {
901914
Some(work) => {
902-
work(&cgcx);
915+
execute_work_item(&cgcx, work);
903916

904917
// Make sure to fail the worker so the main thread can
905918
// tell that there were errors.

0 commit comments

Comments
 (0)