Skip to content

Long term plan: Investigate strategies for non-owned types #9

Open
@Centril

Description

@Centril

Currently, it is impossible to have a S: Strategy where ValueOf<S> is non-owned.

Examples:

  1. We have a base strategy T where ValueOf<T> is owned, and then we use that to make a strategy where ValueOf<S> = &'a ValueOf<T> - This will not type check.
  2. Derived types, for example: 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 of Owned (which defaults to Value) in addition to Value (which may be borrowed). Then TestRunner will return the Owned type instead of Value, but the function under test receives Value.
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 by Box::leak, this may cause problems since tests for large data types may leak huge amounts of memory. This could perhaps be mitigated by letting the ValueTree store the previous value of .current(), and whenever .current() happens, the old value is deallocated. The last value needs to be persisted in the TestRunner somehow if the entire ValueTree did not fail so that it can be cleared.

I'd like your thought's on the desirability of these features.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestThis issue is requesting new functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions