Skip to content

Use unit and element symbol attributes #2365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
39dd06e
moved Concat, Element and Unit symbol files
MirceaS Jan 19, 2021
8f3e91e
added AC symbol fields to Symbol
MirceaS Jan 19, 2021
2434170
code refactoring
MirceaS Jan 22, 2021
4430f49
integrated new functions
MirceaS Jan 25, 2021
236818f
added the strict pragma to modules newly introduced
MirceaS Jan 25, 2021
eceb816
Materialize Nix expressions
MirceaS Jan 25, 2021
6a4f982
updated unparsing function
MirceaS Jan 27, 2021
d5979cb
fixed redundant import issue
MirceaS Jan 27, 2021
4eb41de
fixed error messages
MirceaS Feb 1, 2021
db86bc9
Merge branch 'master' into 2222
MirceaS Feb 3, 2021
fce3629
fixed unit tests and refactored some code
MirceaS Feb 8, 2021
434c43d
Materialize Nix expressions
MirceaS Feb 8, 2021
848e247
Merge branch 'master' into 2222
MirceaS Feb 9, 2021
7146edf
Materialize Nix expressions
MirceaS Feb 9, 2021
238d0ee
refactoring and redefining of Eq/Ord instances
MirceaS Feb 12, 2021
9e213dc
removed no longer relevant comments and refactored some code
MirceaS Feb 12, 2021
a32f065
fixed strictness issue
MirceaS Feb 15, 2021
ff0a162
added unit tests for unparsing failures
MirceaS Feb 18, 2021
fb52f46
Merge branch 'master' into 2222
MirceaS Feb 22, 2021
1102c8e
Materialize Nix expressions
MirceaS Feb 22, 2021
3b9e2e9
Merge branch 'master' into 2222
MirceaS Feb 26, 2021
dd235cf
regenerated regression tests
MirceaS Feb 27, 2021
2cd3a6f
Materialize Nix expressions
MirceaS Feb 27, 2021
07f289c
Merge branch 'master' into 2222
MirceaS Feb 27, 2021
c172528
updated kore file for tiny test
MirceaS Mar 2, 2021
8735ce6
updated integration test kore files
MirceaS Mar 2, 2021
dde2fda
Merge branch 'master' into 2222
MirceaS Mar 2, 2021
a8c8afe
fixed small error
MirceaS Mar 3, 2021
49ab3d6
regenerated regression files again
MirceaS Mar 3, 2021
26d0ca6
removed test for issue 2095
MirceaS Mar 4, 2021
e00d538
addressed some PR comments
MirceaS Mar 5, 2021
b0141a4
prettified error messages for unit, element and concat mismatch
MirceaS Mar 5, 2021
fb7dcaa
added HasCallStack to the new partial functions and their callers
MirceaS Mar 8, 2021
b984cce
Update kore/test/Test/Kore/Step/Simplification/InternalMap.hs
MirceaS Mar 8, 2021
5185c50
made some test easier to read
MirceaS Mar 9, 2021
ec67cfd
Merge branch 'master' into 2222
MirceaS Mar 9, 2021
07b13b5
Materialize Nix expressions
MirceaS Mar 9, 2021
784f96f
fixed merge issue
MirceaS Mar 9, 2021
a56a1fe
Merge branch 'master' into 2222
rv-jenkins Mar 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions kore/kore.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cabal-version: 2.2
--
-- see: https://github.com/sol/hpack
--
-- hash: 2702a5d875e9f185a4aedc5fdcafa951249ccd4ef5edab6f1e96689991c8f13f
-- hash: 80d27d36f0343e3b6779aa37ed5fccc747fd7c1b66c7b9bd2fb27c1f6a2d6403

