-
Notifications
You must be signed in to change notification settings - Fork 506
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
join_slice() #402
Comments
One possibility would be to implement this as a |
We could return some sort of heterogeneous list |
Yes, well, the devil is in that detail. 🙂 A tuple is the closest thing I know to a heterogeneous list, and Rust can't deal with varying tuple lengths generically. (except through macros) And actually, this is a problem for the "slice of closures" too, that slices need a homogeneous type. At least in this case we could use trait objects and homogeneous return values, like:
If you have other ideas, please propose the actual function signature, as writing that out is a great way to figure out what's possible. |
I actually implemented such a macro: macro_rules! join {
( $( self . $lhs:ident = $rhs:expr ; )* ) => {
// Fork-join all of the expressions.
let join!( < $( $lhs , )* ) = join!( > $( $rhs , )* );
// And then assign them to self after they've all been computed.
$(
self.$lhs = $lhs;
)*
};
// Left hand side recursion to nest idents into tuple patterns like
// `(x, (y, (z, ...)))`.
( < ) => {
()
};
( < $x:ident , $( $xs:ident , )* ) => {
( $x , join!( < $( $xs , )* ) )
};
// Right hand side recursion to nest exprs into rayon fork-joins
// like:
//
// rayon::join(
// || x,
// || rayon::join(
// || y,
// || rayon::join(
// || z,
// || ...)))
( > ) => {
()
};
( > $x:expr , $( $xs:expr , )* ) => {
rayon::join( || $x , || join!( > $( $xs , )* ) )
}
} And then usage looks like: join!(
self.used_template_parameters = Some(immut_self.find_used_template_parameters());
self.cannot_derive_copy = Some(immut_self.compute_cannot_derive_copy());
self.has_type_param_in_array = Some(immut_self.compute_has_type_param_in_array());
self.have_vtable = Some(immut_self.compute_has_vtable());
self.cannot_derive_debug = immut_self.compute_cannot_derive_debug();
self.cannot_derive_hash = immut_self.compute_cannot_derive_hash();
self.cannot_derive_partialeq = immut_self.compute_cannot_derive_partialeq();
); Is this something you're interested in merging? If so, I can make a PR with sanity test coverage. (The macro as it is right now is a little specific to my needs at the time, eg assigning to |
Good job, I think that generalizing it would be a good idea to it can take any closure. Which I believe is an expr that we can just pipe into the join function |
@fitzgen Yes I'd like to see that PR! And I agree with @Nokel81 that it should take general I do realize that makes your |
Would it be possible to use a builder pattern to get something like this to work? Something like the following?
|
It would be nice if it was possible to directly create additional items on the "queue".
What I am proposing is a new function that takes a slice of closures (until varadic parameters are a thing) which will add all additional closures that won't be immediately completed onto the queue for work stealing.
p.s. if this is a thing that should be added I am good with giving it a crack
The text was updated successfully, but these errors were encountered: