[Git][ghc/ghc][master] Typeable: Fix module locations of some definitions in GHC.Types

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Fri Dec 9 03:48:18 UTC 2022



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
1d3a8b8e by Matthew Pickering at 2022-12-08T22:47:59-05:00
Typeable: Fix module locations of some definitions in GHC.Types

There was some confusion in Data.Typeable about which module certain
wired-in things were defined in. Just because something is wired-in
doesn't mean it comes from GHC.Prim, in particular things like LiftedRep
and RuntimeRep are defined in GHC.Types and that's the end of the story.

Things like Int#, Float# etc are defined in GHC.Prim as they have no
Haskell definition site at all so we need to generate type
representations for them (which live in GHC.Types).

Fixes #22510

- - - - -


4 changed files:

- compiler/GHC/Tc/Instance/Typeable.hs
- + testsuite/tests/typecheck/should_run/T22510.hs
- + testsuite/tests/typecheck/should_run/T22510.stdout
- testsuite/tests/typecheck/should_run/all.T


Changes:

=====================================
compiler/GHC/Tc/Instance/Typeable.hs
=====================================
@@ -172,7 +172,7 @@ mkTypeableBinds
        } } }
   where
     needs_typeable_binds tc
-      | tc `elem` [runtimeRepTyCon, levityTyCon, vecCountTyCon, vecElemTyCon]
+      | tc `elem` ghcTypesTypeableTyCons
       = False
       | otherwise =
           isAlgTyCon tc
@@ -335,7 +335,14 @@ mkPrimTypeableTodos
                    ; todo2 <- todoForTyCons gHC_PRIM ghc_prim_module_id
                                             ghcPrimTypeableTyCons
 
-                   ; return ( gbl_env' , [todo1, todo2])
+                   ; tcg_env <- getGblEnv
+                   ; let mod_id = case tcg_tr_module tcg_env of  -- Should be set by now
+                                   Just mod_id -> mod_id
+                                   Nothing     -> pprPanic "tcMkTypeableBinds" empty
+
+                   ; todo3 <- todoForTyCons gHC_TYPES mod_id ghcTypesTypeableTyCons
+
+                   ; return ( gbl_env' , [todo1, todo2, todo3])
                    }
            else do gbl_env <- getGblEnv
                    return (gbl_env, [])
@@ -350,12 +357,18 @@ mkPrimTypeableTodos
 -- Note [Built-in syntax and the OrigNameCache] in "GHC.Iface.Env" for more.
 ghcPrimTypeableTyCons :: [TyCon]
 ghcPrimTypeableTyCons = concat
-    [ [ runtimeRepTyCon, levityTyCon, vecCountTyCon, vecElemTyCon ]
-    , map (tupleTyCon Unboxed) [0..mAX_TUPLE_SIZE]
+    [ map (tupleTyCon Unboxed) [0..mAX_TUPLE_SIZE]
     , map sumTyCon [2..mAX_SUM_SIZE]
     , primTyCons
     ]
 
+-- | These are types which are defined in GHC.Types but are needed in order to
+-- typecheck the other generated bindings, therefore to avoid ordering issues we
+-- generate them up-front along with the bindings from GHC.Prim.
+ghcTypesTypeableTyCons :: [TyCon]
+ghcTypesTypeableTyCons = [ runtimeRepTyCon, levityTyCon
+                         , vecCountTyCon, vecElemTyCon ]
+
 data TypeableStuff
     = Stuff { platform       :: Platform        -- ^ Target platform
             , trTyConDataCon :: DataCon         -- ^ of @TyCon@


=====================================
testsuite/tests/typecheck/should_run/T22510.hs
=====================================
@@ -0,0 +1,36 @@
+{-# LANGUAGE MagicHash, UnboxedTuples, UnboxedSums, ScopedTypeVariables, TypeApplications, AllowAmbiguousTypes #-}
+module Main where
+
+import Type.Reflection
+import Data.Proxy
+import GHC.Types
+import GHC.Prim
+
+moduleOf :: forall a . Typeable a => String
+moduleOf = case someTypeRep (Proxy @a) of
+              SomeTypeRep tr -> (show tr ++ ": " ++ (tyConModule $ typeRepTyCon tr))
+
+main = do
+  -- These are in GHC.Types
+  putStrLn $ moduleOf @Levity
+  putStrLn $ moduleOf @'Lifted
+  putStrLn $ moduleOf @RuntimeRep
+  putStrLn $ moduleOf @'IntRep
+  putStrLn $ moduleOf @'BoxedRep
+  putStrLn $ moduleOf @'Lifted
+  putStrLn $ moduleOf @VecCount
+  putStrLn $ moduleOf @'Vec2
+  putStrLn $ moduleOf @VecElem
+  putStrLn $ moduleOf @'Int8ElemRep
+
+  -- This is from GHC.Tuple
+  putStrLn $ moduleOf @((),())
+
+  -- These are in GHC.Prim
+  putStrLn $ moduleOf @(# () , () #)
+--  putStrLn $ moduleOf @(# () | () #)
+--
+  putStrLn $ moduleOf @(Int64#)
+  putStrLn $ moduleOf @(Word64#)
+  putStrLn $ moduleOf @TYPE
+  putStrLn $ moduleOf @CONSTRAINT


=====================================
testsuite/tests/typecheck/should_run/T22510.stdout
=====================================
@@ -0,0 +1,16 @@
+Levity: GHC.Types
+'Lifted: GHC.Types
+RuntimeRep: GHC.Types
+'IntRep: GHC.Types
+'BoxedRep: GHC.Types
+'Lifted: GHC.Types
+VecCount: GHC.Types
+'Vec2: GHC.Types
+VecElem: GHC.Types
+'Int8ElemRep: GHC.Types
+((),()): GHC.Tuple.Prim
+(#,#) ('BoxedRep 'Lifted) ('BoxedRep 'Lifted) () (): GHC.Prim
+Int64#: GHC.Prim
+Word64#: GHC.Prim
+TYPE: GHC.Prim
+CONSTRAINT: GHC.Prim


=====================================
testsuite/tests/typecheck/should_run/all.T
=====================================
@@ -163,3 +163,4 @@ test('T19397M3', extra_files(['T19397S.hs']), compile_and_run, ['-main-is foo'])
 test('T19397M4', extra_files(['T19397S.hs']), compile_and_run, ['-main-is foo'])
 test('T19667', normal, compile_and_run, ['-fhpc'])
 test('T20768', normal, compile_and_run, [''])
+test('T22510', normal, compile_and_run, [''])



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1d3a8b8ec98e6eedf8943e19780ec374c2491e7f

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1d3a8b8ec98e6eedf8943e19780ec374c2491e7f
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/20221208/4e75d023/attachment-0001.html>


More information about the ghc-commits mailing list