Skip to content

Commit 86b8bd1

Browse files
committed
Revert "extractRules: WIP add assertion that ids are unique"
This reverts commit 4a4ce1b.
1 parent 4a4ce1b commit 86b8bd1

File tree

3 files changed

+28
-67
lines changed

3 files changed

+28
-67
lines changed

kore/src/Kore/Exec.hs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ import Kore.Internal.TermLike
103103
import Kore.Log.ErrorRewriteLoop
104104
( errorRewriteLoop
105105
)
106-
import Kore.Log.ErrorRuleMergeDuplicateId
107-
( errorRuleMergeDuplicateIds
108-
)
109106
import Kore.Log.InfoExecDepth
110107
import Kore.Log.KoreLogOptions
111108
( KoreLogOptions (..)
@@ -573,11 +570,10 @@ extractRules
573570
-> [Text]
574571
-> ExceptT Text m (NonEmpty (RewriteRule VariableName))
575572
extractRules rules names = do
573+
-- TODO: assert unique names
576574
let rulesById = mapMaybe ruleById rules
577575
rulesByLabel = mapMaybe ruleByLabel rules
578-
whenDuplicate errorRuleMergeDuplicateIds rulesById
579-
-- whenDuplicate errorRuleMergeDuplicateLabel rulesByLabel
580-
let ruleRegistry = Map.fromList (rulesById <> rulesByLabel)
576+
ruleRegistry = Map.fromList (rulesById <> rulesByLabel)
581577
extractedRules <- traverse (extractRule ruleRegistry) names
582578
case extractedRules of
583579
[] -> throwE "Empty rule list."
@@ -609,24 +605,6 @@ extractRules rules names = do
609605
return
610606
(Map.lookup ruleName registry)
611607

612-
whenDuplicate logError withNames = do
613-
let duplicateNames = findCollisions . mkMapWithCollisions $ withNames
614-
unless (null duplicateNames) (logError duplicateNames)
615-
616-
mkMapWithCollisions
617-
:: Ord key
618-
=> [(key, val)]
619-
-> Map.Map key [val]
620-
mkMapWithCollisions pairs =
621-
Map.fromListWith (<>)
622-
$ (fmap . fmap) pure pairs
623-
624-
findCollisions :: Map.Map key [val] -> Map.Map key [val]
625-
findCollisions = filter (not . isSingleton)
626-
where
627-
isSingleton [_] = True
628-
isSingleton _ = False
629-
630608
assertSingleClaim :: Monad m => [claim] -> m ()
631609
assertSingleClaim claims =
632610
when (length claims > 1) . error

kore/src/Kore/Log/ErrorRuleMergeDuplicateId.hs

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ License : NCSA
55
-}
66

77
module Kore.Log.ErrorRuleMergeDuplicateId
8-
( ErrorRuleMergeDuplicateIds
9-
, errorRuleMergeDuplicateIds
8+
( ErrorRuleMergeDuplicateId
9+
, errorRuleMergeDuplicateId
1010
) where
1111

1212
import Prelude.Kore
@@ -22,10 +22,6 @@ import Data.Generics.Product
2222
import Data.Generics.Wrapped
2323
( _Unwrapped
2424
)
25-
import Data.Map.Strict
26-
( Map
27-
)
28-
import qualified Data.Map.Strict as Map
2925
import Data.Text
3026
( Text
3127
)
@@ -47,48 +43,43 @@ import Pretty
4743
)
4844
import qualified Pretty
4945

