Skip to content

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

Merged
merged 11 commits into from
Sep 22, 2017
Merged

Adds impls for more types in std #58

merged 11 commits into from
Sep 22, 2017

Conversation

remexre
Copy link

@remexre remexre commented Sep 12, 2017

primitives

{i,u}128 should be feature-gated behind a nightly 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

Does it make sense to make a custom singly-linked GcLinkedList type instead of or in addition to having Gc<LinkedList> be supported?

## std::ffi

There should probably be some directions with regards to FFI and GC; does e.g. CString::into_raw unroot?

std::path

std::result

@remexre remexre changed the title Adds impls for isize, (), bumps version. Adds impls for more types in std Sep 13, 2017
@remexre
Copy link
Author

remexre commented Sep 15, 2017

Rebased this for #57.

Copy link
Collaborator

@mystor mystor left a 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 {
Copy link
Collaborator

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?

Copy link
Author

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);
}

Copy link
Author

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?).

Copy link
Collaborator

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 {
Copy link
Collaborator

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?

Copy link
Author

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);
Copy link
Collaborator

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.

Copy link
Author

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?

Copy link
Author

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];
Copy link
Collaborator

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 {
() => {};
Copy link
Collaborator

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
Copy link
Collaborator

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...

@remexre
Copy link
Author

remexre commented Sep 15, 2017

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

@mystor
Copy link
Collaborator

mystor commented Sep 22, 2017

With CString::into_raw, it will be uncallable from a Gc<CString>, as you can't get ownership of the CString, so I don't think we have to worry about its interaction with rooting.

I don't think Gc-specific data structures like your GcLinkedList belong in this crate, but rather in a separate crate which depends on rust-gc. I'd prefer to keep only the core algorithm and standard library Trace implementations in rust-gc.

@remexre
Copy link
Author

remexre commented Sep 22, 2017

Okay, once the unit tests pass, is this good to merge?

Copy link
Collaborator

@mystor mystor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - Thanks :-)

@mystor mystor merged commit c4d5959 into Manishearth:master Sep 22, 2017
@mystor
Copy link
Collaborator

mystor commented Sep 22, 2017

Published as v0.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants