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

Parameterized modules, types and type definitions. #734

Closed
linesthatinterlace opened this issue May 20, 2020 · 4 comments
Closed

Parameterized modules, types and type definitions. #734

linesthatinterlace opened this issue May 20, 2020 · 4 comments
Assignees
Labels
bug Something not working correctly typechecker Issues related to type-checking Cryptol code.

Comments

@linesthatinterlace
Copy link

I came upon this bug in a larger context - I've boiled it down to what I think is a minimum working example:
testp.zip

We have two files: test.cry:

module test where
parameter
    type a : #
    type constraint (fin a) 

type b = (2^^a - 1)

f : [b] -> [3*b]
f x = x # x # x

and test_parameters.cry:

module test_parameters = test where
    type a             = 2

When you try to load test_parameters.cry, you get the following error:

Cryptol> :l test_parameters.cry
Loading module Cryptol
Loading module test

[error] at ./test.cry:1:1--9:16:
  Failed to validate user-specified signature.
    when checking the module's parameters,
    we need to show that
      for any type test::a
      assuming
        • fin test::a
      the following constraints hold:
        • 3 * test::b == test::b + 2 * test::b
            arising from
            matching types
            at ./test.cry:9:7--9:16

However, if we de-parameterize, thus:

module test where
type a             = 2

type b = (2^^a)

f : [b] -> [3*b]
f x = x # x # x

Then test.cry loads.

Something is breaking somewhere involving:

  • The parameterization.
  • The use of exponentials and subtraction in the definition of b.
  • The typechecker's understanding of associativit or addition of types.

Obviously this is a pretty specialised example - but it did come up naturally for me, and I think it is a bug?

@robdockins robdockins added the parameterized modules Related to Cryptol's parameterized modules label Jun 5, 2020
@robdockins robdockins self-assigned this Mar 26, 2021
@robdockins
Copy link
Contributor

Just tried to reproduce this behavior. The printing has changed a bit, but the problem is otherwise unchanged.

Loading module Cryptol
Loading module test
[error] at ./test.cry:1:1--10:16:
  Failed to validate user-specified signature.
    when checking the module's parameters,
    we need to show that
      for any type test::a
      assuming
        • fin test::a
      the following constraints hold:
        • 3 * 2 ^^ test::a - 1 == 2 ^^ test::a - 1 + 2 * 2 ^^ test::a - 1
            arising from
            matching types
            at ./test.cry:10:7--10:16

It seems like the problem is related to the subtraction operator. If I remove it or replace it with (+ 1), the module loads. Likewise, if I replace - 1 with / 2 I get a similar problem. So, partial type functions seem implicated here.

@robdockins
Copy link
Contributor

We should also fix the pretty-printer here, as it seems to be getting operator precedence wrong.

@robdockins robdockins added the bug Something not working correctly label Apr 5, 2021
@robdockins
Copy link
Contributor

Indeed, it doesn't seem related to parameterized modules, really. I can produce essentially the same problem directly.

module test where

f : {a} (fin a) => [2^^a -1] -> [3*(2^^a - 1)]
f x = x # x # x
[error] at test2.cry:4:1--4:16:
  Failed to validate user-specified signature.
    in the definition of 'test::f', at test2.cry:4:1--4:2,
    we need to show that
      for any type a
      assuming
        • fin a
      the following constraints hold:
        • 3 * (2 ^^ a - 1) == 2 ^^ a - 1 + 2 * (2 ^^ a - 1)
            arising from
            matching types
            at test2.cry:4:7--4:16

@robdockins robdockins added typechecker Issues related to type-checking Cryptol code. and removed parameterized modules Related to Cryptol's parameterized modules labels Apr 5, 2021
@robdockins
Copy link
Contributor

Worth noting, the following program is accepted without complaint:

module test where

f : {a} (fin a) => [2^^a - 1] -> [2*(2^^a - 1)]
f x = x # x

robdockins added a commit that referenced this issue Apr 5, 2021
This fixes issue #734, and partially addresses #930.
The basic issue with 734 was that the solver was chosing
spurious counterexamples for the exponent function; in particular,
models where the output was not at least 1.  The fairly restricted
axiom we add here just says that the exponent function is at least
as large as its base for positive inputs.
robdockins added a commit that referenced this issue Apr 6, 2021
This fixes issue #734, and partially addresses #930.
The basic issue with 734 was that the solver was chosing
spurious counterexamples for the exponent function; in particular,
models where the output was not at least 1.  The fairly restricted
axiom we add here just says that the exponent function is at least
as large as its base for positive inputs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something not working correctly typechecker Issues related to type-checking Cryptol code.
Projects
None yet
Development

No branches or pull requests

2 participants