[Git][ghc/ghc][wip/T18291] 2 commits: Allow unsaturated runRW# applications

Ben Gamari gitlab at gitlab.haskell.org
Tue Jun 2 21:05:18 UTC 2020



Ben Gamari pushed to branch wip/T18291 at Glasgow Haskell Compiler / GHC


Commits:
3f3d9196 by Ben Gamari at 2020-06-02T17:05:05-04:00
Allow unsaturated runRW# applications

Previously we had a very aggressive Core Lint check which caught
unsaturated applications of runRW#. However, there is nothing
wrong with such applications and they may naturally arise in desugared
Core. For instance, the desugared Core of Data.Primitive.Array.runArray#
from the `primitive` package contains:

    case ($) (runRW# @_ @_) (\s -> ...) of ...

In this case it's almost certain that ($) will be inlined, turning the
application into a saturated application. However, even if this weren't
the case there isn't a problem: CorePrep (after deleting an unnecessary
case) can simply generate code in its usual way, resulting in a call to
the Haskell definition of runRW#.

Fixes #18291.

- - - - -
ca475ca2 by Ben Gamari at 2020-06-02T17:05:11-04:00
testsuite: Add test for #18291

- - - - -


4 changed files:

- compiler/GHC/Core/Lint.hs
- compiler/GHC/CoreToStg/Prep.hs
- + testsuite/tests/codeGen/should_compile/T18291.hs
- testsuite/tests/codeGen/should_compile/all.T


Changes:

=====================================
compiler/GHC/Core/Lint.hs
=====================================
@@ -923,10 +923,6 @@ lintCoreExpr e@(App _ _)
        ; app_ty <- lintValApp arg3 fun_ty2 arg3_ty
        ; lintCoreArgs app_ty rest }
 
-  | Var fun <- fun
-  , fun `hasKey` runRWKey
-  = failWithL (text "Invalid runRW# application")
-
   | otherwise
   = do { fun_ty <- lintCoreFun fun (length args)
        ; lintCoreArgs fun_ty args }


=====================================
compiler/GHC/CoreToStg/Prep.hs
=====================================
@@ -842,10 +842,6 @@ cpeApp top_env expr
             _          -> cpe_app env arg (CpeApp (Var realWorldPrimId) : rest) (n-1)
              -- TODO: What about casts?
 
-    cpe_app _env (Var f) args n
-        | f `hasKey` runRWKey
-        = pprPanic "cpe_app(runRW#)" (ppr args $$ ppr n)
-
     cpe_app env (Var v) args depth
       = do { v1 <- fiddleCCall v
            ; let e2 = lookupCorePrepEnv env v1
@@ -1018,9 +1014,9 @@ for runRW# applications. See Note [Linting of runRW#] for details on the latter.
 
 Moreover, it's helpful to ensure that runRW's continuation isn't floated out
 (since doing so would then require a call, whereas we would otherwise end up
-with straight-line). Consequently, GHC.Core.Opt.SetLevels.lvlApp has special
-treatment for runRW# applications, ensure the arguments are not floated if
-MFEs.
+with straight-line code). Consequently, GHC.Core.Opt.SetLevels.lvlApp has
+special treatment for runRW# applications, ensure the arguments are not floated
+as MFEs.
 
 Other considered designs
 ------------------------


=====================================
testsuite/tests/codeGen/should_compile/T18291.hs
=====================================
@@ -0,0 +1,5 @@
+{-# LANGUAGE MagicHash #-}
+module T18291 where
+
+hi :: Int
+hi = runRW# $ \_ -> 42


=====================================
testsuite/tests/codeGen/should_compile/all.T
=====================================
@@ -87,3 +87,4 @@ test('T14373d', [],
 
 test('T17648', normal, makefile_test, [])
 test('T17904', normal, compile, ['-O'])
+test('T18291', normal, compile, ['-O0'])



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/24f524705a109f0bcd4d188d08410f6cd8a422b9...ca475ca2029c02065a8d5aa489c6aa3beac49195

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/24f524705a109f0bcd4d188d08410f6cd8a422b9...ca475ca2029c02065a8d5aa489c6aa3beac49195
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/20200602/4187fcee/attachment-0001.html>


More information about the ghc-commits mailing list