50-
newtype ErrorRuleMergeDuplicateIds =
51-
ErrorRuleMergeDuplicateIds
52-
{ unErrorRuleMergeDuplicateIds :: Map Text [SourceLocation]
46+
data ErrorRuleMergeDuplicateId =
47+
ErrorRuleMergeDuplicateId
48+
{ locations :: [SourceLocation]
49+
, ruleId :: Text
5350
}
5451
deriving (Show)
5552
deriving (GHC.Generic)
5653
deriving anyclass (SOP.Generic, SOP.HasDatatypeInfo)
5754

58-
instance Exception ErrorRuleMergeDuplicateIds where
55+
instance Exception ErrorRuleMergeDuplicateId where
5956
toException = toException . SomeEntry
6057
fromException exn =
6158
fromException exn >>= fromEntry
6259

63-
instance Entry ErrorRuleMergeDuplicateIds where
60+
instance Entry ErrorRuleMergeDuplicateId where
6461
entrySeverity _ = Error
6562
helpDoc _ =
6663
"error thrown during rule merging when\
6764
\ multiple rules have the same id"
6865

69-
instance Pretty ErrorRuleMergeDuplicateIds where
70-
pretty (ErrorRuleMergeDuplicateIds duplicateIds) =
71-
Map.foldMapWithKey accum duplicateIds
72-
where
73-
accum ruleId locations =
74-
Pretty.vsep
75-
$ ["The rules at the following locations:"]
76-
<> fmap (Pretty.indent 4 . pretty) locations
77-
<> [ Pretty.indent 2 "all have the following id:"
78-
, Pretty.indent 4 (pretty ruleId)
79-
]
66+
instance Pretty ErrorRuleMergeDuplicateId where
67+
pretty ErrorRuleMergeDuplicateId { locations , ruleId } =
68+
Pretty.vsep
69+
$ ["The rules at the following locations:"]
70+
<> fmap (Pretty.indent 4 . pretty) locations
71+
<> [ Pretty.indent 2 "all have the following id:"
72+
, Pretty.indent 4 (pretty ruleId)
73+
]
8074

81-
errorRuleMergeDuplicateIds :: Map Text [RewriteRule VariableName] -> a
82-
errorRuleMergeDuplicateIds duplicateIds =
83-
throw (ErrorRuleMergeDuplicateIds idsWithlocations)
75+
errorRuleMergeDuplicateId :: [RewriteRule VariableName] -> Text -> a
76+
errorRuleMergeDuplicateId rules ruleId =
77+
throw ErrorRuleMergeDuplicateId { locations, ruleId }
8478
where
85-
idsWithlocations =
86-
(fmap . fmap)
87-
(
88-
Lens.view
89-
( _Unwrapped
90-
. field @"attributes"
91-
. field @"sourceLocation"
92-
)
93-
)
94-
duplicateIds
79+
locations =
80+
Lens.view
81+
( _Unwrapped
82+
. field @"attributes"
83+
. field @"sourceLocation"
84+
)
85+
<$> rules

kore/src/Kore/Log/Registry.hs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@ import Kore.Log.ErrorRewriteLoop
8080
import Kore.Log.ErrorRewritesInstantiation
8181
( ErrorRewritesInstantiation
8282
)
83-
import Kore.Log.ErrorRuleMergeDuplicateId
84-
( ErrorRuleMergeDuplicateIds
85-
)
86-
import Kore.Log.ErrorRuleMergeDuplicateLabel
87-
( ErrorRuleMergeDuplicateLabel
88-
)
8983
import Kore.Log.InfoAttemptUnification
9084
( InfoAttemptUnification
9185
)
@@ -161,8 +155,6 @@ entryHelpDocs :: [Pretty.Doc ()]
161155
, mk $ Proxy @ErrorBottomTotalFunction
162156
, mk $ Proxy @ErrorDecidePredicateUnknown
163157
, mk $ Proxy @ErrorParse
164-
, mk $ Proxy @ErrorRuleMergeDuplicateIds
165-
, mk $ Proxy @ErrorRuleMergeDuplicateLabel
166158
, mk $ Proxy @WarnFunctionWithoutEvaluators
167159
, mk $ Proxy @WarnSymbolSMTRepresentation
168160
, mk $ Proxy @WarnStuckClaimState

0 commit comments

Comments
 (0)