Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debugging custom function to Prelude #1401

Merged
merged 5 commits into from
Jul 20, 2022
Merged

Conversation

jonaprieto
Copy link
Collaborator

@jonaprieto jonaprieto commented Jul 20, 2022

This PR adds a useful custom set of basic debugging functions to the Prelude. In addition, some warnings have been provided in case one forgets to remove them from the codebase.

The main functions are:

traceLabel :: Text -> Text -> a -> a
trace :: Text -> a -> a
traceShow :: Show b => b -> b
traceToFile :: FilePath -> Text -> a -> a
traceToFile' :: Text -> a -> a
traceToFileM :: (Applicative m) => FilePath -> Text -> a -> m ()

An example of how to use them is the following.

-- Typechecker.hs
...
checkStatement s = case s of
  StatementFunction fun -> StatementFunction <$> checkFunctionDef fun
  StatementForeign {} -> return s
  StatementInductive ind ->
     traceToFile "run.log" (ppSimple ind) $
     traceLabel "check inductiveTy" (ppSimple ind) $
     trace (ppSimple ind) $ do 
    ...

The output (with colors) looks like this (using debugTextToFile') :

juvix typecheck example.juvix
[debug] [./juvix.log]:
data T (A : Type) =
  c T
Well done! It type checks

@jonaprieto jonaprieto added the enhancement New feature or request label Jul 20, 2022
@jonaprieto jonaprieto self-assigned this Jul 20, 2022
@jonaprieto jonaprieto marked this pull request as ready for review July 20, 2022 13:56
@jonaprieto jonaprieto added this to the 0.2.2 milestone Jul 20, 2022
src/Juvix/Syntax/MicroJuvix/TypeChecker.hs Outdated Show resolved Hide resolved
src/Juvix/Syntax/MicroJuvix/Pretty.hs Outdated Show resolved Hide resolved
@jonaprieto jonaprieto merged commit ca2f3c4 into main Jul 20, 2022
@jonaprieto jonaprieto deleted the debugging-functions branch July 20, 2022 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants