* [PATCH 0/2] rust: sync: Arc: Any downcasting and assume_init()
@ 2023-02-24 7:59 Asahi Lina
2023-02-24 7:59 ` [PATCH 1/2] rust: sync: arc: implement Arc<dyn Any + Send + Sync>::downcast() Asahi Lina
2023-02-24 7:59 ` [PATCH 2/2] rust: sync: arc: Add UniqueArc<MaybeUninit<T>::assume_init() Asahi Lina
0 siblings, 2 replies; 11+ messages in thread
From: Asahi Lina @ 2023-02-24 7:59 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
Gary Guo, Björn Roy Baron
Cc: rust-for-linux, linux-kernel, asahi, Asahi Lina
Hi everyone,
This short series is part of the set of dependencies for the drm/asahi
Apple M1/M2 GPU driver.
The two patches simply add two missing features to the kernel Arc
implementation which are present in the Rust std version: `Any`
downcasting and `assume_init()`.
Signed-off-by: Asahi Lina <lina@asahilina.net>
---
Asahi Lina (2):
rust: sync: arc: implement Arc<dyn Any + Send + Sync>::downcast()
rust: sync: arc: Add UniqueArc<MaybeUninit<T>::assume_init()
rust/kernel/sync/arc.rs | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
---
base-commit: 83f978b63fa7ad474ca22d7e2772c5988101c9bd
change-id: 20230224-rust-arc-ba3c26ed4e6a
Thank you,
~~ Lina
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/2] rust: sync: arc: implement Arc<dyn Any + Send + Sync>::downcast()
2023-02-24 7:59 [PATCH 0/2] rust: sync: Arc: Any downcasting and assume_init() Asahi Lina
@ 2023-02-24 7:59 ` Asahi Lina
2023-02-24 14:34 ` Martin Rodriguez Reboredo
` (3 more replies)
2023-02-24 7:59 ` [PATCH 2/2] rust: sync: arc: Add UniqueArc<MaybeUninit<T>::assume_init() Asahi Lina
1 sibling, 4 replies; 11+ messages in thread
From: Asahi Lina @ 2023-02-24 7:59 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
Gary Guo, Björn Roy Baron
Cc: rust-for-linux, linux-kernel, asahi, Asahi Lina
This mirrors the standard library's alloc::sync::Arc::downcast().
Based on the Rust standard library implementation, ver 1.62.0,
licensed under "Apache-2.0 OR MIT", from:
https://github.com/rust-lang/rust/tree/1.62.0/library/alloc/src
For copyright details, please see:
https://github.com/rust-lang/rust/blob/1.62.0/COPYRIGHT
Signed-off-by: Asahi Lina <lina@asahilina.net>
---
rust/kernel/sync/arc.rs | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
index a94e303217c6..752bd7c4699e 100644
--- a/rust/kernel/sync/arc.rs
+++ b/rust/kernel/sync/arc.rs
@@ -22,6 +22,7 @@ use crate::{
};
use alloc::boxed::Box;
use core::{
+ any::Any,
fmt,
marker::{PhantomData, Unsize},
mem::{ManuallyDrop, MaybeUninit},
@@ -220,6 +221,27 @@ impl<T: 'static> ForeignOwnable for Arc<T> {
}
}
+impl Arc<dyn Any + Send + Sync> {
+ /// Attempt to downcast the `Arc<dyn Any + Send + Sync>` to a concrete type.
+ // Based on the Rust standard library implementation, ver 1.62.0, which is
+ // Apache-2.0 OR MIT.
+ pub fn downcast<T>(self) -> core::result::Result<Arc<T>, Self>
+ where
+ T: Any + Send + Sync,
+ {
+ if (*self).is::<T>() {
+ // SAFETY: We have just checked that the type is correct, so we can cast the pointer.
+ unsafe {
+ let ptr = self.ptr.cast::<ArcInner<T>>();
+ core::mem::forget(self);
+ Ok(Arc::from_inner(ptr))
+ }
+ } else {
+ Err(self)
+ }
+ }
+}
+
impl<T: ?Sized> Deref for Arc<T> {
type Target = T;
--
2.35.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/2] rust: sync: arc: Add UniqueArc<MaybeUninit<T>::assume_init()
2023-02-24 7:59 [PATCH 0/2] rust: sync: Arc: Any downcasting and assume_init() Asahi Lina
2023-02-24 7:59 ` [PATCH 1/2] rust: sync: arc: implement Arc<dyn Any + Send + Sync>::downcast() Asahi Lina
@ 2023-02-24 7:59 ` Asahi Lina
2023-02-24 14:37 ` Martin Rodriguez Reboredo
` (3 more replies)
1 sibling, 4 replies; 11+ messages in thread
From: Asahi Lina @ 2023-02-24 7:59 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
Gary Guo, Björn Roy Baron
Cc: rust-for-linux, linux-kernel, asahi, Asahi Lina
We can already create `UniqueArc<MaybeUninit<T>>` instances with
`UniqueArc::try_new_uninit()` and write to them with `write()`. Add
the missing unsafe `assume_init()` function to promote it to
`UniqueArc<T>`, so users can do piece-wise initialization of the
contents instead of doing it all at once as long as they keep the
invariants (the same requirements as `MaybeUninit::assume_init()`).
This mirrors the std `Arc::assume_init()` function. In the kernel,
since we have `UniqueArc`, arguably this only belongs there since most
use cases will initialize it immediately after creating it, before
demoting it to `Arc` to share it.
Signed-off-by: Asahi Lina <lina@asahilina.net>
---
rust/kernel/sync/arc.rs | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
index 752bd7c4699e..b8e9477fe865 100644
--- a/rust/kernel/sync/arc.rs
+++ b/rust/kernel/sync/arc.rs
@@ -512,6 +512,15 @@ impl<T> UniqueArc<MaybeUninit<T>> {
/// Converts a `UniqueArc<MaybeUninit<T>>` into a `UniqueArc<T>` by writing a value into it.
pub fn write(mut self, value: T) -> UniqueArc<T> {
self.deref_mut().write(value);
+ // SAFETY: We have just written the contents fully.
+ unsafe { self.assume_init() }
+ }
+
+ /// Returns a UniqueArc<T>, assuming the MaybeUninit<T> has already been initialized.
+ ///
+ /// # Safety
+ /// The contents of the UniqueArc must have already been fully initialized.
+ pub unsafe fn assume_init(self) -> UniqueArc<T> {
let inner = ManuallyDrop::new(self).inner.ptr;
UniqueArc {
// SAFETY: The new `Arc` is taking over `ptr` from `self.inner` (which won't be
--
2.35.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] rust: sync: arc: implement Arc<dyn Any + Send + Sync>::downcast()
2023-02-24 7:59 ` [PATCH 1/2] rust: sync: arc: implement Arc<dyn Any + Send + Sync>::downcast() Asahi Lina
@ 2023-02-24 14:34 ` Martin Rodriguez Reboredo
2023-02-25 0:43 ` Gary Guo
` (2 subsequent siblings)
3 siblings, 0 replies; 11+ messages in thread
From: Martin Rodriguez Reboredo @ 2023-02-24 14:34 UTC (permalink / raw)
To: lina
Cc: alex.gaynor, asahi, bjorn3_gh, boqun.feng, gary, linux-kernel,
ojeda, rust-for-linux, wedsonaf
On Fri, Feb 24, 2023 at 05:09:47PM +0900, Asahi Lina wrote:
> This mirrors the standard library's alloc::sync::Arc::downcast().
>
> Based on the Rust standard library implementation, ver 1.62.0,
> licensed under "Apache-2.0 OR MIT", from:
>
> https://github.com/rust-lang/rust/tree/1.62.0/library/alloc/src
>
> For copyright details, please see:
>
> https://github.com/rust-lang/rust/blob/1.62.0/COPYRIGHT
>
> Signed-off-by: Asahi Lina <lina@asahilina.net>
> ---
> rust/kernel/sync/arc.rs | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
>
> diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
> index a94e303217c6..752bd7c4699e 100644
> --- a/rust/kernel/sync/arc.rs
> +++ b/rust/kernel/sync/arc.rs
> @@ -22,6 +22,7 @@ use crate::{
> };
> use alloc::boxed::Box;
> use core::{
> + any::Any,
> fmt,
> marker::{PhantomData, Unsize},
> mem::{ManuallyDrop, MaybeUninit},
> @@ -220,6 +221,27 @@ impl<T: 'static> ForeignOwnable for Arc<T> {
> }
> }
>
> +impl Arc<dyn Any + Send + Sync> {
> + /// Attempt to downcast the `Arc<dyn Any + Send + Sync>` to a concrete type.
> + // Based on the Rust standard library implementation, ver 1.62.0, which is
> + // Apache-2.0 OR MIT.
> + pub fn downcast<T>(self) -> core::result::Result<Arc<T>, Self>
> + where
> + T: Any + Send + Sync,
> + {
> + if (*self).is::<T>() {
> + // SAFETY: We have just checked that the type is correct, so we can cast the pointer.
> + unsafe {
> + let ptr = self.ptr.cast::<ArcInner<T>>();
> + core::mem::forget(self);
I see, we cast the inner pointer of the `Arc` to the target type which
is wrapped in an `ArcInner` that is then used for another `Arc`. This is
important as this new value now owns the pointer and, by consequence,
it is safe to forget the passed `Arc` as it won't leak the pointer.
Thus, this method is safe.
> + Ok(Arc::from_inner(ptr))
> + }
> + } else {
> + Err(self)
> + }
> + }
> +}
> +
> impl<T: ?Sized> Deref for Arc<T> {
> type Target = T;
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] rust: sync: arc: Add UniqueArc<MaybeUninit<T>::assume_init()
2023-02-24 7:59 ` [PATCH 2/2] rust: sync: arc: Add UniqueArc<MaybeUninit<T>::assume_init() Asahi Lina
@ 2023-02-24 14:37 ` Martin Rodriguez Reboredo
2023-02-25 0:41 ` Gary Guo
` (2 subsequent siblings)
3 siblings, 0 replies; 11+ messages in thread
From: Martin Rodriguez Reboredo @ 2023-02-24 14:37 UTC (permalink / raw)
To: lina
Cc: alex.gaynor, asahi, bjorn3_gh, boqun.feng, gary, linux-kernel,
ojeda, rust-for-linux, wedsonaf
On Fri, Feb 24, 2023 at 04:59:34PM +0900, Asahi Lina wrote:
> We can already create `UniqueArc<MaybeUninit<T>>` instances with
> `UniqueArc::try_new_uninit()` and write to them with `write()`. Add
> the missing unsafe `assume_init()` function to promote it to
> `UniqueArc<T>`, so users can do piece-wise initialization of the
> contents instead of doing it all at once as long as they keep the
> invariants (the same requirements as `MaybeUninit::assume_init()`).
>
> This mirrors the std `Arc::assume_init()` function. In the kernel,
> since we have `UniqueArc`, arguably this only belongs there since most
> use cases will initialize it immediately after creating it, before
> demoting it to `Arc` to share it.
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] rust: sync: arc: Add UniqueArc<MaybeUninit<T>::assume_init()
2023-02-24 7:59 ` [PATCH 2/2] rust: sync: arc: Add UniqueArc<MaybeUninit<T>::assume_init() Asahi Lina
2023-02-24 14:37 ` Martin Rodriguez Reboredo
@ 2023-02-25 0:41 ` Gary Guo
2023-02-27 11:48 ` Andreas Hindborg
2023-03-01 17:23 ` Vincenzo Palazzo
3 siblings, 0 replies; 11+ messages in thread
From: Gary Guo @ 2023-02-25 0:41 UTC (permalink / raw)
To: Asahi Lina
Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
Björn Roy Baron, rust-for-linux, linux-kernel, asahi
On Fri, 24 Feb 2023 16:59:34 +0900
Asahi Lina <lina@asahilina.net> wrote:
> We can already create `UniqueArc<MaybeUninit<T>>` instances with
> `UniqueArc::try_new_uninit()` and write to them with `write()`. Add
> the missing unsafe `assume_init()` function to promote it to
> `UniqueArc<T>`, so users can do piece-wise initialization of the
> contents instead of doing it all at once as long as they keep the
> invariants (the same requirements as `MaybeUninit::assume_init()`).
>
> This mirrors the std `Arc::assume_init()` function. In the kernel,
> since we have `UniqueArc`, arguably this only belongs there since most
> use cases will initialize it immediately after creating it, before
> demoting it to `Arc` to share it.
>
> Signed-off-by: Asahi Lina <lina@asahilina.net>
> ---
> rust/kernel/sync/arc.rs | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
> index 752bd7c4699e..b8e9477fe865 100644
> --- a/rust/kernel/sync/arc.rs
> +++ b/rust/kernel/sync/arc.rs
> @@ -512,6 +512,15 @@ impl<T> UniqueArc<MaybeUninit<T>> {
> /// Converts a `UniqueArc<MaybeUninit<T>>` into a `UniqueArc<T>` by writing a value into it.
> pub fn write(mut self, value: T) -> UniqueArc<T> {
> self.deref_mut().write(value);
> + // SAFETY: We have just written the contents fully.
> + unsafe { self.assume_init() }
> + }
> +
> + /// Returns a UniqueArc<T>, assuming the MaybeUninit<T> has already been initialized.
> + ///
> + /// # Safety
> + /// The contents of the UniqueArc must have already been fully initialized.
The types in doc comments should be surrounded by backticks.
Best,
Gary
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] rust: sync: arc: implement Arc<dyn Any + Send + Sync>::downcast()
2023-02-24 7:59 ` [PATCH 1/2] rust: sync: arc: implement Arc<dyn Any + Send + Sync>::downcast() Asahi Lina
2023-02-24 14:34 ` Martin Rodriguez Reboredo
@ 2023-02-25 0:43 ` Gary Guo
2023-02-27 11:46 ` Andreas Hindborg
2023-03-01 17:22 ` Vincenzo Palazzo
3 siblings, 0 replies; 11+ messages in thread
From: Gary Guo @ 2023-02-25 0:43 UTC (permalink / raw)
To: Asahi Lina
Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
Björn Roy Baron, rust-for-linux, linux-kernel, asahi
On Fri, 24 Feb 2023 16:59:33 +0900
Asahi Lina <lina@asahilina.net> wrote:
> This mirrors the standard library's alloc::sync::Arc::downcast().
>
> Based on the Rust standard library implementation, ver 1.62.0,
> licensed under "Apache-2.0 OR MIT", from:
>
> https://github.com/rust-lang/rust/tree/1.62.0/library/alloc/src
>
> For copyright details, please see:
>
> https://github.com/rust-lang/rust/blob/1.62.0/COPYRIGHT
>
> Signed-off-by: Asahi Lina <lina@asahilina.net>
Reviewed-by: Gary Guo <gary@garyguo.net>
> ---
> rust/kernel/sync/arc.rs | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
>
> diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
> index a94e303217c6..752bd7c4699e 100644
> --- a/rust/kernel/sync/arc.rs
> +++ b/rust/kernel/sync/arc.rs
> @@ -22,6 +22,7 @@ use crate::{
> };
> use alloc::boxed::Box;
> use core::{
> + any::Any,
> fmt,
> marker::{PhantomData, Unsize},
> mem::{ManuallyDrop, MaybeUninit},
> @@ -220,6 +221,27 @@ impl<T: 'static> ForeignOwnable for Arc<T> {
> }
> }
>
> +impl Arc<dyn Any + Send + Sync> {
> + /// Attempt to downcast the `Arc<dyn Any + Send + Sync>` to a concrete type.
> + // Based on the Rust standard library implementation, ver 1.62.0, which is
> + // Apache-2.0 OR MIT.
> + pub fn downcast<T>(self) -> core::result::Result<Arc<T>, Self>
> + where
> + T: Any + Send + Sync,
> + {
> + if (*self).is::<T>() {
> + // SAFETY: We have just checked that the type is correct, so we can cast the pointer.
> + unsafe {
> + let ptr = self.ptr.cast::<ArcInner<T>>();
> + core::mem::forget(self);
> + Ok(Arc::from_inner(ptr))
> + }
> + } else {
> + Err(self)
> + }
> + }
> +}
> +
> impl<T: ?Sized> Deref for Arc<T> {
> type Target = T;
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] rust: sync: arc: implement Arc<dyn Any + Send + Sync>::downcast()
2023-02-24 7:59 ` [PATCH 1/2] rust: sync: arc: implement Arc<dyn Any + Send + Sync>::downcast() Asahi Lina
2023-02-24 14:34 ` Martin Rodriguez Reboredo
2023-02-25 0:43 ` Gary Guo
@ 2023-02-27 11:46 ` Andreas Hindborg
2023-03-01 17:22 ` Vincenzo Palazzo
3 siblings, 0 replies; 11+ messages in thread
From: Andreas Hindborg @ 2023-02-27 11:46 UTC (permalink / raw)
To: Asahi Lina
Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
Gary Guo, Björn Roy Baron, rust-for-linux, linux-kernel,
asahi
Asahi Lina <lina@asahilina.net> writes:
> This mirrors the standard library's alloc::sync::Arc::downcast().
>
> Based on the Rust standard library implementation, ver 1.62.0,
> licensed under "Apache-2.0 OR MIT", from:
>
> https://github.com/rust-lang/rust/tree/1.62.0/library/alloc/src
>
> For copyright details, please see:
>
> https://github.com/rust-lang/rust/blob/1.62.0/COPYRIGHT
>
> Signed-off-by: Asahi Lina <lina@asahilina.net>
> ---
Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com>
> rust/kernel/sync/arc.rs | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
>
> diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
> index a94e303217c6..752bd7c4699e 100644
> --- a/rust/kernel/sync/arc.rs
> +++ b/rust/kernel/sync/arc.rs
> @@ -22,6 +22,7 @@ use crate::{
> };
> use alloc::boxed::Box;
> use core::{
> + any::Any,
> fmt,
> marker::{PhantomData, Unsize},
> mem::{ManuallyDrop, MaybeUninit},
> @@ -220,6 +221,27 @@ impl<T: 'static> ForeignOwnable for Arc<T> {
> }
> }
>
> +impl Arc<dyn Any + Send + Sync> {
> + /// Attempt to downcast the `Arc<dyn Any + Send + Sync>` to a concrete type.
> + // Based on the Rust standard library implementation, ver 1.62.0, which is
> + // Apache-2.0 OR MIT.
> + pub fn downcast<T>(self) -> core::result::Result<Arc<T>, Self>
> + where
> + T: Any + Send + Sync,
> + {
> + if (*self).is::<T>() {
> + // SAFETY: We have just checked that the type is correct, so we can cast the pointer.
> + unsafe {
> + let ptr = self.ptr.cast::<ArcInner<T>>();
> + core::mem::forget(self);
> + Ok(Arc::from_inner(ptr))
> + }
> + } else {
> + Err(self)
> + }
> + }
> +}
> +
> impl<T: ?Sized> Deref for Arc<T> {
> type Target = T;
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] rust: sync: arc: Add UniqueArc<MaybeUninit<T>::assume_init()
2023-02-24 7:59 ` [PATCH 2/2] rust: sync: arc: Add UniqueArc<MaybeUninit<T>::assume_init() Asahi Lina
2023-02-24 14:37 ` Martin Rodriguez Reboredo
2023-02-25 0:41 ` Gary Guo
@ 2023-02-27 11:48 ` Andreas Hindborg
2023-03-01 17:23 ` Vincenzo Palazzo
3 siblings, 0 replies; 11+ messages in thread
From: Andreas Hindborg @ 2023-02-27 11:48 UTC (permalink / raw)
To: Asahi Lina
Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
Gary Guo, Björn Roy Baron, rust-for-linux, linux-kernel,
asahi
Asahi Lina <lina@asahilina.net> writes:
> We can already create `UniqueArc<MaybeUninit<T>>` instances with
> `UniqueArc::try_new_uninit()` and write to them with `write()`. Add
> the missing unsafe `assume_init()` function to promote it to
> `UniqueArc<T>`, so users can do piece-wise initialization of the
> contents instead of doing it all at once as long as they keep the
> invariants (the same requirements as `MaybeUninit::assume_init()`).
>
> This mirrors the std `Arc::assume_init()` function. In the kernel,
> since we have `UniqueArc`, arguably this only belongs there since most
> use cases will initialize it immediately after creating it, before
> demoting it to `Arc` to share it.
>
> Signed-off-by: Asahi Lina <lina@asahilina.net>
> ---
Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com>
> rust/kernel/sync/arc.rs | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
> index 752bd7c4699e..b8e9477fe865 100644
> --- a/rust/kernel/sync/arc.rs
> +++ b/rust/kernel/sync/arc.rs
> @@ -512,6 +512,15 @@ impl<T> UniqueArc<MaybeUninit<T>> {
> /// Converts a `UniqueArc<MaybeUninit<T>>` into a `UniqueArc<T>` by writing a value into it.
> pub fn write(mut self, value: T) -> UniqueArc<T> {
> self.deref_mut().write(value);
> + // SAFETY: We have just written the contents fully.
> + unsafe { self.assume_init() }
> + }
> +
> + /// Returns a UniqueArc<T>, assuming the MaybeUninit<T> has already been initialized.
> + ///
> + /// # Safety
> + /// The contents of the UniqueArc must have already been fully initialized.
> + pub unsafe fn assume_init(self) -> UniqueArc<T> {
> let inner = ManuallyDrop::new(self).inner.ptr;
> UniqueArc {
> // SAFETY: The new `Arc` is taking over `ptr` from `self.inner` (which won't be
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] rust: sync: arc: implement Arc<dyn Any + Send + Sync>::downcast()
2023-02-24 7:59 ` [PATCH 1/2] rust: sync: arc: implement Arc<dyn Any + Send + Sync>::downcast() Asahi Lina
` (2 preceding siblings ...)
2023-02-27 11:46 ` Andreas Hindborg
@ 2023-03-01 17:22 ` Vincenzo Palazzo
3 siblings, 0 replies; 11+ messages in thread
From: Vincenzo Palazzo @ 2023-03-01 17:22 UTC (permalink / raw)
To: Asahi Lina, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho,
Boqun Feng, Gary Guo, Björn Roy Baron
Cc: rust-for-linux, linux-kernel, asahi
> This mirrors the standard library's alloc::sync::Arc::downcast().
>
> Based on the Rust standard library implementation, ver 1.62.0,
> licensed under "Apache-2.0 OR MIT", from:
>
> https://github.com/rust-lang/rust/tree/1.62.0/library/alloc/src
>
> For copyright details, please see:
>
> https://github.com/rust-lang/rust/blob/1.62.0/COPYRIGHT
>
> Signed-off-by: Asahi Lina <lina@asahilina.net>
> ---
Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] rust: sync: arc: Add UniqueArc<MaybeUninit<T>::assume_init()
2023-02-24 7:59 ` [PATCH 2/2] rust: sync: arc: Add UniqueArc<MaybeUninit<T>::assume_init() Asahi Lina
` (2 preceding siblings ...)
2023-02-27 11:48 ` Andreas Hindborg
@ 2023-03-01 17:23 ` Vincenzo Palazzo
3 siblings, 0 replies; 11+ messages in thread
From: Vincenzo Palazzo @ 2023-03-01 17:23 UTC (permalink / raw)
To: Asahi Lina, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho,
Boqun Feng, Gary Guo, Björn Roy Baron
Cc: rust-for-linux, linux-kernel, asahi
> We can already create `UniqueArc<MaybeUninit<T>>` instances with
> `UniqueArc::try_new_uninit()` and write to them with `write()`. Add
> the missing unsafe `assume_init()` function to promote it to
> `UniqueArc<T>`, so users can do piece-wise initialization of the
> contents instead of doing it all at once as long as they keep the
> invariants (the same requirements as `MaybeUninit::assume_init()`).
>
> This mirrors the std `Arc::assume_init()` function. In the kernel,
> since we have `UniqueArc`, arguably this only belongs there since most
> use cases will initialize it immediately after creating it, before
> demoting it to `Arc` to share it.
>
> Signed-off-by: Asahi Lina <lina@asahilina.net>
> ---
Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2023-03-01 17:23 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-24 7:59 [PATCH 0/2] rust: sync: Arc: Any downcasting and assume_init() Asahi Lina
2023-02-24 7:59 ` [PATCH 1/2] rust: sync: arc: implement Arc<dyn Any + Send + Sync>::downcast() Asahi Lina
2023-02-24 14:34 ` Martin Rodriguez Reboredo
2023-02-25 0:43 ` Gary Guo
2023-02-27 11:46 ` Andreas Hindborg
2023-03-01 17:22 ` Vincenzo Palazzo
2023-02-24 7:59 ` [PATCH 2/2] rust: sync: arc: Add UniqueArc<MaybeUninit<T>::assume_init() Asahi Lina
2023-02-24 14:37 ` Martin Rodriguez Reboredo
2023-02-25 0:41 ` Gary Guo
2023-02-27 11:48 ` Andreas Hindborg
2023-03-01 17:23 ` Vincenzo Palazzo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).