From 714bebff44076061d0a719c4eda2cfd213b7ac3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Thu, 21 Jul 2016 08:07:41 +0000 Subject: 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 --- testsuite/tests/unboxedsums/unboxedsums9.hs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 testsuite/tests/unboxedsums/unboxedsums9.hs (limited to 'testsuite/tests/unboxedsums/unboxedsums9.hs') diff --git a/testsuite/tests/unboxedsums/unboxedsums9.hs b/testsuite/tests/unboxedsums/unboxedsums9.hs new file mode 100644 index 0000000000..79927fc58b --- /dev/null +++ b/testsuite/tests/unboxedsums/unboxedsums9.hs @@ -0,0 +1,26 @@ +{-# LANGUAGE UnboxedSums, UnboxedTuples, MagicHash #-} + +module Main where + +type UbxBool = (# (# #) | (# #) #) + +{-# NOINLINE packBool #-} +packBool :: UbxBool -> Bool +packBool (# _ | #) = True +packBool (# | _ #) = False + +{-# NOINLINE unpackBool #-} +unpackBool :: Bool -> UbxBool +unpackBool True = (# (# #) | #) +unpackBool False = (# | (# #) #) + +{-# NOINLINE showUbxBool #-} +showUbxBool :: UbxBool -> String +showUbxBool b = show (packBool b) + +main :: IO () +main = do + putStrLn (showUbxBool (unpackBool True)) + putStrLn (showUbxBool (unpackBool False)) + putStrLn (show (packBool (# (# #) | #))) + putStrLn (show (packBool (# | (# #) #))) -- cgit v1.2.1