-
Notifications
You must be signed in to change notification settings - Fork 161
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
Long term plan: Investigate strategies for non-owned types #9
Comments
I do think it'd be useful, but I also agree that this definitely requires GATs. (If trait aliases become a thing, there might also be a viable option of just adding a lifetime parameter to all the traits that most people wouldn't have to deal with.) I think the problem bears a lot of similarity to "streaming iterators", so it might be best to wait and see how that gets solved and then follow suit. |
Agreed, it is similar to streaming iterators. Once GATs lands I will do some prototyping on nightly to see how much the interface has to change to accommodate generation of borrowed types and how much we have to modify the strategies already provided. If we find a good solution we can perhaps develop it as a separate branch and then merge it in once GATs for lifetimes are stabilized (which might be before GATs for types). |
Hmm while GATs may be the correct way to represent this, they look unlikely to be stabilized anytime soon, and I'm curious as to why this wouldn't work if |
It’d be lovely to revisit this issue now that GATs have been stabilized. Has anybody experimented with it? :) EDIT: A bit about my use case: Due to proptest not supporting non-owned types, I’m unable to randomly generate a tree value whose nodes are allocated in an arena (bumpalo) because I can’t store |
Currently, it is impossible to have a
S: Strategy
whereValueOf<S>
is non-owned.Examples:
T
whereValueOf<T>
is owned, and then we use that to make a strategy whereValueOf<S> = &'a ValueOf<T>
- This will not type check.Cow<'a, X>
.Generally, I think that, any type that has a lifetime can't be generated.
Being able to generate types with lifetimes in them is however useful when you have lifetimes somewhere deep in the hierarchy of a type. To be able to do this soundly, the
ValueTree
must perhaps have a notion ofOwned
(which defaults toValue
) in addition toValue
(which may be borrowed). ThenTestRunner
will return theOwned
type instead ofValue
, but the function under test receivesValue
.I tried to implement this and got
TestRunner
to compile, but no strategies would compile.Solving this may require generic associated types (GAT). I'll experiment with it once we have GAT in nightly.
There's also
*const T
and*mut T
. While it is possible to give a sound strategy for these byBox::leak
, this may cause problems since tests for large data types may leak huge amounts of memory. This could perhaps be mitigated by letting theValueTree
store the previous value of.current()
, and whenever.current()
happens, the old value is deallocated. The last value needs to be persisted in theTestRunner
somehow if the entireValueTree
did not fail so that it can be cleared.I'd like your thought's on the desirability of these features.
The text was updated successfully, but these errors were encountered: