mirror of
https://github.com/github/semantic.git
synced 2024-12-19 12:51:52 +03:00
Use EvaluateModule to signal module loads.
This commit is contained in:
parent
8530a288cd
commit
dd755a4f0b
@ -29,6 +29,7 @@ deriving instance Member NonDet effects => MonadNonDet (Evaluating term value ef
|
||||
type EvaluatingEffects term value
|
||||
= '[ Resumable Prelude.String value
|
||||
, Fail -- Failure with an error message
|
||||
, Resumable (EvaluateModule term) value -- Requests to evaluate a module in the outermost analysis
|
||||
, Reader [Module term] -- The stack of currently-evaluating modules.
|
||||
, State (EnvironmentFor value) -- Environments (both local and global)
|
||||
, State (HeapFor value) -- The heap
|
||||
|
@ -1,4 +1,4 @@
|
||||
{-# LANGUAGE DataKinds, MultiParamTypeClasses, TypeFamilies #-}
|
||||
{-# LANGUAGE DataKinds, MultiParamTypeClasses, ScopedTypeVariables, TypeFamilies #-}
|
||||
{-# OPTIONS_GHC -Wno-redundant-constraints #-} -- For runAnalysis
|
||||
module Control.Abstract.Analysis
|
||||
( MonadAnalysis(..)
|
||||
@ -76,6 +76,7 @@ evaluateModules (m:ms) = withModules ms (evaluateModule m)
|
||||
--
|
||||
-- Looks up the term's name in the cache of evaluated modules first, returns a value if found, otherwise loads/evaluates the module.
|
||||
require :: ( MonadAnalysis term value m
|
||||
, MonadThrow (EvaluateModule term) value m
|
||||
, Ord (LocationFor value)
|
||||
)
|
||||
=> ModuleName
|
||||
@ -86,6 +87,7 @@ require name = getModuleTable >>= maybe (load name) pure . moduleTableLookup nam
|
||||
--
|
||||
-- Always loads/evaluates.
|
||||
load :: ( MonadAnalysis term value m
|
||||
, MonadThrow (EvaluateModule term) value m
|
||||
, Ord (LocationFor value)
|
||||
)
|
||||
=> ModuleName
|
||||
@ -93,10 +95,10 @@ load :: ( MonadAnalysis term value m
|
||||
load name = askModuleTable >>= maybe notFound evalAndCache . moduleTableLookup name
|
||||
where
|
||||
notFound = fail ("cannot load module: " <> show name)
|
||||
evalAndCache :: (MonadAnalysis term value m, Ord (LocationFor value)) => [Module term] -> m (EnvironmentFor value)
|
||||
evalAndCache :: forall term value m . (MonadAnalysis term value m, MonadThrow (EvaluateModule term) value m, Ord (LocationFor value)) => [Module term] -> m (EnvironmentFor value)
|
||||
evalAndCache [] = pure mempty
|
||||
evalAndCache (x:xs) = do
|
||||
void $ evaluateModule x
|
||||
void (throwException (EvaluateModule x) :: m value)
|
||||
env <- filterEnv <$> getExports <*> getEnv
|
||||
modifyModuleTable (moduleTableInsert name env)
|
||||
(env <>) <$> evalAndCache xs
|
||||
|
@ -28,6 +28,7 @@ class Evaluatable constr where
|
||||
, MonadValue value m
|
||||
, Show (LocationFor value)
|
||||
, MonadThrow Prelude.String value m
|
||||
, MonadThrow (EvaluateModule term) value m
|
||||
)
|
||||
=> SubtermAlgebra constr term (m value)
|
||||
default eval :: (MonadThrow Prelude.String value m, Show1 constr) => SubtermAlgebra constr term (m value)
|
||||
|
@ -41,7 +41,7 @@ instance Evaluatable Load where
|
||||
doLoad path shouldWrap
|
||||
eval (Load _) = fail "invalid argument supplied to load, path is required"
|
||||
|
||||
doLoad :: (MonadAnalysis term value m, MonadValue value m, Ord (LocationFor value)) => ByteString -> Bool -> m value
|
||||
doLoad :: (MonadAnalysis term value m, MonadThrow (EvaluateModule term) value m, MonadValue value m, Ord (LocationFor value)) => ByteString -> Bool -> m value
|
||||
doLoad path shouldWrap = do
|
||||
let name = pathToQualifiedName path
|
||||
importedEnv <- isolate (load name)
|
||||
|
Loading…
Reference in New Issue
Block a user