name: kore
version: 0.41.0.0
Expand Down Expand Up @@ -70,7 +70,9 @@ library
Kore.Attribute.Axiom.Symbolic
Kore.Attribute.Axiom.Unit
Kore.Attribute.Comm
Kore.Attribute.Concat
Kore.Attribute.Constructor
Kore.Attribute.Element
Kore.Attribute.Function
Kore.Attribute.Functional
Kore.Attribute.Hook
Expand Down Expand Up @@ -101,12 +103,9 @@ library
Kore.Attribute.Smtlib.Smthook
Kore.Attribute.Smtlib.Smtlib
Kore.Attribute.Sort
Kore.Attribute.Sort.Concat
Kore.Attribute.Sort.Constructors
Kore.Attribute.Sort.ConstructorsBuilder
Kore.Attribute.Sort.Element
Kore.Attribute.Sort.HasDomainValues
Kore.Attribute.Sort.Unit
Kore.Attribute.SortInjection
Kore.Attribute.Source
Kore.Attribute.SourceLocation
Expand All @@ -120,6 +119,7 @@ library
Kore.Attribute.Synthetic
Kore.Attribute.Trusted
Kore.Attribute.UniqueId
Kore.Attribute.Unit
Kore.BugReport
Kore.Builtin
Kore.Builtin.AssocComm.AssocComm
Expand Down Expand Up @@ -916,7 +916,6 @@ test-suite kore-test
Test.Kore.Attribute.Smtlib
Test.Kore.Attribute.Sort.ConstructorsBuilder
Test.Kore.Attribute.Sort.HasDomainValues
Test.Kore.Attribute.Sort.Unit
Test.Kore.Attribute.SortInjection
Test.Kore.Attribute.Subsort
Test.Kore.Attribute.Symbol
Expand All @@ -927,6 +926,7 @@ test-suite kore-test
Test.Kore.Attribute.Symbol.SymbolKywd
Test.Kore.Attribute.Trusted
Test.Kore.Attribute.UniqueId
Test.Kore.Attribute.Unit
Test.Kore.BugReport
Test.Kore.Builtin
Test.Kore.Builtin.AssocComm.CeilSimplifier
Expand Down
95 changes: 95 additions & 0 deletions kore/src/Kore/Attribute/Concat.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{-|
Copyright : (c) Runtime Verification, 2021
License : NCSA
-}

{-# LANGUAGE Strict #-}

module Kore.Attribute.Concat
( Concat (..)
, mergeConcat, toConcat, fromConcat
, concatId, concatSymbol, concatAttribute
) where

import Prelude.Kore

import Data.Default
import qualified Generics.SOP as SOP
import qualified Pretty

import Kore.Attribute.Parser
import Kore.Debug
import Kore.Unparser

-- | @Concat@ represents the @concat@ attribute.
newtype Concat symbol = Concat { getConcat :: Maybe symbol }
deriving (Generic, Eq, Ord, Show)
deriving (Foldable, Functor, Traversable)
deriving anyclass (Hashable)
deriving anyclass (SOP.Generic, SOP.HasDatatypeInfo)
deriving anyclass (Debug, Diff)

mergeConcat
:: (Eq symbol , Unparse symbol)
=> Concat symbol
-> Concat symbol
-> Concat symbol
mergeConcat (Concat Nothing) b = b
mergeConcat a (Concat Nothing) = a
mergeConcat a@(Concat (Just aSymbol)) (Concat (Just bSymbol))
| aSymbol == bSymbol = a
| otherwise = (error . show . Pretty.vsep)
[ "Concat symbol mismatch error! Found both"
, Pretty.indent 4 (unparse aSymbol)
, "and"
, Pretty.indent 4 (unparse bSymbol)
, "inside term. This is a bug."
]

instance Default (Concat symbol) where
def = Concat { getConcat = Nothing }

instance NFData symbol => NFData (Concat symbol)

instance ParseAttributes (Concat SymbolOrAlias) where
parseAttribute = withApplication' parseApplication
where
parseApplication params args Concat { getConcat }
| Just _ <- getConcat = failDuplicate'
| otherwise = do
getZeroParams params
arg <- getOneArgument args
symbol <- getSymbolOrAlias arg
return Concat { getConcat = Just symbol }
withApplication' = withApplication concatId
failDuplicate' = failDuplicate concatId

instance From (Concat SymbolOrAlias) Attributes where
from =
maybe def toAttribute . getConcat
where
toAttribute = from @AttributePattern . concatAttribute

toConcat :: symbol -> Concat symbol
toConcat sym = Concat { getConcat = Just sym }

fromConcat :: HasCallStack => Concat symbol -> symbol
fromConcat Concat {getConcat = Just sym} = sym
fromConcat _ = error "There is no concat symbol to extract"

-- | Kore identifier representing the @concat@ attribute symbol.
concatId :: Id
concatId = "concat"

-- | Kore symbol representing the @concat@ attribute.
concatSymbol :: SymbolOrAlias
concatSymbol =
SymbolOrAlias
{ symbolOrAliasConstructor = concatId
, symbolOrAliasParams = []
}

-- | Kore pattern representing the @concat@ attribute.
concatAttribute :: SymbolOrAlias -> AttributePattern
concatAttribute symbol =
attributePattern concatSymbol [attributePattern_ symbol]
95 changes: 95 additions & 0 deletions kore/src/Kore/Attribute/Element.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{-|
Copyright : (c) Runtime Verification, 2021
License : NCSA
-}

{-# LANGUAGE Strict #-}

module Kore.Attribute.Element
( Element (..)
, mergeElement, toElement, fromElement
, elementId, elementSymbol, elementAttribute
) where

import Prelude.Kore

import Data.Default
import qualified Generics.SOP as SOP
import qualified Pretty

import Kore.Attribute.Parser
import Kore.Debug
import Kore.Unparser

-- | @Element@ represents the @element@ attribute.
newtype Element symbol = Element { getElement :: Maybe symbol }
deriving (Generic, Eq, Ord, Show)
deriving (Foldable, Functor, Traversable)
deriving anyclass (Hashable)
deriving anyclass (SOP.Generic, SOP.HasDatatypeInfo)
deriving anyclass (Debug, Diff)

mergeElement
:: (Eq symbol , Unparse symbol)
=> Element symbol
-> Element symbol
-> Element symbol
mergeElement (Element Nothing) b = b
mergeElement a (Element Nothing) = a
mergeElement a@(Element (Just aSymbol)) (Element (Just bSymbol))
| aSymbol == bSymbol = a
| otherwise = (error . show . Pretty.vsep)
[ "Element symbol mismatch error! Found both"
, Pretty.indent 4 (unparse aSymbol)
, "and"
, Pretty.indent 4 (unparse bSymbol)
, "inside term. This is a bug."
]

instance Default (Element symbol) where
def = Element { getElement = Nothing }

instance NFData symbol => NFData (Element symbol)

-- | Kore identifier representing the @element@ attribute symbol.
elementId :: Id
elementId = "element"

-- | Kore symbol representing the @element@ attribute.
elementSymbol :: SymbolOrAlias
elementSymbol =
SymbolOrAlias
{ symbolOrAliasConstructor = elementId
, symbolOrAliasParams = []
}

-- | Kore pattern representing the @element@ attribute.
elementAttribute :: SymbolOrAlias -> AttributePattern
elementAttribute symbol =
attributePattern elementSymbol [attributePattern_ symbol]

instance ParseAttributes (Element SymbolOrAlias) where
parseAttribute = withApplication' parseApplication
where
parseApplication params args Element { getElement }
| Just _ <- getElement = failDuplicate'
| otherwise = do
getZeroParams params
arg <- getOneArgument args
symbol <- getSymbolOrAlias arg
return Element { getElement = Just symbol }
withApplication' = withApplication elementId
failDuplicate' = failDuplicate elementId

instance From (Element SymbolOrAlias) Attributes where
from =
maybe def toAttribute . getElement
where
toAttribute = from @AttributePattern . elementAttribute

toElement :: symbol -> Element symbol
toElement sym = Element { getElement = Just sym }

fromElement :: HasCallStack => Element symbol -> symbol
fromElement Element {getElement = Just sym} = sym
fromElement _ = error "There is no element symbol to extract"
18 changes: 9 additions & 9 deletions kore/src/Kore/Attribute/Sort.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@ import Prelude.Kore hiding
import qualified Control.Monad as Monad
import Data.Generics.Product

import Kore.Attribute.Concat
import Kore.Attribute.Element
import Kore.Attribute.Hook
import Kore.Attribute.Parser hiding
( Sort
)
import Kore.Attribute.Smtlib.Smtlib
import Kore.Attribute.Sort.Concat
import Kore.Attribute.Sort.Element
import Kore.Attribute.Sort.HasDomainValues
( HasDomainValues
)
import Kore.Attribute.Sort.Unit
import Kore.Attribute.Unit

data Sort =
Sort
{ hook :: !Hook
-- ^ The builtin sort hooked to the sort.
, smtlib :: !Smtlib
-- ^ The user-defined translation of the sort for SMT.
, unit :: !Unit
, unit :: !(Unit SymbolOrAlias)
-- ^ The unit symbol associated with the sort.
, element :: !Element
, element :: !(Element SymbolOrAlias)
-- ^ The element symbol associated with the sort.
, concat :: !Concat
, concat :: !(Concat SymbolOrAlias)
-- ^ The concat symbol associated with the sort.
, hasDomainValues :: !HasDomainValues
-- ^ whether the sort has domain values
Expand Down Expand Up @@ -68,9 +68,9 @@ instance ParseAttributes Sort where
parseAttribute attr =
typed @Hook (parseAttribute attr)
Monad.>=> typed @Smtlib (parseAttribute attr)
Monad.>=> typed @Unit (parseAttribute attr)
Monad.>=> typed @Element (parseAttribute attr)
Monad.>=> typed @Concat (parseAttribute attr)
Monad.>=> typed @(Unit SymbolOrAlias) (parseAttribute attr)
Monad.>=> typed @(Element SymbolOrAlias) (parseAttribute attr)
Monad.>=> typed @(Concat SymbolOrAlias) (parseAttribute attr)
Monad.>=> typed @HasDomainValues (parseAttribute attr)

instance From Sort Attributes where
Expand Down
70 changes: 0 additions & 70 deletions kore/src/Kore/Attribute/Sort/Concat.hs

This file was deleted.

Loading