Others / shredder

Garbage collected smart pointers for Rust
MIT License
266 stars 9 forks source link

Add missing value type `char` #68

Closed oovm closed 3 years ago

oovm commented 3 years ago

The primitive type char is obviously a value type.

oovm commented 3 years ago

By the way, I don't quite understand what value type specifically refers to.

  1. For example, is TypeId(u64) a value type?
  2. If a composite type is composed entirely of value types, should it automatically get Finalize?
Others commented 3 years ago

Regarding the value wording/macro in the code. This is basically shorthand for "rust primitive type", since they all have the same properties. (Being bags of bits, with no interior mutability or other special properties.) It's more of a shortcut macro I wrote to simplify the implementation.

Outside this crate it's easier to use the derive rather than these special purpose shortcuts. I'd love to be able to make structural traits for shredder (where X would automatically get implemented for structs with all fields being X), but that isn't currently possible in Rust stable AFAIK

oovm commented 3 years ago

About sync_value_type

Ok, this represents the primitive type, this macro should not be exported.

I was thinking about C# value types, -- the primitives and struct in C#.

I think we do need a ValueType trait to mark such types.

About sync_vec_like/sync_map_like

In fact, I also need this in my package.

I need to mark some third-party data structures with GC, eg: IndexMap, SmallVec.

(I cannot derive a structure in a third-party package)

I think this is necessary, but the name can indeed be changed.

oovm commented 3 years ago

Oh, forgot the second part, 😥😥😥.

The orphan rule also prohibits me from implementing third-party trait for third-party structures.

Others commented 3 years ago

I think we do need a ValueType Trait to mark such types.

This is an interesting idea, but if you play with this, you'll notice that the blanket impls get rejected due to trait coherence rules. See: https://rust-lang.github.io/chalk/book/clauses/coherence.html

I need to mark some third-party data structures with GC, eg: IndexMap, SmallVec.

This may not work how you want, Rust prevents you from writing impl A for B if you didn't own A or B in your crate. (See: the orphan rule.) This poses problems for all crates like shredder, since it makes it hard to be cross compatible with crates like SmallVec.

In your crate you can work around this by creating a struct that wraps SmallVec, but derefs to SmallVec as well. Also, for widely used crates like smallvec, I might be open to putting an impl in shredder behind a feature flag.

That being said, I'm not in principle opposed to making the macros public as long as unsafe is in the name

Others commented 3 years ago

Heh, you ninja'd my comment about the orphan rule