Skip to content

Commit 7e7bafa

Browse files
committed
Merge branch 'master' into issue-1665--refactor
2 parents d63d128 + c31693a commit 7e7bafa

35 files changed

+657
-248
lines changed

kore/app/exec/Main.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ import Kore.IndexedModule.IndexedModule
8989
import qualified Kore.IndexedModule.MetadataToolsBuilder as MetadataTools
9090
( build
9191
)
92+
import qualified Kore.Internal.OrPattern as OrPattern
9293
import Kore.Internal.Pattern
9394
( Conditional (..)
9495
, Pattern
9596
)
96-
import qualified Kore.Internal.Pattern as Pattern
9797
import Kore.Internal.Predicate
9898
( makePredicate
9999
)
@@ -678,12 +678,15 @@ koreProve execOptions proveOptions = do
678678
maybeAlreadyProvenModule
679679

680680
(exitCode, final) <- case proveResult of
681-
Left Stuck { stuckPattern, provenClaims } -> do
681+
Left Stuck { stuckPatterns, provenClaims } -> do
682682
maybe
683683
(return ())
684684
(lift . saveProven specModule provenClaims)
685685
saveProofs
686-
return (failure $ Pattern.toTermLike stuckPattern)
686+
stuckPatterns
687+
& OrPattern.toTermLike
688+
& failure
689+
& return
687690
Right () -> return success
688691

689692
lift $ renderResult execOptions (unparse final)

kore/package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ library:
156156
source-dirs: src
157157

158158
_common-exe: &common-exe
159+
ghc-options: -eventlog
159160
when:
160161
- condition: flag(threaded)
161162
then:

kore/src/Kore/Attribute/Axiom.hs

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module Kore.Attribute.Axiom
2828
, Constructor (..)
2929
, RuleIndex (..)
3030
, UniqueId (..)
31+
, PriorityAttributes (..)
3132
, axiomSymbolToSymbolOrAlias
3233
, mapAxiomVariables
3334
, parseAxiomAttributes
@@ -207,8 +208,13 @@ instance
207208
, from . owise
208209
]
209210

210-
instance From (Axiom symbol variable) (Priority, Owise) where
211-
from Axiom { priority, owise } = (priority, owise)
211+
instance From (Axiom symbol variable) PriorityAttributes where
212+
from Axiom { priority, owise, simplification } =
213+
PriorityAttributes
214+
{ priorityAttr = priority
215+
, owiseAttr = owise
216+
, simplificationAttr = simplification
217+
}
212218

213219
instance From (Axiom symbol variable) HeatCool where
214220
from Axiom { heatCool } = heatCool
@@ -280,10 +286,49 @@ mapAxiomVariables adj axiom@Axiom { concrete, symbolic } =
280286
, symbolic = mapSymbolicVariables adj symbolic
281287
}
282288

289+
data PriorityAttributes =
290+
PriorityAttributes
291+
{ priorityAttr :: !Priority
292+
, owiseAttr :: !Owise
293+
, simplificationAttr :: !Simplification
294+
}
295+
283296
getPriorityOfAxiom
284-
:: forall attrs. From attrs (Priority, Owise) => attrs -> Integer
285-
getPriorityOfAxiom attrs
286-
| isOwise = owisePriority
287-
| otherwise = fromMaybe defaultPriority getPriority
288-
where
289-
(Priority { getPriority }, Owise { isOwise }) = from @attrs attrs
297+
:: forall attrs
298+
. HasCallStack
299+
=> From attrs PriorityAttributes
300+
=> attrs
301+
-> Integer
302+
getPriorityOfAxiom
303+
(from @attrs ->
304+
PriorityAttributes
305+
{ priorityAttr
306+
, owiseAttr
307+
, simplificationAttr
308+
}
309+
)
310+
=
311+
case (priorityAttr, owiseAttr, simplificationAttr) of
312+
(Priority Nothing, Owise True, NotSimplification) ->
313+
owisePriority
314+
(Priority Nothing, Owise False, NotSimplification) ->
315+
defaultPriority
316+
(Priority (Just value), Owise False, NotSimplification) ->
317+
value
318+
(Priority Nothing, Owise False, IsSimplification Nothing) ->
319+
defaultSimplificationPriority
320+
(Priority Nothing, Owise False, IsSimplification (Just value)) ->
321+
value
322+
-- TODO: remove this case once the frontend
323+
-- modifies the simplification attribute
324+
-- to take an optional priority value
325+
(Priority (Just value), Owise False, IsSimplification Nothing) ->
326+
value
327+
errorCase@(_, _, _) ->
328+
error
329+
("An axiom cannot have the following \
330+
\ combination of attributes: "
331+
<> show errorCase
332+
<> " Please report this error."
333+
)
334+

kore/src/Kore/Attribute/Parser.hs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module Kore.Attribute.Parser
4040
, getTwoParams
4141
, getZeroArguments
4242
, getOneArgument
43+
, getZeroOrOneArguments
4344
, getTwoArguments
4445
, getSymbolOrAlias
4546
, Kore.Attribute.Parser.getStringLiteral
@@ -278,6 +279,19 @@ getOneArgument =
278279
where
279280
arity = length args
280281

282+
getZeroOrOneArguments
283+
:: [AttributePattern]
284+
-> Parser (Maybe AttributePattern)
285+
getZeroOrOneArguments =
286+
\case
287+
[] -> return Nothing
288+
[arg] -> return (Just arg)
289+
args ->
290+
Kore.Error.koreFail
291+
("expected at most one argument, found " <> show arity)
292+
where
293+
arity = length args
294+
281295
{- | Accept exactly two arguments.
282296
-}
283297
getTwoArguments
@@ -317,7 +331,7 @@ getStringLiteral kore =
317331
_ :< StringLiteralF (Const lit) -> return lit
318332
_ -> Kore.Error.koreFail "expected string literal pattern"
319333

320-
{- | Accept a string literal.
334+
{- | Accept a variable.
321335
-}
322336
getVariable :: AttributePattern -> Parser (SomeVariable VariableName)
323337
getVariable kore =

kore/src/Kore/Attribute/Simplification.hs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,30 @@ Informal example of an axiom that would use the simplification attribute:
1919
module Kore.Attribute.Simplification
2020
( Simplification (..)
2121
, simplificationId, simplificationSymbol, simplificationAttribute
22+
, defaultSimplificationPriority
2223
) where
2324

2425
import Prelude.Kore
2526

27+
import Data.Maybe
28+
( maybeToList
29+
)
2630
import qualified Generics.SOP as SOP
2731
import qualified GHC.Generics as GHC
2832

2933
import Kore.Attribute.Parser as Parser
3034
import Kore.Debug
3135

36+
type SimplificationPriority = Maybe Integer
37+
3238
{- | @Simplification@ represents the @simplification@ attribute for axioms.
39+
It takes an optional integer argument which represents the rule's priority.
40+
This allows the possibility of ordering the application of simplification rules.
3341
-}
34-
newtype Simplification = Simplification { isSimplification :: Bool }
35-
deriving (Eq, GHC.Generic, Ord, Show)
42+
data Simplification
43+
= IsSimplification !SimplificationPriority
44+
| NotSimplification
45+
deriving (Eq, Ord, Show, GHC.Generic)
3646

3747
instance SOP.Generic Simplification
3848

@@ -45,7 +55,7 @@ instance Diff Simplification
4555
instance NFData Simplification
4656

4757
instance Default Simplification where
48-
def = Simplification False
58+
def = NotSimplification
4959

5060
-- | Kore identifier representing the @simplification@ attribute symbol.
5161
simplificationId :: Id
@@ -60,11 +70,36 @@ simplificationSymbol =
6070
}
6171

6272
-- | Kore pattern representing the @simplification@ attribute.
63-
simplificationAttribute :: AttributePattern
64-
simplificationAttribute = attributePattern_ simplificationSymbol
73+
simplificationAttribute :: Maybe Integer -> AttributePattern
74+
simplificationAttribute priority =
75+
attributePattern
76+
simplificationSymbol
77+
(fmap attributeInteger (maybeToList priority))
78+
79+
defaultSimplificationPriority :: Integer
80+
defaultSimplificationPriority = 50
6581

