Skip to content

Commit

Permalink
Rename Roots type to Root
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcadman committed Oct 30, 2023
1 parent 00ccdd1 commit 2426167
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 98 deletions.
30 changes: 15 additions & 15 deletions app/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Juvix.Compiler.Concrete.Translation.FromParsed.Analysis.PathResolver
import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.Termination.Checker
import Juvix.Compiler.Pipeline.Run
import Juvix.Data.Error qualified as Error
import Juvix.Extra.Paths.Base
import Juvix.Extra.Paths.Base hiding (rootBuildDir)
import Juvix.Prelude.Pretty hiding
( Doc,
)
Expand All @@ -17,7 +17,7 @@ data App m a where
ExitMsg :: ExitCode -> Text -> App m a
ExitJuvixError :: JuvixError -> App m a
PrintJuvixError :: JuvixError -> App m ()
AskRoots :: App m Roots
AskRoot :: App m Root
AskInvokeDir :: App m (Path Abs Dir)
AskPkgDir :: App m (Path Abs Dir)
AskBuildDir :: App m (Path Abs Dir)
Expand All @@ -38,7 +38,7 @@ makeSem ''App

data RunAppIOArgs = RunAppIOArgs
{ _runAppIOArgsGlobalOptions :: GlobalOptions,
_runAppIOArgsRoots :: Roots
_runAppIOArgsRoot :: Root
}

runAppIO ::
Expand All @@ -49,7 +49,7 @@ runAppIO ::
Sem r a
runAppIO args@RunAppIOArgs {..} =
interpret $ \case
AskPackageGlobal -> return (_runAppIOArgsRoots ^. rootsPackageGlobal)
AskPackageGlobal -> return (_runAppIOArgsRoot ^. rootPackageGlobal)
FromAppPathFile p -> embed (prepathToAbsFile invDir (p ^. pathPath))
GetMainFile m -> getMainFile' m
FromAppPathDir p -> embed (prepathToAbsDir invDir (p ^. pathPath))
Expand All @@ -59,11 +59,11 @@ runAppIO args@RunAppIOArgs {..} =
sup <- Ansi.hSupportsANSIColor stdout
renderIO (not (_runAppIOArgsGlobalOptions ^. globalNoColors) && sup) t
AskGlobalOptions -> return _runAppIOArgsGlobalOptions
AskPackage -> return (_runAppIOArgsRoots ^. rootsPackage)
AskRoots -> return _runAppIOArgsRoots
AskPackage -> return (_runAppIOArgsRoot ^. rootPackage)
AskRoot -> return _runAppIOArgsRoot
AskInvokeDir -> return invDir
AskPkgDir -> return (_runAppIOArgsRoots ^. rootsRootDir)
AskBuildDir -> return (_runAppIOArgsRoots ^. rootsBuildDir)
AskPkgDir -> return (_runAppIOArgsRoot ^. rootRootDir)
AskBuildDir -> return (_runAppIOArgsRoot ^. rootBuildDir)
RunCorePipelineEither input -> do
entry <- embed (getEntryPoint' args input)
embed (corePipelineIOEither entry)
Expand Down Expand Up @@ -100,9 +100,9 @@ runAppIO args@RunAppIOArgs {..} =
<> pack (toFilePath juvixYamlFile)
<> " file"
)
invDir = _runAppIOArgsRoots ^. rootsInvokeDir
invDir = _runAppIOArgsRoot ^. rootInvokeDir
pkg :: Package
pkg = _runAppIOArgsRoots ^. rootsPackage
pkg = _runAppIOArgsRoot ^. rootPackage
g :: GlobalOptions
g = _runAppIOArgsGlobalOptions
printErr e =
Expand All @@ -111,22 +111,22 @@ runAppIO args@RunAppIOArgs {..} =
getEntryPoint' :: RunAppIOArgs -> AppPath File -> IO EntryPoint
getEntryPoint' RunAppIOArgs {..} inputFile = do
let opts = _runAppIOArgsGlobalOptions
roots = _runAppIOArgsRoots
root = _runAppIOArgsRoot
estdin <-
if
| opts ^. globalStdin -> Just <$> getContents
| otherwise -> return Nothing
set entryPointStdin estdin <$> entryPointFromGlobalOptionsPre roots (inputFile ^. pathPath) opts
set entryPointStdin estdin <$> entryPointFromGlobalOptionsPre root (inputFile ^. pathPath) opts

