-
Notifications
You must be signed in to change notification settings - Fork 52
Adds impls for more types in std #58
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
Conversation
Rebased this for #57. |
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.
Thanks! Are you thinking of implementing the rest of the impls which you mention in your first comment in this PR or would you want to do it over a few PRs?
It looks good but I have a couple of silly comments I've added :-).
impl<K: Trace, V: Trace> Finalize for BTreeMap<K, V> {} | ||
unsafe impl<K: Trace, V: Trace> Trace for BTreeMap<K, V> { | ||
custom_trace!(this, { | ||
for (k, v) in this { |
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.
Why not just this.iter().map(mark)
? Shouldn't that work now due to the tuple implementations?
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.
Iterators are lazy, so I'd need to demand the value at some point; I felt a for-loop would be clearer.
Now that I do have the tuple impls, though, I'll change it to
for pair in this {
mark(pair);
}
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.
Ach, cancel that, there's lifetime issues (this
is borrowed, not owned?).
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.
fair, forgot about that - your original code is better.
gc/src/trace.rs
Outdated
} | ||
} | ||
|
||
macro_rules! table_based_finalize_trace { |
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.
Should this be tuple_based
?
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.
Changed to clarify; it's both tuples and functions, so I was like, "It's a table of types."
I'm renaming it to type_arg_tuple_based_finalized_trace_impls
, unless you think that's too long.
fn_finalize_trace_one!(extern "Rust" fn () -> Ret); | ||
fn_finalize_trace_one!(extern "C" fn () -> Ret); | ||
fn_finalize_trace_one!(unsafe extern "Rust" fn () -> Ret); | ||
fn_finalize_trace_one!(unsafe extern "C" fn () -> Ret); |
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 don't think unsafe extern "C" fn (...) -> Ret will get an impl with this macro.
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.
Why not? It's "just" a raw C function pointer, right?
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.
Oh, did you mean literally ...
in the sense of varargs? That appears not to be legal.
gc/src/trace.rs
Outdated
@@ -109,7 +113,71 @@ macro_rules! simple_empty_finalize_trace { | |||
} | |||
} | |||
|
|||
simple_empty_finalize_trace![usize, bool, i8, u8, i16, u16, i32, u32, i64, u64, f32, f64, String]; | |||
simple_empty_finalize_trace![(), isize, usize, bool, i8, u8, i16, u16, i32, u32, i64, u64, f32, f64, char, String, Path, PathBuf]; |
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.
Can you split this over multiple lines?
gc/src/trace.rs
Outdated
} | ||
|
||
macro_rules! tuple_finalize_trace { | ||
() => {}; |
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.
Perhaps add a comment noting that the impl for ()
is handled in the simple_finalize_empty_trace!
invocation above?
@@ -19,7 +19,7 @@ impl<T: ?Sized> Shared<T> { | |||
} | |||
|
|||
pub fn as_ptr(&self) -> *mut T { | |||
self.p.get() | |||
self.p |
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.
Oops - I pushed a separate fix for this...
I still have the questions I listed above for CString, OsString, and LinkedList; I've got a "friendlier" linked list implementation I'd be willing to contribute. Other than that, I'm going to get nightly set up again and check that u/i128 are working, and then I think it's done |
With I don't think |
Okay, once the unit tests pass, is this good to merge? |
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.
LGTM - Thanks :-)
Published as |
primitives
()
isize
char
i128
u128
{i,u}128
should be feature-gated behind anightly
feature.There should be a decision about what the largest tuple arity to support will be -- compiling the impls for each different length it can increase compile times a lot.
For reference,
std
provides trait impls for up to 31-item arrays and 12-tuples.std::collections
BTreeMap
BTreeSet
BinaryHeap
HashMap
HashSet
LinkedList
VecDeque
Does it make sense to make a custom singly-linked
GcLinkedList
type instead of or in addition to havingGc<LinkedList>
be supported?##std::ffi
CString
OsString
There should probably be some directions with regards to FFI and GC; does e.g.CString::into_raw
unroot?std::path
Path
PathBuf
std::result
Result