Skip to content

Commit ad804f9

Browse files
committed
Remove _PREDICATE sort (#2604)
Remove the predicate sort in favour of using known sorts at all call sites. This mostly adds sort arguments to various functions that previously implicitly used _PREDICATE sort. In turn this means removing the various underbar methods previously in `Kore.Internal.TermLike`.
1 parent 8d69854 commit ad804f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+396
-460
lines changed

kore/src/Kore/Builtin/Builtin.hs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ import Kore.Internal.Pattern (
8484
)
8585
import Kore.Internal.Pattern as Pattern (
8686
fromTermLike,
87-
top,
87+
topOf,
8888
withCondition,
8989
)
9090
import Kore.Internal.Predicate (
@@ -101,9 +101,6 @@ import Kore.Internal.TermLike as TermLike
101101
import Kore.Rewriting.RewritingVariable (
102102
RewritingVariableName,
103103
)
104-
import Kore.Sort (
105-
predicateSort,
106-
)
107104
import Kore.Step.Simplification.SimplificationType as SimplificationType (
108105
SimplificationType (..),
109106
)
@@ -473,19 +470,19 @@ isSymbol builtinName Symbol{symbolAttributes = Attribute.Symbol{hook}} =
473470

474471
{- | Is the given sort hooked to the named builtin?
475472
473+
TO DO (callan): fix documentation here
474+
476475
Returns Nothing if the sort is unknown (i.e. the _PREDICATE sort).
477476
Returns Just False if the sort is a variable.
478477
-}
479478
isSort :: Text -> SmtMetadataTools attr -> Sort -> Maybe Bool
480479
isSort builtinName tools sort
481-
| isPredicateSort = Nothing
482480
| SortVariableSort _ <- sort = Nothing
483481
| otherwise =
484482
let MetadataTools{sortAttributes} = tools
485483
Attribute.Sort{hook} = sortAttributes sort
486484
in Just (getHook hook == Just builtinName)
487-
where
488-
isPredicateSort = sort == predicateSort
485+
489486

490487
-- | Run a function evaluator that can terminate early.
491488
getAttemptedAxiom ::
@@ -510,9 +507,10 @@ unifyEqualsUnsolved SimplificationType.And a b = do
510507
unified
511508
predicate <- Monad.Unify.scatter orCondition
512509
return (unified `Pattern.withCondition` predicate)
513-
unifyEqualsUnsolved SimplificationType.Equals a b =
510+
unifyEqualsUnsolved SimplificationType.Equals a b = do
511+
let sort = TermLike.termLikeSort a
514512
return
515-
Pattern.top
513+
(Pattern.topOf sort)
516514
{ predicate = Predicate.markSimplified $ makeEqualsPredicate a b
517515
}
518516

kore/src/Kore/Builtin/EqTerm.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,6 @@ unifyEqTerm unifyChildren (NotSimplifier notSimplifier) eqTerm termLike2
7272
>>= Unify.scatter
7373
| otherwise = empty
7474
where
75+
sort = TermLike.termLikeSort termLike2
7576
EqTerm{operand1, operand2} = eqTerm
76-
eraseTerm = Pattern.fromCondition_ . Pattern.withoutTerm
77+
eraseTerm = Pattern.fromCondition sort . Pattern.withoutTerm

kore/src/Kore/Builtin/Int/Int.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ asPartialPattern ::
101101
Maybe Integer ->
102102
Pattern variable
103103
asPartialPattern resultSort =
104-
maybe Pattern.bottom (asPattern resultSort)
104+
maybe (Pattern.bottomOf resultSort) (asPattern resultSort)
105105

106106
randKey :: IsString s => s
107107
randKey = "INT.rand"

kore/src/Kore/Builtin/List.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ evalGet _ resultSort [_list, _ix] = do
275275
emptyList <|> bothConcrete
276276
where
277277
maybeBottom =
278-
maybe Pattern.bottom Pattern.fromTermLike
278+
maybe (Pattern.bottomOf resultSort) Pattern.fromTermLike
279279
evalGet _ _ _ = Builtin.wrongArity getKey
280280

281281
evalUpdate :: Builtin.Function
@@ -560,7 +560,7 @@ unifyEquals
560560
"Cannot unify lists of different length."
561561
first
562562
second
563-
return Pattern.bottom
563+
return (Pattern.bottomOf sort1)
564564

565565
unifyEqualsFramedRightRight ::
566566
TermLike.Symbol ->

kore/src/Kore/Builtin/Map.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,10 @@ unifyNotInKeys unifyChildren (NotSimplifier notSimplifier) a b =
631631
>>= Unify.scatter
632632
& lift
633633

634+
sort1 = TermLike.termLikeSort a
635+
634636
eraseTerm =
635-
Pattern.fromCondition_ . Pattern.withoutTerm
637+
Pattern.fromCondition sort1 . Pattern.withoutTerm
636638

637639
unifyAndNegate t1 t2 =
638640
do
@@ -646,7 +648,7 @@ unifyNotInKeys unifyChildren (NotSimplifier notSimplifier) a b =
646648
(OrPattern.fromPatterns unificationSolutions)
647649
>>= Unify.scatter
648650

649-
collectConditions terms = fold terms & Pattern.fromCondition_
651+
collectConditions terms = fold terms & Pattern.fromCondition sort1
650652

651653
worker ::
652654
TermLike RewritingVariableName ->
@@ -663,7 +665,7 @@ unifyNotInKeys unifyChildren (NotSimplifier notSimplifier) a b =
663665
mapKeys = symbolicKeys <> concreteKeys
664666
opaqueElements = opaque . unwrapAc $ normalizedMap
665667
if null mapKeys && null opaqueElements
666-
then return Pattern.top
668+
then return (Pattern.topOf sort1)
667669
else do
668670
Monad.guard (not (null mapKeys) || (length opaqueElements > 1))
669671
-- Concrete keys are constructor-like, therefore they are defined

kore/src/Kore/Builtin/String/String.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ asPartialPattern ::
9090
Maybe Text ->
9191
Pattern variable
9292
asPartialPattern resultSort =
93-
maybe Pattern.bottom (asPattern resultSort)
93+
maybe (Pattern.bottomOf resultSort) (asPattern resultSort)
9494

9595
eqKey :: IsString s => s
9696
eqKey = "STRING.eq"

kore/src/Kore/Internal/Inj.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ instance Unparse a => Unparse (Inj a) where
8585

8686
instance Synthetic Sort Inj where
8787
synthetic Inj{injFrom, injTo, injChild} =
88-
injTo & seq (matchSort injFrom injChild)
88+
injTo & seq (sameSort injFrom injChild)
8989
{-# INLINE synthetic #-}
9090

9191
instance Synthetic (FreeVariables variable) Inj where

kore/src/Kore/Internal/OrPattern.hs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module Kore.Internal.OrPattern (
1616
bottom,
1717
isFalse,
1818
isPredicate,
19+
tryGetSort,
1920
top,
2021
isTrue,
2122
toPattern,
@@ -58,7 +59,7 @@ import Kore.Internal.TermLike (
5859
InternalVariable,
5960
Sort,
6061
TermLike,
61-
mkBottom_,
62+
mkBottom,
6263
mkOr,
6364
)
6465
import Kore.Syntax.Variable
@@ -151,10 +152,12 @@ isFalse = isBottom
151152
152153
@
153154
'isTrue' top == True
155+
156+
To do (Callan): should this be renamed `topOf` as elsewhere?
154157
@
155158
-}
156-
top :: InternalVariable variable => OrPattern variable
157-
top = fromPattern Pattern.top
159+
top :: InternalVariable variable => Sort -> OrPattern variable
160+
top sort = fromPattern (Pattern.topOf sort)
158161

159162
-- | 'isTrue' checks if the 'Or' has a single top pattern.
160163
isTrue :: OrPattern variable -> Bool
@@ -164,11 +167,12 @@ isTrue = isTop
164167
toPattern ::
165168
forall variable.
166169
InternalVariable variable =>
170+
Sort ->
167171
OrPattern variable ->
168172
Pattern variable
169-
toPattern multiOr =
173+
toPattern sort multiOr =
170174
case toList multiOr of
171-
[] -> Pattern.bottom
175+
[] -> Pattern.bottomOf sort
172176
[patt] -> patt
173177
patts -> foldr1 mergeWithOr patts
174178
where
@@ -198,14 +202,23 @@ toPattern multiOr =
198202
isPredicate :: OrPattern variable -> Bool
199203
isPredicate = all Pattern.isPredicate
200204

205+
-- | Gets the `Sort` of a non-empty 'OrPattern' and othewise returns `Nothing`.
206+
tryGetSort :: OrPattern variable -> Maybe Sort
207+
tryGetSort multiOr =
208+
case toList multiOr of
209+
[] -> Nothing
210+
p : _ -> Just (Pattern.patternSort p)
211+
212+
201213
-- | Transforms a 'Pattern' into a 'TermLike'.
202214
toTermLike ::
203215
InternalVariable variable =>
216+
Sort ->
204217
OrPattern variable ->
205218
TermLike variable
206-
toTermLike multiOr =
219+
toTermLike sort multiOr =
207220
case toList multiOr of
208-
[] -> mkBottom_
221+
[] -> mkBottom sort
209222
[patt] -> Pattern.toTermLike patt
210223
patts -> foldr1 mkOr (Pattern.toTermLike <$> patts)
211224

kore/src/Kore/Internal/Pattern.hs

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,14 @@ module Kore.Internal.Pattern (
1010
syncSort,
1111
patternSort,
1212
fromCondition,
13-
fromCondition_,
1413
fromTermAndPredicate,
1514
fromPredicateSorted,
16-
bottom,
1715
bottomOf,
1816
isBottom,
1917
isTop,
2018
Kore.Internal.Pattern.mapVariables,
2119
splitTerm,
2220
toTermLike,
23-
top,
2421
topOf,
2522
fromTermLike,
2623
Kore.Internal.Pattern.freeElementVariables,
@@ -81,9 +78,7 @@ import Kore.Internal.TermLike (
8178
TermLike,
8279
mkAnd,
8380
mkBottom,
84-
mkBottom_,
8581
mkTop,
86-
mkTop_,
8782
termLikeSort,
8883
)
8984
import qualified Kore.Internal.TermLike as TermLike
@@ -110,11 +105,7 @@ fromTermAndPredicate term predicate =
110105
, predicate
111106
, substitution = mempty
112107
}
113-
fromCondition_ ::
114-
InternalVariable variable =>
115-
Condition variable ->
116-
Pattern variable
117-
fromCondition_ = (<$) mkTop_
108+
118109
fromCondition ::
119110
InternalVariable variable =>
120111
Sort ->
@@ -239,17 +230,6 @@ toTermLike Conditional{term, predicate, substitution} =
239230
predicateTermLike = Predicate.fromPredicate sort predicate'
240231
sort = termLikeSort pattern'
241232

242-
{- |'bottom' is an expanded pattern that has a bottom condition and that
243-
should become Bottom when transformed to a ML pattern.
244-
-}
245-
bottom :: InternalVariable variable => Pattern variable
246-
bottom =
247-
Conditional
248-
{ term = mkBottom_
249-
, predicate = Predicate.makeFalsePredicate
250-
, substitution = mempty
251-
}
252-
253233
{- | An 'Pattern' where the 'term' is 'Bottom' of the given 'Sort'.
254234
255235
The 'predicate' is set to 'makeFalsePredicate'.
@@ -262,17 +242,6 @@ bottomOf resultSort =
262242
, substitution = mempty
263243
}
264244

265-
{- |'top' is an expanded pattern that has a top condition and that
266-
should become Top when transformed to a ML pattern.
267-
-}
268-
top :: InternalVariable variable => Pattern variable
269-
top =
270-
Conditional
271-
{ term = mkTop_
272-
, predicate = Predicate.makeTruePredicate
273-
, substitution = mempty
274-
}
275-
276245
-- | An 'Pattern' where the 'term' is 'Top' of the given 'Sort'.
277246
topOf :: InternalVariable variable => Sort -> Pattern variable
278247
topOf resultSort =
@@ -342,7 +311,7 @@ coerceSort
342311
{ term =
343312
if isTop term
344313
then mkTop sort
345-
else TermLike.forceSort sort term
314+
else TermLike.sameTermLikeSort sort term
346315
, -- Need to override this since a 'ceil' (say) over a predicate is that
347316
-- predicate with a different sort.
348317
predicate = predicate
@@ -410,9 +379,10 @@ substitute subst Conditional{term, predicate, substitution} =
410379

411380
fromMultiAnd ::
412381
InternalVariable variable =>
382+
Sort ->
413383
MultiAnd (Pattern variable) ->
414384
Pattern variable
415-
fromMultiAnd patterns =
385+
fromMultiAnd sort patterns =
416386
foldr
417387
( \pattern1 ->
418388
pure
@@ -422,4 +392,4 @@ fromMultiAnd patterns =
422392
)
423393
Nothing
424394
patterns
425-
& fromMaybe top
395+
& fromMaybe (topOf sort)

kore/src/Kore/Internal/Predicate.hs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,6 @@ import Kore.Internal.TermLike hiding (
143143
substitute,
144144
)
145145
import qualified Kore.Internal.TermLike as TermLike
146-
import Kore.Sort (
147-
predicateSort,
148-
)
149146
import Kore.TopBottom (
150147
TopBottom (..),
151148
)
@@ -454,11 +451,13 @@ fromPredicate sort = Recursive.fold worker
454451
OrF (Or () t1 t2) -> TermLike.mkOr t1 t2
455452
TopF _ -> TermLike.mkTop sort
456453

454+
457455
fromPredicate_ ::
458456
InternalVariable variable =>
459457
Predicate variable ->
460458
TermLike variable
461-
fromPredicate_ = fromPredicate predicateSort
459+
fromPredicate_ = fromPredicate undefined
460+
462461

463462
{- | Simple type used to track whether a predicate building function performed
464463
a simplification that changed the shape of the resulting term. This is
@@ -682,7 +681,7 @@ makeInPredicate' ::
682681
TermLike variable ->
683682
(Predicate variable, HasChanged)
684683
makeInPredicate' t1 t2 =
685-
(TermLike.makeSortsAgree makeInWorker t1 t2, NotChanged)
684+
(TermLike.checkSortsAgree makeInWorker t1 t2, NotChanged)
686685
where
687686
makeInWorker t1' t2' _ = synthesize $ InF $ In () () t1' t2'
688687

@@ -699,7 +698,7 @@ makeEqualsPredicate' ::
699698
TermLike variable ->
700699
(Predicate variable, HasChanged)
701700
makeEqualsPredicate' t1 t2 =
702-
(TermLike.makeSortsAgree makeEqualsWorker t1 t2, NotChanged)
701+
(TermLike.checkSortsAgree makeEqualsWorker t1 t2, NotChanged)
703702
where
704703
makeEqualsWorker t1' t2' _ = synthesize $ EqualsF $ Equals () () t1' t2'
705704

0 commit comments

Comments
 (0)