Skip to content

Commit eb384ef

Browse files
unifyKequalsEq should apply for both \and and \equals
* unifyKequalsEq should apply for both \and and \equals * Tests for KEqual unification Co-authored-by: Thomas Tuegel <[email protected]>
1 parent 978038e commit eb384ef

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ andEqualsFunctions notSimplifier =
237237
, (BothT, \_ _ s -> Builtin.Bool.unifyBoolNot s)
238238
, (EqualsT, \_ _ s -> Builtin.Int.unifyIntEq s notSimplifier)
239239
, (EqualsT, \_ _ s -> Builtin.String.unifyStringEq s notSimplifier)
240-
, (EqualsT, \_ _ s -> Builtin.KEqual.unifyKequalsEq s notSimplifier)
240+
, (BothT, \_ _ s -> Builtin.KEqual.unifyKequalsEq s notSimplifier)
241241
, (AndT, \_ _ s -> Builtin.KEqual.unifyIfThenElse s)
242242
, (BothT, \_ _ _ -> Builtin.Endianness.unifyEquals)
243243
, (BothT, \_ _ _ -> Builtin.Signedness.unifyEquals)

kore/test/Test/Kore/Step/MockSymbols.hs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import Kore.Attribute.Synthetic
6464
import qualified Kore.Builtin.Bool as Builtin.Bool
6565
import qualified Kore.Builtin.Builtin as Builtin
6666
import qualified Kore.Builtin.Int as Builtin.Int
67+
import qualified Kore.Builtin.KEqual as Builtin.KEqual
6768
import qualified Kore.Builtin.List as List
6869
import qualified Kore.Builtin.Map as Map
6970
import qualified Kore.Builtin.Set as Set
@@ -281,6 +282,8 @@ elementSetId :: Id
281282
elementSetId = testId "elementSet"
282283
unitSetId :: Id
283284
unitSetId = testId "unitSet"
285+
keqBoolId :: Id
286+
keqBoolId = testId "keqBool"
284287
sigmaId :: Id
285288
sigmaId = testId "sigma"
286289
anywhereId :: Id
@@ -660,6 +663,11 @@ unitSetSymbol :: Symbol
660663
unitSetSymbol =
661664
symbol unitSetId [] setSort & functional & hook "SET.unit"
662665

666+
keqBoolSymbol :: Symbol
667+
keqBoolSymbol =
668+
symbol keqBoolId [testSort, testSort] boolSort
669+
& function & functional & hook "KEQUAL.eq"
670+
663671
opaqueSetSymbol :: Symbol
664672
opaqueSetSymbol =
665673
symbol opaqueSetId [testSort] setSort
@@ -1347,6 +1355,13 @@ unitList
13471355
=> TermLike variable
13481356
unitList = Internal.mkApplySymbol unitListSymbol []
13491357

1358+
keqBool
1359+
:: InternalVariable variable
1360+
=> TermLike variable
1361+
-> TermLike variable
1362+
-> TermLike variable
1363+
keqBool t1 t2 = Internal.mkApplySymbol keqBoolSymbol [t1, t2]
1364+
13501365
sigma
13511366
:: InternalVariable variable
13521367
=> HasCallStack
@@ -1463,6 +1478,7 @@ symbols =
14631478
, lessIntSymbol
14641479
, greaterEqIntSymbol
14651480
, tdivIntSymbol
1481+
, keqBoolSymbol
14661482
, sigmaSymbol
14671483
, anywhereSymbol
14681484
, subsubOverloadSymbol
@@ -2047,4 +2063,8 @@ builtinSimplifiers =
20472063
, builtinEvaluation
20482064
(Builtin.Int.builtinFunctions Map.! Builtin.Int.geKey)
20492065
)
2066+
, ( AxiomIdentifier.Application keqBoolId
2067+
, builtinEvaluation
2068+
(Builtin.KEqual.builtinFunctions Map.! Builtin.KEqual.eqKey)
2069+
)
20502070
]

kore/test/Test/Kore/Step/Simplification/AndTerms.hs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,43 @@ test_andTermsSimplification =
11741174
actual <- unify input1 input2
11751175
assertEqual "" expect actual
11761176
]
1177+
1178+
, testGroup "KEquals"
1179+
[ testCase "Equal unification" $ do
1180+
let input1 = Mock.keqBool (cf xVar) a
1181+
input2 = Mock.builtinBool False
1182+
expected = [Condition.top]
1183+
Just actual <- simplifyEquals mempty input1 input2
1184+
assertEqual "" expected actual
1185+
, testCase "And unification" $ do
1186+
let input1 = Mock.keqBool (cf xVar) a
1187+
input2 = Mock.builtinBool False
1188+
expected = [Pattern.top]
1189+
actual <- simplify input1 input2
1190+
assertEqual "" expected actual
1191+
, testCase "And unification fails if pattern\
1192+
\ is not function-like" $ do
1193+
let input1 = Mock.keqBool (TermLike.mkOr a (cf xVar)) b
1194+
input2 = Mock.builtinBool False
1195+
expected =
1196+
TermLike.mkAnd input1 input2
1197+
& Pattern.fromTermLike
1198+
& pure
1199+
actual <- simplify input1 input2
1200+
assertEqual "" expected actual
1201+
, testCase "Equal unification fails if pattern\
1202+
\ is not function-like" $ do
1203+
let input1 = Mock.keqBool (TermLike.mkOr a (cf xVar)) b
1204+
input2 = Mock.builtinBool False
1205+
actual <- simplifyEquals mempty input1 input2
1206+
assertEqual "" Nothing actual
1207+
]
11771208
]
1209+
where
1210+
xVar = mkElemVar Mock.x
1211+
cf = Mock.functionalConstr10
1212+
a = Mock.a
1213+
b = Mock.b
11781214

11791215
mkVariable :: Text -> Variable VariableName
11801216
mkVariable ident =

0 commit comments

Comments
 (0)