Opened 2 years ago

Closed 21 months ago

#14066 closed bug (fixed)

Skolem escape at the kind level

Reported by: simonpj Owned by:
Priority: normal Milestone:
Component: Compiler Version: 8.0.1
Keywords: Cc: RyanGlScott
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: dependent/should_compile/T14066a, dependent/should_fail/T14066{,c,d,e,f,g,h}
Blocked By: Blocking:
Related Tickets: #13364, #14040 Differential Rev(s):
Wiki Page: https://ghc.haskell.org/trac/ghc/wiki/GhcKinds/KindInference

Description (last modified by simonpj)

This program should be rejected

{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE KindSignatures #-}

module Foo2 where

import Data.Kind ( Type )
import Data.Type.Equality
import Data.Proxy
import GHC.Exts

data SameKind :: k -> k -> Type

f (x :: Proxy a) = let g :: forall k (b :: k). SameKind a b
                       g = undefined
                   in ()

But

  • 8.0 rejects it, with an unhelpful message
  • 8.2 accepts it, and the result satisfies Core Lint
  • HEAD accepts it, and produces a Core Lint Error

Change History (10)

comment:1 Changed 2 years ago by simonpj

Description: modified (diff)

comment:2 Changed 2 years ago by simonpj

Probable cause: need an implication constraint in tcExplicitTkBndrs and similarly Implicit.

This might make Note [Scope-check inferred kinds] go away.

Last edited 2 years ago by simonpj (previous) (diff)

comment:3 Changed 2 years ago by simonpj

Fixing this will probably cure #14040.

comment:4 Changed 2 years ago by RyanGlScott

Cc: RyanGlScott added

comment:5 Changed 2 years ago by goldfire

This is a dup of #13364. But this one has more commentary, so keeping this one.

comment:6 Changed 2 years ago by simonpj

Richard: I'm eager to fix this, because it'll help clean up the ghastly mess in Note [Scope-check inferred kinds]. Quit a few other tickets seems to be messing about in this space too.

Any progress?

comment:7 Changed 2 years ago by simonpj

comment:8 Changed 22 months ago by kcsongor

Wiki Page: https://ghc.haskell.org/trac/ghc/wiki/GhcKinds/KindInference

comment:9 Changed 21 months ago by Richard Eisenberg <rae@…>

In faec8d35/ghc:

Track type variable scope more carefully.

The main job of this commit is to track more accurately the scope
of tyvars introduced by user-written foralls. For example, it would
be to have something like this:

  forall a. Int -> (forall k (b :: k). Proxy '[a, b]) -> Bool

In that type, a's kind must be k, but k isn't in scope. We had a
terrible way of doing this before (not worth repeating or describing
here, but see the old tcImplicitTKBndrs and friends), but now
we have a principled approach: make an Implication when kind-checking
a forall. Doing so then hooks into the existing machinery for
preventing skolem-escape, performing floating, etc. This also means
that we bump the TcLevel whenever going into a forall.

The new behavior is done in TcHsType.scopeTyVars, but see also
TcHsType.tc{Im,Ex}plicitTKBndrs, which have undergone significant
rewriting. There are several Notes near there to guide you. Of
particular interest there is that Implication constraints can now
have skolems that are out of order; this situation is reported in
TcErrors.

A major consequence of this is a slightly tweaked process for type-
checking type declarations. The new Note [Use SigTvs in kind-checking
pass] in TcTyClsDecls lays it out.

The error message for dependent/should_fail/TypeSkolEscape has become
noticeably worse. However, this is because the code in TcErrors goes to
some length to preserve pre-8.0 error messages for kind errors. It's time
to rip off that plaster and get rid of much of the kind-error-specific
error messages. I tried this, and doing so led to a lovely error message
for TypeSkolEscape. So: I'm accepting the error message quality regression
for now, but will open up a new ticket to fix it, along with a larger
error-message improvement I've been pondering. This applies also to
dependent/should_fail/{BadTelescope2,T14066,T14066e}, polykinds/T11142.

Other minor changes:
 - isUnliftedTypeKind didn't look for tuples and sums. It does now.

 - check_type used check_arg_type on both sides of an AppTy. But the left
   side of an AppTy isn't an arg, and this was causing a bad error message.
   I've changed it to use check_type on the left-hand side.

 - Some refactoring around when we print (TYPE blah) in error messages.
   The changes decrease the times when we do so, to good effect.
   Of course, this is still all controlled by
   -fprint-explicit-runtime-reps

Fixes #14066 #14749

Test cases: dependent/should_compile/{T14066a,T14749},
            dependent/should_fail/T14066{,c,d,e,f,g,h}

comment:10 Changed 21 months ago by goldfire

Resolution: fixed
Status: newclosed
Test Case: dependent/should_compile/T14066a, dependent/should_fail/T14066{,c,d,e,f,g,h}
Note: See TracTickets for help on using tickets.