Skip to content

Commit

Permalink
Merge Log effect into Logger effect (#3220)
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira authored Dec 3, 2024
1 parent 7db7444 commit af9679d
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 59 deletions.
17 changes: 10 additions & 7 deletions app/Commands/Doctor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,19 @@ documentedMessage w = uncurry DocumentedMessage (first (baseUrl <>) warningInfo)
baseUrl :: Text
baseUrl = "https://docs.juvix.org/" <> V.versionDoc <> "/reference/tooling/doctor/#"

heading :: (Member Log r) => Text -> Sem r ()
heading = log . ("> " <>)
logDoctor :: (Member Logger r) => Text -> Sem r ()
logDoctor = logInfo . mkAnsiText

warning :: (Member Log r) => Text -> Sem r ()
warning = log . (" ! " <>)
heading :: (Member Logger r) => Text -> Sem r ()
heading = logDoctor . ("> " <>)

info :: (Member Log r) => Text -> Sem r ()
info = log . (" | " <>)
warning :: (Member Logger r) => Text -> Sem r ()
warning = logDoctor . (" ! " <>)

type DoctorEff = '[Log, EmbedIO, App]
info :: (Member Logger r) => Text -> Sem r ()
info = logDoctor . (" | " <>)

type DoctorEff = '[Logger, EmbedIO, App]

checkCmdOnPath :: (Members DoctorEff r) => String -> [Text] -> Sem r ()
checkCmdOnPath cmd errMsg =
Expand Down
2 changes: 1 addition & 1 deletion app/TopCommand.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ runTopCommand = \case
DisplayVersion -> runDisplayVersion
DisplayNumericVersion -> runDisplayNumericVersion
DisplayHelp -> showHelpText
Doctor opts -> runLogIO (Doctor.runCommand opts)
Doctor opts -> Doctor.runCommand opts
Isabelle opts -> Isabelle.runCommand opts
Init opts -> Init.init opts
Dev opts -> Dev.runCommand opts
Expand Down
1 change: 0 additions & 1 deletion src/Juvix/Compiler/Pipeline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ type PipelineLocalEff =
GitClone,
Error GitProcessError,
ProcessE,
Log,
Reader EntryPoint,
Files,
Error JuvixError,
Expand Down
1 change: 0 additions & 1 deletion src/Juvix/Compiler/Pipeline/Package/Loader/EvalEff/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ loadPackage' packagePath = do
. runProcessIO
. runFilesIO
. evalTopNameIdGen defaultModuleId
. ignoreLog
. mapError (JuvixError @GitProcessError)
. runGitProcess
. runEvalFileEffIO
Expand Down
1 change: 0 additions & 1 deletion src/Juvix/Compiler/Pipeline/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ compileReplInputIO fp txt = do
. evalInternet hasInternet
. ignoreHighlightBuilder
. runTaggedLockPermissive
. runLogIO
. runFilesIO
. mapError (JuvixError @GitProcessError)
. runProcessIO
Expand Down
2 changes: 0 additions & 2 deletions src/Juvix/Compiler/Pipeline/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ runIOEitherPipeline' entry a = do
. runJuvixError
. runFilesIO
. runReader entry
. runLogIO
. runProcessIO
. mapError (JuvixError @GitProcessError)
. runGitProcess
Expand Down Expand Up @@ -223,7 +222,6 @@ runReplPipelineIOEither' lockMode entry = do
. runFilesIO
. runReader entry
. runTaggedLock lockMode
. runLogIO
. mapError (JuvixError @GitProcessError)
. runProcessIO
. runGitProcess
Expand Down
2 changes: 0 additions & 2 deletions src/Juvix/Data.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module Juvix.Data
module Juvix.Data.Pragmas,
module Juvix.Data.Processed,
module Juvix.Data.Uid,
module Juvix.Data.Logger,
module Juvix.Data.Universe,
module Juvix.Data.Wildcard,
module Juvix.Data.WithLoc,
Expand All @@ -40,7 +39,6 @@ import Juvix.Data.Irrelevant
import Juvix.Data.IsImplicit
import Juvix.Data.Keyword
import Juvix.Data.Loc
import Juvix.Data.Logger
import Juvix.Data.NameId qualified
import Juvix.Data.NumThreads
import Juvix.Data.ParsedItem
Expand Down
4 changes: 2 additions & 2 deletions src/Juvix/Data/Effect.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Juvix.Data.Effect
module Juvix.Data.Effect.Cache,
module Juvix.Data.Effect.NameIdGen,
module Juvix.Data.Effect.Visit,
module Juvix.Data.Effect.Log,
module Juvix.Data.Effect.Logger,
module Juvix.Data.Effect.Internet,
module Juvix.Data.Effect.Forcing,
module Juvix.Data.Effect.TaggedLock,
Expand All @@ -17,7 +17,7 @@ import Juvix.Data.Effect.Fail
import Juvix.Data.Effect.Files
import Juvix.Data.Effect.Forcing
import Juvix.Data.Effect.Internet
import Juvix.Data.Effect.Log
import Juvix.Data.Effect.Logger
import Juvix.Data.Effect.NameIdGen
import Juvix.Data.Effect.PartialDo
import Juvix.Data.Effect.TaggedLock
Expand Down
24 changes: 12 additions & 12 deletions src/Juvix/Data/Effect/Git/Process.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Juvix.Data.Effect.Git.Process.Error
import Juvix.Data.Effect.Process
import Juvix.Data.Effect.TaggedLock
import Juvix.Prelude
import Juvix.Prelude.Pretty

newtype CloneEnv = CloneEnv
{_cloneEnvDir :: Path Abs Dir}
Expand All @@ -24,13 +25,12 @@ runGitCmd args = do
ExitFailure {} ->
throw
( GitCmdError
( GitCmdErrorDetails
{ _gitCmdErrorDetailsCmdPath = cmd,
_gitCmdErrorDetailsArgs = args,
_gitCmdErrorDetailsExitCode = res ^. processResultExitCode,
_gitCmdErrorDetailsMessage = res ^. processResultStderr
}
)
GitCmdErrorDetails
{ _gitCmdErrorDetailsCmdPath = cmd,
_gitCmdErrorDetailsArgs = args,
_gitCmdErrorDetailsExitCode = res ^. processResultExitCode,
_gitCmdErrorDetailsMessage = res ^. processResultStderr
}
)
ExitSuccess -> return (res ^. processResultStdout)

Expand Down Expand Up @@ -72,16 +72,16 @@ gitFetch = whenHasInternet gitFetchOnline
gitFetchOnline :: (Members '[TaggedLock, Reader CloneEnv, Error GitProcessError, ProcessE, Online] r) => Sem r ()
gitFetchOnline = withTaggedLockDir' (void (runGitCmdInDir ["fetch"]))

gitCloneOnline :: (Members '[Log, Error GitProcessError, ProcessE, Online, Reader CloneEnv] r) => Text -> Sem r ()
gitCloneOnline :: (Members '[Logger, Error GitProcessError, ProcessE, Online, Reader CloneEnv] r) => Text -> Sem r ()
gitCloneOnline url = do
p <- asks (^. cloneEnvDir)
log ("Cloning " <> url <> " to " <> pack (toFilePath p))
logInfo (mkAnsiText ("Cloning " <> url <> " to " <> pack (toFilePath p)))
void (runGitCmd ["clone", url, T.pack (toFilePath p)])

cloneGitRepo :: (Members '[Log, Files, ProcessE, Error GitProcessError, Reader CloneEnv, Internet] r) => Text -> Sem r ()
cloneGitRepo :: (Members '[Logger, Files, ProcessE, Error GitProcessError, Reader CloneEnv, Internet] r) => Text -> Sem r ()
cloneGitRepo = whenHasInternet . gitCloneOnline

initGitRepo :: (Members '[TaggedLock, Log, Files, ProcessE, Error GitProcessError, Reader CloneEnv, Internet] r) => Text -> Sem r (Path Abs Dir)
initGitRepo :: (Members '[TaggedLock, Logger, Files, ProcessE, Error GitProcessError, Reader CloneEnv, Internet] r) => Text -> Sem r (Path Abs Dir)
initGitRepo url = do
p <- asks (^. cloneEnvDir)
withTaggedLockDir' (unlessM (directoryExists' p) (cloneGitRepo url))
Expand Down Expand Up @@ -112,7 +112,7 @@ withTaggedLockDir' ma = do

runGitProcess ::
forall r a.
(Members '[TaggedLock, Log, Files, ProcessE, Error GitProcessError, Internet] r) =>
(Members '[TaggedLock, Logger, Files, ProcessE, Error GitProcessError, Internet] r) =>
Sem (GitClone ': r) a ->
Sem r a
runGitProcess = runProvider_ helper
Expand Down
24 changes: 0 additions & 24 deletions src/Juvix/Data/Effect/Log.hs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Juvix.Data.Logger
module Juvix.Data.Effect.Logger
( defaultLoggerOptions,
replLoggerOptions,
defaultLogLevel,
Expand Down
2 changes: 1 addition & 1 deletion src/Parallel/ProgressLog.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Juvix.Compiler.Pipeline.Loader.PathResolver.ImportTree.Base
import Juvix.Compiler.Pipeline.Loader.PathResolver.PackageInfo
import Juvix.Compiler.Pipeline.Options
import Juvix.Data.CodeAnn
import Juvix.Data.Logger
import Juvix.Data.Effect.Logger
import Juvix.Prelude

data ProgressLog :: Effect where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1115,13 +1115,13 @@ tests:
EOF
# compile project
juvix --log-level error compile native HelloWorld.juvix
juvix --log-level info compile native HelloWorld.juvix
# delete the dependency to check that it's not required
rm -rf $temp/dep
# compile project
juvix --log-level error compile native HelloWorld.juvix
juvix --log-level info compile native HelloWorld.juvix
stdout:
contains: ""
stderr:
Expand Down
4 changes: 2 additions & 2 deletions tests/smoke/Commands/compile-dependencies.smoke.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1156,13 +1156,13 @@ tests:
EOF
# compile project
juvix --log-level error compile native HelloWorld.juvix
juvix --log-level info compile native HelloWorld.juvix
# delete the dependency to check that it's not required
rm -rf $temp/dep
# compile project
juvix --log-level error compile native HelloWorld.juvix
juvix --log-level info compile native HelloWorld.juvix
stdout:
contains: ""
stderr:
Expand Down

0 comments on commit af9679d

Please sign in to comment.