Skip to content

Commit 0bd9dc6

Browse files
Unification returns an 'Or' (#390)
1 parent 40be854 commit 0bd9dc6

File tree

27 files changed

+1055
-704
lines changed

27 files changed

+1055
-704
lines changed

src/main/haskell/kore/src/Kore/Builtin/Builtin.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ notImplemented :: Function
264264
notImplemented =
265265
ApplicationFunctionEvaluator notImplemented0
266266
where
267-
notImplemented0 _ _ _ _ = pure (NotApplicable, SimplificationProof)
267+
notImplemented0 _ _ _ _ = pure [(NotApplicable, SimplificationProof)]
268268

269269
{- | Verify a builtin sort declaration.
270270
@@ -630,9 +630,10 @@ functionEvaluator impl =
630630
-> StepPatternSimplifier Object variable
631631
-> Application Object (StepPattern Object variable)
632632
-> Simplifier
633-
( AttemptedFunction Object variable
634-
, SimplificationProof Object
635-
)
633+
[ ( AttemptedFunction Object variable
634+
, SimplificationProof Object
635+
)
636+
]
636637
evaluator
637638
tools
638639
_
@@ -642,10 +643,9 @@ functionEvaluator impl =
642643
(MetadataTools.getResultSort tools -> resultSort)
643644
, applicationChildren
644645
}
645-
=
646-
do
647-
attempt <- impl tools simplifier resultSort applicationChildren
648-
return (attempt, SimplificationProof)
646+
= do
647+
attempt <- impl tools simplifier resultSort applicationChildren
648+
return [(attempt, SimplificationProof)]
649649

650650
{- | Run a parser on a verified domain value.
651651

src/main/haskell/kore/src/Kore/Builtin/KEqual.hs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ evalKEq
127127
-> StepPatternSimplifier Object variable
128128
-> Application Object (StepPattern Object variable)
129129
-> Simplifier
130-
( AttemptedFunction Object variable
131-
, SimplificationProof Object
132-
)
130+
[ ( AttemptedFunction Object variable
131+
, SimplificationProof Object
132+
)
133+
]
133134
evalKEq true false tools substitutionSimplifier _ pat =
134135
case pat of
135136
Application
@@ -162,9 +163,10 @@ evalKIte
162163
-> StepPatternSimplifier Object variable
163164
-> Application Object (StepPattern Object variable)
164165
-> Simplifier
165-
( AttemptedFunction Object variable
166-
, SimplificationProof Object
167-
)
166+
[ ( AttemptedFunction Object variable
167+
, SimplificationProof Object
168+
)
169+
]
168170
evalKIte _ _ _ =
169171
\case
170172
Application { applicationChildren = [expr, t1, t2] } ->

src/main/haskell/kore/src/Kore/Exec.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,11 @@ search
142142
simplifier
143143
target
144144
config
145-
solutions <- searchGraph searchConfig (match searchPattern) executionGraph
145+
solutionsLists <-
146+
searchGraph searchConfig (match searchPattern) executionGraph
146147
let
148+
solutions =
149+
concatMap OrOfExpandedPattern.extractPatterns solutionsLists
147150
orPredicate =
148151
give (symbolOrAliasSorts metadataTools)
149152
$ makeMultipleOrPredicate

src/main/haskell/kore/src/Kore/OnePath/Step.hs

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ import Kore.Step.Strategy
6464
( Strategy )
6565
import qualified Kore.Step.Strategy as Strategy
6666

67-
6867
{- | A strategy primitive: a rewrite rule or builtin simplification step.
6968
-}
7069
data Prim patt rewrite =
@@ -235,38 +234,73 @@ transitionRule
235234
]
236235
transitionApplyWithRemainders _ c@(Bottom, _) = return [c]
237236
transitionApplyWithRemainders _ c@(Stuck _, _) = return [c]
238-
transitionApplyWithRemainders _ (RewritePattern config, _)
237+
transitionApplyWithRemainders
238+
rules
239+
(RewritePattern config, proof)
240+
= transitionMultiApplyWithRemainders rules (config, proof)
241+
242+
transitionMultiApplyWithRemainders
243+
:: [RewriteRule level]
244+
-> ( CommonExpandedPattern level
245+
, StepProof level Variable
246+
)
247+
-> Simplifier
248+
[ ( StrategyPattern (CommonExpandedPattern level)
249+
, StepProof level Variable
250+
)
251+
]
252+
transitionMultiApplyWithRemainders _ (config, _)
239253
| ExpandedPattern.isBottom config = return []
240-
transitionApplyWithRemainders [] (RewritePattern config, proof) =
254+
transitionMultiApplyWithRemainders [] (config, proof) =
241255
return [(Stuck config, proof)]
242-
transitionApplyWithRemainders
256+
transitionMultiApplyWithRemainders
243257
(rule : rules)
244-
patt@(RewritePattern config, proof)
258+
patt@(config, proof)
245259
= do
246-
result <- runExceptT
260+
resultsEither <- runExceptT
247261
$ stepWithRule tools substitutionSimplifier config rule
248-
case result of
249-
Left _ -> transitionApplyWithRemainders rules patt
250-
Right
251-
( StepResult
252-
{ rewrittenPattern
253-
, remainder
254-
}
255-
, proof') -> do
256-
let
257-
combinedProof = proof <> proof'
258-
wrappedRewritten =
259-
if ExpandedPattern.isBottom rewrittenPattern
260-
then Bottom
261-
else RewritePattern rewrittenPattern
262-
remainderResults <-
263-
transitionApplyWithRemainders
264-
rules
265-
(RewritePattern remainder, combinedProof)
266-
return ((wrappedRewritten, proof) : remainderResults)
262+
case resultsEither of
263+
Left _ -> transitionMultiApplyWithRemainders rules patt
264+
Right results -> do
265+
let
266+
rewritten
267+
:: [ ( StrategyPattern (CommonExpandedPattern level)
268+
, StepProof level Variable
269+
)
270+
]
271+
remainders
272+
:: [ ( CommonExpandedPattern level
273+
, StepProof level Variable
274+
)
275+
]
276+
(rewritten, remainders) =
277+
if null results
278+
then ([(Bottom, proof)], [patt])
279+
else unzip (map splitStepResult results)
280+
rewrittenRemainders <-
281+
mapM (transitionMultiApplyWithRemainders rules) remainders
282+
return (concat (rewritten : rewrittenRemainders))
283+
where
284+
splitStepResult
285+
( StepResult
286+
{ rewrittenPattern
287+
, remainder
288+
}
289+
, proof'
290+
)
291+
=
292+
if ExpandedPattern.isBottom rewrittenPattern
293+
then ((Bottom, combinedProof), (remainder, combinedProof))
294+
else
295+
( (RewritePattern rewrittenPattern, combinedProof)
296+
, (remainder, combinedProof)
297+
)
298+
where
299+
combinedProof = proof <> proof'
300+
267301

268302
transitionRemoveDestination
269-
:: (CommonExpandedPattern level)
303+
:: CommonExpandedPattern level
270304
-> ( StrategyPattern (CommonExpandedPattern level)
271305
, StepProof level Variable
272306
)
@@ -303,14 +337,13 @@ transitionRule
303337
let
304338
finalProof = proof1 <> StepProof.simplificationProof proof
305339
patternsWithProofs =
306-
(map
340+
map
307341
(\p ->
308342
( RewritePattern p
309343
, finalProof
310344
)
311345
)
312346
(ExpandedPattern.extractPatterns orResult)
313-
)
314347
if null patternsWithProofs
315348
then return [(Bottom, finalProof)]
316349
else return patternsWithProofs

0 commit comments

Comments
 (0)