[commit: ghc] wip/names3: Unique: Simplify encoding of sum uniques (4fcff2d)
git at git.haskell.org
git at git.haskell.org
Thu Oct 13 22:34:31 UTC 2016
Repository : ssh://git@git.haskell.org/ghc
On branch : wip/names3
Link : http://ghc.haskell.org/trac/ghc/changeset/4fcff2db4b39b44a61c5dde3876c3c490221c1c9/ghc
>---------------------------------------------------------------
commit 4fcff2db4b39b44a61c5dde3876c3c490221c1c9
Author: Ben Gamari <ben at smart-cactus.org>
Date: Sat Aug 20 12:50:49 2016 -0400
Unique: Simplify encoding of sum uniques
The previous encoding was entropically a bit better, but harder to
encode and decode. Now we just split up the integer part of the unique
into a bitfield.
>---------------------------------------------------------------
4fcff2db4b39b44a61c5dde3876c3c490221c1c9
compiler/basicTypes/Unique.hs | 27 +++++++++++----------------
1 file changed, 11 insertions(+), 16 deletions(-)
diff --git a/compiler/basicTypes/Unique.hs b/compiler/basicTypes/Unique.hs
index c933d61..6db4d8a 100644
--- a/compiler/basicTypes/Unique.hs
+++ b/compiler/basicTypes/Unique.hs
@@ -370,31 +370,26 @@ mkTupleDataConUnique Boxed a = mkUnique '7' (3*a) -- ditto (*may* be
mkTupleDataConUnique Unboxed a = mkUnique '8' (3*a)
--------------------------------------------------
--- Sum arities start from 2. A sum of arity N has N data constructors, so it
--- occupies N+1 slots: 1 TyCon + N DataCons.
+-- Sum arities start from 2. The encoding is a bit funny: we break up the
+-- integral part into bitfields for the arity and alternative index (which is
+-- taken to be 0xff in the case of the TyCon)
--
--- So arity 2 sum takes uniques 0 (tycon), 1, 2 (2 data cons)
--- arity 3 sum takes uniques 3 (tycon), 4, 5, 6 (3 data cons)
--- etc.
+-- TyCon for sum of arity k:
+-- 00000000 kkkkkkkk 11111111
+-- DataCon for sum of arity k and alternative n:
+-- 00000000 kkkkkkkk nnnnnnnn
mkSumTyConUnique :: Arity -> Unique
-mkSumTyConUnique arity = mkUnique 'z' (sumUniqsOccupied arity)
+mkSumTyConUnique arity =
+ ASSERT(arity < 0xff)
+ mkUnique 'z' (arity `shiftL` 8 .|. 0xff)
mkSumDataConUnique :: ConTagZ -> Arity -> Unique
mkSumDataConUnique alt arity
| alt >= arity
= panic ("mkSumDataConUnique: " ++ show alt ++ " >= " ++ show arity)
| otherwise
- = mkUnique 'z' (sumUniqsOccupied arity + alt + 1 {- skip the tycon -})
-
--- How many unique slots occupied by sum types (including constructors) up to
--- the given arity?
-sumUniqsOccupied :: Arity -> Int
-sumUniqsOccupied arity
- = ASSERT(arity >= 2)
- -- 3 + 4 + ... + arity
- ((arity * (arity + 1)) `div` 2) - 3
-{-# INLINE sumUniqsOccupied #-}
+ = mkUnique 'z' (arity `shiftL` 8 + alt) {- skip the tycon -}
--------------------------------------------------
dataConRepNameUnique, dataConWorkerUnique :: Unique -> Unique
More information about the ghc-commits
mailing list