Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit f6cd84e

Browse files
committed
Merge branch 'sequence-values-in-the-abstract-domain' into scope-graphs
2 parents 057a4f8 + 0f34dce commit f6cd84e

3 files changed

Lines changed: 25 additions & 18 deletions

File tree

semantic-core/src/Analysis/Concrete.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# LANGUAGE FlexibleContexts, FlexibleInstances, LambdaCase, MultiParamTypeClasses, NamedFieldPuns, OverloadedStrings, RecordWildCards, TypeOperators, UndecidableInstances #-}
1+
{-# LANGUAGE DerivingVia, FlexibleContexts, FlexibleInstances, LambdaCase, MultiParamTypeClasses, NamedFieldPuns, OverloadedStrings, RecordWildCards, TypeOperators, UndecidableInstances #-}
22
module Analysis.Concrete
33
( Concrete(..)
44
, concrete
@@ -28,6 +28,7 @@ import qualified Data.IntSet as IntSet
2828
import Data.Loc
2929
import qualified Data.Map as Map
3030
import Data.Name
31+
import Data.Semigroup (Last (..))
3132
import qualified Data.Set as Set
3233
import Data.Term
3334
import Data.Text (Text, pack)
@@ -47,6 +48,7 @@ data Concrete
4748
| String Text
4849
| Record Env
4950
deriving (Eq, Ord, Show)
51+
deriving Semigroup via Last Concrete
5052

5153
recordFrame :: Concrete -> Maybe Env
5254
recordFrame (Record frame) = Just frame

semantic-core/src/Analysis/Eval.hs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import Prelude hiding (fail)
3030
eval :: ( Carrier sig m
3131
, Member (Reader Loc) sig
3232
, MonadFail m
33+
, Semigroup value
3334
)
3435
=> Analysis address value m
3536
-> (Term Core User -> m value)
@@ -41,12 +42,12 @@ eval Analysis{..} eval = \case
4142
addr <- alloc n
4243
v <- bind n addr (eval (instantiate1 (pure n) b))
4344
v <$ assign addr v
44-
a :>> b -> eval a >> eval b
45+
a :>> b -> (<>) <$> eval a <*> eval b
4546
Named (Ignored n) a :>>= b -> do
4647
a' <- eval a
4748
addr <- alloc n
4849
assign addr a'
49-
bind n addr (eval (instantiate1 (pure n) b))
50+
bind n addr ((a' <>) <$> eval (instantiate1 (pure n) b))
5051
Lam (Named (Ignored n) b) -> abstract eval n (instantiate1 (pure n) b)
5152
f :$ a -> do
5253
f' <- eval f
@@ -210,18 +211,18 @@ ruby = fromBody $ annWith callStack (rec (named' __semantic_global) (do' stateme
210211

211212

212213
data Analysis address value m = Analysis
213-
{ alloc :: User -> m address
214-
, bind :: forall a . User -> address -> m a -> m a
215-
, lookupEnv :: User -> m (Maybe address)
216-
, deref :: address -> m (Maybe value)
217-
, assign :: address -> value -> m ()
218-
, abstract :: (Term Core User -> m value) -> User -> Term Core User -> m value
219-
, apply :: (Term Core User -> m value) -> value -> value -> m value
220-
, unit :: m value
221-
, bool :: Bool -> m value
222-
, asBool :: value -> m Bool
223-
, string :: Text -> m value
224-
, asString :: value -> m Text
225-
, record :: [(User, value)] -> m value
226-
, (...) :: address -> User -> m (Maybe address)
214+
{ alloc :: User -> m address
215+
, bind :: forall a . User -> address -> m a -> m a
216+
, lookupEnv :: User -> m (Maybe address)
217+
, deref :: address -> m (Maybe value)
218+
, assign :: address -> value -> m ()
219+
, abstract :: (Term Core User -> m value) -> User -> Term Core User -> m value
220+
, apply :: (Term Core User -> m value) -> value -> value -> m value
221+
, unit :: m value
222+
, bool :: Bool -> m value
223+
, asBool :: value -> m Bool
224+
, string :: Text -> m value
225+
, asString :: value -> m Text
226+
, record :: [(User, value)] -> m value
227+
, (...) :: address -> User -> m (Maybe address)
227228
}

semantic-core/src/Analysis/Typecheck.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# LANGUAGE DeriveGeneric, DeriveTraversable, FlexibleContexts, FlexibleInstances, LambdaCase, OverloadedStrings, QuantifiedConstraints, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TypeApplications, TypeOperators #-}
1+
{-# LANGUAGE DeriveGeneric, DeriveTraversable, DerivingVia, FlexibleContexts, FlexibleInstances, LambdaCase, OverloadedStrings, QuantifiedConstraints, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TypeApplications, TypeOperators #-}
22
module Analysis.Typecheck
33
( Monotype (..)
44
, Meta
@@ -30,6 +30,7 @@ import qualified Data.Map as Map
3030
import Data.Maybe (fromJust, fromMaybe)
3131
import Data.Name as Name
3232
import Data.Scope
33+
import Data.Semigroup (Last (..))
3334
import qualified Data.Set as Set
3435
import Data.Term
3536
import Data.Void
@@ -44,6 +45,9 @@ data Monotype f a
4445
| Record (Map.Map User (f a))
4546
deriving (Foldable, Functor, Generic1, Traversable)
4647

48+
-- FIXME: Union the effects/annotations on the operands.
49+
deriving via (Last (Term Monotype a)) instance Semigroup (Term Monotype a)
50+
4751
deriving instance (Eq a, forall a . Eq a => Eq (f a), Monad f) => Eq (Monotype f a)
4852
deriving instance (Ord a, forall a . Eq a => Eq (f a)
4953
, forall a . Ord a => Ord (f a), Monad f) => Ord (Monotype f a)

0 commit comments

Comments
 (0)