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

Commits:

4 changed files:

Changes:

  • compiler/GHC/Driver/Main.hs
    ... ... @@ -2548,9 +2548,9 @@ hscAddSptEntries :: HscEnv -> [SptEntry] -> IO ()
    2548 2548
     hscAddSptEntries hsc_env entries = do
    
    2549 2549
         let interp = hscInterp hsc_env
    
    2550 2550
         let add_spt_entry :: SptEntry -> IO ()
    
    2551
    -        add_spt_entry (SptEntry i fpr) = do
    
    2551
    +        add_spt_entry (SptEntry n fpr) = do
    
    2552 2552
                 -- These are only names from the current module
    
    2553
    -            (val, _, _) <- loadName interp hsc_env (idName i)
    
    2553
    +            (val, _, _) <- loadName interp hsc_env n
    
    2554 2554
                 addSptEntry interp fpr val
    
    2555 2555
         mapM_ add_spt_entry entries
    
    2556 2556
     
    

  • compiler/GHC/Iface/Tidy/StaticPtrTable.hs
    ... ... @@ -144,6 +144,7 @@ import GHC.Utils.Outputable as Outputable
    144 144
     import GHC.Linker.Types
    
    145 145
     
    
    146 146
     import GHC.Types.Id
    
    147
    +import GHC.Types.Id.Info ( CafInfo(..) )
    
    147 148
     import GHC.Types.ForeignStubs
    
    148 149
     import GHC.Data.Maybe
    
    149 150
     import GHC.Data.FastString
    
    ... ... @@ -205,7 +206,7 @@ sptCreateStaticBinds opts this_mod binds = do
    205 206
             Nothing      -> return (Nothing, (b, e))
    
    206 207
             Just (_, t, info, arg) -> do
    
    207 208
               (fp, e') <- mkStaticBind t info arg
    
    208
    -          return (Just (SptEntry b fp), (b, foldr Lam e' tvs))
    
    209
    +          return (Just (SptEntry (idName b) fp), (b, foldr Lam e' tvs))
    
    209 210
     
    
    210 211
         mkStaticBind :: Type -> CoreExpr -> CoreExpr
    
    211 212
                      -> StateT Int IO (Fingerprint, CoreExpr)
    
    ... ... @@ -256,12 +257,18 @@ sptModuleInitCode platform this_mod entries
    256 257
         init_fn_body = vcat
    
    257 258
             [  text "static StgWord64 k" <> int i <> text "[2] = "
    
    258 259
                <> pprFingerprint fp <> semi
    
    260
    +        -- Here we don't have access to IdInfo, so we make a
    
    261
    +        -- conservative assumption that the static closure might be
    
    262
    +        -- CAFfy, hence we pass MayHaveCafRefs when constructing a
    
    263
    +        -- CLabel. Regardless, MayHaveCafRefs/NoCafRefs wouldn't make
    
    264
    +        -- any difference here, they would pretty-print to the same
    
    265
    +        -- foreign stub content.
    
    259 266
             $$ text "extern StgPtr "
    
    260
    -           <> (pprCLabel platform $ mkClosureLabel (idName n) (idCafInfo n)) <> semi
    
    267
    +           <> (pprCLabel platform $ mkClosureLabel n MayHaveCafRefs) <> semi
    
    261 268
             $$ text "hs_spt_insert" <> parens
    
    262 269
                  (hcat $ punctuate comma
    
    263 270
                     [ char 'k' <> int i
    
    264
    -                , char '&' <> pprCLabel platform (mkClosureLabel (idName n) (idCafInfo n))
    
    271
    +                , char '&' <> pprCLabel platform (mkClosureLabel n MayHaveCafRefs)
    
    265 272
                     ]
    
    266 273
                  )
    
    267 274
             <> semi
    

  • compiler/GHC/StgToJS/StaticPtr.hs
    ... ... @@ -9,20 +9,35 @@ import GHC.Prelude
    9 9
     import GHC.Linker.Types (SptEntry(..))
    
    10 10
     import GHC.Fingerprint.Type
    
    11 11
     import GHC.Types.Literal
    
    12
    +import GHC.Types.Name
    
    12 13
     
    
    13 14
     import GHC.JS.JStg.Syntax
    
    14 15
     import GHC.JS.Make
    
    16
    +import GHC.JS.Ident (name)
    
    15 17
     
    
    16 18
     import GHC.StgToJS.Symbols
    
    17
    -import GHC.StgToJS.Ids
    
    18 19
     import GHC.StgToJS.Literal
    
    19 20
     import GHC.StgToJS.Types
    
    21
    +import GHC.Utils.Panic (panic)
    
    20 22
     
    
    21 23
     initStaticPtrs :: [SptEntry] -> G JStgStat
    
    22 24
     initStaticPtrs ptrs = mconcat <$> mapM initStatic ptrs
    
    23 25
       where
    
    24
    -    initStatic (SptEntry sp_id (Fingerprint w1 w2)) = do
    
    25
    -      i <- varForId sp_id
    
    26
    +    -- Build a reference to the closure variable for a top-level Name.
    
    27
    +    -- Static pointer bindings are exported, so we can construct the symbol
    
    28
    +    -- directly from the Name's module and OccName.
    
    29
    +    varForName :: Name -> G JStgExpr
    
    30
    +    varForName n = do
    
    31
    +      case nameModule_maybe n of
    
    32
    +        Just m  -> do
    
    33
    +          let sym = mkJsSymbol True m (occNameMangledFS (nameOccName n))
    
    34
    +          pure (ValExpr (JVar (name sym)))
    
    35
    +        Nothing ->
    
    36
    +          -- Shouldn't happen for SPT entries
    
    37
    +          panic "varForName: non-external Name in SptEntry"
    
    38
    +
    
    39
    +    initStatic (SptEntry sp_name (Fingerprint w1 w2)) = do
    
    40
    +      i <- varForName sp_name
    
    26 41
           fpa <- concat <$> mapM (genLit . mkLitWord64 . fromIntegral) [w1,w2]
    
    27 42
           let sptInsert = ApplStat hdHsSptInsert (fpa ++ [i])
    
    28 43
           return $ (hdInitStatic .^ "push") `ApplStat` [Func [] sptInsert]

  • compiler/GHC/Types/SptEntry.hs
    ... ... @@ -3,14 +3,13 @@ module GHC.Types.SptEntry
    3 3
       )
    
    4 4
     where
    
    5 5
     
    
    6
    -import GHC.Types.Var           ( Id )
    
    6
    +import GHC.Types.Name          ( Name )
    
    7 7
     import GHC.Fingerprint.Type    ( Fingerprint )
    
    8 8
     import GHC.Utils.Outputable
    
    9 9
     
    
    10 10
     -- | An entry to be inserted into a module's static pointer table.
    
    11 11
     -- See Note [Grand plan for static forms] in "GHC.Iface.Tidy.StaticPtrTable".
    
    12
    -data SptEntry = SptEntry Id Fingerprint
    
    12
    +data SptEntry = SptEntry !Name !Fingerprint
    
    13 13
     
    
    14 14
     instance Outputable SptEntry where
    
    15
    -  ppr (SptEntry id fpr) = ppr id <> colon <+> ppr fpr
    
    16
    -
    15
    +  ppr (SptEntry n fpr) = ppr n <> colon <+> ppr fpr