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

:dumptests doesn't work for return types other than Bit #946

Closed
brianhuffman opened this issue Nov 1, 2020 · 4 comments
Closed

:dumptests doesn't work for return types other than Bit #946

brianhuffman opened this issue Nov 1, 2020 · 4 comments
Assignees

Comments

@brianhuffman
Copy link
Contributor

Cryptol> :dumptests "test" \(x : [32]) -> x + 1

The expression is not of a testable type.
Type: [32] -> [32]

:dumptests only seems to support functions that return type Bit. I'm feeling like supporting expressions in general (not just theorems) would be helpful. Here I just want to generate some input/output pairs for a function so that when I modify/optimize/etc it I can test to see if I've messed it up.

Originally posted by @weaversa in #611 (comment)

@brianhuffman
Copy link
Contributor Author

Based on this comment in Cryptol/Testing/Random.hs, it's clear that this feature is supposed to work for non-Bit return types. Also these types used to work with :dumptests in version 2.7.

{- | Given a (function) type, compute generators for the function's
arguments. This is like 'testableTypeGenerators', but allows the result to be
any finite type instead of just @Bit@. -}
dumpableType :: forall g. RandomGen g => Type -> Maybe [Gen g Concrete]
dumpableType ty =
case tIsFun ty of
Just (t1, t2) ->
do g <- randomValue Concrete t1
as <- testableTypeGenerators t2
return (g : as)
Nothing ->
do (_ :: Gen g Concrete) <- randomValue Concrete ty
return []

@brianhuffman
Copy link
Contributor Author

Bisecting shows that 64423cb (one of mine; a fix for #615) is the first bad commit.

@brianhuffman brianhuffman self-assigned this Nov 2, 2020
@brianhuffman
Copy link
Contributor Author

It looks like there's a copy-and-paste error in the definition of dumpableType, which was based on the previously-existing function testableTypeGenerators. The call to testableTypeGenerators on line 114 should actually be a recursive call to dumpableType instead.

@weaversa
Copy link
Collaborator

weaversa commented Nov 2, 2020

I’ve been thinking about dumptest recently and ran across some work on automated sampling. I’m just going to paste the references here, but the gist would be to enhance dumptests so that it generated tests based on the structure of the function, rather than purely random tests. It seems like the current research uses SMT techniques to generate good tests, which facilitates integration into Cryptol.

https://people.eecs.berkeley.edu/~rtd/papers/GuidedSampler.pdf

https://arxiv.org/pdf/1905.05358.pdf

brianhuffman pushed a commit that referenced this issue Nov 13, 2020
Fix bug in `dumpableType` function. Fixes #946.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants