Skip to content

Commit 6f5fe0b

Browse files
MirceaSrv-jenkins
andauthored
Fix Ac Unification error and Add new integration test (#2493)
* added new integration test and removed sort check on internalization * Format with fourmolu * made a pattern match more strict * addressed PR comments * fixed golden file * Format with fourmolu * refactored a pattern match * Format with fourmolu * empty commit for test runs Co-authored-by: MirceaS <[email protected]> Co-authored-by: rv-jenkins <[email protected]>
1 parent 31eefe1 commit 6f5fe0b

File tree

7 files changed

+84
-44
lines changed

7 files changed

+84
-44
lines changed

kore/src/Kore/Builtin/AssociativeCommutative.hs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -803,25 +803,25 @@ unifyEqualsNormalizedAc
803803
allElements1
804804
allElements2
805805
Nothing
806-
([opaque], []) ->
807-
lift $
808-
unifyEqualsElementLists'
809-
allElements1
810-
allElements2
811-
(Just opaque)
812-
([], [opaque]) ->
813-
lift $
814-
unifyEqualsElementLists'
815-
allElements2
816-
allElements1
817-
(Just opaque)
818806
([ElemVar_ v1], _)
807+
| null opaqueDifference2 ->
808+
lift $
809+
unifyEqualsElementLists'
810+
allElements1
811+
allElements2
812+
(Just v1)
819813
| null allElements1 ->
820814
unifyOpaqueVariable' v1 allElements2 opaqueDifference2
821815
(_, [ElemVar_ v2])
816+
| null opaqueDifference1 ->
817+
lift $
818+
unifyEqualsElementLists'
819+
allElements2
820+
allElements1
821+
(Just v2)
822822
| null allElements2 ->
823823
unifyOpaqueVariable' v2 allElements1 opaqueDifference1
824-
(_, _) -> empty
824+
_ -> empty
825825
let (unifiedElements, unifierCondition) =
826826
Conditional.splitTerm simpleUnifier
827827
lift $ do
@@ -1204,8 +1204,8 @@ unifyEqualsElementLists ::
12041204
[ConcreteOrWithVariable normalized variable] ->
12051205
-- | Second structure elements
12061206
[ConcreteOrWithVariable normalized variable] ->
1207-
-- | Opaque part of the first structure
1208-
Maybe (TermLike variable) ->
1207+
-- | Opaque element variable of the first structure
1208+
Maybe (ElementVariable variable) ->
12091209
unifier
12101210
( Conditional
12111211
variable
@@ -1274,7 +1274,7 @@ unifyEqualsElementLists
12741274
unifyEqualsChildren
12751275
firstElements
12761276
secondElements
1277-
(Just opaque)
1277+
(Just opaqueElemVar)
12781278
| length firstElements > length secondElements =
12791279
-- The second structure does not include an opaque term, so all the
12801280
-- elements in the first structure must be matched by elements in the second
@@ -1301,26 +1301,26 @@ unifyEqualsElementLists
13011301
"Duplicated element in unification results"
13021302
first
13031303
second
1304-
Just remainderTerm -> case opaque of
1305-
ElemVar_ _
1306-
| TermLike.isFunctionPattern remainderTerm -> do
1307-
opaqueUnifier <- unifyEqualsChildren opaque remainderTerm
1308-
let (opaqueTerm, opaqueCondition) =
1309-
Pattern.splitTerm opaqueUnifier
1310-
result = unifier `andCondition` opaqueCondition
1311-
1312-
return (result, [opaqueTerm])
1313-
_ ->
1314-
error . show . Pretty.vsep $
1315-
[ "Unification case that should be handled somewhere else: \
1316-
\attempting normalized unification with a \
1317-
\non-element-variable opaque term or \
1318-
\non-function maps could lead to infinite loops."
1319-
, Pretty.indent 2 "first="
1320-
, Pretty.indent 4 (unparse first)
1321-
, Pretty.indent 2 "second="
1322-
, Pretty.indent 4 (unparse second)
1323-
]
1304+
Just remainderTerm
1305+
| TermLike.isFunctionPattern remainderTerm -> do
1306+
opaqueUnifier <-
1307+
unifyEqualsChildren
1308+
(mkElemVar opaqueElemVar)
1309+
remainderTerm
1310+
let (opaqueTerm, opaqueCondition) =
1311+
Pattern.splitTerm opaqueUnifier
1312+
result = unifier `andCondition` opaqueCondition
1313+
return (result, [opaqueTerm])
1314+
_ ->
1315+
error . show . Pretty.vsep $
1316+
[ "Unification case that should be handled somewhere else: \
1317+
\attempting normalized unification with \
1318+
\non-function maps could lead to infinite loops."
1319+
, Pretty.indent 2 "first="
1320+
, Pretty.indent 4 (unparse first)
1321+
, Pretty.indent 2 "second="
1322+
, Pretty.indent 4 (unparse second)
1323+
]
13241324
where
13251325
unifyWithPermutations =
13261326
unifyEqualsElementPermutations

kore/src/Kore/Builtin/Map.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,9 @@ internalize ::
499499
TermLike variable ->
500500
TermLike variable
501501
internalize tools termLike
502-
| fromMaybe False (isMapSort tools sort')
503-
, -- Ac.toNormalized is greedy about 'normalizing' opaque terms, we should only
504-
-- apply it if we know the term head is a constructor-like symbol.
505-
App_ symbol _ <- termLike
502+
-- Ac.toNormalized is greedy about 'normalizing' opaque terms, we should only
503+
-- apply it if we know the term head is a constructor-like symbol.
504+
| App_ symbol _ <- termLike
506505
, isConstructorModulo_ symbol =
507506
case Ac.toNormalized @NormalizedMap termLike of
508507
Ac.Bottom -> TermLike.mkBottom sort'

kore/src/Kore/Builtin/Set.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,9 @@ internalize ::
501501
TermLike variable ->
502502
TermLike variable
503503
internalize tools termLike
504-
| fromMaybe False (isSetSort tools sort')
505-
, -- Ac.toNormalized is greedy about 'normalizing' opaque terms, we should only
506-
-- apply it if we know the term head is a constructor-like symbol.
507-
App_ symbol _ <- termLike
504+
-- Ac.toNormalized is greedy about 'normalizing' opaque terms, we should only
505+
-- apply it if we know the term head is a constructor-like symbol.
506+
| App_ symbol _ <- termLike
508507
, isConstructorModulo_ symbol =
509508
case Ac.toNormalized @NormalizedSet termLike of
510509
Ac.Bottom -> TermLike.mkBottom sort'

test/issue-2378/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-2378/test-spec.k

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module VERIFICATION
2+
imports TEST
3+
4+
endmodule
5+
6+
module TEST-SPEC
7+
imports VERIFICATION
8+
9+
claim b(keys(_M:Map)) => c
10+
11+
endmodule
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#Not ( #Exists _0 . #Exists S . {
2+
keys ( _M )
3+
#Equals
4+
S
5+
SetItem ( _0 )
6+
} )
7+
#And
8+
#Not ( {
9+
.Set
10+
#Equals
11+
keys ( _M )
12+
} )
13+
#And
14+
<k>
15+
b ( keys ( _M ) ) ~> _DotVar1 ~> .
16+
</k>

test/issue-2378/test.k

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2020 K Team. All Rights Reserved.
2+
3+
module TEST
4+
imports SET
5+
imports MAP
6+
7+
syntax B ::= b(Set)
8+
| "c"
9+
syntax KItem ::= B
10+
11+
rule b(.Set) => c
12+
rule b(SetItem(_:KItem) S:Set) => b(S)
13+
14+
endmodule

0 commit comments

Comments
 (0)