-
Notifications
You must be signed in to change notification settings - Fork 77
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
Small fixes and improvements before next release #61
Conversation
…rrayIter` Send/Sync.
I just noticed this here: rust-lang/rust#49000, and I think we should model I'll go ahead and push that to this pull request, since it doesn't actually change that much, just a few ergonomics. |
FWIW, I didn't really borrow from |
That’s fair. This crate is MIT licensed anyway, so I wasn’t judging. EDIT: I see now you're the original author of While you’re here, there is a significant problem with both yours and this crates consuming iterators, and that is it is impossible for Rust to fully optimize them. You can look through #57 for my previous work on it, but I’ve spent a lot of time trying to get Rust/LLVM to auto-vectorize certain operations, and we’ve basically just had to roll our own system for it, described in that PR. You might want to be aware of that. |
I'll be happy to get |
I agree you should leave them auto-implemented, but I don't see why |
That... is a good point. So I suppose |
I don't think you need a manual implementation. Using a nightly rustdoc which shows auto impls, this PR documents both auto |
Ah, I hadn't seen that since I try to target stable for public crates. Well, cool, that makes things easier. |
How were you able to prove lifetime invariance for the |
I just copied that test from the Does a variance test like this work for even just |
No, it does not. However, adding |
You're saying "invariance", but AIUI covariance is the opposite. We want this to allow the reduction to a shorter lifetime. I think (I'm not sure though -- variance is confusing!) |
Yeah, it is. Invariance is same/constant/equivalance, Covariance is usually one is less than the other, and the relationships that implies, or something like that. I think you're right, though, since the test does say "covariance". I must have mixed up the words somewhere, and inverting the where statement does make it fail again. Maybe I'll take another look at it again after some sleep and reviewing all the lifetime rules, but for now I guess it doesn't matter much. |
It's interesting. This isn't allowed: fn array<'new>(a: GenericArray<&'static str, U10>) -> GenericArray<&'new str, U10> {
a
}
I don't know what about the array itself is making it invariant. But the underlying data does exhibit covariance -- this is fine: fn array_rebuild<'new>(a: GenericArray<&'static str, U10>) -> GenericArray<&'new str, U10> {
GenericArray { data: a.data }
} |
It's definitely something with This works: struct Test<T, N: ArrayLength<T>>(PhantomData<(T, N)>);
fn test_covariance<'new>(i: Test<&'static str, U10>) -> Test<&'new str, U10> {
i
} but this fails: struct Test<T, N: ArrayLength<T>>(PhantomData<(T, N::ArrayType)>);
fn test_covariance<'new>(i: Test<&'static str, U10>) -> Test<&'new str, U10> {
i
} |
I removed
Send
/Sync
implementations onGenericArrayIter
, because it was a mistake to add them. Rust will automatically implementSend
where possible, andGenericArrayIter
shouldn't beSync
because the indices are not atomic variables.I've improved the generics tests to include most of the common use scenarios, and noted in
functional.rs
thattests/generics.rs
has those as examples.Finally, while writing the previous tests/examples, I noticed I did actually find the
SequenceItem
accessor alias type useful in keeping the generic conditions cleaner, so I added that back in.