Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
191983d
Extract module Kore.Internal.InternalInt
ttuegel Nov 23, 2020
caa4fbb
Move local function simplification tests
ttuegel Nov 24, 2020
e1853b7
Rename pattern BuiltinInt_ to InternalInt_
ttuegel Nov 24, 2020
f966b5c
Extract attribute instances for Int and Bytes
ttuegel Nov 24, 2020
749aabb
Extract Kore.Internal.InternalBool
ttuegel Nov 24, 2020
edcc1aa
Extract Kore.Internal.InternalString
ttuegel Nov 24, 2020
f7205a4
Update kore.cabal
ttuegel Dec 8, 2020
c236a36
De-linting
ttuegel Dec 4, 2020
8b34a81
Restore unification cases for Bool and String
ttuegel Dec 10, 2020
08f5088
retractLocalFunction: Restore cases for literals
ttuegel Dec 10, 2020
7d1744d
findClass: Add cases for literals
ttuegel Dec 10, 2020
ae86c44
test: make golden
ttuegel Dec 9, 2020
15b324f
Format with stylish-haskell
ttuegel Dec 10, 2020
af451b3
Materialize Nix expressions
ttuegel Dec 10, 2020
cbcc5dd
Consolidate Int unification
ttuegel Dec 10, 2020
b670b8e
Add String unification test
ttuegel Dec 10, 2020
383cc2e
Unify String values
ttuegel Dec 10, 2020
bc2c656
Remove illegal unification test case
ttuegel Dec 10, 2020
b8dc6d2
Handle StringLiteral and DomainValue as internals
ttuegel Dec 10, 2020
073a9ac
Rename Bool unification to match Int and String
ttuegel Dec 10, 2020
2d1dfc9
Test contradiction of unevaluated Int function
ttuegel Dec 11, 2020
63e5774
Test contradiction of unevaluated Bool function
ttuegel Dec 11, 2020
641f1af
Test contradiction of unevaluated String function
ttuegel Dec 11, 2020
40a4712
Format with stylish-haskell
ttuegel Dec 11, 2020
eb3dffe
Trigger workflows
ttuegel Dec 11, 2020
3176ecd
Rename BuiltinBool_ to InternalBool_
ttuegel Dec 16, 2020
262016a
Rename BuiltinString_ to InternalString_
ttuegel Dec 16, 2020
f17f818
Clean up
ttuegel Dec 16, 2020
c9c562a
Format with stylish-haskell
ttuegel Dec 16, 2020
170f765
Merge branch 'master' into cleanup--builtin
ttuegel Dec 17, 2020
4f4b332
test_simplify_local_functions: add cases for bool and string
ana-pantilie Dec 17, 2020
68cf8da
Merge branch 'master' into cleanup--builtin
ttuegel Dec 18, 2020
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
6 changes: 6 additions & 0 deletions kore/kore.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ library
Kore.Internal.Condition
Kore.Internal.Conditional
Kore.Internal.Inj
Kore.Internal.InternalBool
Kore.Internal.InternalBytes
Kore.Internal.InternalInt
Kore.Internal.InternalString
Kore.Internal.MultiAnd
Kore.Internal.MultiOr
Kore.Internal.OrCondition
Expand Down Expand Up @@ -287,7 +290,10 @@ library
Kore.Step.Simplification.Inhabitant
Kore.Step.Simplification.Inj
Kore.Step.Simplification.InjSimplifier
Kore.Step.Simplification.InternalBool
Kore.Step.Simplification.InternalBytes
Kore.Step.Simplification.InternalInt
Kore.Step.Simplification.InternalString
Kore.Step.Simplification.Mu
Kore.Step.Simplification.Next
Kore.Step.Simplification.NoConfusion
Expand Down
3 changes: 0 additions & 3 deletions kore/src/Kore/Attribute/Pattern/ConstructorLike.hs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ instance HasConstructorLike key => Synthetic ConstructorLike (Builtin key)
where
synthetic =
\case
BuiltinInt _ -> ConstructorLike . Just $ ConstructorLikeHead
BuiltinBool _ -> ConstructorLike . Just $ ConstructorLikeHead
BuiltinString _ -> ConstructorLike . Just $ ConstructorLikeHead
(BuiltinMap InternalAc
{builtinAcChild = NormalizedMap builtinMapChild}
) -> normalizedAcConstructorLike builtinMapChild
Expand Down
22 changes: 9 additions & 13 deletions kore/src/Kore/Attribute/Pattern/Defined.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ License : NCSA

module Kore.Attribute.Pattern.Defined
( Defined (..)
, alwaysDefined
) where

import Prelude.Kore
Expand All @@ -25,9 +26,6 @@ import Kore.Internal.Inj
( Inj
)
import qualified Kore.Internal.Inj as Inj
import Kore.Internal.InternalBytes
( InternalBytes
)
import qualified Kore.Internal.Symbol as Internal
import Kore.Syntax

Expand All @@ -41,6 +39,9 @@ newtype Defined = Defined { isDefined :: Bool }
deriving anyclass (Debug, Diff)
deriving (Semigroup, Monoid) via All

alwaysDefined :: a -> Defined
alwaysDefined = const (Defined True)

instance Synthetic Defined (And sort) where
synthetic = const (Defined False)
{-# INLINE synthetic #-}
Expand Down Expand Up @@ -166,31 +167,26 @@ normalizedAcDefined ac@(NormalizedAc _ _ _) =
where
sameAsChildren = fold ac


-- | A 'Top' pattern is always 'Defined'.
instance Synthetic Defined (Top sort) where
synthetic = const (Defined True)
synthetic = alwaysDefined
{-# INLINE synthetic #-}

-- | A 'StringLiteral' pattern is always 'Defined'.
instance Synthetic Defined (Const StringLiteral) where
synthetic = const (Defined True)
{-# INLINE synthetic #-}

-- | A 'Bytes' pattern is always 'Defined'.
instance Synthetic Defined (Const InternalBytes) where
synthetic = const (Defined True)
synthetic = alwaysDefined
{-# INLINE synthetic #-}

-- | An 'Inhabitant' pattern is always 'Defined'.
instance Synthetic Defined Inhabitant where
synthetic = const (Defined True)
synthetic = alwaysDefined
{-# INLINE synthetic #-}

-- | An element variable pattern is always 'Defined'.
-- A set variable is not.
instance Synthetic Defined (Const (SomeVariable variable)) where
synthetic (Const unifiedVariable)= Defined (isElementVariable unifiedVariable)
synthetic (Const unifiedVariable) =
Defined (isElementVariable unifiedVariable)
{-# INLINE synthetic #-}

instance Synthetic Defined Inj where
Expand Down
13 changes: 5 additions & 8 deletions kore/src/Kore/Attribute/Pattern/Function.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ License : NCSA

module Kore.Attribute.Pattern.Function
( Function (..)
, alwaysFunction
) where

import Prelude.Kore
Expand All @@ -24,9 +25,6 @@ import Kore.Internal.Inj
( Inj
)
import qualified Kore.Internal.Inj as Inj
import Kore.Internal.InternalBytes
( InternalBytes
)
import qualified Kore.Internal.Symbol as Internal
import Kore.Syntax

Expand All @@ -40,6 +38,10 @@ newtype Function = Function { isFunction :: Bool }
deriving anyclass (Debug, Diff)
deriving (Semigroup, Monoid) via All

alwaysFunction :: a -> Function
alwaysFunction = const (Function True)
{-# INLINE alwaysFunction #-}

instance Synthetic Function (And sort) where
-- TODO (thomas.tuegel):
-- synthetic = getAny . Foldable.foldMap (Any . isFunction)
Expand Down Expand Up @@ -139,11 +141,6 @@ instance Synthetic Function (Const StringLiteral) where
synthetic = const (Function True)
{-# INLINE synthetic #-}

-- | A 'Bytes' pattern is always 'Function'.
instance Synthetic Function (Const InternalBytes) where
synthetic = const (Function True)
{-# INLINE synthetic #-}

-- | An 'Inhabitant' pattern is never 'Function'.
instance Synthetic Function Inhabitant where
synthetic = const (Function False)
Expand Down
26 changes: 7 additions & 19 deletions kore/src/Kore/Attribute/Pattern/Functional.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ License : NCSA

module Kore.Attribute.Pattern.Functional
( Functional (..)
, alwaysFunctional
) where

import Prelude.Kore
Expand All @@ -25,9 +26,6 @@ import Kore.Internal.Inj
( Inj
)
import qualified Kore.Internal.Inj as Inj
import Kore.Internal.InternalBytes
( InternalBytes
)
import qualified Kore.Internal.Symbol as Internal
import Kore.Syntax

Expand All @@ -36,18 +34,13 @@ import Kore.Syntax
newtype Functional = Functional { isFunctional :: Bool }
deriving (Eq, GHC.Generic, Ord, Show)
deriving (Semigroup, Monoid) via All
deriving anyclass (Hashable, NFData)
deriving anyclass (SOP.Generic, SOP.HasDatatypeInfo)
deriving anyclass (Debug, Diff)

instance SOP.Generic Functional

instance SOP.HasDatatypeInfo Functional

instance Debug Functional

instance Diff Functional

instance NFData Functional

instance Hashable Functional
alwaysFunctional :: a -> Functional
alwaysFunctional = const (Functional True)
{-# INLINE alwaysFunctional #-}

instance Synthetic Functional (And sort) where
synthetic = const (Functional False)
Expand Down Expand Up @@ -185,11 +178,6 @@ instance Synthetic Functional (Const StringLiteral) where
synthetic = const (Functional True)
{-# INLINE synthetic #-}

-- | A 'Bytes' pattern is always 'Functional'.
instance Synthetic Functional (Const InternalBytes) where
synthetic = const (Functional True)
{-# INLINE synthetic #-}

-- | An 'Inhabitant' pattern is never 'Functional'.
instance Synthetic Functional Inhabitant where
synthetic = const (Functional False)
Expand Down
4 changes: 1 addition & 3 deletions kore/src/Kore/Attribute/Pattern/Simplified.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Kore.Attribute.Pattern.Simplified
, isFullySimplified
, simplifiedTo
, fullySimplified
, alwaysSimplified
, simplifiedConditionally
, simplifiableConditionally
, unparseTag
Expand Down Expand Up @@ -367,9 +368,6 @@ instance Synthetic Simplified (Rewrites sort) where
{-# INLINE synthetic #-}

instance Synthetic Simplified (Builtin key) where
synthetic (BuiltinInt _) = fullySimplified
synthetic (BuiltinBool _) = fullySimplified
synthetic (BuiltinString _) = fullySimplified
synthetic b@(BuiltinMap _) = notSimplified b
synthetic b@(BuiltinList _) = notSimplified b
synthetic b@(BuiltinSet _) = notSimplified b
Expand Down
42 changes: 19 additions & 23 deletions kore/src/Kore/Builtin/Bool.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Kore.Builtin.Bool
, asPattern
, extractBoolDomainValue
, parse
, unifyBoolValues
, unifyBool
, unifyBoolAnd
, unifyBoolOr
, unifyBoolNot
Expand All @@ -36,6 +36,7 @@ import Control.Error
( MaybeT
)
import qualified Control.Monad as Monad
import Data.Functor.Const
import qualified Data.HashMap.Strict as HashMap
import Data.Map.Strict
( Map
Expand All @@ -44,7 +45,6 @@ import qualified Data.Map.Strict as Map
import Data.Text
( Text
)
import qualified Data.Text as Text
import qualified Text.Megaparsec as Parsec
import qualified Text.Megaparsec.Char as Parsec

Expand All @@ -53,8 +53,8 @@ import Kore.Attribute.Hook
)
import Kore.Builtin.Bool.Bool
import qualified Kore.Builtin.Builtin as Builtin
import qualified Kore.Domain.Builtin as Domain
import qualified Kore.Error
import Kore.Internal.InternalBool
import Kore.Internal.Pattern
( Pattern
)
Expand Down Expand Up @@ -122,11 +122,11 @@ patternVerifierHook =
patternVerifierWorker domainValue =
case externalChild of
StringLiteral_ lit -> do
builtinBoolValue <- Builtin.parseString parse lit
(return . BuiltinF . Domain.BuiltinBool)
Domain.InternalBool
{ builtinBoolSort = domainValueSort
, builtinBoolValue
internalBoolValue <- Builtin.parseString parse lit
(return . InternalBoolF . Const)
InternalBool
{ internalBoolSort = domainValueSort
, internalBoolValue
}
_ -> Kore.Error.koreFail "Expected literal string"
where
Expand All @@ -136,15 +136,9 @@ patternVerifierHook =
-- | get the value from a (possibly encoded) domain value
extractBoolDomainValue
:: Text -- ^ error message Context
-> Builtin child
-> Bool
extractBoolDomainValue ctx =
\case
Domain.BuiltinBool Domain.InternalBool { builtinBoolValue } ->
builtinBoolValue
_ ->
Builtin.verifierBug
$ Text.unpack ctx ++ ": Bool builtin should be internal"
-> TermLike variable
-> Maybe Bool
extractBoolDomainValue _ = matchBool

{- | Parse an integer string literal.
-}
Expand All @@ -171,20 +165,22 @@ builtinFunctions =
]
where
unaryOperator =
Builtin.unaryOperator extractBoolDomainValue asPattern
Builtin.unaryOperator' extractBoolDomainValue asPattern
binaryOperator =
Builtin.binaryOperator extractBoolDomainValue asPattern
Builtin.binaryOperator' extractBoolDomainValue asPattern
xor a b = (a && not b) || (not a && b)
implies a b = not a || b

unifyBoolValues
{- | Unification of @BOOL.Bool@ values.
-}
unifyBool
:: forall variable unifier
. InternalVariable variable
=> MonadUnify unifier
=> TermLike variable
-> TermLike variable
-> MaybeT unifier (Pattern variable)
unifyBoolValues a b =
unifyBool a b =
worker a b <|> worker b a
where
worker termLike1 termLike2
Expand Down Expand Up @@ -285,8 +281,8 @@ unifyBoolNot unifyChildren a b =
{- | Match a @BOOL.Bool@ builtin value.
-}
matchBool :: TermLike variable -> Maybe Bool
matchBool (BuiltinBool_ Domain.InternalBool { builtinBoolValue }) =
Just builtinBoolValue
matchBool (InternalBool_ InternalBool { internalBoolValue }) =
Just internalBoolValue
matchBool _ = Nothing

{- | The @BOOL.and@ hooked symbol applied to @term@-type arguments.
Expand Down
25 changes: 10 additions & 15 deletions kore/src/Kore/Builtin/Bool/Bool.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,20 @@ import Data.Text
( Text
)

import qualified Kore.Domain.Builtin as Domain
import Kore.Internal.InternalBool
import Kore.Internal.Pattern
( Pattern
)
import qualified Kore.Internal.Pattern as Pattern
( fromTermLike
)
import Kore.Internal.TermLike
( Concrete
, DomainValue (DomainValue)
( DomainValue (DomainValue)
, InternalVariable
, Sort
, TermLike
, mkBuiltin
, mkDomainValue
, mkInternalBool
, mkStringLiteral
)
import qualified Kore.Internal.TermLike as TermLike
Expand All @@ -71,18 +70,14 @@ asInternal
-> Bool -- ^ builtin value to render
-> TermLike variable
asInternal builtinBoolSort builtinBoolValue =
TermLike.markSimplified . mkBuiltin
TermLike.markSimplified . mkInternalBool
$ asBuiltin builtinBoolSort builtinBoolValue

asBuiltin
:: Sort -- ^ resulting sort
-> Bool -- ^ builtin value to render
-> Domain.Builtin (TermLike Concrete) (TermLike variable)
asBuiltin builtinBoolSort builtinBoolValue =
Domain.BuiltinBool Domain.InternalBool
{ builtinBoolSort
, builtinBoolValue
}
-> InternalBool
asBuiltin = InternalBool

{- | Render a 'Bool' as a domain value pattern of the given sort.

Expand All @@ -94,16 +89,16 @@ asBuiltin builtinBoolSort builtinBoolValue =
-}
asTermLike
:: InternalVariable variable
=> Domain.InternalBool -- ^ builtin value to render
=> InternalBool -- ^ builtin value to render
-> TermLike variable
asTermLike builtin =
mkDomainValue DomainValue
{ domainValueSort = builtinBoolSort
{ domainValueSort = internalBoolSort
, domainValueChild = mkStringLiteral literal
}
where
Domain.InternalBool { builtinBoolSort } = builtin
Domain.InternalBool { builtinBoolValue = bool } = builtin
InternalBool { internalBoolSort } = builtin
InternalBool { internalBoolValue = bool } = builtin
literal
| bool = "true"
| otherwise = "false"
Expand Down
Loading