Skip to content

Commit 2f1e667

Browse files
committed
Parse and internalise the syntactic attribute
Fix unit tests
1 parent b9e677d commit 2f1e667

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

booster/library/Booster/Definition/Attributes/Base.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module Booster.Definition.Attributes.Base (
3535
Position (..),
3636
FileSource (..),
3737
Priority (..),
38+
SyntacticClauses (..),
3839
pattern IsIdem,
3940
pattern IsNotIdem,
4041
pattern IsAssoc,
@@ -97,6 +98,7 @@ data AxiomAttributes = AxiomAttributes
9798
, preserving :: Flag "preservingDefinedness" -- this will override the computed attribute
9899
, concreteness :: Concreteness
99100
, smtLemma :: Flag "isSMTLemma"
101+
, syntacticClauses :: SyntacticClauses -- indices of conjuncts in rule.requires to be checked syntactically
100102
}
101103
deriving stock (Eq, Ord, Show, Generic)
102104
deriving anyclass (NFData)
@@ -174,6 +176,10 @@ data SymbolType
174176
deriving stock (Eq, Ord, Show, Generic, Data, Lift)
175177
deriving anyclass (NFData, Hashable)
176178

179+
newtype SyntacticClauses = SyntacticClauses [Word8]
180+
deriving stock (Eq, Ord, Read, Show)
181+
deriving newtype (NFData)
182+
177183
pattern IsIdem, IsNotIdem :: Flag "isIdem"
178184
pattern IsIdem = Flag True
179185
pattern IsNotIdem = Flag False

booster/library/Booster/Definition/Attributes/Reader.hs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ instance HasAttributes ParsedAxiom where
7070
<*> (attributes .! "preserves-definedness")
7171
<*> readConcreteness attributes
7272
<*> (attributes .! "smt-lemma")
73+
<*> readSyntacticClauses attributes
7374
where
7475
-- Some rewrite rules are dynamically generated and injected into
7576
-- a running server using the RPC "add-module" endpoint.
@@ -153,6 +154,33 @@ readConcreteness attributes = do
153154
[name, sort] -> Right (Text.encodeUtf8 name, Text.encodeUtf8 sort)
154155
_ -> Left "Invalid variable"
155156

157+
{- | Reads 'syntactic' attribute, returning the set of integer indices.
158+
Reports an error if any of the integers are non-positive or there are duplicates.
159+
Defaults to an empty set.
160+
-}
161+
readSyntacticClauses :: ParsedAttributes -> Except Text SyntacticClauses
162+
readSyntacticClauses attributes = do
163+
syntacticClauses <-
164+
maybe (pure Nothing) ((Just <$>) . mapM (except . readWord8)) $
165+
getAttribute "syntactic" attributes
166+
case syntacticClauses of
167+
Nothing -> pure $ SyntacticClauses []
168+
Just [] -> pure $ SyntacticClauses []
169+
Just more -> pure $ SyntacticClauses more
170+
where
171+
readWord8 str
172+
| all isDigit (Text.unpack str) = first Text.pack $ readEither (Text.unpack str)
173+
| otherwise = Left $ "invalid syntactic clause" <> (Text.pack $ show str)
174+
175+
-- where
176+
-- readWord8 str =
177+
-- readT [] = Right 50 -- HACK to accept `simplification()` from internal modules
178+
-- readT [n]
179+
-- | Text.null n = Right 50 -- HACK to accept `simplification("")`
180+
-- | all isDigit (Text.unpack n) = Priority <$> readEither (Text.unpack n)
181+
-- | otherwise = Left $ "invalid priority value " <> show n
182+
-- readT ns = Left $ "invalid priority value " <> show ns
183+
156184
instance HasAttributes ParsedSymbol where
157185
type Attributes ParsedSymbol = SymbolAttributes
158186

booster/unit-tests/Test/Booster/Pattern/ApplyEquations.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ equation ruleLabel lhs rhs priority =
374374
, concreteness = Unconstrained
375375
, uniqueId = mockUniqueId
376376
, smtLemma = Flag False
377+
, syntacticClauses = SyntacticClauses []
377378
}
378379
, computedAttributes = ComputedAxiomAttributes False []
379380
, existentials = mempty

booster/unit-tests/Test/Booster/Pattern/Rewrite.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ rule ruleLabel lhs rhs priority =
133133
, concreteness = Unconstrained
134134
, uniqueId = mockUniqueId
135135
, smtLemma = Flag False
136+
, syntacticClauses = SyntacticClauses []
136137
}
137138
, computedAttributes = ComputedAxiomAttributes False []
138139
, existentials = mempty

0 commit comments

Comments
 (0)