Implement unboxed sum primitive type
authorÖmer Sinan Ağacan <omeragacan@gmail.com>
Thu, 21 Jul 2016 08:07:41 +0000 (08:07 +0000)
committerÖmer Sinan Ağacan <omeragacan@gmail.com>
Thu, 21 Jul 2016 08:11:27 +0000 (08:11 +0000)
commit714bebff44076061d0a719c4eda2cfd213b7ac3d
treeb697e786a8f5f25e8a47886bc5d5487c01678ec6
parent83e4f49577665278fe08fbaafe2239553f3c448e
Implement unboxed sum primitive type

Summary:
This patch implements primitive unboxed sum types, as described in
https://ghc.haskell.org/trac/ghc/wiki/UnpackedSumTypes.

Main changes are:

- Add new syntax for unboxed sums types, terms and patterns. Hidden
  behind `-XUnboxedSums`.

- Add unlifted unboxed sum type constructors and data constructors,
  extend type and pattern checkers and desugarer.

- Add new RuntimeRep for unboxed sums.

- Extend unarise pass to translate unboxed sums to unboxed tuples right
  before code generation.

- Add `StgRubbishArg` to `StgArg`, and a new type `CmmArg` for better
  code generation when sum values are involved.

- Add user manual section for unboxed sums.

Some other changes:

- Generalize `UbxTupleRep` to `MultiRep` and `UbxTupAlt` to
  `MultiValAlt` to be able to use those with both sums and tuples.

- Don't use `tyConPrimRep` in `isVoidTy`: `tyConPrimRep` is really
  wrong, given an `Any` `TyCon`, there's no way to tell what its kind
  is, but `kindPrimRep` and in turn `tyConPrimRep` returns `PtrRep`.

- Fix some bugs on the way: #12375.

Not included in this patch:

- Update Haddock for new the new unboxed sum syntax.

- `TemplateHaskell` support is left as future work.

For reviewers:

- Front-end code is mostly trivial and adapted from unboxed tuple code
  for type checking, pattern checking, renaming, desugaring etc.

- Main translation routines are in `RepType` and `UnariseStg`.
  Documentation in `UnariseStg` should be enough for understanding
  what's going on.

Credits:

- Johan Tibell wrote the initial front-end and interface file
  extensions.

- Simon Peyton Jones reviewed this patch many times, wrote some code,
  and helped with debugging.

Reviewers: bgamari, alanz, goldfire, RyanGlScott, simonpj, austin,
           simonmar, hvr, erikd

Reviewed By: simonpj

Subscribers: Iceland_jack, ggreif, ezyang, RyanGlScott, goldfire,
             thomie, mpickering

