-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
store structure as a constraint in Scheme domain
- Loading branch information
1 parent
f36ccbc
commit 42af537
Showing
6 changed files
with
83 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,13 @@ | ||
{-# LANGUAGE FlexibleContexts, UndecidableInstances, PatternSynonyms, FlexibleInstances, ConstraintKinds #-} | ||
{-# OPTIONS_GHC -fno-warn-missing-signatures -fno-warn-missing-fields -fno-warn-missing-pattern-synonym-signatures -fno-warn-incomplete-patterns #-} | ||
module Domain.Scheme (SchemeAdrs, Address(..), module Domain.Scheme.Class, module Domain.Scheme.Modular) where | ||
module Domain.Scheme ( | ||
module Domain.Scheme.Class, | ||
module Domain.Scheme.Modular, | ||
module Domain.Scheme.Store | ||
) where | ||
|
||
import Data.Coerce hiding (coerce) | ||
import qualified Data.Coerce as Coerce | ||
import Control.Applicative (Applicative(liftA2)) | ||
import Data.Kind | ||
import Data.Set (Set) | ||
import Data.Default | ||
import qualified Data.Set as Set | ||
import Control.Monad ((>=>), (<=<)) | ||
import qualified Control.Monad as M | ||
|
||
import Prelude hiding (null) | ||
import Data.List hiding (null) | ||
import Control.Monad.Join | ||
import Data.Maybe (isJust) | ||
import Data.DMap ((:->)) | ||
import Data.Kind | ||
import Data.Hashable | ||
import Data.Typeable | ||
|
||
import Domain | ||
import Domain.Scheme.Class | ||
import Domain.Scheme.Modular | ||
import Domain.Scheme.Store | ||
|
||
|
||
|
||
---------------------------------------------- | ||
-- Store interactions | ||
---------------------------------------------- | ||
|
||
-- | A mapping from Scheme addresses | ||
-- to their corresponding values. | ||
-- | ||
-- For a given `v` for which an instance of | ||
-- `SchemeDomain` exists, it computes an association list | ||
-- mapping addresses to the heap allocated-values of the domain. | ||
-- | ||
-- This can be used as the basis for a `Data.DMap`. | ||
type SchemeAdrs v = '[ | ||
Adr v :-> Vlu (Adr v), | ||
PAdr v :-> Vlu (PAdr v), | ||
VAdr v :-> Vlu (VAdr v), | ||
SAdr v :-> Vlu (SAdr v) | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{-# LANGUAGE ConstraintKinds, FlexibleContexts #-} | ||
-- | Memory model for analyses that use the abstract domain for Scheme. | ||
-- | ||
-- It specifies the notion of a "store" which is an abstraction of the actual program memory as a function from a finite set of addresses to an abstract value. | ||
-- | ||
-- The memory of a Scheme program is divided into multiple disjoint regions: | ||
-- | ||
-- * A region to store the values of variables | ||
-- * A region to store strings | ||
-- * A region to store vectors | ||
-- * A region to store pairs | ||
-- | ||
-- All other values are entirely immutable and therefore do not have to be allocated in a store. | ||
-- | ||
-- The Domain.Scheme.Class defines the type for each of these addresses. This module exposes a type level association list that defines a mapping between these addresses and their corresponding abstract values. Furthermore, this module contains a constraint generator that creates `Has` constraints for each address in the Scheme domain. | ||
module Domain.Scheme.Store(SchemeAdrs, StoreDefinedFor) where | ||
|
||
import Domain | ||
import Domain.Scheme.Class | ||
|
||
import Data.Kind | ||
import Data.DMap | ||
import Data.TypeLevel.List | ||
|
||
-- | A mapping from Scheme addresses | ||
-- to their corresponding values. | ||
-- | ||
-- For a given `v` for which an instance of | ||
-- `SchemeDomain` exists, it computes an association list | ||
-- mapping addresses to the heap allocated-values of the domain. | ||
-- | ||
-- This can be used as the basis for a `Data.DMap`. | ||
type SchemeAdrs v = '[ | ||
Adr v :-> Vlu (Adr v), | ||
PAdr v :-> Vlu (PAdr v), | ||
VAdr v :-> Vlu (VAdr v), | ||
SAdr v :-> Vlu (SAdr v) | ||
] | ||
|
||
|
||
-- | Generate a set of inclusion constraints for the `SchemeAdrs` | ||
-- association list. | ||
type family GenerateInclusion xs ks :: Constraint where | ||
GenerateInclusion '[] ks = () | ||
GenerateInclusion (KV adr vlu ': xs) ks = (Has ks (KV adr vlu), GenerateInclusion xs ks) | ||
|
||
-- Set of inclusion constraints for `SchemeAdrs` | ||
type StoreDefinedFor v = | ||
(GenerateInclusion (SchemeAdrs v) (SchemeAdrs v), NoDuplicates (SchemeAdrs v)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
{-# LANGUAGE UndecidableInstances, PolyKinds, FlexibleInstances #-} | ||
{-# LANGUAGE UndecidableInstances, PolyKinds, FlexibleInstances, FlexibleContexts #-} | ||
{-# OPTIONS_GHC -Wno-redundant-constraints #-} | ||
module Data.TypeLevel.List(Has) where | ||
module Data.TypeLevel.List(Has, NoDuplicates) where | ||
|
||
import GHC.TypeError | ||
|
||
|
||
-- | Class that has an instance when the given type level list `l` | ||
-- contains the given value `v` | ||
class Has (l :: [k]) (v :: k) | ||
instance {-# OVERLAPPABLE #-} (Has xs x) => Has (y ': xs) x | ||
instance {-# OVERLAPPING #-} Has (x ': xs) x | ||
instance TypeError (Text "value not in list") => Has '[] v | ||
|
||
-- | Predicate that is satisfied when the gien list does not contain duplicates | ||
class NoDuplicates (l :: [k]) | ||
instance NoDuplicates l -- TODO: implement |