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

WIP: Propagate Cryptol error strings #1344

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

WIP: Propagate Cryptol error strings #1344

wants to merge 1 commit into from

Conversation

RyanGlScott
Copy link
Contributor

This patch adds two new SAWCore primitives:

  • appendString : String -> String -> String, which appends the underlying Text values in a String, and
  • bytesToString : (n : Nat) -> Vec n (Vec 8 Bool) -> String, which converts a Cryptol string (a sequence of 8-bit ASCII characters) to a SAWCore String.

Moreover, this reimplements ecError in terms of appendString/bytesToString such that invoking the Cryptol error function from SAW will preserve the string passed to error. Previously, if you invoked the following in SAW:

sawscript> prove abc {{ error "Descriptive error message" : Bit }}

You would get:

Run-time error: encountered call to the Cryptol 'error' function

Now, you get:

Run-time error: encountered call to the Cryptol 'error' function: Descriptive error message

Fixes #1326.

This patch adds two new SAWCore primitives:

* `appendString : String -> String -> String`, which appends the underlying
  `Text` values in a `String`, and
* `bytesToString : (n : Nat) -> Vec n (Vec 8 Bool) -> String`, which converts a
  Cryptol string (a sequence of 8-bit ASCII characters) to a SAWCore `String`.

Moreover, this reimplements `ecError` in terms of
`appendString`/`bytesToString` such that invoking the Cryptol `error` function
from SAW will preserve the string passed to `error`. Previously, if you invoked
the following in SAW:

```
sawscript> prove abc {{ error "Descriptive error message" : Bit }}
```

You would get:

```
Run-time error: encountered call to the Cryptol 'error' function
```

Now, you get:

```
Run-time error: encountered call to the Cryptol 'error' function: Descriptive error message
```

Fixes #1326.
@@ -903,6 +903,7 @@ primitive expByNat : (a:sort 0) -> a -> (a -> a -> a) -> a -> Nat -> a;

primitive equalString : String -> String -> Bool;

primitive appendString : String -> String -> String;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ptival: I believe saw-core-coq has some special treatment for the appendString function, so I'm not sure if adding it as a primitive here will cause problems.

@@ -343,6 +345,7 @@ asFirstOrderTypeTValue v =
VSort{} -> Nothing
VRecursorType{} -> Nothing
VTyTerm{} -> Nothing
VStringType -> Nothing
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this case. Does it make sense to add a FOTString constructor? I'm unclear what the consequences of that would be.

@@ -371,6 +374,7 @@ suffixTValue tv =
VSort {} -> Nothing
VRecursorType{} -> Nothing
VTyTerm{} -> Nothing
VStringType -> Nothing
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, I'm not sure about this use of Nothing. All of the other Nothing cases in this function also have corresponding Nothing cases in asFirstOrderTypeTValue, so I did the same for VStringType for consistency.

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

Successfully merging this pull request may close these issues.

Invoking Cryptol's error function discards the error string
1 participant