mirror of
https://github.com/github/semantic.git
synced 2024-12-19 12:51:52 +03:00
Define & use UnevaluatedModules/EvaluatedModules synonyms.
This commit is contained in:
parent
770a19770e
commit
bd0b7e965e
@ -12,7 +12,7 @@ import Data.Semilattice.Lower
|
||||
data EvaluatingState location value = EvaluatingState
|
||||
{ environment :: Environment location value
|
||||
, heap :: Heap location value
|
||||
, modules :: ModuleTable (Environment location value, value)
|
||||
, modules :: EvaluatedModules location value
|
||||
, exports :: Exports location value
|
||||
}
|
||||
|
||||
@ -27,14 +27,14 @@ evaluating :: Evaluator location term value
|
||||
': Reader (Environment location value)
|
||||
': State (Environment location value)
|
||||
': State (Heap location value)
|
||||
': State (ModuleTable (Environment location value, value))
|
||||
': State (EvaluatedModules location value)
|
||||
': State (Exports location value)
|
||||
': effects) result
|
||||
-> Evaluator location term value effects (Either String result, EvaluatingState location value)
|
||||
evaluating
|
||||
= fmap (\ ((((result, env), heap), modules), exports) -> (result, EvaluatingState env heap modules exports))
|
||||
. runState lowerBound -- State (Exports location value)
|
||||
. runState lowerBound -- State (ModuleTable (Environment location value, value))
|
||||
. runState lowerBound -- State (EvaluatedModules locaiton value)
|
||||
. runState lowerBound -- State (Heap location value)
|
||||
. runState lowerBound -- State (Environment location value)
|
||||
. runReader lowerBound -- Reader (Environment location value)
|
||||
|
@ -1,6 +1,7 @@
|
||||
{-# LANGUAGE GADTs, RankNTypes, TypeOperators #-}
|
||||
module Control.Abstract.ModuleTable
|
||||
( ModuleTable
|
||||
( UnevaluatedModules
|
||||
, EvaluatedModules
|
||||
, getModuleTable
|
||||
, resolve
|
||||
, listModulesInDir
|
||||
@ -24,6 +25,9 @@ import Data.Abstract.ModuleTable as ModuleTable
|
||||
import Data.Language
|
||||
import Prologue
|
||||
|
||||
type UnevaluatedModules term = ModuleTable [Module term]
|
||||
type EvaluatedModules location value = ModuleTable (Environment location value, value)
|
||||
|
||||
-- | Retrieve the table of evaluated modules.
|
||||
getModuleTable :: Member (State (ModuleTable (Environment location value, value))) effects => Evaluator location term value effects (ModuleTable (Environment location value, value))
|
||||
getModuleTable = raise get
|
||||
@ -34,7 +38,7 @@ modifyModuleTable = raise . modify'
|
||||
|
||||
|
||||
-- | Retrieve the table of unevaluated modules.
|
||||
askModuleTable :: Member (Reader (ModuleTable [Module term])) effects
|
||||
askModuleTable :: Member (Reader (UnevaluatedModules term)) effects
|
||||
=> Evaluator location term value effects (ModuleTable [Module term])
|
||||
askModuleTable = raise ask
|
||||
|
||||
@ -49,14 +53,14 @@ localLoadStack = raiseHandler . local
|
||||
|
||||
|
||||
-- Resolve a list of module paths to a possible module table entry.
|
||||
resolve :: Member (Reader (ModuleTable [Module term])) effects
|
||||
resolve :: Member (Reader (UnevaluatedModules term)) effects
|
||||
=> [FilePath]
|
||||
-> Evaluator location term value effects (Maybe ModulePath)
|
||||
resolve names = do
|
||||
tbl <- askModuleTable
|
||||
pure $ find (`ModuleTable.member` tbl) names
|
||||
|
||||
listModulesInDir :: Member (Reader (ModuleTable [Module term])) effects
|
||||
listModulesInDir :: Member (Reader (UnevaluatedModules term)) effects
|
||||
=> FilePath
|
||||
-> Evaluator location term value effects [ModulePath]
|
||||
listModulesInDir dir = modulePathsInDir dir <$> askModuleTable
|
||||
@ -66,7 +70,7 @@ listModulesInDir dir = modulePathsInDir dir <$> askModuleTable
|
||||
--
|
||||
-- Looks up the term's name in the cache of evaluated modules first, returns if found, otherwise loads/evaluates the module.
|
||||
require :: Members '[ EvalModule term value
|
||||
, Reader (ModuleTable [Module term])
|
||||
, Reader (UnevaluatedModules term)
|
||||
, Reader LoadStack
|
||||
, Resumable (LoadError term)
|
||||
, State (Environment location value)
|
||||
@ -82,7 +86,7 @@ require name = getModuleTable >>= maybeM (load name) . fmap Just . ModuleTable.l
|
||||
--
|
||||
-- Always loads/evaluates.
|
||||
load :: Members '[ EvalModule term value
|
||||
, Reader (ModuleTable [Module term])
|
||||
, Reader (UnevaluatedModules term)
|
||||
, Reader LoadStack
|
||||
, Resumable (LoadError term)
|
||||
, State (Environment location value)
|
||||
|
@ -56,7 +56,7 @@ type EvaluatableConstraints location term value effects =
|
||||
, Reader (Environment location value)
|
||||
, Reader LoadStack
|
||||
, Reader ModuleInfo
|
||||
, Reader (ModuleTable [Module term])
|
||||
, Reader (UnevaluatedModules term)
|
||||
, Reader PackageInfo
|
||||
, Resumable (AddressError location value)
|
||||
, Resumable (EnvironmentError value)
|
||||
@ -178,7 +178,7 @@ evaluatePackageWith :: ( Evaluatable (Base term)
|
||||
] outer
|
||||
, Recursive term
|
||||
, inner ~ (Goto inner' value ': inner')
|
||||
, inner' ~ (LoopControl value ': Return value ': Reader ModuleInfo ': EvalModule term value ': Reader LoadStack ': Reader (ModuleTable [Module term]) ': Reader PackageInfo ': outer)
|
||||
, inner' ~ (LoopControl value ': Return value ': Reader ModuleInfo ': EvalModule term value ': Reader LoadStack ': Reader (UnevaluatedModules term) ': Reader PackageInfo ': outer)
|
||||
)
|
||||
=> (SubtermAlgebra Module term (Evaluator location term value inner value) -> SubtermAlgebra Module term (Evaluator location term value inner value))
|
||||
-> (SubtermAlgebra (Base term) term (Evaluator location term value inner value) -> SubtermAlgebra (Base term) term (Evaluator location term value inner value))
|
||||
@ -197,7 +197,7 @@ evaluatePackageBodyWith :: forall location term value inner inner' outer
|
||||
] outer
|
||||
, Recursive term
|
||||
, inner ~ (Goto inner' value ': inner')
|
||||
, inner' ~ (LoopControl value ': Return value ': Reader ModuleInfo ': EvalModule term value ': Reader LoadStack ': Reader (ModuleTable [Module term]) ': outer)
|
||||
, inner' ~ (LoopControl value ': Return value ': Reader ModuleInfo ': EvalModule term value ': Reader LoadStack ': Reader (UnevaluatedModules term) ': outer)
|
||||
)
|
||||
=> (SubtermAlgebra Module term (Evaluator location term value inner value) -> SubtermAlgebra Module term (Evaluator location term value inner value))
|
||||
-> (SubtermAlgebra (Base term) term (Evaluator location term value inner value) -> SubtermAlgebra (Base term) term (Evaluator location term value inner value))
|
||||
|
@ -29,7 +29,7 @@ defaultAlias :: ImportPath -> Name
|
||||
defaultAlias = name . BC.pack . takeFileName . unPath
|
||||
|
||||
resolveGoImport :: Members '[ Reader ModuleInfo
|
||||
, Reader (ModuleTable [Module term])
|
||||
, Reader (UnevaluatedModules term)
|
||||
, Reader Package.PackageInfo
|
||||
, Resumable ResolutionError
|
||||
, Trace
|
||||
|
@ -35,7 +35,7 @@ instance Evaluatable VariableName
|
||||
-- file, the complete contents of the included file are treated as though it
|
||||
-- were defined inside that function.
|
||||
|
||||
resolvePHPName :: Members '[ Reader (ModuleTable [Module term])
|
||||
resolvePHPName :: Members '[ Reader (UnevaluatedModules term)
|
||||
, Resumable ResolutionError
|
||||
] effects
|
||||
=> ByteString
|
||||
@ -47,7 +47,7 @@ resolvePHPName n = do
|
||||
toName = BC.unpack . dropRelativePrefix . stripQuotes
|
||||
|
||||
include :: ( AbstractValue location value effects
|
||||
, Members '[ Reader (ModuleTable [Module term])
|
||||
, Members '[ Reader (UnevaluatedModules term)
|
||||
, Resumable ResolutionError
|
||||
, State (Environment location value)
|
||||
, State (Exports location value)
|
||||
|
@ -52,7 +52,7 @@ relativeQualifiedName prefix paths = RelativeQualifiedName (BC.unpack prefix) (J
|
||||
-- `parent/two/__init__.py` and
|
||||
-- `parent/three/__init__.py` respectively.
|
||||
resolvePythonModules :: Members '[ Reader ModuleInfo
|
||||
, Reader (ModuleTable [Module term])
|
||||
, Reader (UnevaluatedModules term)
|
||||
, Resumable ResolutionError
|
||||
, Trace
|
||||
] effects
|
||||
|
@ -76,12 +76,12 @@ instance Evaluatable Require where
|
||||
doRequire :: ( AbstractValue location value effects
|
||||
, Members '[ EvalModule term value
|
||||
, Reader LoadStack
|
||||
, Reader (ModuleTable [M.Module term])
|
||||
, Reader (UnevaluatedModules term)
|
||||
, Resumable (LoadError term)
|
||||
, Resumable ResolutionError
|
||||
, State (Environment location value)
|
||||
, State (Exports location value)
|
||||
, State (ModuleTable (Environment location value, value))
|
||||
, State (EvaluatedModules location value)
|
||||
, Trace
|
||||
] effects
|
||||
)
|
||||
@ -114,12 +114,12 @@ instance Evaluatable Load where
|
||||
doLoad :: ( AbstractValue location value effects
|
||||
, Members '[ EvalModule term value
|
||||
, Reader LoadStack
|
||||
, Reader (ModuleTable [M.Module term])
|
||||
, Reader (UnevaluatedModules term)
|
||||
, Resumable (LoadError term)
|
||||
, Resumable ResolutionError
|
||||
, State (Environment location value)
|
||||
, State (Exports location value)
|
||||
, State (ModuleTable (Environment location value, value))
|
||||
, State (EvaluatedModules location value)
|
||||
, Trace
|
||||
] effects
|
||||
)
|
||||
|
@ -35,7 +35,7 @@ toName = FV.name . BC.pack . unPath
|
||||
-- Node.js resolution algorithm: https://nodejs.org/api/modules.html#modules_all_together
|
||||
-- TypeScript has a couple of different strategies, but the main one mimics Node.js.
|
||||
resolveWithNodejsStrategy :: Members '[ Reader M.ModuleInfo
|
||||
, Reader (ModuleTable [M.Module term])
|
||||
, Reader (UnevaluatedModules term)
|
||||
, Resumable ResolutionError
|
||||
, Trace
|
||||
] effects
|
||||
@ -53,7 +53,7 @@ resolveWithNodejsStrategy (ImportPath path NonRelative) exts = resolveNonRelativ
|
||||
-- /root/src/moduleB/package.json (if it specifies a "types" property)
|
||||
-- /root/src/moduleB/index.ts
|
||||
resolveRelativePath :: Members '[ Reader M.ModuleInfo
|
||||
, Reader (ModuleTable [M.Module term])
|
||||
, Reader (UnevaluatedModules term)
|
||||
, Resumable ResolutionError
|
||||
, Trace
|
||||
] effects
|
||||
@ -79,7 +79,7 @@ resolveRelativePath relImportPath exts = do
|
||||
-- /root/node_modules/moduleB.ts, etc
|
||||
-- /node_modules/moduleB.ts, etc
|
||||
resolveNonRelativePath :: Members '[ Reader M.ModuleInfo
|
||||
, Reader (ModuleTable [M.Module term])
|
||||
, Reader (UnevaluatedModules term)
|
||||
, Resumable ResolutionError
|
||||
, Trace
|
||||
] effects
|
||||
@ -100,7 +100,7 @@ resolveNonRelativePath name exts = do
|
||||
Right m -> m <$ traceResolve name m
|
||||
notFound xs = throwResumable $ NotFoundError name xs Language.TypeScript
|
||||
|
||||
resolveTSModule :: Members '[ Reader (ModuleTable [M.Module term]) ] effects
|
||||
resolveTSModule :: Members '[ Reader (UnevaluatedModules term) ] effects
|
||||
=> FilePath
|
||||
-> [String]
|
||||
-> Evaluator location term value effects (Either [FilePath] M.ModulePath)
|
||||
@ -123,12 +123,12 @@ evalRequire :: ( AbstractValue location value effects
|
||||
, Members '[ EvalModule term value
|
||||
, Reader (Environment location value)
|
||||
, Reader LoadStack
|
||||
, Reader (ModuleTable [M.Module term])
|
||||
, Reader (UnevaluatedModules term)
|
||||
, Resumable (LoadError term)
|
||||
, State (Environment location value)
|
||||
, State (Exports location value)
|
||||
, State (Heap location value)
|
||||
, State (ModuleTable (Environment location value, value))
|
||||
, State (EvaluatedModules location value)
|
||||
, Trace
|
||||
] effects
|
||||
, Reducer value (Cell location value)
|
||||
|
Loading…
Reference in New Issue
Block a user