-
Notifications
You must be signed in to change notification settings - Fork 544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rust 1.74 #16416
base: dw/use-latest-master-proof-systems
Are you sure you want to change the base?
Rust 1.74 #16416
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
macro_rules! impl_caml_pointer { | ||
($name: ident => $typ: ty) => { | ||
#[derive(std::fmt::Debug, Clone, ::ocaml_gen::CustomType)] | ||
pub struct $name(pub ::std::rc::Rc<$typ>); | ||
pub struct $name(pub ::std::rc::Rc<std::cell::UnsafeCell<$typ>>); | ||
|
||
impl $name { | ||
extern "C" fn caml_pointer_finalize(v: ocaml::Raw) { | ||
|
@@ -32,15 +32,17 @@ macro_rules! impl_caml_pointer { | |
|
||
impl $name { | ||
pub fn create(x: $typ) -> $name { | ||
$name(::std::rc::Rc::new(x)) | ||
$name(::std::rc::Rc::new(std::cell::UnsafeCell::new(x))) | ||
} | ||
} | ||
|
||
impl ::std::ops::Deref for $name { | ||
type Target = $typ; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&*self.0 | ||
unsafe { | ||
martyall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
&*self.0.get() | ||
} | ||
} | ||
} | ||
|
||
|
@@ -49,16 +51,15 @@ macro_rules! impl_caml_pointer { | |
unsafe { | ||
// Wholely unsafe, Batman! | ||
// We would use [`get_mut_unchecked`] here, but it is nightly-only. | ||
// Instead, we get coerce our constant pointer to a mutable | ||
// pointer, in the knowledge that | ||
// Instead, we use UnsafeCell in the knowledge that | ||
// * all of our mutations called from OCaml are blocking, so | ||
// we won't have multiple live mutable references live | ||
// we won't have multiple live mutable references | ||
// simultaneously, and | ||
// * the underlying pointer is in the correct state to be | ||
// mutable, since we can call [`get_mut_unchecked`] in | ||
// nightly, or can call [`get_mut`] and unwrap if this is | ||
// the only live reference. | ||
&mut *(((&*self.0) as *const Self::Target) as *mut Self::Target) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
&mut *self.0.get() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: implementation of
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This makes me think someone was trying to get around using |
||
} | ||
} | ||
} | ||
|
+1 −1 | .github/workflows/benches.yml | |
+1 −1 | .github/workflows/ci.yml | |
+0 −1 | rust-toolchain | |
+3 −0 | rust-toolchain.toml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note as it is important for the Caml binding: UnsafeCell is implemented as:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we're adding a new indirection? We might lose some performances?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nightly tests were passing with this change, does this mean that that the ocaml bindings lib was able to resolve this on its own or is it just coincidence because maybe the runtime rep is the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intuition is that this
UnsafeCell
should be optimized away. We can discuss