getEntryPointStdin' :: RunAppIOArgs -> IO EntryPoint
getEntryPointStdin' RunAppIOArgs {..} = do
let opts = _runAppIOArgsGlobalOptions
roots = _runAppIOArgsRoots
root = _runAppIOArgsRoot
estdin <-
if
| opts ^. globalStdin -> Just <$> getContents
| otherwise -> return Nothing
set entryPointStdin estdin <$> entryPointFromGlobalOptionsNoFile roots opts
set entryPointStdin estdin <$> entryPointFromGlobalOptionsNoFile root opts

someBaseToAbs' :: (Members '[App] r) => SomeBase a -> Sem r (Path Abs a)
someBaseToAbs' f = do
Expand All @@ -144,7 +144,7 @@ askGenericOptions = project <$> askGlobalOptions
getEntryPoint :: (Members '[Embed IO, App] r) => AppPath File -> Sem r EntryPoint
getEntryPoint inputFile = do
_runAppIOArgsGlobalOptions <- askGlobalOptions
_runAppIOArgsRoots <- askRoots
_runAppIOArgsRoot <- askRoot
embed (getEntryPoint' (RunAppIOArgs {..}) inputFile)

runPipelineTermination :: (Member App r) => AppPath File -> Sem (Termination ': PipelineEff) a -> Sem r a
Expand Down
4 changes: 2 additions & 2 deletions app/Commands/Dev/Geb/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ makeLenses ''ReplState
runCommand :: (Members '[Embed IO, App] r) => GebReplOptions -> Sem r ()
runCommand replOpts = do
invokeDir <- askInvokeDir
roots <- askRoots
root <- askRoot
globalOptions <- askGlobalOptions
let getReplEntryPoint :: SomeBase File -> Repl EntryPoint
getReplEntryPoint inputFile = do
gopts <- State.gets (^. replStateGlobalOptions)
absInputFile :: Path Abs File <- replMakeAbsolute inputFile
set entryPointTarget Backend.TargetGeb
<$> liftIO (entryPointFromGlobalOptions roots absInputFile gopts)
<$> liftIO (entryPointFromGlobalOptions root absInputFile gopts)
embed
( State.evalStateT
(replAction replOpts getReplEntryPoint)
Expand Down
42 changes: 21 additions & 21 deletions app/Commands/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import Juvix.Data.Effect.Git
import Juvix.Data.Effect.Process
import Juvix.Data.Error.GenericError qualified as Error
import Juvix.Data.NameKind
import Juvix.Extra.Paths
import Juvix.Extra.Paths qualified as P
import Juvix.Extra.Stdlib
import Juvix.Extra.Version
import Juvix.Prelude.Pretty
Expand Down Expand Up @@ -81,7 +81,7 @@ printHelpTxt opts = do
|]

replDefaultLoc :: Interval
replDefaultLoc = singletonInterval (mkInitialLoc replPath)
replDefaultLoc = singletonInterval (mkInitialLoc P.replPath)

replFromJust :: Repl a -> Maybe a -> Repl a
replFromJust err = maybe err return
Expand Down Expand Up @@ -140,7 +140,7 @@ loadFile f = do

loadDefaultPrelude :: Repl ()
loadDefaultPrelude = whenJustM defaultPreludeEntryPoint $ \e -> do
root <- Reader.asks (^. replRoots . rootsRootDir)
root <- Reader.asks (^. replRoot . rootRootDir)
let hasInternet = not (e ^. entryPointOffline)
-- The following is needed to ensure that the default location of the
-- standard library exists
Expand All @@ -162,11 +162,11 @@ loadDefaultPrelude = whenJustM defaultPreludeEntryPoint $ \e -> do
$ entrySetup defaultDependenciesConfig
loadEntryPoint e

getReplEntryPoint :: (Roots -> a -> GlobalOptions -> IO EntryPoint) -> a -> Repl EntryPoint
getReplEntryPoint :: (Root -> a -> GlobalOptions -> IO EntryPoint) -> a -> Repl EntryPoint
getReplEntryPoint f inputFile = do
roots <- Reader.asks (^. replRoots)
root <- Reader.asks (^. replRoot)
gopts <- State.gets (^. replStateGlobalOptions)
liftIO (set entryPointSymbolPruningMode KeepAll <$> f roots inputFile gopts)
liftIO (set entryPointSymbolPruningMode KeepAll <$> f root inputFile gopts)

getReplEntryPointFromPrepath :: Prepath File -> Repl EntryPoint
getReplEntryPointFromPrepath = getReplEntryPoint entryPointFromGlobalOptionsPre
Expand Down Expand Up @@ -197,7 +197,7 @@ replCommand opts input = catchAll $ do

eval :: Core.Node -> Repl Core.Node
eval n = do
ep <- getReplEntryPointFromPrepath (mkPrepath (toFilePath replPath))
ep <- getReplEntryPointFromPrepath (mkPrepath (toFilePath P.replPath))
let shouldDisambiguate :: Bool
shouldDisambiguate = not (opts ^. replNoDisambiguate)
(artif', n') <-
Expand Down Expand Up @@ -489,12 +489,12 @@ replTabComplete = Prefix (wordCompleter optsCompleter) defaultMatcher

printRoot :: String -> Repl ()
printRoot _ = do
r <- State.gets (^. replStateRoots . rootsRootDir)
r <- State.gets (^. replStateRoot . rootRootDir)
liftIO $ putStrLn (pack (toFilePath r))

runCommand :: (Members '[Embed IO, App] r) => ReplOptions -> Sem r ()
runCommand opts = do
roots <- askRoots
root <- askRoot
let replAction :: ReplS ()
replAction = do
evalReplOpts
Expand All @@ -511,12 +511,12 @@ runCommand opts = do
globalOptions <- askGlobalOptions
let env =
ReplEnv
{ _replRoots = roots,
{ _replRoot = root,
_replOptions = opts
}
iniState =
ReplState
{ _replStateRoots = roots,
{ _replStateRoot = root,
_replStateContext = Nothing,
_replStateGlobalOptions = globalOptions
}
Expand All @@ -533,23 +533,23 @@ runCommand opts = do
-- | If the package contains the stdlib as a dependency, loads the Prelude
defaultPreludeEntryPoint :: Repl (Maybe EntryPoint)
defaultPreludeEntryPoint = do
roots <- State.gets (^. replStateRoots)
let buildDir = roots ^. rootsBuildDir
root = roots ^. rootsRootDir
pkg = roots ^. rootsPackage
mstdlibPath <- liftIO (runM (runFilesIO (packageStdlib root buildDir (pkg ^. packageDependencies))))
root <- State.gets (^. replStateRoot)
let buildDir = root ^. rootBuildDir
buildRoot = root ^. rootRootDir
pkg = root ^. rootPackage
mstdlibPath <- liftIO (runM (runFilesIO (packageStdlib buildRoot buildDir (pkg ^. packageDependencies))))
case mstdlibPath of
Just stdlibPath ->
Just
. set entryPointResolverRoot stdlibPath
<$> getReplEntryPointFromPath (stdlibPath <//> preludePath)
<$> getReplEntryPointFromPath (stdlibPath <//> P.preludePath)
Nothing -> return Nothing

replMakeAbsolute :: SomeBase b -> Repl (Path Abs b)
replMakeAbsolute = \case
Abs p -> return p
Rel r -> do
invokeDir <- State.gets (^. replStateRoots . rootsInvokeDir)
invokeDir <- State.gets (^. replStateRoot . rootInvokeDir)
return (invokeDir <//> r)

replExpressionUpToScopedAtoms :: Text -> Repl (Concrete.ExpressionAtoms 'Concrete.Scoped)
Expand All @@ -561,7 +561,7 @@ replExpressionUpToScopedAtoms txt = do
. runError
. evalState (ctx ^. replContextArtifacts)
. runReader (ctx ^. replContextEntryPoint)
$ expressionUpToAtomsScoped replPath txt
$ expressionUpToAtomsScoped P.replPath txt
replFromEither x

replExpressionUpToTyped :: Text -> Repl Internal.TypedExpression
Expand All @@ -573,7 +573,7 @@ replExpressionUpToTyped txt = do
. runError
. evalState (ctx ^. replContextArtifacts)
. runReader (ctx ^. replContextEntryPoint)
$ expressionUpToTyped replPath txt
$ expressionUpToTyped P.replPath txt
replFromEither x

compileReplInputIO' :: ReplContext -> Text -> IO (Artifacts, (Either JuvixError (Maybe Core.Node)))
Expand All @@ -582,7 +582,7 @@ compileReplInputIO' ctx txt =
. runState (ctx ^. replContextArtifacts)
. runReader (ctx ^. replContextEntryPoint)
$ do
r <- compileReplInputIO replPath txt
r <- compileReplInputIO P.replPath txt
return (extractNode <$> r)
where
extractNode :: ReplPipelineResult -> Maybe Core.Node
Expand Down
4 changes: 2 additions & 2 deletions app/Commands/Repl/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ data ReplContext = ReplContext
}

data ReplEnv = ReplEnv
{ _replRoots :: Roots,
{ _replRoot :: Root,
_replOptions :: ReplOptions
}

data ReplState = ReplState
{ _replStateRoots :: Roots,
{ _replStateRoot :: Root,
_replStateContext :: Maybe ReplContext,
_replStateGlobalOptions :: GlobalOptions
}
Expand Down
24 changes: 12 additions & 12 deletions app/GlobalOptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,16 @@ parseBuildDir m = do
)
pure AppPath {_pathIsInput = False, ..}

entryPointFromGlobalOptionsPre :: Roots -> Prepath File -> GlobalOptions -> IO EntryPoint
entryPointFromGlobalOptionsPre roots premainFile opts = do
mainFile <- prepathToAbsFile (roots ^. rootsInvokeDir) premainFile
entryPointFromGlobalOptions roots mainFile opts
entryPointFromGlobalOptionsPre :: Root -> Prepath File -> GlobalOptions -> IO EntryPoint
entryPointFromGlobalOptionsPre root premainFile opts = do
mainFile <- prepathToAbsFile (root ^. rootInvokeDir) premainFile
entryPointFromGlobalOptions root mainFile opts

entryPointFromGlobalOptions :: Roots -> Path Abs File -> GlobalOptions -> IO EntryPoint
entryPointFromGlobalOptions roots mainFile opts = do
entryPointFromGlobalOptions :: Root -> Path Abs File -> GlobalOptions -> IO EntryPoint
entryPointFromGlobalOptions root mainFile opts = do
mabsBuildDir :: Maybe (Path Abs Dir) <- mapM (prepathToAbsDir cwd) optBuildDir
let def :: EntryPoint
def = defaultEntryPoint roots mainFile
def = defaultEntryPoint root mainFile
return
def
{ _entryPointNoTermination = opts ^. globalNoTermination,
Expand All @@ -163,13 +163,13 @@ entryPointFromGlobalOptions roots mainFile opts = do
where
optBuildDir :: Maybe (Prepath Dir)
optBuildDir = fmap (^. pathPath) (opts ^. globalBuildDir)
cwd = roots ^. rootsInvokeDir
cwd = root ^. rootInvokeDir

entryPointFromGlobalOptionsNoFile :: Roots -> GlobalOptions -> IO EntryPoint
entryPointFromGlobalOptionsNoFile roots opts = do
entryPointFromGlobalOptionsNoFile :: Root -> GlobalOptions -> IO EntryPoint
entryPointFromGlobalOptionsNoFile root opts = do
mabsBuildDir :: Maybe (Path Abs Dir) <- mapM (prepathToAbsDir cwd) optBuildDir
let def :: EntryPoint
def = defaultEntryPointNoFile roots
def = defaultEntryPointNoFile root
return
def
{ _entryPointNoTermination = opts ^. globalNoTermination,
Expand All @@ -184,4 +184,4 @@ entryPointFromGlobalOptionsNoFile roots opts = do
where
optBuildDir :: Maybe (Prepath Dir)
optBuildDir = fmap (^. pathPath) (opts ^. globalBuildDir)
cwd = roots ^. rootsInvokeDir
cwd = root ^. rootInvokeDir
2 changes: 1 addition & 1 deletion app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ main = do
mbuildDir <- mapM (prepathToAbsDir invokeDir) (_runAppIOArgsGlobalOptions ^? globalBuildDir . _Just . pathPath)
mainFile <- topCommandInputPath cli
mapM_ checkMainFile mainFile
_runAppIOArgsRoots <- findRootAndChangeDir (containingDir <$> mainFile) mbuildDir invokeDir
_runAppIOArgsRoot <- findRootAndChangeDir (containingDir <$> mainFile) mbuildDir invokeDir
runFinal
. resourceToIOFinal
. embedToFinal @IO
Expand Down
18 changes: 9 additions & 9 deletions src/Juvix/Compiler/Pipeline/EntryPoint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,25 @@ data EntryPoint = EntryPoint

makeLenses ''EntryPoint

defaultEntryPoint :: Roots -> Path Abs File -> EntryPoint
defaultEntryPoint roots mainFile =
(defaultEntryPointNoFile roots)
defaultEntryPoint :: Root -> Path Abs File -> EntryPoint
defaultEntryPoint root mainFile =
(defaultEntryPointNoFile root)
{ _entryPointModulePaths = pure mainFile
}

defaultEntryPointNoFile :: Roots -> EntryPoint
defaultEntryPointNoFile roots =
defaultEntryPointNoFile :: Root -> EntryPoint
defaultEntryPointNoFile root =
EntryPoint
{ _entryPointRoot = roots ^. rootsRootDir,
_entryPointResolverRoot = roots ^. rootsRootDir,
{ _entryPointRoot = root ^. rootRootDir,
_entryPointResolverRoot = root ^. rootRootDir,
_entryPointBuildDir = Rel relBuildDir,
_entryPointNoTermination = False,
_entryPointNoPositivity = False,
_entryPointNoCoverage = False,
_entryPointNoStdlib = False,
_entryPointStdin = Nothing,
_entryPointPackage = roots ^. rootsPackage,
_entryPointPackageGlobal = roots ^. rootsPackageGlobal,
_entryPointPackage = root ^. rootPackage,
_entryPointPackageGlobal = root ^. rootPackageGlobal,
_entryPointGenericOptions = defaultGenericOptions,
_entryPointTarget = TargetCore,
_entryPointDebug = False,
Expand Down
8 changes: 4 additions & 4 deletions src/Juvix/Compiler/Pipeline/EntryPoint/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import Juvix.Prelude
defaultEntryPointCwdIO :: Path Abs File -> IO EntryPoint
defaultEntryPointCwdIO mainFile = do
cwd <- getCurrentDir
roots <- findRootAndChangeDir (Just (parent mainFile)) Nothing cwd
return (defaultEntryPoint roots mainFile)
root <- findRootAndChangeDir (Just (parent mainFile)) Nothing cwd
return (defaultEntryPoint root mainFile)

defaultEntryPointNoFileCwdIO :: IO EntryPoint
defaultEntryPointNoFileCwdIO = do
cwd <- getCurrentDir
roots <- findRootAndChangeDir Nothing Nothing cwd
return (defaultEntryPointNoFile roots)
root <- findRootAndChangeDir Nothing Nothing cwd
return (defaultEntryPointNoFile root)
Loading

0 comments on commit 2426167

Please sign in to comment.