Skip to content

Commit bedb3ca

Browse files
authored
Do not ignore antiLeft if argument is Nothing (#2366)
* Do not ignore antiLeft if argument is Nothing * Add integration test
1 parent 19f7475 commit bedb3ca

File tree

5 files changed

+60
-25
lines changed

5 files changed

+60
-25
lines changed

kore/src/Kore/Equation/Application.hs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -158,28 +158,7 @@ attemptEquation
158158
attemptEquation sideCondition termLike equation =
159159
whileDebugAttemptEquation' $ runExceptT $ do
160160
let Equation { left, argument, antiLeft } = equationRenamed
161-
(equation', predicate) <-
162-
case argument of
163-
Nothing -> do
164-
matchResult <- match left termLike & whileMatch
165-
applyMatchResult equationRenamed matchResult
166-
& whileApplyMatchResult
167-
Just argument' -> do
168-
(matchPredicate, matchSubstitution) <-
169-
match left termLike
170-
& whileMatch
171-
matchResults <-
172-
applySubstitutionAndSimplify
173-
argument'
174-
antiLeft
175-
matchSubstitution
176-
& whileMatch
177-
(equation', predicate) <-
178-
applyAndSelectMatchResult matchResults
179-
return
180-
( equation'
181-
, makeAndPredicate predicate matchPredicate
182-
)
161+
(equation', predicate) <- matchAndApplyResults left argument antiLeft
183162
let Equation { requires } = equation'
184163
checkRequires sideCondition predicate requires & whileCheckRequires
185164
let Equation { right, ensures } = equation'
@@ -195,6 +174,29 @@ attemptEquation sideCondition termLike equation =
195174
matchIncremental term1 term2
196175
& MaybeT & noteT matchError
197176

177+
matchAndApplyResults left' argument' antiLeft'
178+
| isNothing argument'
179+
, isNothing antiLeft' = do
180+
matchResult <- match left' termLike & whileMatch
181+
applyMatchResult equationRenamed matchResult
182+
& whileApplyMatchResult
183+
| otherwise = do
184+
(matchPredicate, matchSubstitution) <-
185+
match left' termLike
186+
& whileMatch
187+
matchResults <-
188+
applySubstitutionAndSimplify
189+
argument'
190+
antiLeft'
191+
matchSubstitution
192+
& whileMatch
193+
(equation', predicate) <-
194+
applyAndSelectMatchResult matchResults
195+
return
196+
( equation'
197+
, makeAndPredicate predicate matchPredicate
198+
)
199+
198200
applyAndSelectMatchResult
199201
:: [MatchResult variable]
200202
-> ExceptT
@@ -227,7 +229,7 @@ applySubstitutionAndSimplify
227229
:: HasCallStack
228230
=> MonadSimplify simplifier
229231
=> InternalVariable variable
230-
=> Predicate variable
232+
=> Maybe (Predicate variable)
231233
-> Maybe (Predicate variable)
232234
-> Map (SomeVariableName variable) (TermLike variable)
233235
-> ExceptT
@@ -244,7 +246,7 @@ applySubstitutionAndSimplify
244246
(predicate, Substitution.toMap substitution)
245247
Substitution.mergePredicatesAndSubstitutions
246248
SideCondition.top
247-
(argument : maybeToList antiLeft)
249+
(maybeToList argument <> maybeToList antiLeft)
248250
[from @_ @(Substitution _) matchSubstitution]
249251
& Logic.observeAllT
250252
& (fmap . fmap) toMatchResult

kore/test/Test/Kore/Equation/Application.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ test_applySubstitutionAndSimplify =
501501
)
502502
(Right [actual]) <-
503503
applySubstitutionAndSimplify
504-
mockArgument
504+
(Just mockArgument)
505505
Nothing
506506
mempty
507507
& runExceptT

test/priority/priority-1-spec.k

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module VERIFICATION
2+
imports PRIORITY
3+
4+
syntax KItem ::= runTest ( S )
5+
| doneTest ( S )
6+
7+
rule runTest ( T ) => doneTest ( T )
8+
9+
endmodule
10+
11+
module PRIORITY-1-SPEC
12+
imports VERIFICATION
13+
14+
// This claim should not be provable.
15+
claim <k> runTest ( func4(X:Int) ) => doneTest ( seven ) ... </k>
16+
17+
endmodule
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#Ceil ( func4 ( X ) )
2+
#And
3+
#Not ( {
4+
seven
5+
#Equals
6+
func4 ( X )
7+
} )
8+
#And
9+
<k>
10+
doneTest ( func4 ( X ) ) ~> _DotVar1 ~> .
11+
</k>

test/priority/priority.k

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@ module PRIORITY
3333
rule func3(6) => six
3434
rule func3(_:Int) => seven [owise]
3535

36+
syntax S ::= func4(Int) [function]
37+
rule func4(X:Int) => four
38+
requires func3(X) ==K four
39+
rule func4(_:Int) => seven [owise]
40+
3641
endmodule

0 commit comments

Comments
 (0)