IfaceType.hs 69.7 KB
Newer Older
Austin Seipp's avatar
Austin Seipp committed
1 2 3 4
{-
(c) The University of Glasgow 2006
(c) The GRASP/AQUA Project, Glasgow University, 1993-1998

5

Simon Marlow's avatar
Simon Marlow committed
6
This module defines interface types and binders
Austin Seipp's avatar
Austin Seipp committed
7
-}
8

Ben Gamari's avatar
Ben Gamari committed
9
{-# LANGUAGE CPP, FlexibleInstances, BangPatterns #-}
Sylvain Henry's avatar
Sylvain Henry committed
10
{-# LANGUAGE MultiWayIf #-}
11
{-# LANGUAGE TupleSections #-}
12 13
    -- FlexibleInstances for Binary (DefMethSpec IfaceType)

14
module IfaceType (
15
        IfExtName, IfLclName,
16

17
        IfaceType(..), IfacePredType, IfaceKind, IfaceCoercion(..),
Ningning Xie's avatar
Ningning Xie committed
18
        IfaceMCoercion(..),
19
        IfaceUnivCoProv(..),
20
        IfaceTyCon(..), IfaceTyConInfo(..), IfaceTyConSort(..),
21
        IfaceTyLit(..), IfaceAppArgs(..),
22
        IfaceContext, IfaceBndr(..), IfaceOneShot(..), IfaceLamBndr,
23
        IfaceTvBndr, IfaceIdBndr, IfaceTyConBinder,
Ryan Scott's avatar
Ryan Scott committed
24 25
        IfaceForAllBndr, ArgFlag(..), AnonArgFlag(..),
        ForallVisFlag(..), ShowForAllFlag(..),
26
        mkIfaceForAllTvBndr,
27

28
        ifForAllBndrVar, ifForAllBndrName, ifaceBndrName,
Ningning Xie's avatar
Ningning Xie committed
29
        ifTyConBinderVar, ifTyConBinderName,
30

31
        -- Equality testing
32
        isIfaceLiftedTypeKind,
33

34 35
        -- Conversion from IfaceAppArgs to IfaceTypes/ArgFlags
        appArgsIfaceTypes, appArgsIfaceTypesArgFlags,
36

37
        -- Printing
38
        pprIfaceType, pprParendIfaceType, pprPrecIfaceType,
39
        pprIfaceContext, pprIfaceContextArr,
40
        pprIfaceIdBndr, pprIfaceLamBndr, pprIfaceTvBndr, pprIfaceTyConBinders,
41
        pprIfaceBndrs, pprIfaceAppArgs, pprParendIfaceAppArgs,
42 43
        pprIfaceForAllPart, pprIfaceForAllPartMust, pprIfaceForAll,
        pprIfaceSigmaType, pprIfaceTyLit,
44 45
        pprIfaceCoercion, pprParendIfaceCoercion,
        splitIfaceSigmaTy, pprIfaceTypeApp, pprUserIfaceForAll,
Ben Gamari's avatar
Ben Gamari committed
46
        pprIfaceCoTcApp, pprTyTcApp, pprIfacePrefixApp,
47

48 49 50
        suppressIfaceInvisibles,
        stripIfaceInvisVars,
        stripInvisArgs,
51

52
        mkIfaceTySubst, substIfaceTyVar, substIfaceAppArgs, inDomIfaceTySubst
53 54
    ) where

55 56
#include "HsVersions.h"

57 58
import GhcPrelude

59 60
import {-# SOURCE #-} TysWiredIn ( coercibleTyCon, heqTyCon
                                 , liftedRepDataConTyCon )
61
import {-# SOURCE #-} TyCoRep    ( isRuntimeRepTy )
Ben Gamari's avatar
Ben Gamari committed
62

63
import DynFlags
64
import TyCon hiding ( pprPromotionQuote )
65
import CoAxiom
Simon Marlow's avatar
Simon Marlow committed
66
import Var
67
import PrelNames
Simon Marlow's avatar
Simon Marlow committed
68 69
import Name
import BasicTypes
70
import Binary
71 72
import Outputable
import FastString
Ben Gamari's avatar
Ben Gamari committed
73
import FastStringEnv
74
import Util
75

76
import Data.Maybe( isJust )
77
import qualified Data.Semigroup as Semi
Ben Gamari's avatar
Ben Gamari committed
78

Austin Seipp's avatar
Austin Seipp committed
79 80 81
{-
************************************************************************
*                                                                      *
82
                Local (nested) binders
Austin Seipp's avatar
Austin Seipp committed
83 84 85
*                                                                      *
************************************************************************
-}
86

87
type IfLclName = FastString     -- A local name in iface syntax
88

89 90
type IfExtName = Name   -- An External or WiredIn Name can appear in IfaceSyn
                        -- (However Internal or System Names never should)
91

92
data IfaceBndr          -- Local (non-top-level) binders
93 94
  = IfaceIdBndr {-# UNPACK #-} !IfaceIdBndr
  | IfaceTvBndr {-# UNPACK #-} !IfaceTvBndr
95

96 97
type IfaceIdBndr  = (IfLclName, IfaceType)
type IfaceTvBndr  = (IfLclName, IfaceKind)
98

Simon Peyton Jones's avatar
Simon Peyton Jones committed
99 100 101
ifaceTvBndrName :: IfaceTvBndr -> IfLclName
ifaceTvBndrName (n,_) = n

Ningning Xie's avatar
Ningning Xie committed
102 103 104 105 106 107 108
ifaceIdBndrName :: IfaceIdBndr -> IfLclName
ifaceIdBndrName (n,_) = n

ifaceBndrName :: IfaceBndr -> IfLclName
ifaceBndrName (IfaceTvBndr bndr) = ifaceTvBndrName bndr
ifaceBndrName (IfaceIdBndr bndr) = ifaceIdBndrName bndr

Simon Peyton Jones's avatar
Simon Peyton Jones committed
109
type IfaceLamBndr = (IfaceBndr, IfaceOneShot)
110

111 112
data IfaceOneShot    -- See Note [Preserve OneShotInfo] in CoreTicy
  = IfaceNoOneShot   -- and Note [The oneShot function] in MkId
113 114 115
  | IfaceOneShot


116 117 118 119 120 121 122 123
{-
%************************************************************************
%*                                                                      *
                IfaceType
%*                                                                      *
%************************************************************************
-}

124
-------------------------------
125
type IfaceKind     = IfaceType
126

127 128 129
-- | A kind of universal type, used for types and kinds.
--
-- Any time a 'Type' is pretty-printed, it is first converted to an 'IfaceType'
130
-- before being printed. See Note [Pretty printing via IfaceSyn] in PprTyThing
131
data IfaceType
132
  = IfaceFreeTyVar TyVar                -- See Note [Free tyvars in IfaceType]
133 134
  | IfaceTyVar     IfLclName            -- Type/coercion variable only, not tycon
  | IfaceLitTy     IfaceTyLit
135 136 137 138
  | IfaceAppTy     IfaceType IfaceAppArgs
                             -- See Note [Suppressing invisible arguments] for
                             -- an explanation of why the second field isn't
                             -- IfaceType, analogous to AppTy.
Simon Peyton Jones's avatar
Simon Peyton Jones committed
139
  | IfaceFunTy     AnonArgFlag IfaceType IfaceType
140
  | IfaceForAllTy  IfaceForAllBndr IfaceType
141 142
  | IfaceTyConApp  IfaceTyCon IfaceAppArgs  -- Not necessarily saturated
                                            -- Includes newtypes, synonyms, tuples
143 144
  | IfaceCastTy     IfaceType IfaceCoercion
  | IfaceCoercionTy IfaceCoercion
Ben Gamari's avatar
Ben Gamari committed
145

146
  | IfaceTupleTy                  -- Saturated tuples (unsaturated ones use IfaceTyConApp)
Ben Gamari's avatar
Ben Gamari committed
147
       TupleSort                  -- What sort of tuple?
148
       PromotionFlag                 -- A bit like IfaceTyCon
149
       IfaceAppArgs               -- arity = length args
150
          -- For promoted data cons, the kind args are omitted
151

batterseapower's avatar
batterseapower committed
152
type IfacePredType = IfaceType
153 154
type IfaceContext = [IfacePredType]

155
data IfaceTyLit
156 157
  = IfaceNumTyLit Integer
  | IfaceStrTyLit FastString
158
  deriving (Eq)
159

Ningning Xie's avatar
Ningning Xie committed
160 161
type IfaceTyConBinder = VarBndr IfaceBndr TyConBndrVis
type IfaceForAllBndr  = VarBndr IfaceBndr ArgFlag
162

163 164 165 166
-- | Make an 'IfaceForAllBndr' from an 'IfaceTvBndr'.
mkIfaceForAllTvBndr :: ArgFlag -> IfaceTvBndr -> IfaceForAllBndr
mkIfaceForAllTvBndr vis var = Bndr (IfaceTvBndr var) vis

167 168
-- | Stores the arguments in a type application as a list.
-- See @Note [Suppressing invisible arguments]@.
169 170
data IfaceAppArgs
  = IA_Nil
171 172 173 174 175 176 177 178 179 180 181 182 183
  | IA_Arg IfaceType    -- The type argument

           ArgFlag      -- The argument's visibility. We store this here so
                        -- that we can:
                        --
                        -- 1. Avoid pretty-printing invisible (i.e., specified
                        --    or inferred) arguments when
                        --    -fprint-explicit-kinds isn't enabled, or
                        -- 2. When -fprint-explicit-kinds *is*, enabled, print
                        --    specified arguments in @(...) and inferred
                        --    arguments in @{...}.

           IfaceAppArgs -- The rest of the arguments
184

185
instance Semi.Semigroup IfaceAppArgs where
186 187
  IA_Nil <> xs              = xs
  IA_Arg ty argf rest <> xs = IA_Arg ty argf (rest Semi.<> xs)
188

189 190
instance Monoid IfaceAppArgs where
  mempty = IA_Nil
191
  mappend = (Semi.<>)
Ben Gamari's avatar
Ben Gamari committed
192

193 194 195 196
-- Encodes type constructors, kind constructors,
-- coercion constructors, the lot.
-- We have to tag them in order to pretty print them
-- properly.
197 198
data IfaceTyCon = IfaceTyCon { ifaceTyConName :: IfExtName
                             , ifaceTyConInfo :: IfaceTyConInfo }
199
    deriving (Eq)
200

Ben Gamari's avatar
Ben Gamari committed
201 202 203 204 205 206 207 208 209 210 211 212
-- | The various types of TyCons which have special, built-in syntax.
data IfaceTyConSort = IfaceNormalTyCon          -- ^ a regular tycon

                    | IfaceTupleTyCon !Arity !TupleSort
                      -- ^ e.g. @(a, b, c)@ or @(#a, b, c#)@.
                      -- The arity is the tuple width, not the tycon arity
                      -- (which is twice the width in the case of unboxed
                      -- tuples).

                    | IfaceSumTyCon !Arity
                      -- ^ e.g. @(a | b | c)@

213 214 215 216 217 218
                    | IfaceEqualityTyCon
                      -- ^ A heterogeneous equality TyCon
                      --   (i.e. eqPrimTyCon, eqReprPrimTyCon, heqTyCon)
                      -- that is actually being applied to two types
                      -- of the same kind.  This affects pretty-printing
                      -- only: see Note [Equality predicates in IfaceType]
Ben Gamari's avatar
Ben Gamari committed
219 220
                    deriving (Eq)

221
{- Note [Free tyvars in IfaceType]
222
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Simon Peyton Jones's avatar
Simon Peyton Jones committed
223 224
Nowadays (since Nov 16, 2016) we pretty-print a Type by converting to
an IfaceType and pretty printing that.  This eliminates a lot of
225 226
pretty-print duplication, and it matches what we do with pretty-
printing TyThings. See Note [Pretty printing via IfaceSyn] in PprTyThing.
227 228 229 230 231 232

It works fine for closed types, but when printing debug traces (e.g.
when using -ddump-tc-trace) we print a lot of /open/ types.  These
types are full of TcTyVars, and it's absolutely crucial to print them
in their full glory, with their unique, TcTyVarDetails etc.

233
So we simply embed a TyVar in IfaceType with the IfaceFreeTyVar constructor.
234 235
Note that:

236 237
* We never expect to serialise an IfaceFreeTyVar into an interface file, nor
  to deserialise one.  IfaceFreeTyVar is used only in the "convert to IfaceType
238 239
  and then pretty-print" pipeline.

240
We do the same for covars, naturally.
241

Ben Gamari's avatar
Ben Gamari committed
242 243 244
Note [Equality predicates in IfaceType]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
GHC has several varieties of type equality (see Note [The equality types story]
245
in TysPrim for details).  In an effort to avoid confusing users, we suppress
246 247 248 249 250
the differences during pretty printing unless certain flags are enabled.
Here is how each equality predicate* is printed in homogeneous and
heterogeneous contexts, depending on which combination of the
-fprint-explicit-kinds and -fprint-equality-relations flags is used:

251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
--------------------------------------------------------------------------------------------
|         Predicate             |        Neither flag        |    -fprint-explicit-kinds   |
|-------------------------------|----------------------------|-----------------------------|
| a ~ b         (homogeneous)   |        a ~ b               | (a :: Type) ~  (b :: Type)  |
| a ~~ b,       homogeneously   |        a ~ b               | (a :: Type) ~  (b :: Type)  |
| a ~~ b,       heterogeneously |        a ~~ c              | (a :: Type) ~~ (c :: k)     |
| a ~# b,       homogeneously   |        a ~ b               | (a :: Type) ~  (b :: Type)  |
| a ~# b,       heterogeneously |        a ~~ c              | (a :: Type) ~~ (c :: k)     |
| Coercible a b (homogeneous)   |        Coercible a b       | Coercible @Type a b         |
| a ~R# b,      homogeneously   |        Coercible a b       | Coercible @Type a b         |
| a ~R# b,      heterogeneously |        a ~R# b             | (a :: Type) ~R# (c :: k)    |
|-------------------------------|----------------------------|-----------------------------|
|         Predicate             | -fprint-equality-relations |          Both flags         |
|-------------------------------|----------------------------|-----------------------------|
| a ~ b         (homogeneous)   |        a ~  b              | (a :: Type) ~  (b :: Type)  |
| a ~~ b,       homogeneously   |        a ~~ b              | (a :: Type) ~~ (b :: Type)  |
| a ~~ b,       heterogeneously |        a ~~ c              | (a :: Type) ~~ (c :: k)     |
| a ~# b,       homogeneously   |        a ~# b              | (a :: Type) ~# (b :: Type)  |
| a ~# b,       heterogeneously |        a ~# c              | (a :: Type) ~# (c :: k)     |
| Coercible a b (homogeneous)   |        Coercible a b       | Coercible @Type a b         |
| a ~R# b,      homogeneously   |        a ~R# b             | (a :: Type) ~R# (b :: Type) |
| a ~R# b,      heterogeneously |        a ~R# b             | (a :: Type) ~R# (c :: k)    |
--------------------------------------------------------------------------------------------
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293

(* There is no heterogeneous, representational, lifted equality counterpart
to (~~). There could be, but there seems to be no use for it.)

This table adheres to the following rules:

A. With -fprint-equality-relations, print the true equality relation.
B. Without -fprint-equality-relations:
     i. If the equality is representational and homogeneous, use Coercible.
    ii. Otherwise, if the equality is representational, use ~R#.
   iii. If the equality is nominal and homogeneous, use ~.
    iv. Otherwise, if the equality is nominal, use ~~.
C. With -fprint-explicit-kinds, print kinds on both sides of an infix operator,
   as above; or print the kind with Coercible.
D. Without -fprint-explicit-kinds, don't print kinds.

A hetero-kinded equality is used homogeneously when it is applied to two
identical kinds. Unfortunately, determining this from an IfaceType isn't
possible since we can't see through type synonyms. Consequently, we need to
record whether this particular application is homogeneous in IfaceTyConSort
294 295
for the purposes of pretty-printing.

296
See Note [The equality types story] in TysPrim.
Ben Gamari's avatar
Ben Gamari committed
297 298
-}

299 300
data IfaceTyConInfo   -- Used to guide pretty-printing
                      -- and to disambiguate D from 'D (they share a name)
301
  = IfaceTyConInfo { ifaceTyConIsPromoted :: PromotionFlag
Ben Gamari's avatar
Ben Gamari committed
302
                   , ifaceTyConSort       :: IfaceTyConSort }
303
    deriving (Eq)
304

Ningning Xie's avatar
Ningning Xie committed
305 306 307 308
data IfaceMCoercion
  = IfaceMRefl
  | IfaceMCo IfaceCoercion

309
data IfaceCoercion
Ningning Xie's avatar
Ningning Xie committed
310 311
  = IfaceReflCo       IfaceType
  | IfaceGReflCo      Role IfaceType (IfaceMCoercion)
312 313 314
  | IfaceFunCo        Role IfaceCoercion IfaceCoercion
  | IfaceTyConAppCo   Role IfaceTyCon [IfaceCoercion]
  | IfaceAppCo        IfaceCoercion IfaceCoercion
Ningning Xie's avatar
Ningning Xie committed
315
  | IfaceForAllCo     IfaceBndr IfaceCoercion IfaceCoercion
316 317
  | IfaceCoVarCo      IfLclName
  | IfaceAxiomInstCo  IfExtName BranchIndex [IfaceCoercion]
318 319 320 321
  | IfaceAxiomRuleCo  IfLclName [IfaceCoercion]
       -- There are only a fixed number of CoAxiomRules, so it suffices
       -- to use an IfaceLclName to distinguish them.
       -- See Note [Adding built-in type families] in TcTypeNats
322 323 324 325 326 327 328 329
  | IfaceUnivCo       IfaceUnivCoProv Role IfaceType IfaceType
  | IfaceSymCo        IfaceCoercion
  | IfaceTransCo      IfaceCoercion IfaceCoercion
  | IfaceNthCo        Int IfaceCoercion
  | IfaceLRCo         LeftOrRight IfaceCoercion
  | IfaceInstCo       IfaceCoercion IfaceCoercion
  | IfaceKindCo       IfaceCoercion
  | IfaceSubCo        IfaceCoercion
Simon Peyton Jones's avatar
Simon Peyton Jones committed
330 331
  | IfaceFreeCoVar    CoVar    -- See Note [Free tyvars in IfaceType]
  | IfaceHoleCo       CoVar    -- ^ See Note [Holes in IfaceCoercion]
332 333 334 335 336 337

data IfaceUnivCoProv
  = IfaceUnsafeCoerceProv
  | IfacePhantomProv IfaceCoercion
  | IfaceProofIrrelProv IfaceCoercion
  | IfacePluginProv String
338

Simon Peyton Jones's avatar
Simon Peyton Jones committed
339 340 341 342 343 344 345 346 347 348
{- Note [Holes in IfaceCoercion]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When typechecking fails the typechecker will produce a HoleCo to stand
in place of the unproven assertion. While we generally don't want to
let these unproven assertions leak into interface files, we still need
to be able to pretty-print them as we use IfaceType's pretty-printer
to render Types. For this reason IfaceCoercion has a IfaceHoleCo
constructor; however, we fails when asked to serialize to a
IfaceHoleCo to ensure that they don't end up in an interface file.

349

350 351
%************************************************************************
%*                                                                      *
352
                Functions over IFaceTypes
Austin Seipp's avatar
Austin Seipp committed
353 354 355
*                                                                      *
************************************************************************
-}
356

Ben Gamari's avatar
Ben Gamari committed
357 358 359
ifaceTyConHasKey :: IfaceTyCon -> Unique -> Bool
ifaceTyConHasKey tc key = ifaceTyConName tc `hasKey` key

360
isIfaceLiftedTypeKind :: IfaceKind -> Bool
361
isIfaceLiftedTypeKind (IfaceTyConApp tc IA_Nil)
362 363
  = isLiftedTypeKindTyConName (ifaceTyConName tc)
isIfaceLiftedTypeKind (IfaceTyConApp tc
364 365
                       (IA_Arg (IfaceTyConApp ptr_rep_lifted IA_Nil)
                               Required IA_Nil))
Ben Gamari's avatar
Ben Gamari committed
366
  =  tc `ifaceTyConHasKey` tYPETyConKey
Richard Eisenberg's avatar
Richard Eisenberg committed
367
  && ptr_rep_lifted `ifaceTyConHasKey` liftedRepDataConKey
368 369
isIfaceLiftedTypeKind _ = False

370
splitIfaceSigmaTy :: IfaceType -> ([IfaceForAllBndr], [IfacePredType], IfaceType)
371
-- Mainly for printing purposes
372 373 374 375 376 377 378 379 380 381 382 383
--
-- Here we split nested IfaceSigmaTy properly.
--
-- @
-- forall t. T t => forall m a b. M m => (a -> m b) -> t a -> m (t b)
-- @
--
-- If you called @splitIfaceSigmaTy@ on this type:
--
-- @
-- ([t, m, a, b], [T t, M m], (a -> m b) -> t a -> m (t b))
-- @
384
splitIfaceSigmaTy ty
385 386 387 388
  = case (bndrs, theta) of
      ([], []) -> (bndrs, theta, tau)
      _        -> let (bndrs', theta', tau') = splitIfaceSigmaTy tau
                   in (bndrs ++ bndrs', theta ++ theta', tau')
389
  where
390
    (bndrs, rho)   = split_foralls ty
batterseapower's avatar
batterseapower committed
391
    (theta, tau)   = split_rho rho
392

393 394
    split_foralls (IfaceForAllTy bndr ty)
        = case split_foralls ty of { (bndrs, rho) -> (bndr:bndrs, rho) }
395 396
    split_foralls rho = ([], rho)

Simon Peyton Jones's avatar
Simon Peyton Jones committed
397
    split_rho (IfaceFunTy InvisArg ty1 ty2)
398
        = case split_rho ty2 of { (ps, tau) -> (ty1:ps, tau) }
399
    split_rho tau = ([], tau)
400

401
suppressIfaceInvisibles :: DynFlags -> [IfaceTyConBinder] -> [a] -> [a]
402
suppressIfaceInvisibles dflags tys xs
403 404 405 406 407
  | gopt Opt_PrintExplicitKinds dflags = xs
  | otherwise = suppress tys xs
    where
      suppress _       []      = []
      suppress []      a       = a
408 409 410
      suppress (k:ks) (x:xs)
        | isInvisibleTyConBinder k =     suppress ks xs
        | otherwise                = x : suppress ks xs
411

412
stripIfaceInvisVars :: DynFlags -> [IfaceTyConBinder] -> [IfaceTyConBinder]
413
stripIfaceInvisVars dflags tyvars
414
  | gopt Opt_PrintExplicitKinds dflags = tyvars
415
  | otherwise = filterOut isInvisibleTyConBinder tyvars
416

Ningning Xie's avatar
Ningning Xie committed
417 418 419
-- | Extract an 'IfaceBndr' from an 'IfaceForAllBndr'.
ifForAllBndrVar :: IfaceForAllBndr -> IfaceBndr
ifForAllBndrVar = binderVar
420 421 422

-- | Extract the variable name from an 'IfaceForAllBndr'.
ifForAllBndrName :: IfaceForAllBndr -> IfLclName
Ningning Xie's avatar
Ningning Xie committed
423
ifForAllBndrName fab = ifaceBndrName (ifForAllBndrVar fab)
424

Ningning Xie's avatar
Ningning Xie committed
425 426 427
-- | Extract an 'IfaceBndr' from an 'IfaceTyConBinder'.
ifTyConBinderVar :: IfaceTyConBinder -> IfaceBndr
ifTyConBinderVar = binderVar
428

429
-- | Extract the variable name from an 'IfaceTyConBinder'.
430
ifTyConBinderName :: IfaceTyConBinder -> IfLclName
Ningning Xie's avatar
Ningning Xie committed
431
ifTyConBinderName tcb = ifaceBndrName (ifTyConBinderVar tcb)
432

433 434 435 436
ifTypeIsVarFree :: IfaceType -> Bool
-- Returns True if the type definitely has no variables at all
-- Just used to control pretty printing
ifTypeIsVarFree ty = go ty
437
  where
438
    go (IfaceTyVar {})         = False
439
    go (IfaceFreeTyVar {})     = False
440
    go (IfaceAppTy fun args)   = go fun && go_args args
Simon Peyton Jones's avatar
Simon Peyton Jones committed
441
    go (IfaceFunTy _ arg res)  = go arg && go res
442 443 444 445 446 447 448
    go (IfaceForAllTy {})      = False
    go (IfaceTyConApp _ args)  = go_args args
    go (IfaceTupleTy _ _ args) = go_args args
    go (IfaceLitTy _)          = True
    go (IfaceCastTy {})        = False -- Safe
    go (IfaceCoercionTy {})    = False -- Safe

449
    go_args IA_Nil = True
450
    go_args (IA_Arg arg _ args) = go arg && go_args args
451

452 453 454 455 456
{- Note [Substitution on IfaceType]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Substitutions on IfaceType are done only during pretty-printing to
construct the result type of a GADT, and does not deal with binders
(eg IfaceForAll), so it doesn't need fancy capture stuff.  -}
457

458
type IfaceTySubst = FastStringEnv IfaceType -- Note [Substitution on IfaceType]
459

460 461 462 463 464 465 466
mkIfaceTySubst :: [(IfLclName,IfaceType)] -> IfaceTySubst
-- See Note [Substitution on IfaceType]
mkIfaceTySubst eq_spec = mkFsEnv eq_spec

inDomIfaceTySubst :: IfaceTySubst -> IfaceTvBndr -> Bool
-- See Note [Substitution on IfaceType]
inDomIfaceTySubst subst (fs, _) = isJust (lookupFsEnv subst fs)
467 468

substIfaceType :: IfaceTySubst -> IfaceType -> IfaceType
469
-- See Note [Substitution on IfaceType]
470 471 472
substIfaceType env ty
  = go ty
  where
473
    go (IfaceFreeTyVar tv)    = IfaceFreeTyVar tv
474
    go (IfaceTyVar tv)        = substIfaceTyVar env tv
475
    go (IfaceAppTy  t ts)     = IfaceAppTy  (go t) (substIfaceAppArgs env ts)
Simon Peyton Jones's avatar
Simon Peyton Jones committed
476
    go (IfaceFunTy af t1 t2)  = IfaceFunTy af (go t1) (go t2)
477
    go ty@(IfaceLitTy {})     = ty
478 479
    go (IfaceTyConApp tc tys) = IfaceTyConApp tc (substIfaceAppArgs env tys)
    go (IfaceTupleTy s i tys) = IfaceTupleTy s i (substIfaceAppArgs env tys)
480
    go (IfaceForAllTy {})     = pprPanic "substIfaceType" (ppr ty)
481 482 483
    go (IfaceCastTy ty co)    = IfaceCastTy (go ty) (go_co co)
    go (IfaceCoercionTy co)   = IfaceCoercionTy (go_co co)

Ningning Xie's avatar
Ningning Xie committed
484 485 486 487 488 489
    go_mco IfaceMRefl    = IfaceMRefl
    go_mco (IfaceMCo co) = IfaceMCo $ go_co co

    go_co (IfaceReflCo ty)           = IfaceReflCo (go ty)
    go_co (IfaceGReflCo r ty mco)    = IfaceGReflCo r (go ty) (go_mco mco)
    go_co (IfaceFunCo r c1 c2)       = IfaceFunCo r (go_co c1) (go_co c2)
490 491 492
    go_co (IfaceTyConAppCo r tc cos) = IfaceTyConAppCo r tc (go_cos cos)
    go_co (IfaceAppCo c1 c2)         = IfaceAppCo (go_co c1) (go_co c2)
    go_co (IfaceForAllCo {})         = pprPanic "substIfaceCoercion" (ppr ty)
493
    go_co (IfaceFreeCoVar cv)        = IfaceFreeCoVar cv
494
    go_co (IfaceCoVarCo cv)          = IfaceCoVarCo cv
Simon Peyton Jones's avatar
Simon Peyton Jones committed
495
    go_co (IfaceHoleCo cv)           = IfaceHoleCo cv
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
    go_co (IfaceAxiomInstCo a i cos) = IfaceAxiomInstCo a i (go_cos cos)
    go_co (IfaceUnivCo prov r t1 t2) = IfaceUnivCo (go_prov prov) r (go t1) (go t2)
    go_co (IfaceSymCo co)            = IfaceSymCo (go_co co)
    go_co (IfaceTransCo co1 co2)     = IfaceTransCo (go_co co1) (go_co co2)
    go_co (IfaceNthCo n co)          = IfaceNthCo n (go_co co)
    go_co (IfaceLRCo lr co)          = IfaceLRCo lr (go_co co)
    go_co (IfaceInstCo c1 c2)        = IfaceInstCo (go_co c1) (go_co c2)
    go_co (IfaceKindCo co)           = IfaceKindCo (go_co co)
    go_co (IfaceSubCo co)            = IfaceSubCo (go_co co)
    go_co (IfaceAxiomRuleCo n cos)   = IfaceAxiomRuleCo n (go_cos cos)

    go_cos = map go_co

    go_prov IfaceUnsafeCoerceProv    = IfaceUnsafeCoerceProv
    go_prov (IfacePhantomProv co)    = IfacePhantomProv (go_co co)
    go_prov (IfaceProofIrrelProv co) = IfaceProofIrrelProv (go_co co)
    go_prov (IfacePluginProv str)    = IfacePluginProv str
513

514 515
substIfaceAppArgs :: IfaceTySubst -> IfaceAppArgs -> IfaceAppArgs
substIfaceAppArgs env args
516 517
  = go args
  where
518 519
    go IA_Nil              = IA_Nil
    go (IA_Arg ty arg tys) = IA_Arg (substIfaceType env ty) arg (go tys)
520 521 522 523 524

substIfaceTyVar :: IfaceTySubst -> IfLclName -> IfaceType
substIfaceTyVar env tv
  | Just ty <- lookupFsEnv env tv = ty
  | otherwise                     = IfaceTyVar tv
525

526

Austin Seipp's avatar
Austin Seipp committed
527 528 529
{-
************************************************************************
*                                                                      *
530
                Functions over IfaceAppArgs
Austin Seipp's avatar
Austin Seipp committed
531 532 533
*                                                                      *
************************************************************************
-}
534

535
stripInvisArgs :: DynFlags -> IfaceAppArgs -> IfaceAppArgs
536
stripInvisArgs dflags tys
537
  | gopt Opt_PrintExplicitKinds dflags = tys
538
  | otherwise = suppress_invis tys
539
    where
540
      suppress_invis c
541
        = case c of
542 543 544 545
            IA_Nil -> IA_Nil
            IA_Arg t argf ts
              |  isVisibleArgFlag argf
              -> IA_Arg t argf $ suppress_invis ts
546 547
              -- Keep recursing through the remainder of the arguments, as it's
              -- possible that there are remaining invisible ones.
Ningning Xie's avatar
Ningning Xie committed
548 549
              -- See the "In type declarations" section of Note [VarBndrs,
              -- TyCoVarBinders, TyConBinders, and visibility] in TyCoRep.
550 551
              |  otherwise
              -> suppress_invis ts
552

553 554
appArgsIfaceTypes :: IfaceAppArgs -> [IfaceType]
appArgsIfaceTypes IA_Nil = []
555 556 557 558 559 560
appArgsIfaceTypes (IA_Arg t _ ts) = t : appArgsIfaceTypes ts

appArgsIfaceTypesArgFlags :: IfaceAppArgs -> [(IfaceType, ArgFlag)]
appArgsIfaceTypesArgFlags IA_Nil = []
appArgsIfaceTypesArgFlags (IA_Arg t a ts)
                                 = (t, a) : appArgsIfaceTypesArgFlags ts
561

562 563
ifaceVisAppArgsLength :: IfaceAppArgs -> Int
ifaceVisAppArgsLength = go 0
Ben Gamari's avatar
Ben Gamari committed
564
  where
565 566 567 568
    go !n IA_Nil = n
    go n  (IA_Arg _ argf rest)
      | isVisibleArgFlag argf = go (n+1) rest
      | otherwise             = go n rest
Ben Gamari's avatar
Ben Gamari committed
569

Austin Seipp's avatar
Austin Seipp committed
570
{-
571 572
Note [Suppressing invisible arguments]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
573 574 575
We use the IfaceAppArgs data type to specify which of the arguments to a type
should be displayed when pretty-printing, under the control of
-fprint-explicit-kinds.
576
See also Type.filterOutInvisibleTypes.
577
For example, given
578

579 580
    T :: forall k. (k->*) -> k -> *    -- Ordinary kind polymorphism
    'Just :: forall k. k -> 'Maybe k   -- Promoted
581

582 583
we want

584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
    T * Tree Int    prints as    T Tree Int
    'Just *         prints as    Just *

For type constructors (IfaceTyConApp), IfaceAppArgs is a quite natural fit,
since the corresponding Core constructor:

    data Type
      = ...
      | TyConApp TyCon [Type]

Already puts all of its arguments into a list. So when converting a Type to an
IfaceType (see toIfaceAppArgsX in ToIface), we simply use the kind of the TyCon
(which is cached) to guide the process of converting the argument Types into an
IfaceAppArgs list.

We also want this behavior for IfaceAppTy, since given:

    data Proxy (a :: k)
    f :: forall (t :: forall a. a -> Type). Proxy Type (t Bool True)

We want to print the return type as `Proxy (t True)` without the use of
-fprint-explicit-kinds (#15330). Accomplishing this is trickier than in the
tycon case, because the corresponding Core constructor for IfaceAppTy:

    data Type
      = ...
      | AppTy Type Type

Only stores one argument at a time. Therefore, when converting an AppTy to an
IfaceAppTy (in toIfaceTypeX in ToIface), we:

1. Flatten the chain of AppTys down as much as possible
2. Use typeKind to determine the function Type's kind
3. Use this kind to guide the process of converting the argument Types into an
   IfaceAppArgs list.

By flattening the arguments like this, we obtain two benefits:

(a) We can reuse the same machinery to pretty-print IfaceTyConApp arguments as
    we do IfaceTyApp arguments, which means that we only need to implement the
    logic to filter out invisible arguments once.
(b) Unlike for tycons, finding the kind of a type in general (through typeKind)
    is not a constant-time operation, so by flattening the arguments first, we
    decrease the number of times we have to call typeKind.
628

629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
Note [Pretty-printing invisible arguments]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Note [Suppressing invisible arguments] is all about how to avoid printing
invisible arguments when the -fprint-explicit-kinds flag is disables. Well,
what about when it's enabled? Then we can and should print invisible kind
arguments, and this Note explains how we do it.

As two running examples, consider the following code:

  {-# LANGUAGE PolyKinds #-}
  data T1 a
  data T2 (a :: k)

When displaying these types (with -fprint-explicit-kinds on), we could just
do the following:

  T1 k a
  T2 k a

That certainly gets the job done. But it lacks a crucial piece of information:
is the `k` argument inferred or specified? To communicate this, we use visible
kind application syntax to distinguish the two cases:

  T1 @{k} a
  T2 @k   a

Here, @{k} indicates that `k` is an inferred argument, and @k indicates that
`k` is a specified argument. (See
Note [VarBndrs, TyCoVarBinders, TyConBinders, and visibility] in TyCoRep for
a lengthier explanation on what "inferred" and "specified" mean.)

Austin Seipp's avatar
Austin Seipp committed
660 661
************************************************************************
*                                                                      *
662
                Pretty-printing
Austin Seipp's avatar
Austin Seipp committed
663 664 665
*                                                                      *
************************************************************************
-}
666

Ben Gamari's avatar
Ben Gamari committed
667 668 669 670 671 672 673 674 675 676 677
if_print_coercions :: SDoc  -- ^ if printing coercions
                   -> SDoc  -- ^ otherwise
                   -> SDoc
if_print_coercions yes no
  = sdocWithDynFlags $ \dflags ->
    getPprStyle $ \style ->
    if gopt Opt_PrintExplicitCoercions dflags
         || dumpStyle style || debugStyle style
    then yes
    else no

678
pprIfaceInfixApp :: PprPrec -> SDoc -> SDoc -> SDoc -> SDoc
679
pprIfaceInfixApp ctxt_prec pp_tc pp_ty1 pp_ty2
680
  = maybeParen ctxt_prec opPrec $
681
    sep [pp_ty1, pp_tc <+> pp_ty2]
682

683
pprIfacePrefixApp :: PprPrec -> SDoc -> [SDoc] -> SDoc
684
pprIfacePrefixApp ctxt_prec pp_fun pp_tys
685
  | null pp_tys = pp_fun
686
  | otherwise   = maybeParen ctxt_prec appPrec $
687
                  hang pp_fun 2 (sep pp_tys)
688

Austin Seipp's avatar
Austin Seipp committed
689
-- ----------------------------- Printing binders ------------------------------------
690 691 692

instance Outputable IfaceBndr where
    ppr (IfaceIdBndr bndr) = pprIfaceIdBndr bndr
Ben Gamari's avatar
Ben Gamari committed
693
    ppr (IfaceTvBndr bndr) = char '@' <+> pprIfaceTvBndr False bndr
694 695 696 697

pprIfaceBndrs :: [IfaceBndr] -> SDoc
pprIfaceBndrs bs = sep (map ppr bs)

698 699 700 701
pprIfaceLamBndr :: IfaceLamBndr -> SDoc
pprIfaceLamBndr (b, IfaceNoOneShot) = ppr b
pprIfaceLamBndr (b, IfaceOneShot)   = ppr b <> text "[OneShot]"

Ben Gamari's avatar
Ben Gamari committed
702
pprIfaceIdBndr :: IfaceIdBndr -> SDoc
703
pprIfaceIdBndr (name, ty) = parens (ppr name <+> dcolon <+> ppr ty)
704

Ben Gamari's avatar
Ben Gamari committed
705 706
pprIfaceTvBndr :: Bool -> IfaceTvBndr -> SDoc
pprIfaceTvBndr use_parens (tv, ki)
707
  | isIfaceLiftedTypeKind ki = ppr tv
Ben Gamari's avatar
Ben Gamari committed
708 709 710 711
  | otherwise                = maybe_parens (ppr tv <+> dcolon <+> ppr ki)
  where
    maybe_parens | use_parens = parens
                 | otherwise  = id
712

713
pprIfaceTyConBinders :: [IfaceTyConBinder] -> SDoc
714
pprIfaceTyConBinders = sep . map go
715
  where
716 717 718 719 720
    go :: IfaceTyConBinder -> SDoc
    go (Bndr (IfaceIdBndr bndr) _) = pprIfaceIdBndr bndr
    go (Bndr (IfaceTvBndr bndr) vis) =
      -- See Note [Pretty-printing invisible arguments]
      case vis of
Simon Peyton Jones's avatar
Simon Peyton Jones committed
721 722 723
        AnonTCB  VisArg    -> ppr_bndr True
        AnonTCB  InvisArg  -> ppr_bndr True  -- Rare; just promoted GADT data constructors
                                             -- Should we print them differently?
724 725 726 727 728
        NamedTCB Required  -> ppr_bndr True
        NamedTCB Specified -> char '@' <> ppr_bndr True
        NamedTCB Inferred  -> char '@' <> braces (ppr_bndr False)
      where
        ppr_bndr use_parens = pprIfaceTvBndr use_parens bndr
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743

instance Binary IfaceBndr where
    put_ bh (IfaceIdBndr aa) = do
            putByte bh 0
            put_ bh aa
    put_ bh (IfaceTvBndr ab) = do
            putByte bh 1
            put_ bh ab
    get bh = do
            h <- getByte bh
            case h of
              0 -> do aa <- get bh
                      return (IfaceIdBndr aa)
              _ -> do ab <- get bh
                      return (IfaceTvBndr ab)
744 745 746 747 748 749 750 751 752 753 754

instance Binary IfaceOneShot where
    put_ bh IfaceNoOneShot = do
            putByte bh 0
    put_ bh IfaceOneShot = do
            putByte bh 1
    get bh = do
            h <- getByte bh
            case h of
              0 -> do return IfaceNoOneShot
              _ -> do return IfaceOneShot
755

Austin Seipp's avatar
Austin Seipp committed
756
-- ----------------------------- Printing IfaceType ------------------------------------
757 758 759

---------------------------------
instance Outputable IfaceType where
760
  ppr ty = pprIfaceType ty
761

Ben Gamari's avatar
Ben Gamari committed
762
pprIfaceType, pprParendIfaceType :: IfaceType -> SDoc
763 764
pprIfaceType       = pprPrecIfaceType topPrec
pprParendIfaceType = pprPrecIfaceType appPrec
765

766
pprPrecIfaceType :: PprPrec -> IfaceType -> SDoc
767 768
-- We still need `eliminateRuntimeRep`, since the `pprPrecIfaceType` maybe
-- called from other places, besides `:type` and `:info`.
769
pprPrecIfaceType prec ty = eliminateRuntimeRep (ppr_ty prec) ty
770

Simon Peyton Jones's avatar
Simon Peyton Jones committed
771 772 773 774
ppr_sigma :: PprPrec -> IfaceType -> SDoc
ppr_sigma ctxt_prec ty
  = maybeParen ctxt_prec funPrec (pprIfaceSigmaType ShowForAllMust ty)

775
ppr_ty :: PprPrec -> IfaceType -> SDoc
Simon Peyton Jones's avatar
Simon Peyton Jones committed
776 777 778
ppr_ty ctxt_prec ty@(IfaceForAllTy {})        = ppr_sigma ctxt_prec ty
ppr_ty ctxt_prec ty@(IfaceFunTy InvisArg _ _) = ppr_sigma ctxt_prec ty

Krzysztof Gogolewski's avatar
Krzysztof Gogolewski committed
779
ppr_ty _         (IfaceFreeTyVar tyvar) = ppr tyvar  -- This is the main reason for IfaceFreeTyVar!
780
ppr_ty _         (IfaceTyVar tyvar)     = ppr tyvar  -- See Note [TcTyVars in IfaceType]
Ben Gamari's avatar
Ben Gamari committed
781
ppr_ty ctxt_prec (IfaceTyConApp tc tys) = pprTyTcApp ctxt_prec tc tys
782
ppr_ty ctxt_prec (IfaceTupleTy i p tys) = pprTuple ctxt_prec i p tys
Ben Gamari's avatar
Ben Gamari committed
783
ppr_ty _         (IfaceLitTy n)         = pprIfaceTyLit n
784
        -- Function types
Simon Peyton Jones's avatar
Simon Peyton Jones committed
785
ppr_ty ctxt_prec (IfaceFunTy _ ty1 ty2)  -- Should be VisArg
786
  = -- We don't want to lose synonyms, so we mustn't use splitFunTys here.
787 788
    maybeParen ctxt_prec funPrec $
    sep [ppr_ty funPrec ty1, sep (ppr_fun_tail ty2)]
789
  where
Simon Peyton Jones's avatar
Simon Peyton Jones committed
790
    ppr_fun_tail (IfaceFunTy VisArg ty1 ty2)
791
      = (arrow <+> ppr_ty funPrec ty1) : ppr_fun_tail ty2
792
    ppr_fun_tail other_ty
793
      = [arrow <+> pprIfaceType other_ty]
794

795
ppr_ty ctxt_prec (IfaceAppTy t ts)
Ben Gamari's avatar
Ben Gamari committed
796 797 798 799 800
  = if_print_coercions
      ppr_app_ty
      ppr_app_ty_no_casts
  where
    ppr_app_ty =
801 802 803
        sdocWithDynFlags $ \dflags ->
        pprIfacePrefixApp ctxt_prec
                          (ppr_ty funPrec t)
804
                          (map (ppr_app_arg appPrec) (tys_wo_kinds dflags))
805

806
    tys_wo_kinds dflags = appArgsIfaceTypesArgFlags $ stripInvisArgs dflags ts
Ben Gamari's avatar
Ben Gamari committed
807 808 809

    -- Strip any casts from the head of the application
    ppr_app_ty_no_casts =
810 811 812
        case t of
          IfaceCastTy head _ -> ppr_ty ctxt_prec (mk_app_tys head ts)
          _                  -> ppr_app_ty
Ben Gamari's avatar
Ben Gamari committed
813

814
    mk_app_tys :: IfaceType -> IfaceAppArgs -> IfaceType
Ben Gamari's avatar
Ben Gamari committed
815 816
    mk_app_tys (IfaceTyConApp tc tys1) tys2 =
        IfaceTyConApp tc (tys1 `mappend` tys2)
817
    mk_app_tys t1 tys2 = IfaceAppTy t1 tys2
818

819
ppr_ty ctxt_prec (IfaceCastTy ty co)
Ben Gamari's avatar
Ben Gamari committed
820
  = if_print_coercions
821
      (parens (ppr_ty topPrec ty <+> text "|>" <+> ppr co))
Ben Gamari's avatar
Ben Gamari committed
822
      (ppr_ty ctxt_prec ty)
823 824

ppr_ty ctxt_prec (IfaceCoercionTy co)
Ben Gamari's avatar
Ben Gamari committed
825 826 827
  = if_print_coercions
      (ppr_co ctxt_prec co)
      (text "<>")
828

829 830 831 832 833 834 835 836
{- Note [Defaulting RuntimeRep variables]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RuntimeRep variables are considered by many (most?) users to be little
more than syntactic noise. When the notion was introduced there was a
signficant and understandable push-back from those with pedagogy in
mind, which argued that RuntimeRep variables would throw a wrench into
nearly any teach approach since they appear in even the lowly ($)
function's type,
Ben Gamari's avatar
Ben Gamari committed
837 838 839 840 841 842 843

    ($) :: forall (w :: RuntimeRep) a (b :: TYPE w). (a -> b) -> a -> b

which is significantly less readable than its non RuntimeRep-polymorphic type of

    ($) :: (a -> b) -> a -> b

844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
Moreover, unboxed types don't appear all that often in run-of-the-mill
Haskell programs, so it makes little sense to make all users pay this
syntactic overhead.

For this reason it was decided that we would hide RuntimeRep variables
for now (see #11549). We do this by defaulting all type variables of
kind RuntimeRep to LiftedRep. This is done in a pass right before
pretty-printing (defaultRuntimeRepVars, controlled by
-fprint-explicit-runtime-reps)

This applies to /quantified/ variables like 'w' above.  What about
variables that are /free/ in the type being printed, which certainly
happens in error messages.  Suppose (Trac #16074) we are reporting a
mismatch between two skolems
          (a :: RuntimeRep) ~ (b :: RuntimeRep)
We certainly don't want to say "Can't match LiftedRep ~ LiftedRep"!

But if we are printing the type
    (forall (a :: Type r). blah
we do want to turn that (free) r into LiftedRep, so it prints as
    (forall a. blah)

Conclusion: keep track of whether we we are in the kind of a
binder; ohly if so, convert free RuntimeRep variables to LiftedRep.
Ben Gamari's avatar
Ben Gamari committed
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884
-}

-- | Default 'RuntimeRep' variables to 'LiftedPtr'. e.g.
--
-- @
-- ($) :: forall (r :: GHC.Types.RuntimeRep) a (b :: TYPE r).
--        (a -> b) -> a -> b
-- @
--
-- turns in to,
--
-- @ ($) :: forall a (b :: *). (a -> b) -> a -> b @
--
-- We do this to prevent RuntimeRep variables from incurring a significant
-- syntactic overhead in otherwise simple type signatures (e.g. ($)). See
-- Note [Defaulting RuntimeRep variables] and #11549 for further discussion.
--
885 886
defaultRuntimeRepVars :: IfaceType -> IfaceType
defaultRuntimeRepVars ty = go False emptyFsEnv ty
Ben Gamari's avatar
Ben Gamari committed
887
  where
888 889 890 891 892 893 894
    go :: Bool              -- True <=> Inside the kind of a binder
       -> FastStringEnv ()  -- Set of enclosing forall-ed RuntimeRep variables
       -> IfaceType         --  (replace them with LiftedRep)
       -> IfaceType
    go ink subs (IfaceForAllTy (Bndr (IfaceTvBndr (var, var_kind)) argf) ty)
     | isRuntimeRep var_kind
      , isInvisibleArgFlag argf -- Don't default *visible* quantification
Ningning Xie's avatar
Ningning Xie committed
895
                                -- or we get the mess in #13963
Ben Gamari's avatar
Ben Gamari committed
896
      = let subs' = extendFsEnv subs var ()
897 898 899
            -- Record that we should replace it with LiftedRep,
            -- and recurse, discarding the forall
        in go ink subs' ty
Ningning Xie's avatar
Ningning Xie committed