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 inference weirdness in the presence of type synonyms with unused arguments #894

Closed
brianhuffman opened this issue Sep 15, 2020 · 0 comments · Fixed by #902
Closed
Assignees
Labels
bug Something not working correctly low-hanging fruit For issues that should be easy to fix typechecker Issues related to type-checking Cryptol code.
Milestone

Comments

@brianhuffman
Copy link
Contributor

Fun fact: You can get the cryptol type checker to infer, for a closed expression, a type that contains an unresolved unification variable. Here's the source file:

type Int n = Integer

foo : {n} (fin n) => [n] -> Int n
foo x = `n
Loading module Cryptol
Loading module Main
[warning] at foo.cry:6:10--6:11 Unused name: n
[warning] at foo.cry:6:6--6:9:
  Assuming  n to have a numeric type
Main> :t foo 0x0
foo 0x0 : Int n`941

This is caused by an apparent bug in the definition of type variable substitution for cryptol types. When I saw the following case in the definition of apSubstMaybe (which is supposed to return Just t' to indicate that the substitution did something, and Nothing to indicate that the substitution left the value unchanged) I thought it was probably wrong and so I constructed this example to check.

TUser f ts t -> do t1 <- apSubstMaybe su t
return (TUser f (map (apSubst su) ts) t1)

The constructor TUser contains both a list of the type synonym arguments, and also the body of the type synonym's definition. It's possible to define a type synonym in Cryptol whose body doesn't use all the arguments. But this code assumes that if the body is unchanged by the substitution, then the arguments will also be unchanged. The above example violates this assumption.

@yav yav added bug Something not working correctly typechecker Issues related to type-checking Cryptol code. labels Sep 17, 2020
@atomb atomb added the low-hanging fruit For issues that should be easy to fix label Sep 22, 2020
@atomb atomb added this to the 2.10.0 milestone Sep 22, 2020
@brianhuffman brianhuffman self-assigned this Sep 22, 2020
brianhuffman pushed a commit that referenced this issue Sep 23, 2020
We also needed to rewrite `anyJust2` to make it more strict,
to avoid reintroducing the space leak of issue #888.
brianhuffman pushed a commit that referenced this issue Sep 23, 2020
brianhuffman pushed a commit that referenced this issue Sep 23, 2020
We also needed to rewrite `anyJust2` to make it more strict,
to avoid reintroducing the space leak of issue #888.
brianhuffman pushed a commit that referenced this issue Sep 23, 2020
@brianhuffman brianhuffman mentioned this issue Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something not working correctly low-hanging fruit For issues that should be easy to fix typechecker Issues related to type-checking Cryptol code.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants