1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-29 10:33:15 +03:00

Fix pipeline setup in the repl (#2046)

This pr fixes a bug where the repl would crash if it had the implicit
stdlib dependency and the .juvix-build/stdlib directory did not yet
exist. This bug was not exposed in the smoke tests because the
.juvix-build was never cleared.

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
This commit is contained in:
Jan Mas Rovira 2023-05-03 20:04:31 +02:00 committed by GitHub
parent cdc2d5fd2e
commit aace4ca514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 20 deletions

View File

@ -87,7 +87,7 @@ jobs:
uses: jaxxstorm/action-install-gh-release@v1.10.0
with:
repo: wasmerio/wasmer
tag: latest
tag: v3.2.1
binaries-location: bin
cache: true
@ -178,7 +178,7 @@ jobs:
uses: jaxxstorm/action-install-gh-release@v1.10.0
with:
repo: wasmerio/wasmer
tag: latest
tag: v3.2.1
binaries-location: bin
cache: true

View File

@ -12,6 +12,7 @@ import Data.String.Interpolate (i, __i)
import Evaluator
import Juvix.Compiler.Concrete.Data.Scope (scopePath)
import Juvix.Compiler.Concrete.Data.ScopedName (absTopModulePath)
import Juvix.Compiler.Concrete.Translation.FromParsed.Analysis.PathResolver (runPathResolver)
import Juvix.Compiler.Core qualified as Core
import Juvix.Compiler.Core.Extra.Value
import Juvix.Compiler.Core.Info qualified as Info
@ -21,6 +22,7 @@ import Juvix.Compiler.Core.Transformation qualified as Core
import Juvix.Compiler.Core.Transformation.DisambiguateNames (disambiguateNames)
import Juvix.Compiler.Internal.Language qualified as Internal
import Juvix.Compiler.Internal.Pretty qualified as Internal
import Juvix.Compiler.Pipeline.Setup (entrySetup)
import Juvix.Data.Error.GenericError qualified as Error
import Juvix.Extra.Paths
import Juvix.Extra.Stdlib
@ -123,11 +125,20 @@ runCommand opts = do
entryPoint <- getReplEntryPoint f
loadEntryPoint entryPoint
loadPrelude :: Repl ()
loadPrelude = loadDefaultPrelude
loadDefaultPrelude :: Repl ()
loadDefaultPrelude = whenJustM defaultPreludeEntryPoint loadEntryPoint
loadDefaultPrelude = whenJustM defaultPreludeEntryPoint $ \e -> do
let root = roots ^. rootsRootDir
-- The following is needed to ensure that the default location of the
-- standard library exists
void
. liftIO
. runM
. runFilesIO
. runError @Text
. runReader e
. runPathResolver root
$ entrySetup
loadEntryPoint e
printRoot :: String -> Repl ()
printRoot _ = do
@ -267,7 +278,7 @@ runCommand opts = do
welcomeMsg
unless
(opts ^. replNoPrelude || gopts ^. globalNoStdlib)
(maybe loadPrelude (loadFile . (^. pathPath)) (opts ^. replInputFile))
(maybe loadDefaultPrelude (loadFile . (^. pathPath)) (opts ^. replInputFile))
finaliser :: Repl ExitDecision
finaliser = return Exit

View File

@ -7,6 +7,7 @@ module Juvix.Compiler.Concrete.Translation.FromParsed.Analysis.PathResolver
withPath,
withPathFile,
expectedModulePath,
runPathResolver,
runPathResolverPipe,
runPathResolverPipe',
ResolverState,

View File

@ -28,20 +28,20 @@ ensureStdlib rootDir buildDir deps =
whenJustM (packageStdlib rootDir buildDir deps) $ \stdlibRoot ->
runReader stdlibRoot updateStdlib
packageStdlib :: Members '[Files] r => Path Abs Dir -> Path Abs Dir -> [Dependency] -> Sem r (Maybe (Path Abs Dir))
packageStdlib rootDir buildDir = firstJustM (isStdLib rootDir buildDir)
isStdLib :: Members '[Files] r => Path Abs Dir -> Path Abs Dir -> Dependency -> Sem r (Maybe (Path Abs Dir))
isStdLib rootDir buildDir (Dependency dep) = do
adir <- canonicalDir rootDir dep
let mstdlib :: Maybe (Path Rel Dir) = stripProperPrefix buildDir adir
return $
if
| mstdlib == Just relStdlibDir -> Just stdLibBuildDir
| otherwise -> Nothing
packageStdlib :: forall r. Members '[Files] r => Path Abs Dir -> Path Abs Dir -> [Dependency] -> Sem r (Maybe (Path Abs Dir))
packageStdlib rootDir buildDir = firstJustM isStdLib
where
stdLibBuildDir :: Path Abs Dir
stdLibBuildDir = juvixStdlibDir buildDir
isStdLib :: Dependency -> Sem r (Maybe (Path Abs Dir))
isStdLib (Dependency dep) = do
adir <- canonicalDir rootDir dep
let mstdlib :: Maybe (Path Rel Dir) = stripProperPrefix buildDir adir
return $
if
| mstdlib == Just relStdlibDir -> Just stdLibBuildDir
| otherwise -> Nothing
where
stdLibBuildDir :: Path Abs Dir
stdLibBuildDir = juvixStdlibDir buildDir
writeStdlib :: forall r. (Members '[Reader StdlibRoot, Files] r) => Sem r ()
writeStdlib = do