[Git][ghc/ghc][wip/sand-witch/mksolo-hash] Rename Solo# data constructor to MkSolo# (T24673)

Andrei Borzenkov (@sand-witch) gitlab at gitlab.haskell.org
Fri Apr 26 08:50:50 UTC 2024



Andrei Borzenkov pushed to branch wip/sand-witch/mksolo-hash at Glasgow Haskell Compiler / GHC


Commits:
01125364 by Andrei Borzenkov at 2024-04-26T12:50:27+04:00
Rename Solo# data constructor to MkSolo# (T24673)

- data Solo# a = (# a #)
+ data Solo# a = MkSolo# a

And `(# foo #)` syntax now becomes just a syntactic
sugar for `MkSolo# a`.

- - - - -


11 changed files:

- compiler/GHC/Builtin/Types.hs
- libraries/ghc-boot/GHC/Utils/Encoding.hs
- libraries/ghc-experimental/src/Data/Tuple/Experimental.hs
- libraries/ghc-prim/GHC/Types.hs
- libraries/template-haskell/Language/Haskell/TH/Syntax.hs
- testsuite/tests/interface-stability/ghc-experimental-exports.stdout
- + testsuite/tests/rename/should_fail/T24673.hs
- + testsuite/tests/rename/should_fail/T24673.stderr
- testsuite/tests/rename/should_fail/all.T
- testsuite/tests/simplStg/should_compile/T15226b.stderr
- testsuite/tests/th/TH_tuple1.stdout


Changes:

=====================================
compiler/GHC/Builtin/Types.hs
=====================================
@@ -1015,7 +1015,7 @@ mkUnboxedTupleStr ns 0
   | isDataConNameSpace ns = "(##)"
   | otherwise             = "Unit#"
 mkUnboxedTupleStr ns 1
-  | isDataConNameSpace ns = "(# #)"  -- See Note [One-tuples]
+  | isDataConNameSpace ns = "MkSolo#"  -- See Note [One-tuples]
   | otherwise             = "Solo#"
 mkUnboxedTupleStr ns ar
   | isDataConNameSpace ns = "(#" ++ commas ar ++ "#)"


=====================================
libraries/ghc-boot/GHC/Utils/Encoding.hs
=====================================
@@ -79,7 +79,7 @@ The basic encoding scheme is this.
         :+              ZCzp
         ()              Z0T     0-tuple
         (,,,,)          Z5T     5-tuple
