Skip to content
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

Some more typeintersect tests #21339

Merged
merged 1 commit into from
Apr 10, 2017
Merged

Some more typeintersect tests #21339

merged 1 commit into from
Apr 10, 2017

Conversation

martinholters
Copy link
Member

Conversion of the list from #19998 (comment) to tests. For those which have been fixed in the meantime, I have use the @testintersect macro. There is one @test_skip at the end because that one loops infinitely (?) or sometimes throws a stack overflow.

A word about the fuzz testing that produced those:
I start with creating a random type that is an Int64, a Float64, a Val{T} with T being a random type again, or a Tuple{T1,T2, ...} of a random number of random types T1, T2, etc. For the random types inside a Val or Tuple, a constant integer is also possible. Note that these types may be large and deep, but don't contain Unions, Varargs, or UnionAlls, so I hoped these would still be easy ones... Anyway, the type thus obtained is x.
I then apply random widening by replacing random parts of the type x with TypeVars, potentially introducing the same TypeVar multiple times if the same type is to be replaced more than once. All introduced TypeVars are bound by UnionAlls at the outermost layer. This process is done twice to obtain a and b, such that x<:a and x<:b.
With these types, it is verified that

  • typeintersect(a,b) == typeintersect(b,a)
  • x <: typeintersect(a,b)
  • typeintersect(a,b) <: a
  • typeintersect(a,b) <: b

If any of these conditions is violated, the combination x, a, b is reduced while maintaining the same violation. The reduction tries steps such as removing tuple elements or unwrapping (i.e. Tuple{T} -> T or Val{T} -> T).

Once we get (most of) these right, I will add things like Unions, Varargs, inner UnionAlls, TypeVar bounds other than Bottom <: T <: Any, ...

@timholy
Copy link
Member

timholy commented Apr 10, 2017

I like the fuzzing, and I wonder if it's worth making it a repo. Cherry-picking the failures is great for coming up with a not-too-large test set, but of course there's always the risk that fixes to those specific problems will break other things that used to pass. Some kind of overall statistics that can be run episodically might be helpful.

@ararslan ararslan added test This change adds or pertains to unit tests types and dispatch Types, subtyping and method dispatch labels Apr 10, 2017
@JeffBezanson JeffBezanson merged commit 1db3279 into master Apr 10, 2017
@JeffBezanson
Copy link
Member

Thanks!

@martinholters martinholters deleted the mh/subtype_tests branch April 10, 2017 19:02
@martinholters
Copy link
Member Author

I like the fuzzing, and I wonder if it's worth making it a repo.

Up at https://github.com/martinholters/TypeFuzz.jl

@Keno
Copy link
Member

Keno commented May 18, 2017

Might be worth running the subtype predicate through AFL with appropriate mutators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test This change adds or pertains to unit tests types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants