Skip to content

Commit 2e4fc06

Browse files
authored
Merge pull request #1281 from GaloisInc/string-text
Convert more uses of `String` to `Text`.
2 parents 130a107 + 3303426 commit 2e4fc06

File tree

16 files changed

+49
-44
lines changed

16 files changed

+49
-44
lines changed

cryptol-saw-core/src/Verifier/SAW/TypedTerm.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Verifier.SAW.TypedTerm where
1010
import Control.Monad (foldM)
1111
import Data.Map (Map)
1212
import qualified Data.Map as Map
13+
import Data.Text (Text)
1314

1415
import Cryptol.ModuleSystem.Name (nameIdent)
1516
import qualified Cryptol.TypeCheck.AST as C
@@ -62,7 +63,7 @@ applyTypedTerms :: SharedContext -> TypedTerm -> [TypedTerm] -> IO TypedTerm
6263
applyTypedTerms sc = foldM (applyTypedTerm sc)
6364

6465
-- | Create an abstract defined constant with the specified name and body.
65-
defineTypedTerm :: SharedContext -> String -> TypedTerm -> IO TypedTerm
66+
defineTypedTerm :: SharedContext -> Text -> TypedTerm -> IO TypedTerm
6667
defineTypedTerm sc name (TypedTerm schema t) =
6768
do ty <- scTypeOf sc t
6869
TypedTerm schema <$> scConstant sc name t ty

saw-core-what4/src/Verifier/SAW/Simulator/What4/ReturnTrip.hs

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import Data.Ratio
4949
import Data.Sequence (Seq)
5050
import qualified Data.Sequence as Seq
5151
import Data.Word(Word64)
52+
import Data.Text (Text)
5253
import qualified Data.Text as Text
5354

5455
import What4.BaseTypes
@@ -148,7 +149,7 @@ baseSCType sym sc bt =
148149

149150
-- | Create a new symbolic variable.
150151
sawCreateVar :: SAWCoreState n
151-
-> String -- ^ the name of the variable
152+
-> Text -- ^ the name of the variable
152153
-> SC.Term
153154
-> IO SC.Term
154155
sawCreateVar st nm tp = do
@@ -539,7 +540,7 @@ evaluateExpr sym st sc cache = f []
539540
B.UninterpVarKind -> do
540541
tp <- baseSCType sym sc (B.bvarType bv)
541542
SAWExpr <$> sawCreateVar st nm tp
542-
where nm = Text.unpack $ solverSymbolAsText $ B.bvarName bv
543+
where nm = solverSymbolAsText $ B.bvarName bv
543544
B.LatchVarKind ->
544545
unsupported sym "SAW backend does not support latch variables"
545546
B.QuantifierVarKind -> do

saw-core/src/Verifier/SAW/Constant.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ Portability : non-portable (language extensions)
88
-}
99

1010
module Verifier.SAW.Constant (scConst) where
11+
12+
import Data.Text (Text)
13+
1114
import Verifier.SAW.SharedTerm
1215
import Verifier.SAW.Rewriter
1316
import Verifier.SAW.Conversion
1417

15-
scConst :: SharedContext -> String -> Term -> IO Term
18+
scConst :: SharedContext -> Text -> Term -> IO Term
1619
scConst sc name t = do
1720
ty <- scTypeOf sc t
1821
ty' <- rewriteSharedTerm sc (addConvs natConversions emptySimpset) ty

saw-core/src/Verifier/SAW/Rewriter.hs

+2-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ import qualified Data.List as List
6868
import qualified Data.Map as Map
6969
import Data.Set (Set)
7070
import qualified Data.Set as Set
71-
import qualified Data.Text as Text
7271
import Control.Monad.Trans.Writer.Strict
7372
import Numeric.Natural
7473

@@ -222,7 +221,7 @@ scMatch sc pat term =
222221
let fvy = looseVars y `intersectBitSets` (completeBitSet depth)
223222
guard (fvy `unionBitSets` fvj == fvj)
224223
let fixVar t (nm, ty) =
225-
do v <- scFreshGlobal sc (Text.unpack nm) ty
224+
do v <- scFreshGlobal sc nm ty
226225
let Just ec = R.asExtCns v
227226
t' <- instantiateVar sc 0 v t
228227
return (t', ec)
@@ -882,7 +881,7 @@ doHoistIfs sc ss hoistCache itePat = go
882881
goF _ (Pi nm tp body) = goBinder scPi nm tp body
883882

884883
goBinder close nm tp body = do
885-
(ec, body') <- scOpenTerm sc (Text.unpack nm) tp 0 body
884+
(ec, body') <- scOpenTerm sc nm tp 0 body
886885
(body'', conds) <- go body'
887886
let (stuck, float) = List.partition (\(_,ecs) -> Set.member ec ecs) conds
888887

saw-core/src/Verifier/SAW/SharedTerm.hs

+12-13
Original file line numberDiff line numberDiff line change
@@ -392,17 +392,16 @@ scShowTerm sc opts t =
392392
pure (showTermWithNames opts env t)
393393

394394
-- | Create a global variable with the given identifier (which may be "_") and type.
395-
scFreshEC :: SharedContext -> String -> a -> IO (ExtCns a)
396-
scFreshEC sc x tp = do
397-
i <- scFreshGlobalVar sc
398-
let x' = Text.pack x
399-
let uri = scFreshNameURI x' i
400-
let nmi = ImportedName uri [x',Text.pack (x <> "#" <> show i)]
401-
scRegisterName sc i nmi
402-
pure (EC i nmi tp)
395+
scFreshEC :: SharedContext -> Text -> a -> IO (ExtCns a)
396+
scFreshEC sc x tp =
397+
do i <- scFreshGlobalVar sc
398+
let uri = scFreshNameURI x i
399+
let nmi = ImportedName uri [x, x <> "#" <> Text.pack (show i)]
400+
scRegisterName sc i nmi
401+
pure (EC i nmi tp)
403402

404403
-- | Create a global variable with the given identifier (which may be "_") and type.
405-
scFreshGlobal :: SharedContext -> String -> Term -> IO Term
404+
scFreshGlobal :: SharedContext -> Text -> Term -> IO Term
406405
scFreshGlobal sc x tp = scExtCns sc =<< scFreshEC sc x tp
407406

408407
-- | Returns shared term associated with ident.
@@ -1213,7 +1212,7 @@ scSort sc s = scFlatTermF sc (Sort s)
12131212
scNat :: SharedContext -> Natural -> IO Term
12141213
scNat sc n = scFlatTermF sc (NatLit n)
12151214

1216-
-- | Create a literal term (of saw-core type @String@) from a 'String'.
1215+
-- | Create a literal term (of saw-core type @String@) from a 'Text'.
12171216
scString :: SharedContext -> Text -> IO Term
12181217
scString sc s = scFlatTermF sc (StringLit s)
12191218

@@ -1324,7 +1323,7 @@ scFunAll :: SharedContext
13241323
-> IO Term
13251324
scFunAll sc argTypes resultType = foldrM (scFun sc) resultType argTypes
13261325

1327-
-- | Create a lambda term from a parameter name (as a 'String'), parameter type
1326+
-- | Create a lambda term from a parameter name (as a 'LocalName'), parameter type
13281327
-- (as a 'Term'), and a body. Regarding deBruijn indices, in the body of the
13291328
-- function, an index of 0 refers to the bound parameter.
13301329
scLambda :: SharedContext
@@ -1378,7 +1377,7 @@ scLocalVar sc i = scTermF sc (LocalVar i)
13781377
-- indices. If the body contains any ExtCns variables, they will be
13791378
-- abstracted over and reapplied to the resulting constant.
13801379
scConstant :: SharedContext
1381-
-> String -- ^ The name
1380+
-> Text -- ^ The name
13821381
-> Term -- ^ The body
13831382
-> Term -- ^ The type
13841383
-> IO Term
@@ -2337,7 +2336,7 @@ scTreeSize = fst . go (0, Map.empty)
23372336
-- | `openTerm sc nm ty i body` replaces the loose deBruijn variable `i`
23382337
-- with a fresh external constant (with name `nm`, and type `ty`) in `body`.
23392338
scOpenTerm :: SharedContext
2340-
-> String
2339+
-> Text
23412340
-> Term
23422341
-> DeBruijnIndex
23432342
-> Term

saw-remote-api/src/SAWServer/JVMCrucibleSetup.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import Data.Foldable ( traverse_ )
2626
import Data.Map (Map)
2727
import qualified Data.Map as Map
2828
import Data.Maybe ( maybeToList )
29-
import qualified Data.Text as T
3029

3130
import qualified Cryptol.Parser.AST as P
3231
import Cryptol.Utils.Ident (mkIdent)
@@ -120,7 +119,7 @@ interpretJVMSetup fileReader bic cenv0 ss = evalStateT (traverse_ go ss) (mempty
120119
go (SetupReturn v) = get >>= \env -> lift $ getSetupVal env v >>= jvm_return
121120
-- TODO: do we really want two names here?
122121
go (SetupFresh name@(ServerName n) debugName ty) =
123-
do t <- lift $ jvm_fresh_var (T.unpack debugName) ty
122+
do t <- lift $ jvm_fresh_var debugName ty
124123
(env, cenv) <- get
125124
put (env, CEnv.bindTypedTerm (mkIdent n, t) cenv)
126125
save name (Val (MS.SetupTerm t))

saw-remote-api/src/SAWServer/LLVMCrucibleSetup.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import Data.Aeson (FromJSON(..), withObject, (.:))
2525
import Data.ByteString (ByteString)
2626
import Data.Map (Map)
2727
import qualified Data.Map as Map
28-
import qualified Data.Text as T
2928

3029
import qualified Cryptol.Parser.AST as P
3130
import Cryptol.Utils.Ident (mkIdent)
@@ -102,7 +101,7 @@ compileLLVMContract fileReader bic ghostEnv cenv0 c =
102101
Nothing -> return ()
103102
where
104103
setupFresh (ContractVar n dn ty) =
105-
do t <- llvm_fresh_var (T.unpack dn) (llvmType ty)
104+
do t <- llvm_fresh_var dn (llvmType ty)
106105
return (n, t)
107106

108107
setupState allocs (env, cenv) vars =

src/SAWScript/Builtins.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ showPrim v = do
130130
opts <- fmap rwPPOpts getTopLevelRW
131131
return (SV.showsPrecValue opts 0 v "")
132132

133-
definePrim :: String -> TypedTerm -> TopLevel TypedTerm
133+
definePrim :: Text -> TypedTerm -> TopLevel TypedTerm
134134
definePrim name (TypedTerm schema rhs) =
135135
do sc <- getSharedContext
136136
ty <- io $ Cryptol.importSchema sc Cryptol.emptyEnv schema
@@ -526,7 +526,7 @@ goal_assume =
526526
do sc <- SV.scriptTopLevel getSharedContext
527527
execTactic (tacticAssume sc)
528528

529-
goal_intro :: String -> ProofScript TypedTerm
529+
goal_intro :: Text -> ProofScript TypedTerm
530530
goal_intro s =
531531
do sc <- SV.scriptTopLevel getSharedContext
532532
execTactic (tacticIntro sc s)
@@ -986,7 +986,7 @@ check_goal =
986986
fixPos :: Pos
987987
fixPos = PosInternal "FIXME"
988988

989-
freshSymbolicPrim :: String -> C.Schema -> TopLevel TypedTerm
989+
freshSymbolicPrim :: Text -> C.Schema -> TopLevel TypedTerm
990990
freshSymbolicPrim x schema@(C.Forall [] [] ct) = do
991991
sc <- getSharedContext
992992
cty <- io $ Cryptol.importType sc Cryptol.emptyEnv ct

src/SAWScript/Crucible/Common/Setup/Type.hs

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module SAWScript.Crucible.Common.Setup.Type
3535
import Control.Lens
3636
import Control.Monad.State (StateT)
3737
import Control.Monad.IO.Class (MonadIO(liftIO))
38+
import Data.Text (Text)
3839

3940
import qualified Cryptol.TypeCheck.Type as Cryptol (Type)
4041
import qualified Verifier.SAW.Cryptol as Cryptol (importType, emptyEnv)
@@ -101,7 +102,7 @@ addCondition cond = currentState . MS.csConditions %= (cond : )
101102
freshTypedExtCns ::
102103
MonadIO m =>
103104
SharedContext {- ^ shared context -} ->
104-
String {- ^ variable name -} ->
105+
Text {- ^ variable name -} ->
105106
Cryptol.Type {- ^ variable type -} ->
106107
CrucibleSetupT arch m TypedExtCns
107108
freshTypedExtCns sc name cty =
@@ -116,7 +117,7 @@ freshTypedExtCns sc name cty =
116117
freshVariable ::
117118
MonadIO m =>
118119
SharedContext {- ^ shared context -} ->
119-
String {- ^ variable name -} ->
120+
Text {- ^ variable name -} ->
120121
Cryptol.Type {- ^ variable type -} ->
121122
CrucibleSetupT arch m TypedTerm
122123
freshVariable sc name cty =

src/SAWScript/Crucible/JVM/Builtins.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import qualified Data.Map as Map
5555
import Data.Set (Set)
5656
import qualified Data.Set as Set
5757
import qualified Data.Sequence as Seq
58+
import Data.Text (Text)
5859
import qualified Data.Text as Text
5960
import qualified Data.Vector as V
6061
import Data.Void (absurd)
@@ -955,7 +956,7 @@ typeOfJavaType jty =
955956
-- | Generate a fresh variable term. The name will be used when
956957
-- pretty-printing the variable in debug output.
957958
jvm_fresh_var ::
958-
String {- ^ variable name -} ->
959+
Text {- ^ variable name -} ->
959960
JavaType {- ^ variable type -} ->
960961
JVMSetupM TypedTerm {- ^ fresh typed term -}
961962
jvm_fresh_var name jty =

src/SAWScript/Crucible/LLVM/Builtins.hs

+4-3
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ import qualified Data.HashMap.Strict as HashMap
106106
import qualified Data.Set as Set
107107
import Data.Sequence (Seq)
108108
import qualified Data.Sequence as Seq
109+
import Data.Text (Text)
109110
import qualified Data.Text as Text
110111
import qualified Data.Vector as V
111112
import Prettyprinter
@@ -1439,7 +1440,7 @@ setupArg sc sym ecRef tp = do
14391440
freshGlobal cty sc_tp =
14401441
do ecs <- readIORef ecRef
14411442
let len = Seq.length ecs
1442-
ec <- scFreshEC sc ("arg_"++show len) sc_tp
1443+
ec <- scFreshEC sc ("arg_" <> Text.pack (show len)) sc_tp
14431444
writeIORef ecRef (ecs Seq.|> TypedExtCns cty ec)
14441445
scFlatTermF sc (ExtCns ec)
14451446

@@ -1649,7 +1650,7 @@ cryptolTypeOfActual dl mt =
16491650
-- | Generate a fresh variable term. The name will be used when
16501651
-- pretty-printing the variable in debug output.
16511652
llvm_fresh_var ::
1652-
String {- ^ variable name -} ->
1653+
Text {- ^ variable name -} ->
16531654
L.Type {- ^ variable type -} ->
16541655
LLVMCrucibleSetupM TypedTerm {- ^ fresh typed term -}
16551656
llvm_fresh_var name lty =
@@ -1665,7 +1666,7 @@ llvm_fresh_var name lty =
16651666
Just cty -> Setup.freshVariable sc name cty
16661667

16671668
llvm_fresh_cryptol_var ::
1668-
String ->
1669+
Text ->
16691670
Cryptol.Schema ->
16701671
LLVMCrucibleSetupM TypedTerm
16711672
llvm_fresh_cryptol_var name s =

src/SAWScript/Crucible/LLVM/ResolveSetupValue.hs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Stability : provisional
1010
{-# LANGUAGE GADTs #-}
1111
{-# LANGUAGE LambdaCase #-}
1212
{-# LANGUAGE ImplicitParams #-}
13+
{-# LANGUAGE OverloadedStrings #-}
1314
{-# LANGUAGE ScopedTypeVariables #-}
1415
{-# LANGUAGE TypeApplications #-}
1516
{-# LANGUAGE TypeOperators #-}

src/SAWScript/Crucible/LLVM/Skeleton/Builtins.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ buildArg arg idx
202202
$ arg ^. argSkelType . typeSkelLLVMType
203203
pure (Just val, Nothing, arg ^. argSkelName)
204204
where
205-
ident = maybe ("arg" <> show idx) Text.unpack $ arg ^. argSkelName
205+
ident = maybe ("arg" <> Text.pack (show idx)) id $ arg ^. argSkelName
206206

207207
skeleton_prestate ::
208208
FunctionSkeleton ->
@@ -237,7 +237,7 @@ rebuildArg (arg, prearg) idx
237237
-> LLVM.Array (fromIntegral $ s ^. sizeGuessElems) pt
238238
| otherwise -> pt
239239
_ -> pt
240-
ident = maybe ("arg" <> show idx) Text.unpack nm
240+
ident = maybe ("arg" <> Text.pack (show idx)) id nm
241241
in do
242242
val' <- llvm_fresh_var ident t
243243
llvm_points_to True ptr $ anySetupTerm val'
@@ -255,7 +255,7 @@ skeleton_poststate skel prestate = do
255255
case skel ^. funSkelRet . typeSkelLLVMType of
256256
LLVM.PrimType LLVM.Void -> pure ()
257257
t -> do
258-
ret <- llvm_fresh_var ("return value of " <> (Text.unpack $ skel ^. funSkelName)) t
258+
ret <- llvm_fresh_var ("return value of " <> (skel ^. funSkelName)) t
259259
llvm_return $ anySetupTerm ret
260260
pure $ SkeletonState{..}
261261

src/SAWScript/JavaExpr.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import Language.JVM.Common (ppFldId)
6868

6969
import Data.List (intercalate)
7070
import Data.List.Split
71+
import Data.Text (Text)
7172
import qualified Data.Text as Text
7273
import qualified Data.Vector as V
7374
import Text.Read hiding (lift)
@@ -209,7 +210,7 @@ data LogicExpr =
209210
}
210211
deriving (Show)
211212

212-
scJavaValue :: SharedContext -> Term -> String -> IO Term
213+
scJavaValue :: SharedContext -> Term -> Text -> IO Term
213214
scJavaValue sc ty name = do
214215
scFreshGlobal sc name ty
215216

src/SAWScript/Proof.hs

+5-5
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ evalProp sc unints (Prop p) =
188188
Just t -> pure t
189189
Nothing -> fail "goal_eval: expected EqTrue"
190190

191-
ecs <- traverse (\(nm, ty) -> scFreshEC sc (Text.unpack nm) ty) args
191+
ecs <- traverse (\(nm, ty) -> scFreshEC sc nm ty) args
192192
vars <- traverse (scExtCns sc) ecs
193193
t0 <- instantiateVarList sc 0 (reverse vars) body'
194194

@@ -726,7 +726,7 @@ predicateToSATQuery sc unintSet tm0 =
726726
case evalFOT mmap tp of
727727
Nothing -> fail ("predicateToSATQuery: expected first order type: " ++ showTerm tp)
728728
Just fot ->
729-
do ec <- scFreshEC sc (Text.unpack lnm) tp
729+
do ec <- scFreshEC sc lnm tp
730730
etm <- scExtCns sc ec
731731
body' <- instantiateVar sc 0 etm body
732732
processTerm mmap (Map.insert ec fot vars) body'
@@ -779,7 +779,7 @@ propToSATQuery sc unintSet prop =
779779
case evalFOT mmap tp of
780780
Nothing -> fail ("propToSATQuery: expected first order type: " ++ showTerm tp)
781781
Just fot ->
782-
do ec <- scFreshEC sc (Text.unpack lnm) tp
782+
do ec <- scFreshEC sc lnm tp
783783
etm <- scExtCns sc ec
784784
body' <- instantiateVar sc 0 etm body
785785
processTerm mmap (Map.insert ec fot vars) xs body'
@@ -830,12 +830,12 @@ goalApply sc rule goal = applyFirst (asPiLists (unProp rule))
830830
-- for the binder. Return the generated fresh term.
831831
tacticIntro :: (F.MonadFail m, MonadIO m) =>
832832
SharedContext ->
833-
String {- ^ Name to give to the variable. If empty, will be chosen automatically from the goal. -} ->
833+
Text {- ^ Name to give to the variable. If empty, will be chosen automatically from the goal. -} ->
834834
Tactic m TypedTerm
835835
tacticIntro sc usernm = Tactic \goal ->
836836
case asPi (unProp (goalProp goal)) of
837837
Just (nm, tp, body) ->
838-
do let name = if null usernm then Text.unpack nm else usernm
838+
do let name = if Text.null usernm then nm else usernm
839839
xv <- liftIO $ scFreshEC sc name tp
840840
x <- liftIO $ scExtCns sc xv
841841
tt <- liftIO $ mkTypedTerm sc x

src/SAWScript/Prover/MRSolver.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import Control.Monad.Reader
1313
import Control.Monad.State
1414
import Control.Monad.Except
1515
import Data.Semigroup
16-
import qualified Data.Text as Text
1716

1817
import Prettyprinter
1918

@@ -614,7 +613,7 @@ askMRSolver sc smt_conf timeout t1 t2 =
614613
flip evalStateT init_st $ runExceptT $
615614
do mrSolveEq (Type tp1) (Type tp2)
616615
let (pi_args, ret_tp) = asPiList tp1
617-
vars <- mapM (\(x, x_tp) -> liftSC2 scFreshGlobal (Text.unpack x) x_tp) pi_args
616+
vars <- mapM (\(x, x_tp) -> liftSC2 scFreshGlobal x x_tp) pi_args
618617
case asCompMApp ret_tp of
619618
Just _ -> return ()
620619
Nothing -> throwError (NotCompFunType tp1)

0 commit comments

Comments
 (0)