Skip to content

Commit 9a77ee5

Browse files
authored
Fix SideCondition normalization error (#2239)
* Pattern.simplify: Avoid SideCondition normalization problems * Add test/issue-2221
1 parent 6b439ed commit 9a77ee5

File tree

6 files changed

+2910
-1
lines changed

6 files changed

+2910
-1
lines changed

kore/src/Kore/Step/Simplification/Pattern.hs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Kore.Step.Simplification.Pattern
1111
import Prelude.Kore
1212

1313

14+
import qualified Kore.Internal.Condition as Condition
1415
import qualified Kore.Internal.Conditional as Conditional
1516
import Kore.Internal.OrPattern
1617
( OrPattern
@@ -75,8 +76,19 @@ simplify sideCondition pattern' =
7576
let (term, simplifiedCondition) =
7677
Conditional.splitTerm withSimplifiedCondition
7778
term' = substitute (toMap $ substitution simplifiedCondition) term
79+
simplifiedCondition' =
80+
-- Combine the predicate and the substitution. The substitution
81+
-- has already been applied to the term being simplified. This
82+
-- is only to make SideCondition.andCondition happy, below,
83+
-- because there might be substitution variables in
84+
-- sideCondition. That's allowed because we are only going to
85+
-- send the side condition to the solver, but we should probably
86+
-- fix SideCondition.andCondition instead.
87+
simplifiedCondition
88+
& Condition.toPredicate
89+
& Condition.fromPredicate
7890
termSideCondition =
79-
sideCondition `SideCondition.andCondition` simplifiedCondition
91+
sideCondition `SideCondition.andCondition` simplifiedCondition'
8092
simplifiedTerm <- simplifyConditionalTerm termSideCondition term'
8193
let simplifiedPattern =
8294
Conditional.andCondition simplifiedTerm simplifiedCondition

test/issue-2221/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include $(CURDIR)/../include.mk

test/issue-2221/spec.kore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[]
2+
module INVALID-SIZE
3+
4+
// imports
5+
import LIST-SIZER []
6+
7+
8+
// claims
9+
// claim `<generatedTop>`(`<k>`(inj{MyList,KItem}(_0)),_DotVar0,`<size>`(#token("0","Int")))=>`<generatedTop>`(`<k>`(.K),_DotVar0,`<size>`(#token("0","Int"))) requires #token("true","Bool") ensures #token("true","Bool") [contentStartColumn(9), contentStartLine(4), org.kframework.attributes.Location(Location(4,9,5,25)), org.kframework.attributes.Source(Source(/home/stephen/work/k-experiments/list-sizer/././specs/invalid-size.spec)), org.kframework.definition.Production(syntax #RuleContent ::= #RuleBody [klabel(#ruleNoConditions), symbol])]
10+
claim{} \implies{SortGeneratedTopCell{}} (
11+
\and{SortGeneratedTopCell{}} (
12+
\top{SortGeneratedTopCell{}}(), Lbl'-LT-'generatedTop'-GT-'{}(Lbl'-LT-'k'-GT-'{}(kseq{}(inj{SortMyList{}, SortKItem{}}(Var'Unds'0:SortMyList{}),dotk{}())),Var'Unds'DotVar0:SortGeneratedCounterCell{},Lbl'-LT-'size'-GT-'{}(\dv{SortInt{}}("0")))), weakAlwaysFinally{SortGeneratedTopCell{}} (
13+
\and{SortGeneratedTopCell{}} (
14+
\top{SortGeneratedTopCell{}}(), Lbl'-LT-'generatedTop'-GT-'{}(Lbl'-LT-'k'-GT-'{}(dotk{}()),Var'Unds'DotVar0:SortGeneratedCounterCell{},Lbl'-LT-'size'-GT-'{}(\dv{SortInt{}}("0"))))))
15+
[org'Stop'kframework'Stop'attributes'Stop'Source{}("Source(/home/stephen/work/k-experiments/list-sizer/././specs/invalid-size.spec)"), org'Stop'kframework'Stop'definition'Stop'Production{}(), contentStartLine{}(), contentStartColumn{}(), org'Stop'kframework'Stop'attributes'Stop'Location{}("Location(4,9,5,25)")]
16+
17+
endmodule [org'Stop'kframework'Stop'attributes'Stop'Location{}("Location(1,1,6,9)"), org'Stop'kframework'Stop'attributes'Stop'Source{}("Source(/home/stephen/work/k-experiments/list-sizer/././specs/invalid-size.spec)")]

test/issue-2221/test-issue-2221.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
exec kore-exec \
3+
vdefinition.kore \
4+
--module LIST-SIZER \
5+
--smt-timeout 40 \
6+
--smt z3 \
7+
--strategy all \
8+
--log-level \
9+
warning \
10+
--enable-log-timestamps \
11+
--prove spec.kore \
12+
--spec-module INVALID-SIZE \
13+
--graph-search breadth-first \
14+
\
15+
\
16+
"$@"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* Created: Kore.Internal.OrPattern.toTermLike */
2+
/* Spa */
3+
\and{SortGeneratedTopCell{}}(
4+
/* Fl Fn D Sfa */
5+
Lbl'-LT-'generatedTop'-GT-'{}(
6+
/* Fl Fn D Sfa Cl */ Lbl'-LT-'k'-GT-'{}(/* Fl Fn D Sfa Cl */ dotk{}()),
7+
/* Fl Fn D Sfa */
8+
Lbl'-LT-'generatedCounter'-GT-'{}(
9+
/* Fl Fn D Sfa */ Var'Unds'DotVar1:SortInt{}
10+
),
11+
/* Fl Fn D Sfa Cl */
12+
Lbl'-LT-'size'-GT-'{}(
13+
/* Fl Fn D Sfa Cl */ /* builtin: */ \dv{SortInt{}}("1")
14+
)
15+
),
16+
/* Created: Kore.Internal.Predicate.makeAndPredicate */
17+
/* Spa */
18+
\and{SortGeneratedTopCell{}}(
19+
/* Spa */
20+
\equals{SortMyList{}, SortGeneratedTopCell{}}(
21+
/* Fl Fn D Sfa */ Var'Unds'0:SortMyList{},
22+
/* Fl Fn D Sfa */
23+
Lbl'UndsUndsUnds'LIST-SIZER-SYNTAX'Unds'MyList'Unds'Int'Unds'MyList{}(
24+
/* Fl Fn D Sfa */ Var'Unds'E:SortInt{},
25+
/* Fl Fn D Sfa Cl */
26+
Lbl'Stop'MyList'Unds'LIST-SIZER-SYNTAX'Unds'MyList{}()
27+
)
28+
),
29+
/* Spa */
30+
\equals{SortMyList{}, SortGeneratedTopCell{}}(
31+
/* Fl Fn D Sfa */ VarL:SortMyList{},
32+
/* Fl Fn D Sfa Cl */
33+
Lbl'Stop'MyList'Unds'LIST-SIZER-SYNTAX'Unds'MyList{}()
34+
)
35+
)
36+
)

0 commit comments

Comments
 (0)