Skip to content

Commit

Permalink
Emulate <Box<F> as FnOnce>::call_once without alloca
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Mar 10, 2020
1 parent 240d56c commit dcc86d3
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 326 deletions.
73 changes: 0 additions & 73 deletions patches/0015-Remove-usage-of-unsized-locals.patch

This file was deleted.

68 changes: 0 additions & 68 deletions patches/0017-Fix-libtest-compilation.patch
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,6 @@ diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs
index 8b76080..9e65de2 100644
--- a/src/libtest/lib.rs
+++ b/src/libtest/lib.rs
@@ -52,7 +52,7 @@ use std::fmt;
use std::{
env, io,
io::prelude::Write,
- panic::{self, catch_unwind, AssertUnwindSafe, PanicInfo},
+ panic::{self, PanicInfo},
process::{self, Command, Termination},
sync::mpsc::{channel, Sender},
sync::{Arc, Mutex},
@@ -1493,7 +1493,7 @@ pub fn run_test(
fn run_test_inner(
desc: TestDesc,
monitor_ch: Sender<CompletedTest>,
- testfn: Box<dyn FnOnce() + Send>,
+ testfn: Box<impl FnOnce() + Send + 'static>,
opts: TestRunOpts,
) {
let concurrency = opts.concurrency;
@@ -1509,7 +1509,7 @@ pub fn run_test(
// If the platform is single-threaded we're just going to run
// the test synchronously, regardless of the concurrency
Expand All @@ -38,55 +20,5 @@ index 8b76080..9e65de2 100644
if concurrency == Concurrent::Yes && supports_threads {
let cfg = thread::Builder::new().name(name.as_slice().to_owned());
cfg.spawn(runtest).unwrap();
@@ -1531,17 +1531,8 @@ pub fn run_test(
// Benchmarks aren't expected to panic, so we run them all in-process.
crate::bench::benchmark(desc, monitor_ch, opts.nocapture, benchfn);
}
- DynTestFn(f) => {
- match strategy {
- RunStrategy::InProcess => (),
- _ => panic!("Cannot run dynamic test fn out-of-process"),
- };
- run_test_inner(
- desc,
- monitor_ch,
- Box::new(move || __rust_begin_short_backtrace(f)),
- test_run_opts,
- );
+ DynTestFn(_f) => {
+ unimplemented!();
}
StaticTestFn(f) => run_test_inner(
desc,
@@ -1604,10 +1592,10 @@ fn get_result_from_exit_code(desc: &TestDesc, code: i32) -> TestResult {
fn run_test_in_process(
desc: TestDesc,
nocapture: bool,
report_time: bool,
- testfn: Box<dyn FnOnce() + Send>,
+ testfn: Box<impl FnOnce() + Send + 'static>,
monitor_ch: Sender<CompletedTest>,
time_opts: Option<time::TestTimeOptions>,
) {
// Buffer for capturing standard I/O
let data = Arc::new(Mutex::new(Vec::new()));
@@ -1623,7 +1611,7 @@ fn run_test_in_process(desc: TestDesc,
};

let start = report_time.then(Instant::now);
- let result = catch_unwind(AssertUnwindSafe(testfn));
+ let result = Ok::<(), Box<dyn std::any::Any + Send>>(testfn());
let exec_time = start.map(|start| {
let duration = start.elapsed();
TestExecTime(duration)
@@ -1688,7 +1676,7 @@ fn spawn_test_subprocess(desc: TestDesc, report_time: bool, monitor_ch: Sender<M
monitor_ch.send(message).unwrap();
}

-fn run_test_in_spawned_subprocess(desc: TestDesc, testfn: Box<dyn FnOnce() + Send>) -> ! {
+fn run_test_in_spawned_subprocess(desc: TestDesc, testfn: Box<impl FnOnce() + Send + 'static>) -> ! {
let builtin_panic_hook = panic::take_hook();
let record_result = Arc::new(move |panic_info: Option<&'_ PanicInfo<'_>>| {
let test_result = match panic_info {
--
2.20.1
174 changes: 0 additions & 174 deletions patches/0018-Add-FnBox-back.patch

This file was deleted.

16 changes: 10 additions & 6 deletions src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fn local_place<'tcx>(
fx.local_map[&local]
}

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

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

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

let is_ssa = ssa_analyzed[local] == crate::analyze::SsaKind::Ssa;
let is_ssa = ssa_analyzed[local] == crate::analyze::SsaKind::Ssa;

local_place(fx, local, layout, is_ssa);
local_place(fx, local, layout, is_ssa);
}
}

fx.bcx
Expand Down
Loading

0 comments on commit dcc86d3

Please sign in to comment.