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

Exhaustiveness-checking warning loses module namespace upon reload #1797

Open
RyanGlScott opened this issue Feb 7, 2025 · 1 comment
Open
Labels
bug Something not working correctly type-guards UX Issues related to the user experience (e.g., improved error messages)

Comments

@RyanGlScott
Copy link
Contributor

Consider this program:

module GuardOrder where

parameter
  type w: #
  type w' = 2 ^^ w
  type b = 2 ^^ w'

f' : [b] -> [b]
f' x
  | b == 2 => ~ x
  | b > 2 => x
  | b < 2 => x

Currently, Cryptol deems f' to be inexhaustive (see #1796 for more on this, but this is a separate issue than what I am reporting here). If you load this module into Cryptol, then the warning is:

$ ~/Software/cryptol-3.2.0/bin/cryptol Bug.cry 
┏━╸┏━┓╻ ╻┏━┓╺┳╸┏━┓╻  
┃  ┣┳┛┗┳┛┣━┛ ┃ ┃ ┃┃  
┗━╸╹┗╸ ╹ ╹   ╹ ┗━┛┗━╸
version 3.2.0 (1bcb75c)
https://cryptol.net  :? for help

Loading module Cryptol
Loading interface module `parameter` interface of GuardOrder
Loading module GuardOrder
[warning] at Bug.cry:9:1--9:3:
  Could not prove that the constraint guards used in defining GuardOrder::f' were exhaustive.

Note that the warning message mentions GuardOrder::f', which includes the module namespace (as expected). So far, so good.

Now let's reload the program:

GuardOrder(parameterized)> :reload
Loading module Cryptol
Loading interface module `parameter` interface of GuardOrder
Loading module GuardOrder
[warning] at Bug.cry:9:1--9:3:
  Could not prove that the constraint guards used in defining f' were exhaustive.

This time, the warning mentions f', not GuardOrder::f'. Somehow, the module namespace disappeared in the process of reloading the program!


As a more extreme example, let's quit Cryptol:

GuardOrder(parameterized)> :quit

And invoke Cryptol on it again:

$ ~/Software/cryptol-3.2.0/bin/cryptol Bug.cry 
┏━╸┏━┓╻ ╻┏━┓╺┳╸┏━┓╻  
┃  ┣┳┛┗┳┛┣━┛ ┃ ┃ ┃┃  
┗━╸╹┗╸ ╹ ╹   ╹ ┗━┛┗━╸
version 3.2.0 (1bcb75c)
https://cryptol.net  :? for help

Loading module Cryptol
Loading interface module `parameter` interface of GuardOrder
Loading module GuardOrder
[warning] at Bug.cry:9:1--9:3:
  Could not prove that the constraint guards used in defining GuardOrder::f' were exhaustive.

Again, it mentions GuardOrder::f'—so far, so good. Now, without exiting the Cryptol REPL, let's modify the program to add another definition, which is also deemed inexhaustive:

module GuardOrder where

parameter
  type w: #
  type w' = 2 ^^ w
  type b = 2 ^^ w'

f' : [b] -> [b]
f' x
  | b == 2 => ~ x
  | b > 2 => x
  | b < 2 => x

// This definition is new
f'' : [b] -> [b]
f'' x
  | b == 2 => ~ x
  | b > 2 => x

If we reload the REPL now, we get:

GuardOrder(parameterized)> :reload
Loading module Cryptol
Loading interface module `parameter` interface of GuardOrder
Loading module GuardOrder
[warning] at Bug.cry:16:1--16:4:
  Could not prove that the constraint guards used in defining GuardOrder::f'' were exhaustive.
[warning] at Bug.cry:9:1--9:3:
  Could not prove that the constraint guards used in defining f' were exhaustive.

Note that the warning for the newly added definition mentions GuardOrder::f'', which does include a module namespace, but the warning for the old definition mentions f', which does not include a module namespace! Very strange indeed.

@RyanGlScott RyanGlScott added bug Something not working correctly type-guards UX Issues related to the user experience (e.g., improved error messages) labels Feb 7, 2025
@yav
Copy link
Member

yav commented Feb 7, 2025

The bug here is more likely that we do print the qualified names, rather that we don't. This all has to do with a system where we qualify names only when they are not in scope or ambiguous (I think it was based on GHC originally) but we are not very consistent about using it. Also, I think there are some cases where we don't know which scope we are talking about. Have a look in Utils.PP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something not working correctly type-guards UX Issues related to the user experience (e.g., improved error messages)
Projects
None yet
Development

No branches or pull requests

2 participants