mirror of
https://github.com/github/semantic.git
synced 2024-12-01 09:15:01 +03:00
Remove redundant constraints and imports
This commit is contained in:
parent
e08b1100e4
commit
97545f0ae7
@ -53,7 +53,6 @@ import Data.Abstract.Live
|
||||
import Data.Abstract.Module (ModuleInfo)
|
||||
import Data.Abstract.Name
|
||||
import Data.Span (Span)
|
||||
import qualified Data.Set as Set
|
||||
import qualified Data.Map.Strict as Map
|
||||
import Prologue
|
||||
import Data.Abstract.Ref
|
||||
@ -65,7 +64,6 @@ withScopeAndFrame :: forall term address value m a sig. (
|
||||
, Member (Reader ModuleInfo) sig
|
||||
, Member (Reader Span) sig
|
||||
, Member (Resumable (BaseError (HeapError address))) sig
|
||||
, Member (Resumable (BaseError (ScopeError address))) sig
|
||||
, Member (State (Heap address address value)) sig
|
||||
, Member (State (ScopeGraph address)) sig
|
||||
, Carrier sig m
|
||||
@ -114,7 +112,6 @@ scopeLookup :: forall address value sig m term. (
|
||||
, Member (Reader Span) sig
|
||||
, Member (Resumable (BaseError (HeapError address))) sig
|
||||
, Member (State (Heap address address value)) sig
|
||||
, Member (State (ScopeGraph address)) sig
|
||||
, Carrier sig m
|
||||
)
|
||||
=> address
|
||||
@ -146,15 +143,10 @@ putCurrentFrame address = modify @(Heap address address value) (\heap -> heap {
|
||||
-- | Inserts a new frame into the heap with the given scope and links.
|
||||
newFrame :: forall address value sig m term. (
|
||||
Member (State (Heap address address value)) sig
|
||||
, Member (Reader ModuleInfo) sig
|
||||
, Member (Reader Span) sig
|
||||
, Ord address
|
||||
, Member (Allocator address) sig
|
||||
, Member (State (ScopeGraph address)) sig
|
||||
, Member Fresh sig
|
||||
, Carrier sig m
|
||||
, Show address
|
||||
, Show value
|
||||
)
|
||||
=> address
|
||||
-> Map EdgeLabel (Map address address)
|
||||
@ -167,13 +159,8 @@ newFrame scope links = do
|
||||
|
||||
-- | Evaluates the action within the frame of the given frame address.
|
||||
withFrame :: forall term address value sig m a. (
|
||||
Member (Resumable (BaseError (HeapError address))) sig
|
||||
, Member (Reader ModuleInfo) sig
|
||||
, Member (Reader Span) sig
|
||||
, Member (State (Heap address address value)) sig
|
||||
, Carrier sig m
|
||||
, Show value
|
||||
, Show address
|
||||
)
|
||||
=> address
|
||||
-> Evaluator term address value m a -- Not sure about this `sig` here (substituting `sig` for `effects`)
|
||||
@ -233,7 +220,6 @@ withChildFrame :: ( Member (Allocator address) sig
|
||||
, Member (Reader Span) sig
|
||||
, Member (Resumable (BaseError (HeapError address))) sig
|
||||
, Member (Resumable (BaseError (ScopeError address))) sig
|
||||
, Member (Deref value) sig
|
||||
, Ord address
|
||||
, Carrier sig m
|
||||
, Show address
|
||||
@ -264,12 +250,10 @@ deref slot@Address{..} = gets (Heap.getSlot slot) >>= maybeM (throwAddressError
|
||||
|
||||
putSlotDeclarationScope :: forall address value sig m term. ( Member (State (Heap address address value)) sig
|
||||
, Member (State (ScopeGraph address)) sig
|
||||
, Member (Resumable (BaseError (ScopeError address))) sig
|
||||
, Member (Resumable (BaseError (HeapError address))) sig
|
||||
, Member (Reader ModuleInfo) sig
|
||||
, Member (Reader Span) sig
|
||||
, Ord address
|
||||
, Show address
|
||||
, Carrier sig m
|
||||
)
|
||||
=> Address address
|
||||
@ -315,11 +299,9 @@ lookupDeclarationFrame decl = do
|
||||
|
||||
-- | Follow a path through the heap and return the frame address associated with the declaration.
|
||||
lookupFrameAddress :: ( Member (State (Heap address address value)) sig
|
||||
, Member (State (ScopeGraph address)) sig
|
||||
, Member (Reader ModuleInfo) sig
|
||||
, Member (Reader Span) sig
|
||||
, Member (Resumable (BaseError (HeapError address))) sig
|
||||
, Member (Resumable (BaseError (ScopeError address))) sig
|
||||
, Ord address
|
||||
, Carrier sig m
|
||||
)
|
||||
@ -331,7 +313,7 @@ lookupFrameAddress path = do
|
||||
where
|
||||
go path address = case path of
|
||||
Hole -> throwHeapError (LookupLinkError path)
|
||||
DPath decl position -> pure address
|
||||
DPath _ _ -> pure address
|
||||
p@(EPath edge nextScopeAddress path') -> do
|
||||
linkMap <- frameLinks address
|
||||
let frameAddress = do
|
||||
@ -353,14 +335,11 @@ frameLinks address = maybeM (throwHeapError $ LookupLinksError address) . Heap.f
|
||||
|
||||
|
||||
bindFrames :: ( Ord address
|
||||
, Member (Reader ModuleInfo) sig
|
||||
, Member (Reader Span) sig
|
||||
, Member (Resumable (BaseError (ScopeError address))) sig
|
||||
, Member (State (Heap address address value)) sig
|
||||
, Carrier sig m
|
||||
)
|
||||
=> Heap address address value
|
||||
-> Evaluator term address value m ()
|
||||
, Member (State (Heap address address value)) sig
|
||||
, Carrier sig m
|
||||
)
|
||||
=> Heap address address value
|
||||
-> Evaluator term address value m ()
|
||||
bindFrames oldHeap = do
|
||||
currentHeap <- get
|
||||
let newHeap = Heap.heap oldHeap <> Heap.heap currentHeap
|
||||
@ -403,29 +382,30 @@ assign addr value = do
|
||||
-- Garbage collection
|
||||
|
||||
-- | Collect any addresses in the heap not rooted in or reachable from the given 'Live' set.
|
||||
gc :: ( Member (State (Heap address address value)) sig
|
||||
, Ord address
|
||||
, ValueRoots address value
|
||||
, Carrier sig m
|
||||
)
|
||||
=> Live address -- ^ The set of addresses to consider rooted.
|
||||
-- gc :: ( Member (State (Heap address address value)) sig
|
||||
-- , Ord address
|
||||
-- , ValueRoots address value
|
||||
-- , Carrier sig m
|
||||
-- )
|
||||
-- => Live address -- ^ The set of addresses to consider rooted.
|
||||
-- -> Evaluator term address value m ()
|
||||
gc :: Live address -- ^ The set of addresses to consider rooted.
|
||||
-> Evaluator term address value m ()
|
||||
gc roots =
|
||||
-- gc roots =
|
||||
gc _ =
|
||||
-- TODO: Implement frame garbage collection
|
||||
undefined
|
||||
-- modifyHeap (heapRestrict <*> reachable roots)
|
||||
|
||||
-- | Compute the set of addresses reachable from a given root set in a given heap.
|
||||
reachable :: ( Ord address
|
||||
, ValueRoots address value
|
||||
)
|
||||
reachable :: Ord address
|
||||
=> Live address -- ^ The set of root addresses.
|
||||
-> Heap address address value -- ^ The heap to trace addresses through.
|
||||
-> Live address -- ^ The set of addresses reachable from the root set.
|
||||
reachable roots heap = go mempty roots
|
||||
reachable roots _ = go mempty roots
|
||||
where go seen set = case liveSplit set of
|
||||
Nothing -> seen
|
||||
Just (a, as) -> undefined -- go (liveInsert a seen) $ case heapLookupAll a heap of
|
||||
Just (_, _) -> undefined -- go (liveInsert a seen) $ case heapLookupAll a heap of
|
||||
-- Just values -> liveDifference (foldr ((<>) . valueRoots) mempty values <> as) seen
|
||||
-- _ -> seen
|
||||
|
||||
@ -472,6 +452,7 @@ instance Eq address => Eq1 (HeapError address) where
|
||||
liftEq _ (LookupLinksError a) (LookupLinksError b) = a == b
|
||||
liftEq _ (LookupLinkError a) (LookupLinkError b) = a == b
|
||||
liftEq _ (LookupFrameError a) (LookupFrameError b) = a == b
|
||||
liftEq _ _ _ = False
|
||||
|
||||
throwHeapError :: ( Member (Resumable (BaseError (HeapError address))) sig
|
||||
, Member (Reader ModuleInfo) sig
|
||||
@ -487,7 +468,7 @@ runHeapError :: (Carrier sig m, Effect sig)
|
||||
-> Evaluator term address value m (Either (SomeError (BaseError (HeapError address))) a)
|
||||
runHeapError = raiseHandler runResumable
|
||||
|
||||
runHeapErrorWith :: (Carrier sig m, Effect sig)
|
||||
runHeapErrorWith :: Carrier sig m
|
||||
=> (forall resume. (BaseError (HeapError address)) resume -> Evaluator term address value m resume)
|
||||
-> Evaluator term address value (ResumableWithC (BaseError (HeapError address)) (Eff m)) a
|
||||
-> Evaluator term address value m a
|
||||
|
@ -22,7 +22,6 @@ module Control.Abstract.Modules
|
||||
import Control.Abstract.Evaluator
|
||||
import Control.Effect.Carrier
|
||||
import Control.Effect.Sum
|
||||
import Data.Abstract.Environment
|
||||
import Data.Abstract.BaseError
|
||||
import Data.Abstract.Module
|
||||
import Data.Abstract.ModuleTable as ModuleTable
|
||||
|
@ -38,11 +38,9 @@ import Control.Abstract.Evaluator hiding (Local)
|
||||
import Data.Abstract.Module
|
||||
import Data.Abstract.BaseError
|
||||
import Control.Effect.Carrier
|
||||
import Control.Effect.Sum
|
||||
import Data.Abstract.Name hiding (name)
|
||||
import Data.Abstract.ScopeGraph (Declaration (..), EdgeLabel, Reference, ScopeGraph, Address(..), Scope(..))
|
||||
import qualified Data.Abstract.ScopeGraph as ScopeGraph
|
||||
import qualified Data.Map.Strict as Map
|
||||
import Data.Span
|
||||
import Prelude hiding (lookup)
|
||||
import Prologue
|
||||
@ -93,9 +91,6 @@ insertEdge label target = modify (ScopeGraph.insertEdge label target)
|
||||
|
||||
-- | Bind all of the scopes from a 'ScopeGraph'.
|
||||
bindAll :: ( Ord address
|
||||
, Member (Reader ModuleInfo) sig
|
||||
, Member (Reader Span) sig
|
||||
, Member (Resumable (BaseError (ScopeError address))) sig
|
||||
, Member (State (ScopeGraph address)) sig
|
||||
, Carrier sig m
|
||||
)
|
||||
@ -152,13 +147,10 @@ insertImportReference :: ( Member (Resumable (BaseError (ScopeError address))) s
|
||||
-> Scope address
|
||||
-> Evaluator term address value m ()
|
||||
insertImportReference ref decl g scopeAddress scope = do
|
||||
newScope <- maybeM (throwScopeError LookupScopeError) (ScopeGraph.insertImportReference ref decl g scopeAddress scope)
|
||||
newScope <- maybeM (throwScopeError LookupScopeError) (ScopeGraph.insertImportReference ref decl g scope)
|
||||
insertScope scopeAddress newScope
|
||||
|
||||
insertScope :: ( Member (Resumable (BaseError (ScopeError address))) sig
|
||||
, Member (Reader ModuleInfo) sig
|
||||
, Member (Reader Span) sig
|
||||
, Member (State (ScopeGraph address)) sig
|
||||
insertScope :: ( Member (State (ScopeGraph address)) sig
|
||||
, Carrier sig m
|
||||
, Ord address
|
||||
)
|
||||
@ -210,7 +202,7 @@ withScope scope action = do
|
||||
_ -> modify (\g -> g { ScopeGraph.currentScope = prevScope })
|
||||
pure value
|
||||
|
||||
putCurrentScope :: (Ord address, Member (State (ScopeGraph address)) sig, Carrier sig m) => address -> Evaluator term address value m ()
|
||||
putCurrentScope :: (Member (State (ScopeGraph address)) sig, Carrier sig m) => address -> Evaluator term address value m ()
|
||||
putCurrentScope scope = modify (\g -> g { ScopeGraph.currentScope = Just scope })
|
||||
|
||||
throwScopeError :: ( Member (Resumable (BaseError (ScopeError address))) sig
|
||||
@ -232,7 +224,7 @@ data ScopeError address return where
|
||||
deriving instance Eq (ScopeError address return)
|
||||
deriving instance Show (ScopeError address return)
|
||||
instance Show address => Show1 (ScopeError address) where liftShowsPrec _ _ = showsPrec
|
||||
instance Eq address => Eq1 (ScopeError address) where
|
||||
instance Eq1 (ScopeError address) where
|
||||
liftEq _ (ScopeError m1 n1) (ScopeError m2 n2) = m1 == m2 && n1 == n2
|
||||
liftEq _ CurrentScopeError CurrentScopeError = True
|
||||
liftEq _ LookupScopeError LookupScopeError = True
|
||||
|
@ -11,7 +11,6 @@ module Data.Abstract.Heap
|
||||
, initFrame
|
||||
, newFrame
|
||||
, heapSize
|
||||
, currentFrame
|
||||
, Position(..)
|
||||
, pathPosition
|
||||
, pathDeclaration
|
||||
@ -23,8 +22,6 @@ import Data.Abstract.Live
|
||||
import Data.Abstract.ScopeGraph (EdgeLabel(..), Declaration(..), Path(..), Position(..), Address(..), ScopeGraph, pathPosition, pathDeclaration, lookupScopePath)
|
||||
import qualified Data.Map.Strict as Map
|
||||
import qualified Data.IntMap as IntMap
|
||||
import qualified Data.Map.Monoidal as Monoidal
|
||||
import Data.Semigroup.Reducer
|
||||
import Prologue
|
||||
import Prelude hiding (lookup)
|
||||
|
||||
@ -67,14 +64,6 @@ setSlot Address{..} value h@Heap{} =
|
||||
h { heap = Map.insert frameAddress (frame { slots = IntMap.insert (unPosition position) value slotMap }) (heap h) }
|
||||
Nothing -> h
|
||||
|
||||
lookup :: (Ord address, Ord scope) => address -> Path scope -> Declaration -> Heap scope address value -> Maybe scope
|
||||
lookup address (DPath d _) declaration heap = guard (d == declaration) >> scopeLookup address heap
|
||||
lookup address (EPath label scope path) declaration heap = do
|
||||
frame <- frameLookup address heap
|
||||
scopeMap <- Map.lookup label (links frame)
|
||||
nextAddress <- Map.lookup scope scopeMap
|
||||
lookup nextAddress path declaration heap
|
||||
|
||||
lookupDeclaration :: (Ord address, Show address) => Declaration -> ScopeGraph address -> Heap address address value -> Maybe (Address address)
|
||||
lookupDeclaration Declaration{..} scopeGraph heap = do
|
||||
path <- lookupScopePath unDeclaration scopeGraph
|
||||
@ -87,13 +76,14 @@ lookupFrameAddress path h@Heap{..} = do
|
||||
go path frameAddress
|
||||
where
|
||||
go path address = case path of
|
||||
DPath decl position -> pure address
|
||||
DPath _ _ -> pure address
|
||||
EPath edge nextScopeAddress path' -> do
|
||||
linkMap <- frameLinks address h
|
||||
frameAddress <- do
|
||||
scopeMap <- Map.lookup edge linkMap
|
||||
Map.lookup nextScopeAddress scopeMap
|
||||
go path' frameAddress
|
||||
Hole -> Nothing
|
||||
|
||||
newFrame :: (Ord address) => scope -> address -> Map EdgeLabel (Map scope address) -> Heap scope address value -> Heap scope address value
|
||||
newFrame scope address links = insertFrame address (Frame scope links mempty)
|
||||
@ -110,9 +100,6 @@ fillFrame address slots heap =
|
||||
Just frame -> insertFrame address (frame { slots = slots }) heap
|
||||
Nothing -> heap
|
||||
|
||||
deleteFrame :: Ord address => address -> Heap scope address value -> Heap scope address value
|
||||
deleteFrame address h@Heap{..} = h { heap = Map.delete address heap }
|
||||
|
||||
-- | The number of frames in the `Heap`.
|
||||
heapSize :: Heap scope address value -> Int
|
||||
heapSize = Map.size . heap
|
||||
|
@ -4,7 +4,6 @@ module Data.Abstract.Ref
|
||||
, Ref (..)
|
||||
) where
|
||||
|
||||
import Data.Abstract.Name
|
||||
import Data.Abstract.ScopeGraph (Address(..))
|
||||
import Data.Bifunctor
|
||||
|
||||
@ -16,8 +15,8 @@ data ValueRef address value where
|
||||
LvalMember :: Address address -> ValueRef address value
|
||||
|
||||
instance Bifunctor ValueRef where
|
||||
bimap f g (Rval v) = Rval (g v)
|
||||
bimap f g (LvalMember slot@Address{..}) = LvalMember (slot { frameAddress = f frameAddress })
|
||||
bimap _ g (Rval v) = Rval (g v)
|
||||
bimap f _ (LvalMember slot@Address{..}) = LvalMember (slot { frameAddress = f frameAddress })
|
||||
|
||||
deriving instance (Eq value, Eq address) => Eq (ValueRef address value)
|
||||
deriving instance (Ord value, Ord address) => Ord (ValueRef address value)
|
||||
|
@ -168,7 +168,7 @@ insertImportReference ref decl@Declaration{..} g@ScopeGraph{..} scope = do
|
||||
-- Return the first path to the declaration through the scopes.
|
||||
getFirst (foldMap (First . (\scope -> go scope (path . EPath edge scope))) scopes)
|
||||
|
||||
lookupScopePath :: (Ord scopeAddress, Show scopeAddress) => Name -> ScopeGraph scopeAddress -> Maybe (Path scopeAddress)
|
||||
lookupScopePath :: Ord scopeAddress => Name -> ScopeGraph scopeAddress -> Maybe (Path scopeAddress)
|
||||
lookupScopePath declaration g@ScopeGraph{..} = do
|
||||
currentAddress <- currentScope
|
||||
go currentAddress id
|
||||
|
Loading…
Reference in New Issue
Block a user