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

crucible-syntax: Allow exotic characters in fresh atom names #1266

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions crucible-syntax/src/Lang/Crucible/Syntax/Concrete.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1564,21 +1564,24 @@ atomSetter (AtomName anText) =

fresh =
do t <- reading (unary Fresh isType)
describe "user symbol" $
case userSymbol (T.unpack anText) of
Left err -> describe (T.pack (show err)) empty
Right nm ->
do loc <- position
case t of
Some (FloatRepr fi) ->
Some <$>
freshAtom loc (FreshFloat fi (Just nm))
Some NatRepr ->
Some <$> freshAtom loc (FreshNat (Just nm))
Some tp
| AsBaseType bt <- asBaseType tp ->
Some <$> freshAtom loc (FreshConstant bt (Just nm))
| otherwise -> describe "atomic type" $ empty
-- Note that we are using safeSymbol below to create a What4 symbol
-- name, which will Z-encode names that aren't legal solver names. This
-- includes names that include hyphens, which are very common in
-- S-expression syntax. This is fine to do, since the Z-encoded name
-- name is only used for solver purposes; the original, unencoded name
-- is recorded separately.
let nm = safeSymbol (T.unpack anText)
loc <- position
case t of
Some (FloatRepr fi) ->
Some <$>
freshAtom loc (FreshFloat fi (Just nm))
Some NatRepr ->
Some <$> freshAtom loc (FreshNat (Just nm))
Some tp
| AsBaseType bt <- asBaseType tp ->
Some <$> freshAtom loc (FreshConstant bt (Just nm))
| otherwise -> describe "atomic type" $ empty
RyanGlScott marked this conversation as resolved.
Show resolved Hide resolved

evaluated =
do Pair _ e' <- reading synth
Expand Down
10 changes: 10 additions & 0 deletions crucible-syntax/test-data/exotic-fresh-names.cbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; A regression test for #1024.

(defun @exotic-fresh-names () Bool
(start start:
; Although the list of allowable characters in What4 solver names is very
; small, we can nevertheless define atom names with unallowable characters
; by Z-encoding them under the hood.
(let ω (fresh Bool)) ; Fancy Unicode characters
(let hyphens-are-fine (fresh Bool)) ; Hyphens
(return (and ω hyphens-are-fine))))
17 changes: 17 additions & 0 deletions crucible-syntax/test-data/exotic-fresh-names.out.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(defun @exotic-fresh-names () Bool
(start start:
(let ω (fresh Bool))
(let hyphens-are-fine (fresh Bool))
(return (and ω hyphens-are-fine))))

exotic-fresh-names
%0
% 8:12
$0 = fresh BaseBoolRepr zenc!z3c9U
% 9:27
$1 = fresh BaseBoolRepr zenc!hyphenszmarezmfine
% 10:13
$2 = and($0, $1)
% 10:5
return $2
% no postdom
Loading