Skip to content

WIP: unboxed classes

sheaf requested to merge sheaf/ghc:unlifted-classes into master

In this MR I'm currently experimenting with the following:

  1. For newtype-like classes, allow the class field to be representation-polymorphic, mirrorring -XUnliftedNewtypes.

    • This enables unboxed implicit parameters.

    • This allows users to introduce classes whose return kind is CONSTRAINT r, for an r which is different from LiftedRep.

  2. For datacon-like classes:

    a. Allow the return kind of the class to be CONSTRAINT UnliftedRep, as with -XUnliftedDataTypes.

    b. Allow unlifted/unboxed methods.

(1) seems rather straightforward and doesn't seem to be causing undue trouble to GHC. I think this is a rather compelling application of representation-polymorphic newtypes.
(2a) runs into trouble with instances, as the class instance dictionary is now an unlifted type (if the instance has no context), and we can't have top-level unlifted bindings.
(2b) runs into trouble when defining the class itself, because GHC generates unlifted top-level Ids for its unlifted class methods (also putting them in the compulsory unfolding of the instance DFunId). I think it should be possible to make these local bindings in a let clause, but the compulsory unfolding of the DFunId complicates things somewhat.

Edited by sheaf

Merge request reports