Skip to content

Commit 7670313

Browse files
authored
Merge pull request #2474 from GaloisInc/bh/variable
saw-core: Rename 'ExtCns' term constructor to 'Variable'.
2 parents 30e6e90 + 7350a49 commit 7670313

File tree

39 files changed

+160
-161
lines changed

39 files changed

+160
-161
lines changed

crucible-mir-comp/src/Mir/Compositional/Builder.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import Lang.Crucible.Simulator
4646
import Lang.Crucible.Types
4747

4848
import qualified SAWCore.Prelude as SAW
49-
import qualified SAWCore.Recognizer as SAW (asExtCns)
49+
import qualified SAWCore.Recognizer as SAW (asVariable)
5050
import qualified SAWCore.SharedTerm as SAW
5151
import qualified SAWCoreWhat4.ReturnTrip as SAW
5252
import qualified CryptolSAWCore.TypedTerm as SAW
@@ -399,7 +399,7 @@ gatherAsserts msb =
399399
gatherSubsts postOnlyVars vars [] [] asserts'
400400
substTerms <- forM substs $ \(Pair var expr) -> do
401401
varTerm <- liftIO $ eval $ W4.BoundVarExpr var
402-
varEc <- case SAW.asExtCns varTerm of
402+
varEc <- case SAW.asVariable varTerm of
403403
Just ec -> return ec
404404
Nothing -> error $ "eval of BoundVarExpr produced non-ExtCns ?" ++ show varTerm
405405
exprTerm <- liftIO $ eval expr

crucible-mir-comp/src/Mir/Compositional/Convert.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ exprToTerm sym sc w4VarMapRef val = liftIO $ do
330330
ty <- SAW.baseSCType sym sc (W4.exprType val)
331331
ec <- SAW.scFreshEC sc "w4expr" ty
332332
modifyIORef w4VarMapRef $ Map.insert (SAW.ecVarIndex ec) (Some val)
333-
term <- SAW.scExtCns sc ec
333+
term <- SAW.scVariable sc ec
334334
return term
335335

336336
regToTerm :: forall sym t st fs tp0 m.

crucible-mir-comp/src/Mir/Compositional/Override.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ matchArg sym sc eval allocSpecs md shp0 rv0 sv0 = go shp0 rv0 sv0
365365
go (PrimShape _ _btpr) expr (MS.SetupTerm tt) = do
366366
loc <- use MS.osLocation
367367
exprTerm <- liftIO $ eval expr
368-
case SAW.asExtCns $ SAW.ttTerm tt of
368+
case SAW.asVariable $ SAW.ttTerm tt of
369369
Just ec -> do
370370
let var = SAW.ecVarIndex ec
371371
sub <- use MS.termSub

crux-mir-comp/src/Mir/Cryptol.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import qualified CryptolSAWCore.Prelude as SAW
5858
import qualified CryptolSAWCore.CryptolEnv as SAW
5959
import qualified SAWCore.SharedTerm as SAW
6060
import qualified SAWCoreWhat4.ReturnTrip as SAW
61-
import qualified SAWCore.Recognizer as SAW (asExtCns)
61+
import qualified SAWCore.Recognizer as SAW (asVariable)
6262
import qualified CryptolSAWCore.TypedTerm as SAW
6363

6464
import SAWCentral.Crucible.MIR.TypeShape
@@ -303,7 +303,7 @@ munge sym shp0 rv0 = do
303303
visitExprVars visitCache x $ \var -> do
304304
let expr = W4.BoundVarExpr var
305305
term <- eval' expr
306-
ec <- case SAW.asExtCns term of
306+
ec <- case SAW.asVariable term of
307307
Just ec -> return ec
308308
Nothing -> error "eval on BoundVarExpr produced non-ExtCns?"
309309
modifyIORef w4VarMapRef $ Map.insert (SAW.ecVarIndex ec) (Some expr)

cryptol-saw-core/src/CryptolSAWCore/Monadify.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ asTypedGlobalDef t =
173173
Constant nm ->
174174
let ty = resolvedNameType (requireNameInMap nm ?mm)
175175
in Just $ GlobalDef (nameInfo nm) (nameIndex nm) ty t
176-
FTermF (ExtCns ec) ->
176+
FTermF (Variable ec) ->
177177
Just $ GlobalDef (ecName ec) (ecVarIndex ec) (ecType ec) t
178178
_ -> Nothing
179179

