[Git][ghc/ghc][wip/andreask/infer_bottom] TagAnalysis: Treat all bottom ids as tagged during analysis.

Andreas Klebinger (@AndreasK) gitlab at gitlab.haskell.org
Tue May 14 22:08:53 UTC 2024



Andreas Klebinger pushed to branch wip/andreask/infer_bottom at Glasgow Haskell Compiler / GHC


Commits:
0833d415 by Andreas Klebinger at 2024-05-14T23:53:18+02:00
TagAnalysis: Treat all bottom ids as tagged during analysis.

Ticket #24806 showed that we also need to treat dead end thunks as
tagged during the analysis.

- - - - -


2 changed files:

- compiler/GHC/Stg/InferTags.hs
- compiler/GHC/Stg/InferTags/Rewrite.hs


Changes:

=====================================
compiler/GHC/Stg/InferTags.hs
=====================================
@@ -301,13 +301,14 @@ inferTagExpr env (StgApp fun args)
     (info, StgApp fun args)
   where
     !fun_arity = idArity fun
-    info | fun_arity == 0 -- Unknown arity => Thunk or unknown call
-         = TagDunno
-
+    info
          | isDeadEndId fun
          , fun_arity == length args -- Implies we will simply call the function.
          = TagTagged -- See Note [Bottom functions are TagTagged]
 
+         | fun_arity == 0 -- Unknown arity => Thunk or unknown call
+         = TagDunno
+
          | Just (TagSig res_info) <- tagSigInfo (idInfo fun)
          , fun_arity == length args  -- Saturated
          = res_info
@@ -500,6 +501,11 @@ it safely any tag sig we like.
 So we give it TagTagged, as it allows the combined tag sig of the case expression
 to be the combination of all non-bottoming branches.
 
+NB: After the analysis is done we go back to treating bottoming functions as
+untagged to ensure they are evaluated as expected in code like:
+
+  case bottom_id of { ...}
+
 -}
 
 -----------------------------


=====================================
compiler/GHC/Stg/InferTags/Rewrite.hs
=====================================
@@ -241,7 +241,10 @@ indicates a bug in the tag inference implementation.
 For this reason we assert that we are running in interactive mode if a lookup fails.
 -}
 isTagged :: Id -> RM Bool
-isTagged v = do
+isTagged v
+    -- See Note [Bottom functions are TagTagged]
+    | isDeadEndId v = pure False
+    | otherwise = do
     this_mod <- getMod
     -- See Note [Tag inference for interactive contexts]
     let lookupDefault v = assertPpr (isInteractiveModule this_mod)



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0833d415660db7060d0a1242d7227c6d360c694f

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0833d415660db7060d0a1242d7227c6d360c694f
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/20240514/75ffffe3/attachment-0001.html>


More information about the ghc-commits mailing list