6682
instance ParseAttributes Simplification where
67-
parseAttribute = parseBoolAttribute simplificationId
83+
parseAttribute =
84+
withApplication' parseSimplification
85+
where
86+
parseSimplification params args NotSimplification = do
87+
Parser.getZeroParams params
88+
arg <- Parser.getZeroOrOneArguments args
89+
case arg of
90+
Just arg' -> do
91+
stringLiteral <- Parser.getStringLiteral arg'
92+
integer <- Parser.parseInteger stringLiteral
93+
return (IsSimplification (Just integer))
94+
Nothing ->
95+
return (IsSimplification Nothing)
96+
parseSimplification _ _ _ =
97+
failDuplicate'
98+
99+
withApplication' = Parser.withApplication simplificationId
100+
failDuplicate' = Parser.failDuplicate simplificationId
68101

69102
instance From Simplification Attributes where
70-
from = toBoolAttributes simplificationAttribute
103+
from NotSimplification = def
104+
from (IsSimplification maybePriority) =
105+
from @AttributePattern (simplificationAttribute maybePriority)

kore/src/Kore/Equation/Equation.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,9 @@ refreshVariables
354354

355355
isSimplificationRule :: Equation variable -> Bool
356356
isSimplificationRule Equation { attributes } =
357-
isSimplification
358-
where
359-
Attribute.Simplification { isSimplification } =
360-
Attribute.simplification attributes
357+
case Attribute.simplification attributes of
358+
Attribute.IsSimplification _ -> True
359+
_ -> False
361360

362361
equationPriority :: Equation variable -> Integer
363362
equationPriority = Attribute.getPriorityOfAxiom . attributes

kore/src/Kore/Exec.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,10 @@ exec breadthLimit verifiedModule strategy initialTerm =
224224
let
225225
updateQueue = \as ->
226226
Strategy.unfoldDepthFirst as
227-
>=> lift . Strategy.applyBreadthLimit breadthLimit
227+
>=> lift
228+
. Strategy.applyBreadthLimit
229+
breadthLimit
230+
dropStrategy
228231
transit instr config =
229232
Strategy.transitionRule transitionRule instr config
230233
& runTransitionT
@@ -238,6 +241,7 @@ exec breadthLimit verifiedModule strategy initialTerm =
238241
let finalTerm = forceSort initialSort $ Pattern.toTermLike finalConfig
239242
return (exitCode, finalTerm)
240243
where
244+
dropStrategy = snd
241245
-- Get the first final configuration of an execution graph.
242246
getFinalConfigOf = takeFirstResult >=> orElseBottom
243247
where

kore/src/Kore/Log/WarnBottomTotalFunction.hs renamed to kore/src/Kore/Log/ErrorBottomTotalFunction.hs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ License : NCSA
44
55
-}
66