cryptol-saw-core/src/CryptolSAWCore/TypedTerm.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import qualified SAWSupport.Pretty as PPS (defaultOpts)
2929

3030
import CryptolSAWCore.Cryptol (scCryptolType, Env, importKind, importSchema)
3131
import SAWCore.FiniteValue
32-
import SAWCore.Recognizer (asExtCns)
32+
import SAWCore.Recognizer (asVariable)
3333
import SAWCore.SharedTerm
3434
import SAWCore.SCTypeCheck (scTypeCheckError)
3535
import SAWCore.Term.Pretty (ppTerm)
@@ -189,7 +189,7 @@ typedTermOfFirstOrderValue sc fov =
189189
t <- scFirstOrderValue sc fov
190190
pure $ TypedTerm (TypedTermSchema (C.tMono cty)) t
191191

192-
-- Typed external constants ----------------------------------------------------
192+
-- Typed named variables -------------------------------------------------------
193193

194194
data TypedExtCns =
195195
TypedExtCns
@@ -198,17 +198,17 @@ data TypedExtCns =
198198
}
199199
deriving Show
200200

201-
-- | Recognize 'TypedTerm's that are external constants.
201+
-- | Recognize 'TypedTerm's that are named variables.
202202
asTypedExtCns :: TypedTerm -> Maybe TypedExtCns
203203
asTypedExtCns (TypedTerm tp t) =
204204
do cty <- ttIsMono tp
205-
ec <- asExtCns t
205+
ec <- asVariable t
206206
pure $ TypedExtCns cty ec
207207

208208
-- | Make a 'TypedTerm' from a 'TypedExtCns'.
209209
typedTermOfExtCns :: SharedContext -> TypedExtCns -> IO TypedTerm
210210
typedTermOfExtCns sc (TypedExtCns cty ec) =
211-
TypedTerm (TypedTermSchema (C.tMono cty)) <$> scExtCns sc ec
211+
TypedTerm (TypedTermSchema (C.tMono cty)) <$> scVariable sc ec
212212

213213
abstractTypedExts :: SharedContext -> [TypedExtCns] -> TypedTerm -> IO TypedTerm
214214
abstractTypedExts sc tecs (TypedTerm (TypedTermSchema (C.Forall params props ty)) trm) =

saw-central/src/SAWCentral/Builtins.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ extract_uninterp unints opaques tt =
758758
let tt' = tt{ ttTerm = tm }
759759

