Skip to content

Typechecked AST for recursive top-level call refers to non-exported HsVar.

Code:

module B where

aaa x = aaa x

bbb = aaa 1

In the renamed AST

The reference is to the exported aaa (span 3:1-3, sort WiredIn), which is as expected (by me at least). (dump with ghc-dump-tree with some local mods compiled by GHC 7.10.2)

                                      (HsApp
                                              (L /tmp/B.hs:3:9-11
                                                 (HsVar
                   here ------------>    { n_loc = /tmp/B.hs:3:1-3                          <----------- here
                                                      , n_sort =  { WiredIn = Module main B }
                                                      , VarName = aaa
                                                      }))
                                              (L /tmp/B.hs:3:13
                                                 (HsVar
                                                      { n_loc = /tmp/B.hs:3:5
                                                      , n_sort = Internal
                                                      , VarName = x
                                                      })))))

In the typechecked AST

Here the call target changes to internal (as described by the monomorphic binding abe_mono).

(HsApp
                                             (L /tmp/B.hs:3:9-11
                                                (HsVar
                                                     { varType =
                                                           { t -> t =
                                                               FunTy
                                                                 (TyVarTy
                                                                      { varType =
                                                                           { * = TyConApp * [] }
                                                                      , n_loc = /tmp/B.hs:3:1-13
                                                                      , n_sort = Internal
                                                                      , TvName = t
                                                                      })
                                                                 (TyVarTy
                                                                      { varType =
                                                                           { * = TyConApp * [] }
                                                                      , n_loc = /tmp/B.hs:3:1-13
                                                                      , n_sort = Internal
                                                                      , TvName = t
                                                                      })
                                                           }
                 here ------------->   , n_loc = /tmp/B.hs:3:1-13  
                                                     , n_sort = Internal
                                                     , VarName = aaa
                                                     }))
                                             (L /tmp/B.hs:3:13
                                                (HsVar
                                                     { varType =
                                                           { t =
                                                               TyVarTy
                                                                   { varType =
                                                                        { * = TyConApp * [] }
                                                                   , n_loc = /tmp/B.hs:3:1-13
                                                                   , n_sort = Internal
                                                                   , TvName = t
                                                                   }
                                                           }
                                                     , n_loc = /tmp/B.hs:3:5
                                                     , n_sort = Internal
                                                     , VarName = x
                                                     })))))

(Just remarking, that GHC 7.8 and 7.10 seem to have improved the span ranges a bit over 7.6, so trying to reproduce with 7.6 the span will be the shorter one on the function name, but the sort will still be the internal).

Note that referring the function in a non-recursive way seem to refer to the exported (abe_poly) binding.

From the perspective of a tooling writer, this difference is somewhat surprising, and is a case to be handled separately.

  • Is there a fundamental reason why the reference changes after Typechecking?
  • Since I'm not deeply familiar with the AST, I might miss something. Does it happen in other cases too that sometimes abe_poly is referred, sometimes the abe_mono? If so, what is the rule?
Trac metadata
Trac field Value
Version 7.10.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
{ n_loc = /tmp/B.hs:3:1-3 <----------- here\r\n , n_sort = { WiredIn = Module main B }\r\n , VarName = aaa\r\n }))\r\n (L /tmp/B.hs:3:13\r\n (HsVar\r\n { n_loc = /tmp/B.hs:3:5\r\n , n_sort = Internal\r\n , VarName = x\r\n })))))\r\n}}}\r\n\r\n=== In the typechecked AST\r\n\r\nHere the call target changes to internal (as described by the monomorphic binding abe_mono).\r\n\r\n{{{\r\n(HsApp\r\n (L /tmp/B.hs:3:9-11\r\n (HsVar\r\n { varType =\r\n { t -> t =\r\n FunTy\r\n (TyVarTy\r\n { varType =\r\n { * = TyConApp * [] }\r\n , n_loc = /tmp/B.hs:3:1-13\r\n , n_sort = Internal\r\n , TvName = t\r\n })\r\n (TyVarTy\r\n { varType =\r\n { * = TyConApp * [] }\r\n , n_loc = /tmp/B.hs:3:1-13\r\n , n_sort = Internal\r\n , TvName = t\r\n })\r\n }\r\n here -------------> , n_loc = /tmp/B.hs:3:1-13 \r\n , n_sort = Internal\r\n , VarName = aaa\r\n }))\r\n (L /tmp/B.hs:3:13\r\n (HsVar\r\n { varType =\r\n { t =\r\n TyVarTy\r\n { varType =\r\n { * = TyConApp * [] }\r\n , n_loc = /tmp/B.hs:3:1-13\r\n , n_sort = Internal\r\n , TvName = t\r\n }\r\n }\r\n , n_loc = /tmp/B.hs:3:5\r\n , n_sort = Internal\r\n , VarName = x\r\n })))))\r\n}}}\r\n\r\n(Just remarking, that GHC 7.8 and 7.10 seem to have improved the span ranges a bit over 7.6, so trying to reproduce with 7.6 the span will be the shorter one on the function name, but the sort will still be the internal).\r\n\r\nNote that referring the function in a non-recursive way seem to refer to the exported (abe_poly) binding.\r\n\r\nFrom the perspective of a tooling writer, this difference is somewhat surprising, and is a case to be handled separately.\r\n\r\n * Is there a fundamental reason why the reference changes after Typechecking?\r\n\r\n * Since I'm not deeply familiar with the AST, I might miss something. Does it happen in other cases too that sometimes abe_poly is referred, sometimes the abe_mono? If so, what is the rule?","type_of_failure":"OtherFailure","blocking":[]} -->
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information