From aace4ca514b03819efabc570f4c24976e4473a1d Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 3 May 2023 20:04:31 +0200 Subject: [PATCH] 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 --- .github/workflows/ci.yml | 4 +-- app/Commands/Repl.hs | 21 +++++++++++---- .../FromParsed/Analysis/PathResolver.hs | 1 + src/Juvix/Extra/Stdlib.hs | 26 +++++++++---------- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 626ebe230..ca62ed21b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/app/Commands/Repl.hs b/app/Commands/Repl.hs index 29edb641f..b376935bb 100644 --- a/app/Commands/Repl.hs +++ b/app/Commands/Repl.hs @@ -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 diff --git a/src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/PathResolver.hs b/src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/PathResolver.hs index 910ac4150..ce0d90398 100644 --- a/src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/PathResolver.hs +++ b/src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/PathResolver.hs @@ -7,6 +7,7 @@ module Juvix.Compiler.Concrete.Translation.FromParsed.Analysis.PathResolver withPath, withPathFile, expectedModulePath, + runPathResolver, runPathResolverPipe, runPathResolverPipe', ResolverState, diff --git a/src/Juvix/Extra/Stdlib.hs b/src/Juvix/Extra/Stdlib.hs index 2c04a087d..373aab608 100644 --- a/src/Juvix/Extra/Stdlib.hs +++ b/src/Juvix/Extra/Stdlib.hs @@ -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