760760
let f = traverse $ \(ec,vs) ->
761-
do ectm <- scExtCns sc ec
761+
do ectm <- scVariable sc ec
762762
vs' <- filterCryTerms sc vs
763763
pure (ectm, vs')
764764
repls' <- io (traverse f repls)
@@ -779,7 +779,7 @@ extract_uninterp unints opaques tt =
779779
unless (Set.null boundAndUsed)
780780
(do ppOpts <- getTopLevelPPOpts
781781
vs <- io $ forM (Set.toList boundAndUsed) $ \ec ->
782-
do pptm <- scPrettyTerm ppOpts <$> scExtCns sc ec
782+
do pptm <- scPrettyTerm ppOpts <$> scVariable sc ec
783783
let ppty = scPrettyTerm ppOpts (ecType ec)
784784
return (pptm <> " : " <> ppty)
785785
printOutLnTop Warn $ unlines $
@@ -827,17 +827,17 @@ build_congruence sc tm =
827827
fail "congruence_for: cannot build congruence for dependent functions"
828828

829829
loop [] vars =
830-
do lvars <- mapM (scExtCns sc . fst) (reverse vars)
831-
rvars <- mapM (scExtCns sc . snd) (reverse vars)
830+
do lvars <- mapM (scVariable sc . fst) (reverse vars)
831+
rvars <- mapM (scVariable sc . snd) (reverse vars)
832832
let allVars = concat [ [l,r] | (l,r) <- reverse vars ]
833833

834834
basel <- scApplyAll sc tm lvars
835835
baser <- scApplyAll sc tm rvars
836836
baseeq <- scEqTrue sc =<< scEq sc basel baser
837837

838838
let f x (l,r) =
839-
do l' <- scExtCns sc l
840-
r' <- scExtCns sc r
839+
do l' <- scVariable sc l
840+
r' <- scVariable sc r
841841
eq <- scEqTrue sc =<< scEq sc l' r'
842842
scFun sc eq x
843843
finalEq <- foldM f baseeq vars
@@ -1345,7 +1345,7 @@ proveByBVInduction script t =
13451345
do wt <- io $ scNat sc w
13461346
natty <- io $ scNatType sc
13471347
toNat <- io $ scGlobalDef sc "Prelude.bvToNat"
1348-
vars <- io $ mapM (scExtCns sc) pis
1348+
vars <- io $ mapM (scVariable sc) pis
13491349
innerVars <-
13501350
io $ sequence $
13511351
[ scFreshGlobal sc ("i_" <> toShortName (ecName ec)) (ecType ec) | ec <- pis ]

saw-central/src/SAWCentral/Crucible/Common/Override.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ refreshTerms sc ss =
552552
where
553553
freshenTerm (TypedExtCns _cty ec) =
554554
do ec' <- liftIO $ scFreshEC sc (toShortName (ecName ec)) (ecType ec)
555-
new <- liftIO $ scExtCns sc ec'
555+
new <- liftIO $ scVariable sc ec'
556556
return (ecVarIndex ec, new)
557557

558558
-- | An override packaged together with its preconditions, labeled with some
@@ -723,7 +723,7 @@ matchTerm sc md prepost real expect =
723723
do let loc = MS.conditionLoc md
724724
free <- OM (use osFree)
725725
case unwrapTermF expect of
726-
FTermF (ExtCns ec)
726+
FTermF (Variable ec)
727727
| Set.member (ecVarIndex ec) free ->
728728
do assignTerm sc md prepost (ecVarIndex ec) real
729729

saw-central/src/SAWCentral/Crucible/JVM/Builtins.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ verifyPoststate cc mspec env0 globals ret mdMap =
790790
[ (ecVarIndex ec, ec)
791791
| tt <- mspec ^. MS.csPreState . MS.csFreshVars
792792
, let ec = tecExt tt ]
793-
terms0 <- io $ traverse (scExtCns sc) ecs0
793+
terms0 <- io $ traverse (scVariable sc) ecs0
794794

795795
let initialFree = Set.fromList (map (ecVarIndex . tecExt)
796796
(view (MS.csPostState . MS.csFreshVars) mspec))

saw-central/src/SAWCentral/Crucible/LLVM/Builtins.hs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,12 @@ llvm_compositional_extract (Some lm) nm func_name lemmas checkSat setup tactic =
394394
lemmas' <- checkModuleCompatibility lm lemmas
395395
withMethodSpec checkSat lm nm setup $ \cc method_spec ->
396396
do let value_input_parameters = mapMaybe
397-
(\(_, setup_value) -> setupValueAsExtCns setup_value)
397+
(\(_, setup_value) -> setupValueAsVariable setup_value)
398398
(Map.elems $ method_spec ^. MS.csArgBindings)
399399
let reference_input_parameters = mapMaybe
400400
(\case
401-
LLVMPointsTo _ _ _ setup_value -> llvmPointsToValueAsExtCns setup_value
402-
LLVMPointsToBitfield _ _ _ val -> setupValueAsExtCns val)
401+
LLVMPointsTo _ _ _ setup_value -> llvmPointsToValueAsVariable setup_value
402+
LLVMPointsToBitfield _ _ _ val -> setupValueAsVariable val)
403403
(method_spec ^. MS.csPreState ^. MS.csPointsTos)
404404
let input_parameters = nub $ value_input_parameters ++ reference_input_parameters
405405
let pre_free_variables = Map.fromList $
@@ -416,13 +416,13 @@ llvm_compositional_extract (Some lm) nm func_name lemmas checkSat setup tactic =
416416

417417
let return_output_parameter =
418418
case method_spec ^. MS.csRetValue of
419-
Just setup_value -> setupValueAsExtCns setup_value
419+
Just setup_value -> setupValueAsVariable setup_value
420420
Nothing -> Nothing
421421
let reference_output_parameters =
422422
mapMaybe
423423
(\case
424-
LLVMPointsTo _ _ _ setup_value -> llvmPointsToValueAsExtCns setup_value
425-
LLVMPointsToBitfield _ _ _ val -> setupValueAsExtCns val)
424+
LLVMPointsTo _ _ _ setup_value -> llvmPointsToValueAsVariable setup_value
425+
LLVMPointsToBitfield _ _ _ val -> setupValueAsVariable val)
426426
(method_spec ^. MS.csPostState ^. MS.csPointsTos)
427427
let output_parameters =
428428
nub $ filter (isNothing . (Map.!?) pre_free_variables) $
@@ -458,7 +458,7 @@ llvm_compositional_extract (Some lm) nm func_name lemmas checkSat setup tactic =
458458
extracted_func_const <-
459459
io $ scConstant' shared_context nmi extracted_func
460460
=<< scTypeOf shared_context extracted_func
461-
input_terms <- io $ traverse (scExtCns shared_context) input_parameters
461+
input_terms <- io $ traverse (scVariable shared_context) input_parameters
462462
applied_extracted_func <- io $ scApplyAll shared_context extracted_func_const input_terms
463463
applied_extracted_func_selectors <-
464464
io $ forM [1 .. (length output_parameters)] $ \i ->
@@ -512,17 +512,17 @@ llvm_compositional_extract (Some lm) nm func_name lemmas checkSat setup tactic =
512512
ps <- io (MS.mkProvedSpec MS.SpecProved extracted_method_spec stats vcs lemmaSet diff)
513513
returnLLVMProof (SomeLLVM ps)
514514

