Skip to content
  • Richard Eisenberg's avatar
    Refactor kindGeneralize and friends · d9c6b86e
    Richard Eisenberg authored and Marge Bot's avatar Marge Bot committed
    This commit should have no change in behavior.(*)
    
    The observation was that Note [Recipe for checking a signature]
    says that every metavariable in a type-checked type must either
      (A) be generalized
      (B) be promoted
      (C) be zapped.
    Yet the code paths for doing these were all somewhat separate.
    This led to some steps being skipped. This commit shores this
    all up. The key innovation is TcHsType.kindGeneralizeSome, with
    appropriate commentary.
    
    This commit also sets the stage for #15809, by turning the
    WARNing about bad level-numbers in generalisation into an
    ASSERTion. The actual fix for #15809 will be in a separate
    commit.
    
    Other changes:
     * zonkPromoteType is now replaced by kindGeneralizeNone.
       This might have a small performance degradation, because
       zonkPromoteType zonked and promoted all at once. The new
       code path promotes first, and then zonks.
    
     * A call to kindGeneralizeNone was added in tcHsPartialSigType.
       I think this was a lurking bug, because it did not follow
       Note [Recipe for checking a signature]. I did not try to
       come up with an example showing the bug. This is the (*)
       above.
    
       Because of this change, there is an error message regression
       in partial-sigs/should_fail/T14040a. This problem isn't really
       a direct result of this refactoring, but is a symptom of
       something deeper. See #16775, which addresses the deeper
       problem.
    
     * I added a short-cut to quantifyTyVars, in case there's
       nothing to quantify.
    
     * There was a horribly-outdated Note that wasn't referred
       to. Gone now.
    
     * While poking around with T14040a, I discovered a small
       mistake in the Coercion.simplifyArgsWorker. Easy to fix,
       happily.
    
     * See new Note [Free vars in coercion hole] in TcMType.
       Previously, we were doing the wrong thing when looking
       at a coercion hole in the gather-candidates algorithm.
       Fixed now, with lengthy explanation.
    
    Metric Decrease:
      T14683
    d9c6b86e