orium / archery Goto Github PK
View Code? Open in Web Editor NEWAbstract over the atomicity of reference-counting pointers in rust
License: Mozilla Public License 2.0
Abstract over the atomicity of reference-counting pointers in rust
License: Mozilla Public License 2.0
Title pretty much sums it up: it would be nice to be able to #[derive(Serialize, Deserialize)]
on types containing SharedPointer
.
The following program should fail to compile, but it doesn't and crashes at runtime:
use std::cell::Cell;
type Arc<T> = archery::SharedPointer<T, archery::ArcK>;
fn main() {
let cell = Arc::new(Cell::new(None));
let jhs = [(); 2].map(|()| {
let cell = Arc::clone(&cell);
std::thread::spawn(move || loop {
// concurrent access of a `!Sync` cell from multiple threads
cell.take();
cell.set(Some(Box::new(42)));
})
});
for jh in jhs {
jh.join().unwrap();
}
}
$ cargo run --release --quiet
free(): unaligned chunk detected in tcache 2
fish: Job 1, 'cargo run --release' terminated by signal SIGABRT (Abort)
Thanks for your work on this crate!
Are there any plans to support Weak pointers?
Issue created for future reference.
This is a rustc issue in the way Clone
is derived.
The problem is that
#[derive(Clone)]
struct AThing<T, C: RcPointerKind> {
field: RcPointer<C, T>,
}
expands to
impl<T: Clone, C: Clone + RcPointerKind> Clone for AThing<T, C> { ... }
which requires C
to implement Clone
. In practice it should only require the type of AThing::field
to be implement Clone
. See rust-lang/rust#26925 (comment) for details.
I don't yet know enough to be able to determine whether this would break invariants that must be upheld.
Would it be possible & feasible to do this so that RcK
& ArcK
impl Clone
?
I have a type (Value
) and would like to derive/impl Clone
for it:
pub enum Value<P: archery::SharedPointerKind> {
Map(Map<P>),
}
#[derive(Debug, Clone)]
pub struct Map<P: SharedPointerKind>(pub(crate) RawMap<P>);
pub type RawMap<P> = rpds::HashTrieMap<Value<P>, Value<P>, P>;
To do so and actually make use of it like so, I have to add + Clone
to all of my P: archery::SharedPointerKind
s which results in an error because RcK
& ArcK
are not Clone
.
Thank you for the excellent library!
Running the tests with release currently fails, i.e.
cargo test --release
Part of the reason is that the compile-fail tests hardcode debug
into the path here:
Line 51 in 11bdf0a
However even when I fixed that path I still got weird failures. Perhaps we could slap a #![cfg(debug_assertions)]
on the compile-fail tests?
Looking at the API of StaticRc
and SharedPointerKind
I think it would be possible to add support for static-rc
behind a feature flag.
What do you think?
This won't compile under architecture that does not support atomic instructions such as riscv32imc-unknown-none-elf
. But on a higher level of thoughts this means the entire Arc/ArcK should be disabled
With alloc now available it'd be nice to use this crate in a no-std environment.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.