Skip to content

Commit 26d5649

Browse files
authored
Merge pull request #75 from Copilot-Language/T74-reject-multiple-triggers-same-name
Reject multiple triggers with the same name. Refs #74.
2 parents 9021bcc + 67b270e commit 26d5649

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

copilot-verifier/CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2025-01-20
2+
* Reject specs that use multiple triggers with the same name. (#74)
3+
14
2024-11-08
25
* Version bump (4.1). (#72)
36

copilot-verifier/src/Copilot/Verifier.hs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module Copilot.Verifier
2323
) where
2424

2525
import Control.Lens (view, (^.), to)
26-
import Control.Monad (foldM, forM_, when)
26+
import Control.Monad (foldM, forM_, unless, when)
2727
import Control.Monad.IO.Class (liftIO)
2828
import Control.Monad.State (execStateT, lift, StateT(..))
2929
import Data.Aeson (ToJSON)
@@ -33,7 +33,7 @@ import qualified Data.Text as Text
3333
import qualified Data.Map.Strict as Map
3434
import Data.IORef (newIORef, modifyIORef', readIORef, IORef)
3535
import qualified Text.LLVM.AST as L
36-
import Data.List (genericLength)
36+
import Data.List (genericLength, sort)
3737
import Data.List.NonEmpty (NonEmpty(..))
3838
import qualified Data.List.NonEmpty as NE
3939
import qualified Data.Vector as V
@@ -511,10 +511,26 @@ verifyStepBisimulation opts cruxOpts adapters csettings clRefs simctx llvmMod mo
511511
let prepTrigger (nm, guard, _) =
512512
do gv <- freshGlobalVar halloc (Text.pack (nm ++ "_called")) NatRepr
513513
return (nm, gv, guard)
514-
triggerGlobals <- mapM prepTrigger (CW4.triggerState prfbundle)
514+
515+
checkDuplicateTriggerNames :: [Name] -> IO ()
516+
checkDuplicateTriggerNames triggers =
517+
traverse_ checkDuplicateTriggerName $ NE.group $ sort triggers
518+
519+
checkDuplicateTriggerName :: NonEmpty Name -> IO ()
520+
checkDuplicateTriggerName (trig :| dupTrigs) =
521+
unless (null dupTrigs) $
522+
fail $ unlines
523+
[ "The specification invokes the `" ++ trig ++
524+
"` trigger function multiple times,"
525+
, "which copilot-verifier does not currently support."
526+
, "See https://github.com/Copilot-Language/copilot-verifier/issues/74."
527+
]
528+
let triggerState = CW4.triggerState prfbundle
529+
checkDuplicateTriggerNames $ map (\(nm,_,_) -> nm) triggerState
530+
triggerGlobals <- mapM prepTrigger triggerState
515531

516532
-- execute the step function
517-
let overrides = zipWith (triggerOverride clRefs) triggerGlobals (CW4.triggerState prfbundle)
533+
let overrides = zipWith (triggerOverride clRefs) triggerGlobals triggerState
518534
mem'' <- executeStep opts csettings clRefs simctx memVar mem' llvmMod modTrans triggerGlobals overrides (CW4.assumptions prfbundle) (CW4.sideConds prfbundle)
519535

520536
-- assert the poststate is in the relation

0 commit comments

Comments
 (0)