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

type mismatch in Cryptol.Eval.Concrete.toExpr #851

Closed
msaaltink opened this issue Jul 30, 2020 · 2 comments · Fixed by #855
Closed

type mismatch in Cryptol.Eval.Concrete.toExpr #851

msaaltink opened this issue Jul 30, 2020 · 2 comments · Fixed by #855
Assignees
Labels
bug Something not working correctly

Comments

@msaaltink
Copy link
Contributor

In this spec

type base t = { zero: t }

B: base Bool
B = { zero = False }

foo: {t,k} (fin k) => base t -> [k]t
foo B = repeat B.zero

bar: {t,k} (fin k, k>=1) => [k]t -> [k]t -> [k]t -> [k]t
bar p q m = p

baz: {k,t} (fin k, k >= 1) => [k]t -> [k]t -> [k]t
baz p q = q

property problem p =
  p != foo B ==> bar p (baz p 0x03) 0x03 == foo B

running :check problem crashes Cryptol:

Main> :check problem 
Using random testing.
problem 0x82 = False
cryptol: You have encountered a bug in Cryptol's implementation.
*** Please create an issue at https://github.com/GaloisInc/cryptol/issues

%< --------------------------------------------------- 
  Revision:  c53f3cf1723235ad6b428e8b7be6b752823767a7
  Branch:    HEAD
  Location:  Cryptol.Eval.Concrete.toExpr
  Message:   type mismatch:
             [8]Cryptol::Bool
             130
CallStack (from HasCallStack):
  panic, called at src/Cryptol/Utils/Panic.hs:21:9 in cryptol-2.9.0-IwOb2yTO6mD35k7fNx79Kk:Cryptol.Utils.Panic
  panic, called at src/Cryptol/Eval/Concrete.hs:99:13 in cryptol-2.9.0-IwOb2yTO6mD35k7fNx79Kk:Cryptol.Eval.Concrete
%< --------------------------------------------------- 
@brianhuffman
Copy link
Contributor

I think I found the problem: It's this line of code in function toExpr, which is supposed to produce a Cryptol AST corresponding to a value of the given type.

(TCon (TC TCSeq) [a,(TCon (TC TCBit) [])], VWord _ wval) -> do

I believe this example program leads to a situation where the value is a VWord, but the pattern TCon (TC TCBit) [] for the sequence element type doesn't match, because type Bit is hidden behind the type synonym Bool. (Note that changing Bool to Bit in the example program fixes the problem.)

To fix this, we should use the view patterns we have for types that use tNoUser to unfold type synonyms, following the advice in the comment above the function definition:

-- XXX: View patterns would probably clean up this definition a lot.

@brianhuffman brianhuffman added the bug Something not working correctly label Jul 30, 2020
@brianhuffman brianhuffman self-assigned this Jul 30, 2020
@brianhuffman
Copy link
Contributor

I just want to point out that :exhaust problem triggers the same bug. This is important because I'd like to use this example as a regression test, but I can't use :check because it is non-deterministic and doesn't have reproducible output. So the regression test will use :exhaust instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something not working correctly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants