mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00
Re-introduce FnBox
This commit is contained in:
parent
85ce626865
commit
1db38c0dfc
@ -44,53 +44,16 @@ index f6dee7c..0c6a8c0 100644
|
|||||||
#[unstable(feature = "coerce_unsized", issue = "27732")]
|
#[unstable(feature = "coerce_unsized", issue = "27732")]
|
||||||
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}
|
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}
|
||||||
|
|
||||||
diff --git a/src/libstd/sys_common/at_exit_imp.rs b/src/libstd/sys_common/at_exit_imp.rs
|
|
||||||
index 1181b86..20f9251 100644
|
|
||||||
--- a/src/libstd/sys_common/at_exit_imp.rs
|
|
||||||
+++ b/src/libstd/sys_common/at_exit_imp.rs
|
|
||||||
@@ -38,6 +38,7 @@ unsafe fn init() -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
+/*
|
|
||||||
pub fn cleanup() {
|
|
||||||
for i in 1..=ITERS {
|
|
||||||
unsafe {
|
|
||||||
@@ -60,6 +61,7 @@ pub fn cleanup() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+*/
|
|
||||||
|
|
||||||
pub fn push(f: Box<dyn FnOnce()>) -> bool {
|
|
||||||
unsafe {
|
|
||||||
diff --git a/src/libstd/sys_common/mod.rs b/src/libstd/sys_common/mod.rs
|
|
||||||
index 6260c3b..611ed7e 100644
|
|
||||||
--- a/src/libstd/sys_common/mod.rs
|
|
||||||
+++ b/src/libstd/sys_common/mod.rs
|
|
||||||
@@ -127,7 +127,6 @@ pub fn cleanup() {
|
|
||||||
CLEANUP.call_once(|| unsafe {
|
|
||||||
sys::args::cleanup();
|
|
||||||
sys::stack_overflow::cleanup();
|
|
||||||
- at_exit_imp::cleanup();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
diff --git a/src/libstd/sys_common/thread.rs b/src/libstd/sys_common/thread.rs
|
diff --git a/src/libstd/sys_common/thread.rs b/src/libstd/sys_common/thread.rs
|
||||||
index b2142e7..718bb1c 100644
|
index b2142e7..718bb1c 100644
|
||||||
--- a/src/libstd/sys_common/thread.rs
|
--- a/src/libstd/sys_common/thread.rs
|
||||||
+++ b/src/libstd/sys_common/thread.rs
|
+++ b/src/libstd/sys_common/thread.rs
|
||||||
@@ -6,12 +6,7 @@ use crate::sys::thread as imp;
|
@@ -6,7 +6,7 @@ pub unsafe fn start_thread(main: *mut u8) {
|
||||||
|
let _handler = stack_overflow::Handler::new();
|
||||||
|
|
||||||
#[allow(dead_code)]
|
// Finally, let's run some code.
|
||||||
pub unsafe fn start_thread(main: *mut u8) {
|
|
||||||
- // Next, set up our stack overflow handler which may get triggered if we run
|
|
||||||
- // out of stack.
|
|
||||||
- let _handler = stack_overflow::Handler::new();
|
|
||||||
-
|
|
||||||
- // Finally, let's run some code.
|
|
||||||
- Box::from_raw(main as *mut Box<dyn FnOnce()>)()
|
- Box::from_raw(main as *mut Box<dyn FnOnce()>)()
|
||||||
+ panic!("Threads are not yet supported, because cranelift doesn't support atomics.");
|
+ Box::from_raw(main as *mut Box<dyn FnBox()>)()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn min_stack() -> usize {
|
pub fn min_stack() -> usize {
|
||||||
@ -101,7 +64,7 @@ index f4a1783..362b537 100644
|
|||||||
@@ -40,5 +40,7 @@ impl Thread {
|
@@ -40,5 +40,7 @@ impl Thread {
|
||||||
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
|
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
|
||||||
pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
|
pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
|
||||||
+ panic!("Threads are not yet supported, because cranelift doesn't support atomics.");
|
+ panic!("Warning: Threads are not yet fully supported, because cranelift doesn't support atomics.");
|
||||||
+
|
+
|
||||||
let p = box p;
|
let p = box p;
|
||||||
let mut native: libc::pthread_t = mem::zeroed();
|
let mut native: libc::pthread_t = mem::zeroed();
|
||||||
|
173
patches/0018-Add-FnBox-back.patch
Normal file
173
patches/0018-Add-FnBox-back.patch
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
From 8617310c3c9e192080df6a0c7b4835d3f02e27b9 Mon Sep 17 00:00:00 2001
|
||||||
|
From: bjorn3 <bjorn3@users.noreply.github.com>
|
||||||
|
Date: Fri, 1 Nov 2019 20:58:30 +0100
|
||||||
|
Subject: [PATCH] Add FnBox back
|
||||||
|
|
||||||
|
---
|
||||||
|
src/liballoc/boxed.rs | 13 +++++++++++++
|
||||||
|
src/libstd/prelude/v1.rs | 2 +-
|
||||||
|
src/libstd/sys/cloudabi/thread.rs | 2 +-
|
||||||
|
src/libstd/sys/hermit/thread.rs | 4 ++--
|
||||||
|
src/libstd/sys/unix/thread.rs | 4 ++--
|
||||||
|
src/libstd/sys_common/at_exit_imp.rs | 6 +++---
|
||||||
|
src/libstd/sys_common/mod.rs | 2 +-
|
||||||
|
src/libstd/sys_common/thread.rs | 2 +-
|
||||||
|
src/libstd/thread/mod.rs | 2 +-
|
||||||
|
9 files changed, 25 insertions(+), 12 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs
|
||||||
|
index ef9b648..e32b870 100644
|
||||||
|
--- a/src/liballoc/boxed.rs
|
||||||
|
+++ b/src/liballoc/boxed.rs
|
||||||
|
@@ -1079,3 +1079,16 @@ impl<F: ?Sized + Future + Unpin> Future for Box<F> {
|
||||||
|
F::poll(Pin::new(&mut *self), cx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
+pub trait FnBox<A>: FnOnce<A> {
|
||||||
|
+ #[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
+ extern "rust-call" fn call_box(self: Box<Self>, args: A) -> Self::Output;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
+impl<A, F: FnOnce<A>> FnBox<A> for F {
|
||||||
|
+ extern "rust-call" fn call_box(self: Box<Self>, args: A) -> Self::Output {
|
||||||
|
+ <F as FnOnce<A>>::call_once(*self, args)
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
diff --git a/src/libstd/prelude/v1.rs b/src/libstd/prelude/v1.rs
|
||||||
|
index 3e4cf91..1f50eb3 100644
|
||||||
|
--- a/src/libstd/prelude/v1.rs
|
||||||
|
+++ b/src/libstd/prelude/v1.rs
|
||||||
|
@@ -94,6 +94,6 @@ pub use core::prelude::v1::{
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[doc(no_inline)]
|
||||||
|
-pub use crate::boxed::Box;
|
||||||
|
+pub use crate::boxed::{Box, FnBox};
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[doc(no_inline)]
|
||||||
|
pub use crate::string::{String, ToString};
|
||||||
|
diff --git a/src/libstd/sys/cloudabi/thread.rs b/src/libstd/sys/cloudabi/thread.rs
|
||||||
|
index 240b6ea..6f71c6b 100644
|
||||||
|
--- a/src/libstd/sys/cloudabi/thread.rs
|
||||||
|
+++ b/src/libstd/sys/cloudabi/thread.rs
|
||||||
|
@@ -21,7 +21,7 @@ unsafe impl Sync for Thread {}
|
||||||
|
|
||||||
|
impl Thread {
|
||||||
|
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
|
||||||
|
- pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
|
||||||
|
+ pub unsafe fn new(stack: usize, p: Box<dyn FnBox()>) -> io::Result<Thread> {
|
||||||
|
let p = box p;
|
||||||
|
let mut native: libc::pthread_t = mem::zeroed();
|
||||||
|
let mut attr: libc::pthread_attr_t = mem::zeroed();
|
||||||
|
diff --git a/src/libstd/sys/hermit/thread.rs b/src/libstd/sys/hermit/thread.rs
|
||||||
|
index 99a9c83..b8bc392 100644
|
||||||
|
--- a/src/libstd/sys/hermit/thread.rs
|
||||||
|
+++ b/src/libstd/sys/hermit/thread.rs
|
||||||
|
@@ -44,9 +44,9 @@ unsafe impl Sync for Thread {}
|
||||||
|
pub const DEFAULT_MIN_STACK_SIZE: usize = 262144;
|
||||||
|
|
||||||
|
impl Thread {
|
||||||
|
pub unsafe fn new_with_coreid(
|
||||||
|
_stack: usize,
|
||||||
|
- p: Box<dyn FnOnce()>,
|
||||||
|
+ p: Box<dyn FnBox()>,
|
||||||
|
core_id: isize,
|
||||||
|
) -> io::Result<Thread> {
|
||||||
|
let p = box p;
|
||||||
|
@@ -67,7 +67,7 @@ impl Thread {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
|
||||||
|
+ pub unsafe fn new(stack: usize, p: Box<dyn FnBox()>) -> io::Result<Thread> {
|
||||||
|
Thread::new_with_coreid(stack, p, -1 /* = no specific core */)
|
||||||
|
}
|
||||||
|
|
||||||
|
diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs
|
||||||
|
index 143cf2f..a6e8faf 100644
|
||||||
|
--- a/src/libstd/sys/unix/thread.rs
|
||||||
|
+++ b/src/libstd/sys/unix/thread.rs
|
||||||
|
@@ -38,8 +38,8 @@ unsafe fn pthread_attr_setstacksize(_attr: *mut libc::pthread_attr_t,
|
||||||
|
|
||||||
|
impl Thread {
|
||||||
|
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
|
||||||
|
- pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
|
||||||
|
+ pub unsafe fn new(stack: usize, p: Box<dyn FnBox()>) -> io::Result<Thread> {
|
||||||
|
panic!("Warning: Threads are not yet fully supported, because cranelift doesn't support atomics.");
|
||||||
|
|
||||||
|
let p = box p;
|
||||||
|
let mut native: libc::pthread_t = mem::zeroed();
|
||||||
|
diff --git a/src/libstd/sys_common/at_exit_imp.rs b/src/libstd/sys_common/at_exit_imp.rs
|
||||||
|
index cdb72ee..e523333 100644
|
||||||
|
--- a/src/libstd/sys_common/at_exit_imp.rs
|
||||||
|
+++ b/src/libstd/sys_common/at_exit_imp.rs
|
||||||
|
@@ -6,7 +6,7 @@ use crate::mem;
|
||||||
|
use crate::ptr;
|
||||||
|
use crate::sys_common::mutex::Mutex;
|
||||||
|
|
||||||
|
-type Queue = Vec<Box<dyn FnOnce()>>;
|
||||||
|
+type Queue = Vec<Box<dyn FnBox()>>;
|
||||||
|
|
||||||
|
// NB these are specifically not types from `std::sync` as they currently rely
|
||||||
|
// on poisoning and this module needs to operate at a lower level than requiring
|
||||||
|
@@ -53,14 +53,14 @@ pub fn cleanup() {
|
||||||
|
let queue: Box<Queue> = Box::from_raw(queue);
|
||||||
|
for to_run in *queue {
|
||||||
|
// We are not holding any lock, so reentrancy is fine.
|
||||||
|
- to_run();
|
||||||
|
+ to_run.call_box(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-pub fn push(f: Box<dyn FnOnce()>) -> bool {
|
||||||
|
+pub fn push(f: Box<dyn FnBox()>) -> bool {
|
||||||
|
unsafe {
|
||||||
|
let _guard = LOCK.lock();
|
||||||
|
if init() {
|
||||||
|
diff --git a/src/libstd/sys_common/mod.rs b/src/libstd/sys_common/mod.rs
|
||||||
|
index 7a0bcd0..668bef2 100644
|
||||||
|
--- a/src/libstd/sys_common/mod.rs
|
||||||
|
+++ b/src/libstd/sys_common/mod.rs
|
||||||
|
@@ -113,7 +113,7 @@ pub trait FromInner<Inner> {
|
||||||
|
/// closure will be run once the main thread exits. Returns `Err` to indicate
|
||||||
|
/// that the closure could not be registered, meaning that it is not scheduled
|
||||||
|
/// to be run.
|
||||||
|
-pub fn at_exit<F: FnOnce() + Send + 'static>(f: F) -> Result<(), ()> {
|
||||||
|
+pub fn at_exit<F: FnBox() + Send + 'static>(f: F) -> Result<(), ()> {
|
||||||
|
if at_exit_imp::push(Box::new(f)) { Ok(()) } else { Err(()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
diff --git a/src/libstd/sys_common/thread.rs b/src/libstd/sys_common/thread.rs
|
||||||
|
index c638be9..5c18a18 100644
|
||||||
|
--- a/src/libstd/sys_common/thread.rs
|
||||||
|
+++ b/src/libstd/sys_common/thread.rs
|
||||||
|
@@ -10,7 +10,7 @@ pub unsafe fn start_thread(main: *mut u8) {
|
||||||
|
let _handler = stack_overflow::Handler::new();
|
||||||
|
|
||||||
|
// Finally, let's run some code.
|
||||||
|
- Box::from_raw(main as *mut Box<dyn FnBox()>)()
|
||||||
|
+ Box::from_raw(main as *mut Box<dyn FnBox()>).call_box(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn min_stack() -> usize {
|
||||||
|
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs
|
||||||
|
index 0ffa6ac..4a3e3d6 100644
|
||||||
|
--- a/src/libstd/thread/mod.rs
|
||||||
|
+++ b/src/libstd/thread/mod.rs
|
||||||
|
@@ -485,7 +485,7 @@ impl Builder {
|
||||||
|
// returning.
|
||||||
|
native: Some(imp::Thread::new(
|
||||||
|
stack_size,
|
||||||
|
- mem::transmute::<Box<dyn FnOnce() + 'a>, Box<dyn FnOnce() + 'static>>(Box::new(
|
||||||
|
+ mem::transmute::<Box<dyn FnBox() + 'a>, Box<dyn FnBox() + 'static>>(Box::new(
|
||||||
|
main,
|
||||||
|
)),
|
||||||
|
)?),
|
||||||
|
--
|
||||||
|
2.20.1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user