Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,865
    • Issues 4,865
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 461
    • Merge requests 461
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #17897
Closed
Open
Created Mar 05, 2020 by Richard Eisenberg@raeDeveloper

`-fprint-typechecker-elaboration` prints type applications twice

We have

{-# LANGUAGE TypeApplications #-}

module Bug where

x = id @Int

and say

ghc -c Bug.hs -ddump-tc -fprint-typechecker-elaboration

to witness

[1 of 1] Compiling Bug              ( Bug2.hs, Bug2.o )
TYPE SIGNATURES
  x :: Int -> Int
Dependent modules: []
Dependent packages: [base-4.14.0.0, ghc-prim-0.6.1,
                     integer-gmp-1.0.2.0]

==================== Typechecker ====================
Bug.$trModule
  = GHC.Types.Module
      (GHC.Types.TrNameS "main"#) (GHC.Types.TrNameS "Bug"#)
AbsBinds [] []
  {Exports: [x <= x_atL
               wrap: <>]
   Exported types: x :: Int -> Int
                   [LclId]
   Binds: x = id @Int @Int
   Evidence: [EvBinds{}]}

In the Binds: field immediately above, we see x = id @Int @Int. That double type application is very strange, and surely looks wrong. Yet this module is compiled without a problem, and its desugared syntax is just fine. What on earth is going on?

The problem is that -fprint-typechecker-elaboration prints out HsWrappers. When type-checking a polymorphic call (like id), we instantiate any quantified variables by using wrappers. In this case, we follow the user's direction and instantiate id with Int. All good. This is the first @Int we see. But, the HsSyn retains the visible type application, and we print that @Int as well. Thus getting two @Ints. HsSyn visible type applications are dropped during desugaring (as they should be -- the wrappers have already incorporated what the user is trying to do with them), so all is well after desugaring. This is all jolly confusing.

What should we do? I propose not printing type applications when printing HsExpr GhcTc when -fprint-typechecker-elaboration is on. That's not ideal, though, because normally -fprint-typechecker-elaboration should give us strictly more information. So perhaps a middle road is to still print the user-written type applications with -fprint-typechecker-elaboration -dppr-debug, but clearly signpost which applications are from wrappers (and should be desugared) and which are just in HsSyn (and will be ignored).

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking