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

GHC ghc-devs at haskell.org
Mon Mar 4 18:51:02 UTC 2019


#15952: Reduce zonking-related invariants in the type checker
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  task              |               Status:  closed
        Priority:  normal            |            Milestone:  8.10.1
       Component:  Compiler          |              Version:  8.6.2
      Resolution:  fixed             |             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:                    |  https://gitlab.haskell.org/ghc/ghc/merge_requests/206
-------------------------------------+-------------------------------------

Comment (by Simon Peyton Jones <simonpj@…>):

 In [changeset:"682783828275cca5fd8bf5be5b52054c75e0e22c/ghc" 6827838/ghc]:
 {{{
 #!CommitTicketReference repository="ghc"
 revision="682783828275cca5fd8bf5be5b52054c75e0e22c"
 Make a smart mkAppTyM

 This patch finally delivers on Trac #15952.  Specifically

 * Completely remove Note [The tcType invariant], along with
   its complicated consequences (IT1-IT6).

 * Replace Note [The well-kinded type invariant] with:

       Note [The Purely Kinded Type Invariant (PKTI)]

 * Instead, establish the (PKTI) in TcHsType.tcInferApps,
   by using a new function mkAppTyM when building a type
   application.  See Note [mkAppTyM].

 * As a result we can remove the delicate mkNakedXX functions
   entirely.  Specifically, mkNakedCastTy retained lots of
   extremly delicate Refl coercions which just cluttered
   everything up, and(worse) were very vulnerable to being
   silently eliminated by (say) substTy. This led to a
   succession of bug reports.

 The result is noticeably simpler to explain, simpler
 to code, and Richard and I are much more confident that
 it is correct.

 It does not actually fix any bugs, but it brings us closer.
 E.g. I hoped it'd fix #15918 and #15799, but it doesn't quite
 do so.  However, it makes it much easier to fix.

 I also did a raft of other minor refactorings:

 * Use tcTypeKind consistently in the type checker

 * Rename tcInstTyBinders to tcInvisibleTyBinders,
   and refactor it a bit

 * Refactor tcEqType, pickyEqType, tcEqTypeVis
   Simpler, probably more efficient.

 * Make zonkTcType zonk TcTyCons, at least if they have
   any free unification variables -- see zonk_tc_tycon
   in TcMType.zonkTcTypeMapper.

   Not zonking these TcTyCons was actually a bug before.

 * Simplify try_to_reduce_no_cache in TcFlatten (a lot)

 * Combine checkExpectedKind and checkExpectedKindX.
   And then combine the invisible-binder instantation code
   Much simpler now.

 * Fix a little bug in TcMType.skolemiseQuantifiedTyVar.
   I'm not sure how I came across this originally.

 * Fix a little bug in TyCoRep.isUnliftedRuntimeRep
   (the ASSERT was over-zealous).  Again I'm not certain
   how I encountered this.

 * Add a missing solveLocalEqualities in
   TcHsType.tcHsPartialSigType.
   I came across this when trying to get level numbers
   right.
 }}}

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


More information about the ghc-tickets mailing list