mirror of
https://github.com/github/semantic.git
synced 2024-12-26 08:25:19 +03:00
Specialize the scope graph analysis to Name.
This commit is contained in:
parent
4962104008
commit
6191f2e1be
@ -12,6 +12,7 @@ import Analysis.Carrier.Env.Monovariant
|
||||
import qualified Analysis.Carrier.Heap.Monovariant as A
|
||||
import Analysis.File
|
||||
import Analysis.FlowInsensitive
|
||||
import Analysis.Name
|
||||
import Control.Applicative (Alternative (..))
|
||||
import Control.Carrier.Fail.WithLoc
|
||||
import Control.Effect.Carrier
|
||||
@ -51,15 +52,15 @@ instance Ord name => Monoid (ScopeGraph name) where
|
||||
mempty = ScopeGraph Map.empty
|
||||
|
||||
scopeGraph
|
||||
:: (Ord name, Ord (term name))
|
||||
:: Ord (term Name)
|
||||
=> (forall sig m
|
||||
. (Carrier sig m, Member (Reader Path.AbsRelFile) sig, Member (Reader Span) sig, MonadFail m)
|
||||
=> Analysis term name name (ScopeGraph name) m
|
||||
-> (term name -> m (ScopeGraph name))
|
||||
-> (term name -> m (ScopeGraph name))
|
||||
=> Analysis term Name Name (ScopeGraph Name) m
|
||||
-> (term Name -> m (ScopeGraph Name))
|
||||
-> (term Name -> m (ScopeGraph Name))
|
||||
)
|
||||
-> [File (term name)]
|
||||
-> (Heap name (ScopeGraph name), [File (Either (Path.AbsRelFile, Span, String) (ScopeGraph name))])
|
||||
-> [File (term Name)]
|
||||
-> (Heap Name (ScopeGraph Name), [File (Either (Path.AbsRelFile, Span, String) (ScopeGraph Name))])
|
||||
scopeGraph eval
|
||||
= run
|
||||
. runFresh
|
||||
@ -67,46 +68,44 @@ scopeGraph eval
|
||||
. traverse (runFile eval)
|
||||
|
||||
runFile
|
||||
:: forall term name m sig
|
||||
:: forall term m sig
|
||||
. ( Carrier sig m
|
||||
, Effect sig
|
||||
, Member Fresh sig
|
||||
, Member (State (Heap name (ScopeGraph name))) sig
|
||||
, Ord name
|
||||
, Ord (term name)
|
||||
, Member (State (Heap Name (ScopeGraph Name))) sig
|
||||
, Ord (term Name)
|
||||
)
|
||||
=> (forall sig m
|
||||
. (Carrier sig m, Member (Reader Path.AbsRelFile) sig, Member (Reader Span) sig, MonadFail m)
|
||||
=> Analysis term name name (ScopeGraph name) m
|
||||
-> (term name -> m (ScopeGraph name))
|
||||
-> (term name -> m (ScopeGraph name))
|
||||
=> Analysis term Name Name (ScopeGraph Name) m
|
||||
-> (term Name -> m (ScopeGraph Name))
|
||||
-> (term Name -> m (ScopeGraph Name))
|
||||
)
|
||||
-> File (term name)
|
||||
-> m (File (Either (Path.AbsRelFile, Span, String) (ScopeGraph name)))
|
||||
-> File (term Name)
|
||||
-> m (File (Either (Path.AbsRelFile, Span, String) (ScopeGraph Name)))
|
||||
runFile eval file = traverse run file
|
||||
where run = runReader (filePath file)
|
||||
. runReader (fileSpan file)
|
||||
. runEnv @name
|
||||
. runReader (Map.empty @name @Ref)
|
||||
. runEnv @Name
|
||||
. runReader (Map.empty @Name @Ref)
|
||||
. runFail
|
||||
. fmap fold
|
||||
. convergeTerm (Proxy @name) (A.runHeap @name @(ScopeGraph name) . fix (cacheTerm . eval scopeGraphAnalysis))
|
||||
. convergeTerm (Proxy @Name) (A.runHeap @Name @(ScopeGraph Name) . fix (cacheTerm . eval scopeGraphAnalysis))
|
||||
|
||||
scopeGraphAnalysis
|
||||
:: forall term name m sig
|
||||
:: forall term m sig
|
||||
. ( Alternative m
|
||||
, Carrier sig m
|
||||
, Member (Env name name) sig
|
||||
, Member (A.Heap name (ScopeGraph name)) sig
|
||||
, Member (Env Name Name) sig
|
||||
, Member (A.Heap Name (ScopeGraph Name)) sig
|
||||
, Member (Reader Path.AbsRelFile) sig
|
||||
, Member (Reader Span) sig
|
||||
, Ord name
|
||||
)
|
||||
=> Analysis term name name (ScopeGraph name) m
|
||||
=> Analysis term Name Name (ScopeGraph Name) m
|
||||
scopeGraphAnalysis = Analysis{..}
|
||||
where abstract eval name body = do
|
||||
addr <- alloc @name @name name
|
||||
A.assign @name @(ScopeGraph name) name mempty
|
||||
addr <- alloc @Name @Name name
|
||||
A.assign @Name @(ScopeGraph Name) name mempty
|
||||
bind name addr (eval body)
|
||||
apply _ f a = pure (f <> a)
|
||||
unit = pure mempty
|
||||
@ -120,6 +119,6 @@ scopeGraphAnalysis = Analysis{..}
|
||||
path <- ask
|
||||
span <- ask
|
||||
let v' = ScopeGraph (Map.singleton (Decl k path span) mempty) <> v
|
||||
(k, v') <$ A.assign @name addr v'
|
||||
(k, v') <$ A.assign @Name addr v'
|
||||
pure (foldMap snd fields')
|
||||
_ ... m = pure (Just m)
|
||||
|
Loading…
Reference in New Issue
Block a user