515-
setupValueAsExtCns :: SetupValue (LLVM arch) -> Maybe (ExtCns Term)
516-
setupValueAsExtCns =
515+
setupValueAsVariable :: SetupValue (LLVM arch) -> Maybe (ExtCns Term)
516+
setupValueAsVariable =
517517
\case
518-
SetupTerm term -> asExtCns $ ttTerm term
518+
SetupTerm term -> asVariable $ ttTerm term
519519
_ -> Nothing
520520

521-
llvmPointsToValueAsExtCns :: LLVMPointsToValue arch -> Maybe (ExtCns Term)
522-
llvmPointsToValueAsExtCns =
521+
llvmPointsToValueAsVariable :: LLVMPointsToValue arch -> Maybe (ExtCns Term)
522+
llvmPointsToValueAsVariable =
523523
\case
524-
ConcreteSizeValue val -> setupValueAsExtCns val
525-
SymbolicSizeValue arr _sz -> asExtCns $ ttTerm arr
524+
ConcreteSizeValue val -> setupValueAsVariable val
525+
SymbolicSizeValue arr _sz -> asVariable $ ttTerm arr
526526

527527
-- | Check that all the overrides/lemmas were actually from this module
528528
checkModuleCompatibility ::
@@ -1599,7 +1599,7 @@ verifyPoststate cc mspec env0 globals ret mdMap invSubst =
15991599
[ (ecVarIndex ec, ec)
16001600
| tt <- mspec ^. MS.csPreState . MS.csFreshVars
16011601
, let ec = tecExt tt ]
1602-
terms0 <- io $ traverse (scExtCns sc) ecs0
1602+
terms0 <- io $ traverse (scVariable sc) ecs0
16031603

16041604
let initialFree =
16051605
Set.fromList
@@ -1888,7 +1888,7 @@ setupArg sc sym ecRef tp = do
18881888
let len = Seq.length ecs
18891889
ec <- scFreshEC sc ("arg_" <> Text.pack (show len)) sc_tp
18901890
writeIORef ecRef (ecs Seq.|> TypedExtCns cty ec)
1891-
scFlatTermF sc (ExtCns ec)
1891+
scVariable sc ec
18921892

18931893
setupArgs ::
18941894
SharedContext ->

0 commit comments

Comments
 (0)