Skip to content

Commit dcc86d3

Browse files
committed
Emulate <Box<F> as FnOnce>::call_once without alloca
Fixes #884 cc #15
1 parent 240d56c commit dcc86d3

5 files changed

+97
-326
lines changed

patches/0015-Remove-usage-of-unsized-locals.patch

-73
This file was deleted.

patches/0017-Fix-libtest-compilation.patch

-68
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,6 @@ diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs
1111
index 8b76080..9e65de2 100644
1212
--- a/src/libtest/lib.rs
1313
+++ b/src/libtest/lib.rs
14-
@@ -52,7 +52,7 @@ use std::fmt;
15-
use std::{
16-
env, io,
17-
io::prelude::Write,
18-
- panic::{self, catch_unwind, AssertUnwindSafe, PanicInfo},
19-
+ panic::{self, PanicInfo},
20-
process::{self, Command, Termination},
21-
sync::mpsc::{channel, Sender},
22-
sync::{Arc, Mutex},
23-
@@ -1493,7 +1493,7 @@ pub fn run_test(
24-
fn run_test_inner(
25-
desc: TestDesc,
26-
monitor_ch: Sender<CompletedTest>,
27-
- testfn: Box<dyn FnOnce() + Send>,
28-
+ testfn: Box<impl FnOnce() + Send + 'static>,
29-
opts: TestRunOpts,
30-
) {
31-
let concurrency = opts.concurrency;
3214
@@ -1509,7 +1509,7 @@ pub fn run_test(
3315
// If the platform is single-threaded we're just going to run
3416
// the test synchronously, regardless of the concurrency
@@ -38,55 +20,5 @@ index 8b76080..9e65de2 100644
3820
if concurrency == Concurrent::Yes && supports_threads {
3921
let cfg = thread::Builder::new().name(name.as_slice().to_owned());
4022
cfg.spawn(runtest).unwrap();
41-
@@ -1531,17 +1531,8 @@ pub fn run_test(
42-
// Benchmarks aren't expected to panic, so we run them all in-process.
43-
crate::bench::benchmark(desc, monitor_ch, opts.nocapture, benchfn);
44-
}
45-
- DynTestFn(f) => {
46-
- match strategy {
47-
- RunStrategy::InProcess => (),
48-
- _ => panic!("Cannot run dynamic test fn out-of-process"),
49-
- };
50-
- run_test_inner(
51-
- desc,
52-
- monitor_ch,
53-
- Box::new(move || __rust_begin_short_backtrace(f)),
54-
- test_run_opts,
55-
- );
56-
+ DynTestFn(_f) => {
57-
+ unimplemented!();
58-
}
59-
StaticTestFn(f) => run_test_inner(
60-
desc,
61-
@@ -1604,10 +1592,10 @@ fn get_result_from_exit_code(desc: &TestDesc, code: i32) -> TestResult {
62-
fn run_test_in_process(
63-
desc: TestDesc,
64-
nocapture: bool,
65-
report_time: bool,
66-
- testfn: Box<dyn FnOnce() + Send>,
67-
+ testfn: Box<impl FnOnce() + Send + 'static>,
68-
monitor_ch: Sender<CompletedTest>,
69-
time_opts: Option<time::TestTimeOptions>,
70-
) {
71-
// Buffer for capturing standard I/O
72-
let data = Arc::new(Mutex::new(Vec::new()));
73-
@@ -1623,7 +1611,7 @@ fn run_test_in_process(desc: TestDesc,
74-
};
75-
76-
let start = report_time.then(Instant::now);
77-
- let result = catch_unwind(AssertUnwindSafe(testfn));
78-
+ let result = Ok::<(), Box<dyn std::any::Any + Send>>(testfn());
79-
let exec_time = start.map(|start| {
80-
let duration = start.elapsed();
81-
TestExecTime(duration)
82-
@@ -1688,7 +1676,7 @@ fn spawn_test_subprocess(desc: TestDesc, report_time: bool, monitor_ch: Sender<M
83-
monitor_ch.send(message).unwrap();
84-
}
85-
86-
-fn run_test_in_spawned_subprocess(desc: TestDesc, testfn: Box<dyn FnOnce() + Send>) -> ! {
87-
+fn run_test_in_spawned_subprocess(desc: TestDesc, testfn: Box<impl FnOnce() + Send + 'static>) -> ! {
88-
let builtin_panic_hook = panic::take_hook();
89-
let record_result = Arc::new(move |panic_info: Option<&'_ PanicInfo<'_>>| {
90-
let test_result = match panic_info {
9123
--
9224
2.20.1

patches/0018-Add-FnBox-back.patch

-174
This file was deleted.

src/abi/mod.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ fn local_place<'tcx>(
288288
fx.local_map[&local]
289289
}
290290

291-
pub fn codegen_fn_prelude(fx: &mut FunctionCx<'_, '_, impl Backend>, start_block: Block) {
291+
pub fn codegen_fn_prelude(fx: &mut FunctionCx<'_, '_, impl Backend>, start_block: Block, should_codegen_locals: bool) {
292292
let ssa_analyzed = crate::analyze::analyze(fx);
293293

294294
#[cfg(debug_assertions)]
@@ -405,13 +405,17 @@ pub fn codegen_fn_prelude(fx: &mut FunctionCx<'_, '_, impl Backend>, start_block
405405
}
406406
}
407407

408-
for local in fx.mir.vars_and_temps_iter() {
409-
let ty = fx.monomorphize(&fx.mir.local_decls[local].ty);
410-
let layout = fx.layout_of(ty);
408+
// HACK should_codegen_locals required for the ``implement `<Box<F> as FnOnce>::call_once`
409+
// without `alloca``` hack in `base::trans_fn`.
410+
if should_codegen_locals {
411+
for local in fx.mir.vars_and_temps_iter() {
412+
let ty = fx.monomorphize(&fx.mir.local_decls[local].ty);
413+
let layout = fx.layout_of(ty);
411414

412-
let is_ssa = ssa_analyzed[local] == crate::analyze::SsaKind::Ssa;
415+
let is_ssa = ssa_analyzed[local] == crate::analyze::SsaKind::Ssa;
413416

414-
local_place(fx, local, layout, is_ssa);
417+
local_place(fx, local, layout, is_ssa);
418+
}
415419
}
416420

417421
fx.bcx

0 commit comments

Comments
 (0)