Skip to content

Commit

Permalink
Fix pipeline setup in the repl (#2046)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
janmasrovira and paulcadman authored May 3, 2023
1 parent cdc2d5f commit aace4ca
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
21 changes: 16 additions & 5 deletions app/Commands/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Juvix.Compiler.Concrete.Translation.FromParsed.Analysis.PathResolver
withPath,
withPathFile,
expectedModulePath,
runPathResolver,
runPathResolverPipe,
runPathResolverPipe',
ResolverState,
Expand Down
26 changes: 13 additions & 13 deletions src/Juvix/Extra/Stdlib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aace4ca

Please sign in to comment.