Differential Revision: https://phabricator.haskell.org/D2259
128 files changed:
compiler/basicTypes/BasicTypes.hs
compiler/basicTypes/DataCon.hs
compiler/basicTypes/Id.hs
compiler/basicTypes/IdInfo.hs
compiler/basicTypes/Unique.hs
compiler/cmm/CLabel.hs
compiler/cmm/CmmExpr.hs
compiler/cmm/CmmLayoutStack.hs
compiler/cmm/CmmLive.hs
compiler/cmm/CmmParse.y
compiler/cmm/CmmUtils.hs
compiler/cmm/MkGraph.hs
compiler/cmm/PprCmmExpr.hs
compiler/codeGen/StgCmm.hs
compiler/codeGen/StgCmmBind.hs
compiler/codeGen/StgCmmClosure.hs
compiler/codeGen/StgCmmCon.hs
compiler/codeGen/StgCmmEnv.hs
compiler/codeGen/StgCmmExpr.hs
compiler/codeGen/StgCmmForeign.hs
compiler/codeGen/StgCmmHeap.hs
compiler/codeGen/StgCmmLayout.hs
compiler/codeGen/StgCmmMonad.hs
compiler/codeGen/StgCmmPrim.hs
compiler/codeGen/StgCmmUtils.hs
compiler/coreSyn/CoreArity.hs
compiler/coreSyn/CoreLint.hs
compiler/deSugar/Check.hs
compiler/deSugar/Coverage.hs
compiler/deSugar/DsArrows.hs
compiler/deSugar/DsExpr.hs
compiler/deSugar/DsForeign.hs
compiler/deSugar/Match.hs
compiler/ghc.cabal.in
compiler/ghc.mk
compiler/ghci/ByteCodeGen.hs
compiler/ghci/ByteCodeItbls.hs
compiler/ghci/RtClosureInspect.hs
compiler/hsSyn/HsExpr.hs
compiler/hsSyn/HsPat.hs
compiler/hsSyn/HsTypes.hs
compiler/hsSyn/HsUtils.hs
compiler/iface/BinIface.hs
compiler/iface/MkIface.hs
compiler/main/Constants.hs
compiler/main/DynFlags.hs
compiler/main/InteractiveEval.hs
compiler/parser/Lexer.x
compiler/parser/Parser.y
compiler/parser/RdrHsSyn.hs
compiler/prelude/PrelNames.hs
compiler/prelude/PrimOp.hs
compiler/prelude/TysWiredIn.hs
compiler/prelude/TysWiredIn.hs-boot
compiler/profiling/SCCfinal.hs
compiler/rename/RnExpr.hs
compiler/rename/RnPat.hs
compiler/rename/RnTypes.hs
compiler/simplStg/RepType.hs [new file with mode: 0644]
compiler/simplStg/SimplStg.hs
compiler/simplStg/StgStats.hs
compiler/simplStg/UnariseStg.hs
compiler/stgSyn/CoreToStg.hs
compiler/stgSyn/StgLint.hs
compiler/stgSyn/StgSyn.hs
compiler/stranal/WwLib.hs
compiler/typecheck/TcExpr.hs
compiler/typecheck/TcHsSyn.hs
compiler/typecheck/TcHsType.hs
compiler/typecheck/TcPat.hs
compiler/typecheck/TcPatSyn.hs
compiler/typecheck/TcRnTypes.hs
compiler/typecheck/TcType.hs
compiler/types/TyCoRep.hs
compiler/types/TyCon.hs
compiler/types/Type.hs
compiler/types/Type.hs-boot
compiler/utils/Outputable.hs
compiler/vectorise/Vectorise/Builtins/Base.hs
compiler/vectorise/Vectorise/Type/TyConDecl.hs
docs/users_guide/glasgow_exts.rst
includes/stg/MiscClosures.h
libraries/ghc-boot-th/GHC/LanguageExtensions/Type.hs
libraries/ghc-prim/GHC/Types.hs
rts/StgMiscClosures.cmm
testsuite/tests/driver/T4437.hs
testsuite/tests/unboxedsums/Makefile [new file with mode: 0644]
testsuite/tests/unboxedsums/T12375.hs [new file with mode: 0644]
testsuite/tests/unboxedsums/T12375.stdout [new file with mode: 0644]
testsuite/tests/unboxedsums/all.T [new file with mode: 0644]
testsuite/tests/unboxedsums/empty_sum.hs [new file with mode: 0644]
testsuite/tests/unboxedsums/empty_sum.stdout [new file with mode: 0644]
testsuite/tests/unboxedsums/ffi1.hs [new file with mode: 0644]
testsuite/tests/unboxedsums/ffi1.stderr [new file with mode: 0644]
testsuite/tests/unboxedsums/module/Lib.hs [new file with mode: 0644]
testsuite/tests/unboxedsums/module/Main.hs [new file with mode: 0644]
testsuite/tests/unboxedsums/module/Makefile [new file with mode: 0644]
testsuite/tests/unboxedsums/module/all.T [new file with mode: 0644]
testsuite/tests/unboxedsums/module/sum_mod.stdout [new file with mode: 0644]
testsuite/tests/unboxedsums/sum_rr.hs [new file with mode: 0644]
testsuite/tests/unboxedsums/sum_rr.stderr [new file with mode: 0644]
testsuite/tests/unboxedsums/thunk.hs [new file with mode: 0644]
testsuite/tests/unboxedsums/thunk.stdout [new file with mode: 0644]
testsuite/tests/unboxedsums/unarise.hs [new file with mode: 0644]
testsuite/tests/unboxedsums/unarise.stdout [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums1.hs [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums1.stdout [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums10.hs [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums10.stdout [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums11.hs [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums11.stdout [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums2.hs [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums2.stdin [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums2.stdout [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums3.hs [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums3.stdout [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums4.hs [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums4.stderr [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums5.hs [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums6.hs [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums6.stdout [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums7.hs [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums7.stdout [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums8.hs [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums8.stdout [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums9.hs [new file with mode: 0644]
testsuite/tests/unboxedsums/unboxedsums9.stdout [new file with mode: 0644]
utils/mkUserGuidePart/Options/Language.hs