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

Support importing Cryptol enums into SAWCore #2052

Open
RyanGlScott opened this issue Apr 16, 2024 · 1 comment
Open

Support importing Cryptol enums into SAWCore #2052

RyanGlScott opened this issue Apr 16, 2024 · 1 comment
Labels
missing cryptol features Issues about features in Cryptol that don't work in SAW subsystem: cryptol-saw-core Issues related to Cryptol -> saw-core translation with cryptol-saw-core type: feature request Issues requesting a new feature or capability
Milestone

Comments

@RyanGlScott
Copy link
Contributor

RyanGlScott commented Apr 16, 2024

Since #2020, SAW bundles a version of Cryptol that includes support for Cryptol's enum declarations. It it still not possible to import Cryptol files that define enums into SAWCore, however. For example, given this Cryptol and SAW file:

// Test.cry
enum Foo = MkFoo
// test.saw
import "Test.cry";

If you run test.saw, it will throw an error message:

$ ~/Software/saw-1.1/bin/saw test.saw
[13:24:15.614] Loading file "/home/ryanscott/Documents/Hacking/SAW/test.saw"
[13:24:15.634] genNominalConstrurctors: `enum` is not yet supported
CallStack (from HasCallStack):
  error, called at src/Verifier/SAW/Cryptol.hs:2034:22 in cryptol-saw-core-0.1-inplace:Verifier.SAW.Cryptol

Alternatively, you might also see this error message if you load a program which uses (but does not define) an enum:

// Test.cry

f : Option () -> ()
f x =
  case x of
    None -> ()
    Some y -> y
$ ~/Software/saw-1.1/bin/saw test.saw
[13:25:05.093] Loading file "/home/ryanscott/Documents/Hacking/SAW/test.saw"
[13:25:05.113] importType: `enum` is not yet supported
CallStack (from HasCallStack):
  error, called at src/Verifier/SAW/Cryptol.hs:274:25 in cryptol-saw-core-0.1-inplace:Verifier.SAW.Cryptol

This issue tracks lifting this restriction. (A further step would be to allow using Cryptol enums in MIR specifications, as proposed in #1976.)


In order to import an enum into SAWCore, we need to have a corresponding SAWCore representation. Two possible representations that we could pick are:

  1. Map each Cryptol enum declaration to a SAWCore data declaration with the same field types.
  2. Map each Cryptol enum declaration to a value defined in terms of Eithers, which provides an "anonymous sum" representation.
@RyanGlScott RyanGlScott added type: feature request Issues requesting a new feature or capability subsystem: cryptol-saw-core Issues related to Cryptol -> saw-core translation with cryptol-saw-core labels Apr 16, 2024
@RyanGlScott
Copy link
Contributor Author

It is also possible to make SAW outright panic by using an enum in the return type of a function:

// Test.cry

f : Option ()
f = None
$ ~/Software/saw-1.1/bin/saw test.saw
[13:33:52.133] Loading file "/home/ryanscott/Documents/Hacking/SAW/test.saw"
[13:33:52.155] You have encountered a bug in cryptol-saw-core's implementation.
*** Please create an issue at https://github.com/GaloisInc/saw-script/issues

%< --------------------------------------------------- 
  Revision:  5c16c876f35f0abdf0b412a5387e220b15b7f990
  Branch:    release-1.1 (uncommited files present)
  Location:  importExpr
  Message:   unknown variable: Name {nUnique = 4188, nInfo = GlobalName UserName (OrigName {ogNamespace = NSConstructor, ogModule = TopModule (ModName "Cryptol" NormalName), ogSource = FromDefinition, ogName = Ident False NormalName "None", ogFromParam = Nothing}), nFixity = Nothing, nLoc = Range {from = Position {line = 645, col = 17}, to = Position {line = 645, col = 21}, source = "/home/ryanscott/Software/saw-1.1/lib/Cryptol.cry"}}
CallStack (from HasCallStack):
  panic, called at src/Verifier/SAW/Cryptol/Panic.hs:13:9 in cryptol-saw-core-0.1-inplace:Verifier.SAW.Cryptol.Panic
  panic, called at src/Verifier/SAW/Cryptol.hs:1081:25 in cryptol-saw-core-0.1-inplace:Verifier.SAW.Cryptol
%< ---------------------------------------------------

It's not obvious to me if it is straightforward to fix this panic without doing all of the necessary legwork to support enums wholesale, but I thought I'd mention it here as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
missing cryptol features Issues about features in Cryptol that don't work in SAW subsystem: cryptol-saw-core Issues related to Cryptol -> saw-core translation with cryptol-saw-core type: feature request Issues requesting a new feature or capability
Projects
None yet
Development

No branches or pull requests

3 participants