Implement the -XUnliftedNewtypes extension.
authorAndrew Martin <andrew.thaddeus@gmail.com>
Sun, 12 May 2019 13:23:25 +0000 (09:23 -0400)
committerMarge Bot <ben+marge-bot@smart-cactus.org>
Fri, 14 Jun 2019 14:48:13 +0000 (10:48 -0400)
commiteffdd948056923f3bc03688c24d7e0339d6272f5
tree02a3cb68ce1680db89c8440ba8beea808cbf4a11
parent3bc6df3223f62a8366e2e4267bac23aa08e6a939
Implement the -XUnliftedNewtypes extension.

GHC Proposal: 0013-unlifted-newtypes.rst
Discussion: https://github.com/ghc-proposals/ghc-proposals/pull/98
Issues: #15219, #1311, #13595, #15883
Implementation Details:
  Note [Implementation of UnliftedNewtypes]
  Note [Unifying data family kinds]
  Note [Compulsory newtype unfolding]

This patch introduces the -XUnliftedNewtypes extension. When this
extension is enabled, GHC drops the restriction that the field in
a newtype must be of kind (TYPE 'LiftedRep). This allows types
like Int# and ByteArray# to be used in a newtype. Additionally,
coerce is made levity-polymorphic so that it can be used with
newtypes over unlifted types.

The bulk of the changes are in TcTyClsDecls.hs. With -XUnliftedNewtypes,
getInitialKind is more liberal, introducing a unification variable to
return the kind (TYPE r0) rather than just returning (TYPE 'LiftedRep).
When kind-checking a data constructor with kcConDecl, we attempt to
unify the kind of a newtype with the kind of its field's type. When
typechecking a data declaration with tcTyClDecl, we again perform a
unification. See the implementation note for more on this.

Co-authored-by: Richard Eisenberg <rae@richarde.dev>
113 files changed:
compiler/basicTypes/Id.hs
compiler/basicTypes/MkId.hs
compiler/codeGen/StgCmmForeign.hs
compiler/deSugar/DsExpr.hs
compiler/hsSyn/HsTypes.hs
compiler/main/DynFlags.hs
compiler/main/TidyPgm.hs
compiler/prelude/TysPrim.hs
compiler/prelude/primops.txt.pp
compiler/rename/RnSource.hs
compiler/typecheck/TcErrors.hs
compiler/typecheck/TcEvidence.hs
compiler/typecheck/TcHsType.hs
compiler/typecheck/TcInstDcls.hs
compiler/typecheck/TcMType.hs
compiler/typecheck/TcSimplify.hs
compiler/typecheck/TcTyClsDecls.hs
compiler/typecheck/TcTypeable.hs
compiler/types/Coercion.hs
compiler/types/Type.hs
docs/users_guide/8.10.1-notes.rst
docs/users_guide/glasgow_exts.rst
libraries/base/Control/Category.hs
libraries/base/Data/Coerce.hs
libraries/base/Data/Type/Coercion.hs
libraries/base/GHC/Base.hs
libraries/base/changelog.md
libraries/ghc-boot-th/GHC/LanguageExtensions/Type.hs
libraries/ghc-prim/GHC/Types.hs
testsuite/tests/codeGen/should_fail/T13233.stderr
testsuite/tests/driver/T4437.hs
testsuite/tests/driver/recomp006/recomp006.stderr
testsuite/tests/ffi/should_run/UnliftedNewtypesByteArrayOffset.hs [new file with mode: 0644]
testsuite/tests/ffi/should_run/UnliftedNewtypesByteArrayOffset.stdout [new file with mode: 0644]
testsuite/tests/ffi/should_run/UnliftedNewtypesByteArrayOffset_c.c [new file with mode: 0644]
testsuite/tests/ffi/should_run/all.T
testsuite/tests/module/mod130.stderr
testsuite/tests/module/mod147.stderr
testsuite/tests/polykinds/T14561.stderr
testsuite/tests/rename/should_fail/T15607.stderr
testsuite/tests/safeHaskell/ghci/p4.stderr
testsuite/tests/safeHaskell/ghci/p6.stderr
testsuite/tests/typecheck/should_compile/UnlifNewUnify.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_compile/UnliftedNewtypesDifficultUnification.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_compile/UnliftedNewtypesForall.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_compile/UnliftedNewtypesGnd.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_compile/UnliftedNewtypesLPFamily.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_compile/UnliftedNewtypesUnassociatedFamily.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_compile/UnliftedNewtypesUnifySig.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_compile/VtaCoerce.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_compile/all.T
testsuite/tests/typecheck/should_compile/tc211.stderr
testsuite/tests/typecheck/should_compile/valid_hole_fits.stderr
testsuite/tests/typecheck/should_fail/T10971d.stderr
testsuite/tests/typecheck/should_fail/T12729.stderr
testsuite/tests/typecheck/should_fail/T13902.stderr
testsuite/tests/typecheck/should_fail/T15883.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T15883.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T15883b.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T15883b.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T15883c.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T15883c.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T15883d.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T15883d.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T15883e.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T15883e.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T8603.stderr
testsuite/tests/typecheck/should_fail/UnliftedNewtypesCoerceFail.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesCoerceFail.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesConstraintFamily.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesConstraintFamily.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesFail.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesFail.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesFamilyKindFail1.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesFamilyKindFail1.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesFamilyKindFail2.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesFamilyKindFail2.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesInfinite.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesInfinite.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesInstanceFail.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesInstanceFail.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesLevityBinder.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesLevityBinder.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesMismatchedKind.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesMismatchedKind.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesMismatchedKindRecord.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesMismatchedKindRecord.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesMultiFieldGadt.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesMultiFieldGadt.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesNotEnabled.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesNotEnabled.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesOverlap.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/UnliftedNewtypesOverlap.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/all.T
testsuite/tests/typecheck/should_fail/mc24.stderr
testsuite/tests/typecheck/should_fail/tcfail004.stderr
testsuite/tests/typecheck/should_fail/tcfail005.stderr
testsuite/tests/typecheck/should_fail/tcfail079.stderr
testsuite/tests/typecheck/should_fail/tcfail140.stderr
testsuite/tests/typecheck/should_fail/tcfail159.stderr
testsuite/tests/typecheck/should_fail/tcfail189.stderr
testsuite/tests/typecheck/should_fail/tcfail206.stderr
testsuite/tests/typecheck/should_run/UnliftedNewtypesCoerceRun.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_run/UnliftedNewtypesCoerceRun.stdout [new file with mode: 0644]
testsuite/tests/typecheck/should_run/UnliftedNewtypesDependentFamilyRun.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_run/UnliftedNewtypesDependentFamilyRun.stdout [new file with mode: 0644]
testsuite/tests/typecheck/should_run/UnliftedNewtypesFamilyRun.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_run/UnliftedNewtypesFamilyRun.stdout [new file with mode: 0644]
testsuite/tests/typecheck/should_run/UnliftedNewtypesIdentityRun.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_run/UnliftedNewtypesIdentityRun.stdout [new file with mode: 0644]
testsuite/tests/typecheck/should_run/UnliftedNewtypesRun.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_run/UnliftedNewtypesRun.stdout [new file with mode: 0644]
testsuite/tests/typecheck/should_run/all.T