Opened 4 months ago

Last modified 7 weeks ago

#14939 new bug

Lint error in forall type

Reported by: Iceland_jack Owned by:
Priority: normal Milestone:
Component: Compiler Version: 8.5
Keywords: StaticPointers Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


This is an odd bug

{-# Language StaticPointers #-}

import Data.Kind

type Cat ob = ob -> ob -> Type

type Alg cls ob = ob

newtype Frí (cls::Type -> Constraint) :: (Type -> Alg cls Type) where
  Frí :: { with :: forall x. cls x => (a -> x) -> x } 
      -> Frí cls a

data AlgCat (cls::Type -> Constraint) :: Cat (Alg cls Type) where
  AlgCat :: (cls a, cls b) => (a -> b) -> AlgCat cls a b

leftAdj :: AlgCat cls (Frí cls a) b -> (a -> b)
leftAdj (AlgCat f) a = undefined 

causes a

$ ./ghc-stage2 --interactive -ignore-dot-ghci -dcore-lint 222-bug.hs
GHCi, version 8.5.20180128:  :? for help
[1 of 1] Compiling Main             ( 222-bug.hs, interpreted )
*** Core Lint errors : in result of Float out(FOS {Lam = Just 0,
                                                   Consts = True,
                                                   OverSatApps = False}) ***
<no location info>: warning:
    In the type ‘forall (cls :: * -> Constraint) (b :: Alg cls *). b’
    Variable escape in forall: forall (cls :: *
                                              -> Constraint) (b :: Alg cls *).
*** Offending Program ***
  :: forall (cls :: * -> Constraint) a.
     Frí cls a -> forall x. cls x => (a -> x) -> x
[LclIdX[[RecSel]], Arity=2]

 ..  . --->8------->8------->8--- ..

Change History (5)

comment:1 Changed 4 months ago by monoidal

Smaller version:

{-# Language StaticPointers, TypeInType, GADTs #-}

import Data.Kind

type Alg cls = Type

data AlgCat (cls::Type) :: Alg cls -> Type where

leftAdj :: AlgCat cls a -> a
leftAdj f = undefined 

comment:2 Changed 7 weeks ago by simonpj

Summary: StaticPointers + -dcore-lint: cause Core Lint error??Lint error in forall type

The Lint error is this:

    In the type `forall (cls :: * -> Constraint) (b :: Alg cls *). b'
    Variable escape in forall: forall (cls :: * -> Constraint)
                                      (b :: Alg cls *).

The complaint is because the kind of the body of the forall is Alg cls *, but the forall binds cls so it looks as if cls escapes. But actually it is fine because

type Alg cls ob = ob

so Alg cls * is really just *, and the cls argument is not mentioned in the expansion.

I conclude that the program is fine and it's Lint that is at fault.

c.f. TcUnify.occCheckExpand and CoreUtils.coreAltsType which deal with the same problem. A single systematic solution eludes me.

I worry that Type.typeKind suffers from the same problem, in the ForAllTy case.

comment:3 Changed 7 weeks ago by Simon Peyton Jones <simonpj@…>

In 9d600ea6/ghc:

Expand type synonyms when Linting a forall

Trac #14939 showed a type like
   type Alg cls ob = ob
   f :: forall (cls :: * -> Constraint) (b :: Alg cls *). b

where the kind of the forall looks like (Alg cls *), with a
free cls. This tripped up Core Lint.

I fixed this by making Core Lint a bit more forgiving, expanding
type synonyms if necessary.

I'm worried that this might not be the whole story; notably
typeKind looks suspect.  But it certainly fixes this problem.

comment:4 Changed 7 weeks ago by simonpj

Richard, I'd be interested in what you think here, esp re typeKind.

comment:5 Changed 7 weeks ago by goldfire

I've commented on the commit on Phab. You're right that typeKind is wrong in this same way.

Note: See TracTickets for help on using tickets.