7-
module Kore.Log.WarnBottomTotalFunction
8-
( WarnBottomTotalFunction (..)
9-
, warnBottomTotalFunction
7+
module Kore.Log.ErrorBottomTotalFunction
8+
( ErrorBottomTotalFunction (..)
9+
, errorBottomTotalFunction
1010
) where
1111

1212
import Prelude.Kore
@@ -29,35 +29,35 @@ import qualified Pretty
2929
import Log
3030
import qualified SQL
3131

32-
newtype WarnBottomTotalFunction =
33-
WarnBottomTotalFunction
32+
newtype ErrorBottomTotalFunction =
33+
ErrorBottomTotalFunction
3434
{ term :: TermLike VariableName
3535
}
3636
deriving (Show)
3737
deriving (GHC.Generic)
3838

39-
instance SOP.Generic WarnBottomTotalFunction
39+
instance SOP.Generic ErrorBottomTotalFunction
4040

41-
instance SOP.HasDatatypeInfo WarnBottomTotalFunction
41+
instance SOP.HasDatatypeInfo ErrorBottomTotalFunction
4242

43-
instance Pretty WarnBottomTotalFunction where
44-
pretty WarnBottomTotalFunction { term } =
43+
instance Pretty ErrorBottomTotalFunction where
44+
pretty ErrorBottomTotalFunction { term } =
4545
Pretty.vsep
4646
[ "Evaluating total function"
4747
, Pretty.indent 4 (unparse term)
4848
, "has resulted in \\bottom."
4949
]
5050

51-
instance Entry WarnBottomTotalFunction where
52-
entrySeverity _ = Warning
53-
helpDoc _ = "warn when a total function is undefined"
51+
instance Entry ErrorBottomTotalFunction where
52+
entrySeverity _ = Error
53+
helpDoc _ = "errors raised when a total function is undefined"
5454

55-
instance SQL.Table WarnBottomTotalFunction
55+
instance SQL.Table ErrorBottomTotalFunction
5656

57-
warnBottomTotalFunction
57+
errorBottomTotalFunction
5858
:: MonadLog logger
5959
=> InternalVariable variable
6060
=> TermLike variable
6161
-> logger ()
62-
warnBottomTotalFunction (mapVariables (pure toVariableName) -> term) =
63-
logEntry WarnBottomTotalFunction { term }
62+
errorBottomTotalFunction (mapVariables (pure toVariableName) -> term) =
63+
logEntry ErrorBottomTotalFunction { term }

kore/src/Kore/Log/Registry.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ import Kore.Log.DebugSubstitutionSimplifier
6262
import Kore.Log.DebugUnification
6363
( DebugUnification
6464
)
65+
import Kore.Log.ErrorBottomTotalFunction
66+
( ErrorBottomTotalFunction
67+
)
6568
import Kore.Log.ErrorException
6669
( ErrorException
6770
)
@@ -77,9 +80,6 @@ import Kore.Log.InfoAttemptUnification
7780
import Kore.Log.InfoReachability
7881
( InfoReachability
7982
)
80-
import Kore.Log.WarnBottomTotalFunction
81-
( WarnBottomTotalFunction
82-
)
8383
import Kore.Log.WarnDecidePredicateUnknown
8484
( WarnDecidePredicateUnknown
8585
)
@@ -131,7 +131,7 @@ entryHelpDocs :: [Pretty.Doc ()]
131131
, mk $ Proxy @DebugProofState
132132
, mk $ Proxy @DebugAppliedRewriteRules
133133
, mk $ Proxy @DebugSubstitutionSimplifier
134-
, mk $ Proxy @WarnBottomTotalFunction
134+
, mk $ Proxy @ErrorBottomTotalFunction
135135
, mk $ Proxy @WarnDecidePredicateUnknown
136136
, mk $ Proxy @WarnFunctionWithoutEvaluators
137137
, mk $ Proxy @WarnSymbolSMTRepresentation

kore/src/Kore/Log/SQLite.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import Kore.Log.DebugEvaluateCondition
3535
import Kore.Log.DebugSubstitutionSimplifier
3636
( DebugSubstitutionSimplifier
3737
)
38-
import Kore.Log.WarnBottomTotalFunction
39-
( WarnBottomTotalFunction
38+
import Kore.Log.ErrorBottomTotalFunction
39+
( ErrorBottomTotalFunction
4040
)
4141
import Kore.Log.WarnFunctionWithoutEvaluators
4242
( WarnFunctionWithoutEvaluators
@@ -127,7 +127,7 @@ foldMapEntries mapEntry =
127127
mconcat
128128
[ mapEntry (Proxy @DebugEvaluateCondition)
129129
, mapEntry (Proxy @DebugSubstitutionSimplifier)
130-
, mapEntry (Proxy @WarnBottomTotalFunction)
130+
, mapEntry (Proxy @ErrorBottomTotalFunction)
131131
, mapEntry (Proxy @WarnFunctionWithoutEvaluators)
132132
, mapEntry (Proxy @WarnSymbolSMTRepresentation)
133133
]

0 commit comments

Comments
 (0)