Skip to content

-ddump-rn-ast and -ddump-tc-ast not working in ghci?

Summary

-ddump-parsed-ast seems to be working fine when compiling modules or when enabled with :set -ddump-parsed-ast in ghci. -ddump-rn-ast and -ddump-tc-ast only seem to have an effect when compiling a module, not when enabled in ghci.

Steps to reproduce

$ ghci
GHCi, version 8.8.1: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/alp/.ghci
Prelude λ> :set -ddump-parsed-ast -ddump-rn-ast -ddump-tc-ast
Prelude λ> 1

==================== Parser AST ====================

(Just
 ({ <interactive>:2:1 }
  (BodyStmt
   (NoExt)
   ({ <interactive>:2:1 }
    (HsOverLit
     (NoExt)
     (OverLit
      (NoExt)
      (HsIntegral
       (IL
        (SourceText
         "1")
        (False)
        (1)))
      (HsLit
       (NoExt)
       (HsString
        (SourceText
         "noExpr")
        {FastString: "noExpr"})))))
   (SyntaxExpr
    (HsLit
     (NoExt)
     (HsString
      (NoSourceText)
      {FastString: "noSyntaxExpr"}))
    []
    (WpHole))
   (SyntaxExpr
    (HsLit
     (NoExt)
     (HsString
      (NoSourceText)
      {FastString: "noSyntaxExpr"}))
    []
    (WpHole)))))


1

The same behaviour can be observed with ghc -ddump-parsed-ast -ddump-rn-ast -ddump-tc-ast -e '1'.

Expected behavior

The ASTs for all 3 phases are printed, instead of just the parsed AST, just like when passing those options while compiling a module:

$ cat X.hs
module X where

a = if a then False else True

$ ghc -c -ddump-parsed-ast -ddump-rn-ast -ddump-tc-ast X.hs

==================== Parser AST ====================

({ X.hs:1:1 }
 (HsModule
  (Just
   ({ X.hs:2:8 }
    {ModuleName: X}))
  (Nothing)
  []
  [({ X.hs:4:1-29 }
    (ValD
     (NoExt)
     (FunBind
      (NoExt)
      ({ X.hs:4:1 }
       (Unqual
        {OccName: a}))
      (MG
       (NoExt)
       ({ X.hs:4:1-29 }
        [({ X.hs:4:1-29 }
          (Match
           (NoExt)
           (FunRhs
            ({ X.hs:4:1 }
             (Unqual
              {OccName: a}))
            (Prefix)
            (NoSrcStrict))
           []
           (GRHSs
            (NoExt)
            [({ X.hs:4:3-29 }
              (GRHS
               (NoExt)
               []
               ({ X.hs:4:5-29 }
                (HsIf
                 (NoExt)
                 (Just
                  (SyntaxExpr
                   (HsLit
                    (NoExt)
                    (HsString
                     (NoSourceText)
                     {FastString: "noSyntaxExpr"}))
                   []
                   (WpHole)))
                 ({ X.hs:4:8 }
                  (HsVar
                   (NoExt)
                   ({ X.hs:4:8 }
                    (Unqual
                     {OccName: a}))))
                 ({ X.hs:4:15-19 }
                  (HsVar
                   (NoExt)
                   ({ X.hs:4:15-19 }
                    (Unqual
                     {OccName: False}))))
                 ({ X.hs:4:26-29 }
                  (HsVar
                   (NoExt)
                   ({ X.hs:4:26-29 }
                    (Unqual
                     {OccName: True}))))))))]
            ({ <no location info> }
             (EmptyLocalBinds
              (NoExt))))))])
       (FromSource))
      (WpHole)
      [])))]
  (Nothing)
  (Nothing)))



==================== Typechecker ====================

{Bag(Located (HsBind Var)):
 [({ <no location info> }
   (VarBind
    (NoExt)
    {Var: X.$trModule}
    ({ <no location info> }
     (HsApp
      (NoExt)
      ({ <no location info> }
       (HsApp
        (NoExt)
        ({ <no location info> }
         (HsConLikeOut
          (NoExt)
          ({abstract:ConLike})))
        ({ <no location info> }
         (HsPar
          (NoExt)
          ({ <no location info> }
           (HsApp
            (NoExt)
            ({ <no location info> }
             (HsConLikeOut
              (NoExt)
              ({abstract:ConLike})))
            ({ <no location info> }
             (HsLit
              (NoExt)
              (HsStringPrim
               (NoSourceText)
               "main")))))))))
      ({ <no location info> }
       (HsPar
        (NoExt)
        ({ <no location info> }
         (HsApp
          (NoExt)
          ({ <no location info> }
           (HsConLikeOut
            (NoExt)
            ({abstract:ConLike})))
          ({ <no location info> }
           (HsLit
            (NoExt)
            (HsStringPrim
             (NoSourceText)
             "X")))))))))
    (False)))
 ,({ X.hs:4:1-29 }
   (AbsBinds
    (NoExt)
    []
    []
    [(ABE
      (NoExt)
      {Var: a}
      {Var: a_aWq}
      (WpHole)
      (SpecPrags
       []))]
    [({abstract:TcEvBinds})]
    {Bag(Located (HsBind Var)):
     [({ X.hs:4:1-29 }
       (FunBind
        {NameSet:
         []}
        ({ X.hs:4:1 }
         {Var: a_aWq})
        (MG
         (MatchGroupTc
          []
          (TyConApp
           ({abstract:TyCon})
           []))
         ({ X.hs:4:1-29 }
          [({ X.hs:4:1-29 }
            (Match
             (NoExt)
             (FunRhs
              ({ X.hs:4:1 }
               {Name: a_aWq})
              (Prefix)
              (NoSrcStrict))
             []
             (GRHSs
              (NoExt)
              [({ X.hs:4:3-29 }
                (GRHS
                 (NoExt)
                 []
                 ({ X.hs:4:5-29 }
                  (HsIf
                   (NoExt)
                   (Nothing)
                   ({ X.hs:4:8 }
                    (HsVar
                     (NoExt)
                     ({ <no location info> }
                      {Var: a_aWq})))
                   ({ X.hs:4:15-19 }
                    (HsConLikeOut
                     (NoExt)
                     ({abstract:ConLike})))
                   ({ X.hs:4:26-29 }
                    (HsConLikeOut
                     (NoExt)
                     ({abstract:ConLike})))))))]
              ({ <no location info> }
               (EmptyLocalBinds
                (NoExt))))))])
         (FromSource))
        (WpHole)
        []))]}
    (False)))]}


==================== Renamer ====================

(Just
 ((,,,)
  (HsGroup
   (NoExt)
   (XValBindsLR
    (NValBinds
     [((,)
       (Recursive)
       {Bag(Located (HsBind Name)):
        [({ X.hs:4:1-29 }
          (FunBind
           {NameSet:
            [{Name: X.a}]}
           ({ X.hs:4:1 }
            {Name: X.a})
           (MG
            (NoExt)
            ({ X.hs:4:1-29 }
             [({ X.hs:4:1-29 }
               (Match
                (NoExt)
                (FunRhs
                 ({ X.hs:4:1 }
                  {Name: X.a})
                 (Prefix)
                 (NoSrcStrict))
                []
                (GRHSs
                 (NoExt)
                 [({ X.hs:4:3-29 }
                   (GRHS
                    (NoExt)
                    []
                    ({ X.hs:4:5-29 }
                     (HsIf
                      (NoExt)
                      (Nothing)
                      ({ X.hs:4:8 }
                       (HsVar
                        (NoExt)
                        ({ X.hs:4:8 }
                         {Name: X.a})))
                      ({ X.hs:4:15-19 }
                       (HsVar
                        (NoExt)
                        ({ X.hs:4:15-19 }
                         {Name: GHC.Types.False})))
                      ({ X.hs:4:26-29 }
                       (HsVar
                        (NoExt)
                        ({ X.hs:4:26-29 }
                         {Name: GHC.Types.True})))))))]
                 ({ <no location info> }
                  (EmptyLocalBinds
                   (NoExt))))))])
            (FromSource))
           (WpHole)
           []))]})]
     []))
   []
   []
   []
   []
   []
   []
   []
   []
   []
   [])
  [({ X.hs:2:8 }
    (ImportDecl
     (NoExt)
     (NoSourceText)
     ({ X.hs:2:8 }
      {ModuleName: Prelude})
     (Nothing)
     (False)
     (False)
     (False)
     (True)
     (Nothing)
     (Nothing)))]
  (Nothing)
  (Nothing)))

Environment

  • GHC version used: 8.6.5, 8.8.1

Optional:

  • Operating System: NixOS
  • System Architecture: x86_64
Edited by Alp Mestanogullari
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information