-        (# #)           Z1H     unboxed 1-tuple (note the space)
+        (##)            Z0H     unboxed 0-tuple
         (#,,,,#)        Z5H     unboxed 5-tuple
 -}
 
@@ -212,7 +212,6 @@ decode_tuple d rest
     go n (c : rest) | isDigit c = go (10*n + digitToInt c) rest
     go 0 ('T':rest)     = "()" ++ zDecodeString rest
     go n ('T':rest)     = '(' : replicate (n-1) ',' ++ ")" ++ zDecodeString rest
-    go 1 ('H':rest)     = "(# #)" ++ zDecodeString rest
     go n ('H':rest)     = '(' : '#' : replicate (n-1) ',' ++ "#)" ++ zDecodeString rest
     go n other = error ("decode_tuple: " ++ show n ++ ' ':other)
 
@@ -223,15 +222,13 @@ for 3-tuples or unboxed 3-tuples respectively.  No other encoding starts
         Z<digit>
 
 * "(##)" is the tycon for an unboxed 0-tuple
-* "(# #)" is the tycon for an unboxed 1-tuple
 
-* "()" is the tycon for a boxed 0-tuple.
+* "()" is the tycon for a boxed 0-tuple
 -}
 
 maybe_tuple :: UserString -> Maybe EncodedString
 
 maybe_tuple "(##)" = Just("Z0H")
-maybe_tuple "(# #)" = Just("Z1H")
 maybe_tuple ('(' : '#' : cs) = case count_commas (0::Int) cs of
                                  (n, '#' : ')' : _) -> Just ('Z' : shows (n+1) "H")
                                  _                  -> Nothing


=====================================
libraries/ghc-experimental/src/Data/Tuple/Experimental.hs
=====================================
@@ -21,7 +21,7 @@ module Data.Tuple.Experimental (
 
   -- * Unboxed tuples
   Unit#,
-  Solo#,
+  Solo#(..),
   Tuple0#,
   Tuple1#,
   Tuple2#,


=====================================
libraries/ghc-prim/GHC/Types.hs
=====================================
@@ -65,7 +65,7 @@ module GHC.Types (
 
         -- * Unboxed tuples
         Unit#,
-        Solo#,
+        Solo#(..),
         Tuple0#,
         Tuple1#,
         Tuple2#,
@@ -889,7 +889,7 @@ type Unit# :: TYPE (TupleRep '[])
 data Unit# = (# #)
 
 type Solo# :: TYPE rep -> TYPE (TupleRep '[rep])
-data Solo# a = (# a #)
+data Solo# a = MkSolo# a
 
 type Tuple0# = Unit#
 type Tuple1# = Solo#


=====================================
libraries/template-haskell/Language/Haskell/TH/Syntax.hs
=====================================
@@ -1938,10 +1938,7 @@ mk_tup_name n space boxed
     solo
       | space == DataName = "MkSolo"
       | otherwise = "Solo"
-
-    unboxed_solo
-      | space == DataName = "(# #)"
-      | otherwise = "Solo#"
+    unboxed_solo = solo ++ "#"
 
 -- Unboxed sum data and type constructors
 -- | Unboxed sum data constructor


=====================================
testsuite/tests/interface-stability/ghc-experimental-exports.stdout
=====================================
@@ -2633,7 +2633,7 @@ module Data.Tuple.Experimental where
   type Solo :: * -> *
   data Solo a = MkSolo a
   type Solo# :: forall (k :: GHC.Types.RuntimeRep). TYPE k -> TYPE (GHC.Types.TupleRep '[k])
-  data Solo# a = ...
+  data Solo# a = MkSolo# a
   type Tuple0 :: *
   type Tuple0 = ()
   type Tuple0# :: GHC.Types.ZeroBitType


=====================================
testsuite/tests/rename/should_fail/T24673.hs
=====================================
@@ -0,0 +1,8 @@
+{-# LANGUAGE UnboxedTuples, MagicHash, NoListTuplePuns #-}
+
+module T24673 where
+
+import Data.Tuple.Experimental
+
+
+f = (# 42 #) + MkSolo# 42


=====================================
testsuite/tests/rename/should_fail/T24673.stderr
=====================================
@@ -0,0 +1,20 @@
+
+T24673.hs:8:5: error: [GHC-18872]
+    • Couldn't match a lifted type with an unlifted type
+      When matching types
+        a :: *
+        (# a0 #) :: TYPE (GHC.Types.TupleRep [GHC.Types.LiftedRep])
+    • In the first argument of ‘(+)’, namely ‘(# 42 #)’
+      In the expression: (# 42 #) + MkSolo# 42
+      In an equation for ‘f’: f = (# 42 #) + MkSolo# 42
+    • Relevant bindings include f :: a (bound at T24673.hs:8:1)
+
+T24673.hs:8:16: error: [GHC-18872]
+    • Couldn't match a lifted type with an unlifted type
+      When matching types
+        a :: *
+        (# a1 #) :: TYPE (GHC.Types.TupleRep [GHC.Types.LiftedRep])
+    • In the second argument of ‘(+)’, namely ‘MkSolo# 42’
+      In the expression: (# 42 #) + MkSolo# 42
+      In an equation for ‘f’: f = (# 42 #) + MkSolo# 42
+    • Relevant bindings include f :: a (bound at T24673.hs:8:1)


=====================================
testsuite/tests/rename/should_fail/all.T
=====================================
@@ -227,3 +227,4 @@ test('T23570b', [extra_files(['T23570_aux.hs'])], multimod_compile, ['T23570b',
 test('T17594b', req_th, compile_fail, [''])
 test('T14032c', normal, compile_fail, [''])
 test('T14032f', normal, compile_fail, [''])
+test('T24673', normal, compile_fail, [''])


=====================================
testsuite/tests/simplStg/should_compile/T15226b.stderr
=====================================
@@ -20,7 +20,7 @@ T15226b.bar1
           sat [Occ=Once1] :: T15226b.Str (GHC.Internal.Maybe.Maybe a)
           [LclId] =
               T15226b.Str! [sat];
-        } in  (# #) [sat];
+        } in  MkSolo# [sat];
         };
 
 T15226b.bar


=====================================
testsuite/tests/th/TH_tuple1.stdout
=====================================
@@ -6,5 +6,5 @@ GHC.Tuple.MkSolo 1 :: GHC.Tuple.Solo GHC.Num.Integer.Integer
 SigE (AppE (AppE (ConE GHC.Types.(#,#)) (LitE (IntegerL 1))) (LitE (IntegerL 2))) (AppT (AppT (ConT GHC.Types.Tuple2#) (ConT GHC.Num.Integer.Integer)) (ConT GHC.Num.Integer.Integer))
 GHC.Types.(#,#) 1 2 :: GHC.Types.Tuple2# GHC.Num.Integer.Integer
                                          GHC.Num.Integer.Integer
-SigE (AppE (ConE GHC.Types.(# #)) (LitE (IntegerL 1))) (AppT (ConT GHC.Types.Solo#) (ConT GHC.Num.Integer.Integer))
-GHC.Types.(# #) 1 :: GHC.Types.Solo# GHC.Num.Integer.Integer
+SigE (AppE (ConE GHC.Types.MkSolo#) (LitE (IntegerL 1))) (AppT (ConT GHC.Types.Solo#) (ConT GHC.Num.Integer.Integer))
+GHC.Types.MkSolo# 1 :: GHC.Types.Solo# GHC.Num.Integer.Integer



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/01125364a631f5db613f1bfc5e2b23544c79b636

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/01125364a631f5db613f1bfc5e2b23544c79b636
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240426/b894eb0b/attachment-0001.html>


More information about the ghc-commits mailing list