Skip to content

Type signatures break evidence for syntactic constructs in hie files

Summary

Bindings that make use of syntactic constructs requiring special type class instances (Monad with do notation, Num with integer literals, Enum with ranges, IsString, IsList, etc.) refer to all relevant evidence variables in their corresponding nodes in .hie files only if the binding has no top-level type signature.

Steps to reproduce

Compile the following with ghc -fwrite-ide-info:

module Modulo1 where

data Modulo1 = Zero

instance Num Modulo1 where
  fromInteger _ = Zero

zero = 0 :: Modulo1

zero' :: Modulo1
zero' = 0

Inspect the generated .hie file using hiedb dump. Only zero contains an evidence use for $fNumModulo1, zero' does not.

zero:

  92   │   Node@Modulo1.hs:8:1-19: Source: From source
  93   │                           {(annotations: {(FunBind, HsBindLR), (Match, Match),
  94   │                                           (XHsBindsLR, HsBindLR)}), 
  95   │                            (types: [0]), 
  96   │                            (identifier info: {(name $fNumModulo1,  Details:  Just 1 {usage of evidence variable}), 
  97   │                                               (name $dNum,  Details:  Just 1 {evidence variable bound by a let, depending on: [$fNumModulo1]
  98   │                                                                               with scope: LocalScope Modulo1.hs:8:1-19
  99   │                                                                               bound at: Modulo1.hs:8:1-19})})}
 100   │                           

zero':

 136   │   Node@Modulo1.hs:11:1-9: Source: From source
 137   │                           {(annotations: {(FunBind, HsBindLR), (Match, Match),
 138   │                                           (XHsBindsLR, HsBindLR)}), 
 139   │                            (types: [0]),  (identifier info: {})}
 140   │                           

Expected behavior

zero and zero' should both have evidence uses of $fNumModulo1.

Environment

  • GHC version used: 9.4.5, 9.6.1

Possible cause

From my own investigation, the problem seems to come from the typechecker. For bindings without a type signature the evidence goes into the abs_ev_binds field of their corresponding AbsBinds. Meanwhile, for bindings with a type signature the evidence is instead assigned to tcg_ev_binds in TcGblEnv.

Edited by Vasily Sterekhov
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information