[GHC] #15952: Reduce zonking-related invariants in the type checker

GHC ghc-devs at haskell.org
Thu Dec 6 09:18:25 UTC 2018


#15952: Reduce zonking-related invariants in the type checker
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  task              |               Status:  new
        Priority:  normal            |            Milestone:  8.6.3
       Component:  Compiler          |              Version:  8.6.2
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 When we execute Step 2a, there are two differences
 between `typeKind` and `tcTypeKind`:

 1. `tcTypeKind` respects the distinction between `Constraint` and `Type`.
 Concretely, this means that `typeKind` uses `coreView` and `tcTypeKind`
 uses `tcView`; and the treatment of `FunTy` differs too.

 2. `tcTypeKind` is monadic.  This key change lets us remove some
 `zonkTcType`s, and all the `naked` business.

 These are separate issues.  In `TcErrors`, for example, the types are all
 zonked, so (2) is
 not important; and yet making things monadic is a pain.  So here's an
 idea:

 * '''Make `typeKind` respect the `Constraint`/`Type` distinction.'''

 So `typeKind (Eq Int)` would return `Constraint` rather than `Type`.  But
 that doesn't matter!
 In Core-land, those two types are treated identically, so it doesn't
 matter if `typeKind`
 returns one vs the other!

 Then in `TcErrors` we can safely call the (pure) `typeKind`.

 ---------------

 To make `tcTypeKind` monadic we need a monadic version of `tcEqType`,
 because `tcEqType` calls
 `tcTypeKind` to compare the kinds of the two types.  That may in any case
 be advantageous,
 because a monadic `tcEqType` will return True more often.

 We probably want to keep the pure version for occasions where we know the
 types are zonked.

 ---------------
 A couple of notes about `tcEqType`:

 * `tcEqType` currently returns `Maye Bool` to indicate that, when the
 types differ, whether they differ only in an invisible position. This is
 used just once, in `TcErrors`. Rather than return `Maybe Bool`, whith its
 assocaited allocation etc,

   I suggest we pass in a `Bool` flag saying whether to take invisible args
 into account.  Then in `TcErrors` we can call `tcEqType` twice (with the
 flag set to True and False) and behave appropriately.

   This is only needed for the pure version (used in `TcErrors`). The
 monadic version ignores this visiblity stuff.

 * `tc_eq_type` currently takes a "view" function which is always `tcView`.
 Let's specialise to `tcView`.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15952#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list