Changes between Initial Version and Version 2 of Ticket #5426


Ignore:
Timestamp:
Nov 9, 2011 10:26:10 PM (4 years ago)
Author:
simonpj
Comment:

This is indeed terrible. It arises becaues the comment in Type.typePrimRep doesn't hold:

	-- Types of the form 'f a' must be of kind *, not *#, so
	-- we are guaranteed that they are represented by pointers.
	-- The reason is that f must have kind *->*, not *->*#, because
	-- (we claim) there is no way to constrain f's kind any other
	-- way.

The reason it can go wrong is because used to admit kinds like * -> !; and even used to parse them!

No more. In the upcoming PolyKinds stuff, we've simplified kinds a bit so there are never any of those nasty ! or # things under an arrow. (Except in the kinds of some primitive type constructors like State# or MutVar#, and we insist that they are always saturated.) In short, we can't abstract over kinds involving the wierd constants !, #, and that's what you were doing here.

I'll assign this to Pedro to close after doing these things:

  • Remove the "!" case from the parser for kinds. Was
    akind   :: { Located Kind }
            : '*'                   { L1 liftedTypeKind }
            | '!'                   { L1 unliftedTypeKind }
            | CONID                 {% checkKindName (L1 (getCONID $1)) }
            | '(' kind ')'          { LL (unLoc $2) }
    
    It's probably different now anyway.
  • When kind-checking types, make sure that in a TyConApp, a tycon returning an unliftedKind is always saturated. All these tycons are WiredIn so it should be a cheap and easy test.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #5426

    • Property Priority changed from normal to high
    • Property Milestone changed from to 7.6.1
  • Ticket #5426 – Description

    initial v2  
    2626It can easily be modified to provoke a segfault instead.
    2727
    28 The problem here is that when generating the code for foo, Type.typePrimRep assumes that any TyApp has Ptr representation and so expects that argument to be a word wide.
     28The problem here is that when generating the code for foo, `Type.typePrimRep` assumes that any `TyApp` has `Ptr` representation and so expects that argument to be a word wide.
    2929
    30 Unfortunately, the State# TyCon has kind (* -> #) and is represented by VoidRep, so we can make the call site of foo believe that the argument to foo is of width 0... havoc ensues.
     30Unfortunately, the `State# TyCon` has kind `(* -> #)` and is represented by `VoidRep`, so we can make the call site of foo believe that the argument to foo is of width 0... havoc ensues.
    3131
    32 One way to fix this is to encode representation in the kind hierarchy, so we have WordRep, IntRep, VoidRep all subkinds of #. Then we can know the representation of types without relying on deconstructing them.
     32One way to fix this is to encode representation in the kind hierarchy, so we have `WordRep`, `IntRep`, `VoidRep` all subkinds of #. Then we can know the representation of types without relying on deconstructing them.