[Git][ghc/ghc][wip/ppc64-fix-T25155-T25240] 4 commits: DmdAnal: Make `prompt#` lazy (#25439)
Peter Trommler (@trommler)
gitlab at gitlab.haskell.org
Thu Nov 14 10:58:10 UTC 2024
Peter Trommler pushed to branch wip/ppc64-fix-T25155-T25240 at Glasgow Haskell Compiler / GHC
Commits:
00d58ae1 by Sebastian Graf at 2024-11-13T15:21:23-05:00
DmdAnal: Make `prompt#` lazy (#25439)
This applies the same treatment to `prompt#` as for `catch#`.
See `Note [Strictness for mask/unmask/catch/prompt]`.
Fixes #25439.
- - - - -
93233a66 by Ben Gamari at 2024-11-13T15:21:59-05:00
boot: Do not attempt to update config.sub
While Apple ARM hardware was new we found that the autoconf scripts
included in some boot packages were too old. As a mitigation for this,
we introduced logic in the `boot` script to update the `config.sub`
with that from the GHC tree. However, this causes submodules which
have `config.sub` committted to appear to be dirty. This is a
considerable headache.
Now since `config.sub` with full platform support is more common we can
remove `boot`'s `config.sub` logic.
Fixes #19574.
- - - - -
0b29d063 by Peter Trommler at 2024-11-14T10:58:01+00:00
Fix requirements on T25240
T25240 doesn't need RTS linker, GHCi is sufficient and GHCi can also be
dynamically linked.
- - - - -
c1e137c3 by Peter Trommler at 2024-11-14T10:58:01+00:00
Fix requirements for T25155
Loading C objects requires RTS linker.
- - - - -
7 changed files:
- boot
- compiler/GHC/Builtin/primops.txt.pp
- + testsuite/tests/dmdanal/should_run/T25439.hs
- + testsuite/tests/dmdanal/should_run/T25439.stdout
- testsuite/tests/dmdanal/should_run/all.T
- testsuite/tests/ghci/linking/T25240/all.T
- testsuite/tests/ghci/linking/all.T
Changes:
=====================================
boot
=====================================
@@ -66,9 +66,6 @@ def autoreconf():
for dir_ in ['.', 'rts'] + glob.glob('libraries/*/'):
if os.path.isfile(os.path.join(dir_, 'configure.ac')):
print("Booting %s" % dir_)
- # Update config.sub in submodules
- if dir_ != '.' and os.path.isfile(os.path.join(dir_, 'config.sub')):
- shutil.copyfile('config.sub', os.path.join(dir_, 'config.sub'))
processes[dir_] = subprocess.Popen(['sh', '-c', reconf_cmd], cwd=dir_)
# Wait for all child processes to finish.
=====================================
compiler/GHC/Builtin/primops.txt.pp
=====================================
@@ -2663,18 +2663,45 @@ primop CasMutVarOp "casMutVar#" GenPrimOp
section "Exceptions"
------------------------------------------------------------------------
--- Note [Strictness for mask/unmask/catch]
--- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+-- Note [Strict IO wrappers]
+-- ~~~~~~~~~~~~~~~~~~~~~~~~~
-- Consider this example, which comes from GHC.IO.Handle.Internals:
--- wantReadableHandle3 f ma b st
+-- wantReadableHandle3 f mv b st
-- = case ... of
--- DEFAULT -> case ma of MVar a -> ...
--- 0# -> maskAsyncExceptions# (\st -> case ma of MVar a -> ...)
+-- DEFAULT -> case mv of MVar a -> ...
+-- 0# -> maskAsyncExceptions# (\st -> case mv of MVar a -> ...)
-- The outer case just decides whether to mask exceptions, but we don't want
--- thereby to hide the strictness in 'ma'! Hence the use of strictOnceApply1Dmd
--- in mask and unmask. But catch really is lazy in its first argument, see
--- #11555. So for IO actions 'ma' we often use a wrapper around it that is
--- head-strict in 'ma': GHC.IO.catchException.
+-- thereby to hide the strictness in `mv`! Hence the use of strictOnceApply1Dmd
+-- in mask#, unmask# and atomically# (where we use strictManyApply1Dmd to respect
+-- that it potentially calls its action multiple times).
+--
+-- Note [Strictness for catch-style primops]
+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+-- The catch#-style primops always call their action, just like outlined
+-- in Note [Strict IO wrappers].
+-- However, it is important that we give their first arg lazyApply1Dmd and not
+-- strictOnceApply1Dmd, like for mask#. Here is why. Consider a call
+--
+-- catch# act handler s
+--
+-- If `act = raiseIO# ...`, using strictOnceApply1Dmd for `act` would mean that
+-- the call forwards the dead-end flag from `act` (see Note [Dead ends] and
+-- Note [Precise exceptions and strictness analysis]).
+-- This would cause dead code elimination to discard the continuation of the
+-- catch# call, among other things. This first came up in #11555.
+--
+-- Hence catch# uses lazyApply1Dmd in order /not/ to forward the dead-end flag
+-- from `act`. (This is a bit brutal, but the language of strictness types is
+-- not expressive enough to give it a more precise semantics that is still
+-- sound.)
+-- For perf reasons we often (but not always) choose to use a wrapper around
+-- catch# that is head-strict in `act`: GHC.IO.catchException.
+--
+-- A similar caveat applies to prompt#, which can be seen as a
+-- generalisation of catch# as explained in GHC.Prim#continuations#.
+-- The reason is that even if `act` appears dead-ending (e.g., looping)
+-- `prompt# tag ma s` might return alright due to a (higher-order) use of
+-- `control0#` in `act`. This came up in #25439.
primop CatchOp "catch#" GenPrimOp
(State# RealWorld -> (# State# RealWorld, a_reppoly #) )
@@ -2691,7 +2718,7 @@ primop CatchOp "catch#" GenPrimOp
strictness = { \ _arity -> mkClosedDmdSig [ lazyApply1Dmd
, lazyApply2Dmd
, topDmd] topDiv }
- -- See Note [Strictness for mask/unmask/catch]
+ -- See Note [Strictness for catch-style primops]
out_of_line = True
effect = ReadWriteEffect
-- Either inner computation might potentially raise an unchecked exception,
@@ -2757,7 +2784,7 @@ primop MaskAsyncExceptionsOp "maskAsyncExceptions#" GenPrimOp
in continuation-style primops\" for details. }
with
strictness = { \ _arity -> mkClosedDmdSig [strictOnceApply1Dmd,topDmd] topDiv }
- -- See Note [Strictness for mask/unmask/catch]
+ -- See Note [Strict IO wrappers]
out_of_line = True
effect = ReadWriteEffect
@@ -2772,6 +2799,7 @@ primop MaskUninterruptibleOp "maskUninterruptible#" GenPrimOp
in continuation-style primops\" for details. }
with
strictness = { \ _arity -> mkClosedDmdSig [strictOnceApply1Dmd,topDmd] topDiv }
+ -- See Note [Strict IO wrappers]
out_of_line = True
effect = ReadWriteEffect
@@ -2786,7 +2814,7 @@ primop UnmaskAsyncExceptionsOp "unmaskAsyncExceptions#" GenPrimOp
in continuation-style primops\" for details. }
with
strictness = { \ _arity -> mkClosedDmdSig [strictOnceApply1Dmd,topDmd] topDiv }
- -- See Note [Strictness for mask/unmask/catch]
+ -- See Note [Strict IO wrappers]
out_of_line = True
effect = ReadWriteEffect
@@ -2972,7 +3000,8 @@ primop PromptOp "prompt#" GenPrimOp
-> State# RealWorld -> (# State# RealWorld, a #)
{ See "GHC.Prim#continuations". }
with
- strictness = { \ _arity -> mkClosedDmdSig [topDmd, strictOnceApply1Dmd, topDmd] topDiv }
+ strictness = { \ _arity -> mkClosedDmdSig [topDmd, lazyApply1Dmd, topDmd] topDiv }
+ -- See Note [Strictness for catch-style primops]
out_of_line = True
effect = ReadWriteEffect
@@ -3000,7 +3029,7 @@ primop AtomicallyOp "atomically#" GenPrimOp
-> State# RealWorld -> (# State# RealWorld, a_levpoly #)
with
strictness = { \ _arity -> mkClosedDmdSig [strictManyApply1Dmd,topDmd] topDiv }
- -- See Note [Strictness for mask/unmask/catch]
+ -- See Note [Strict IO wrappers]
out_of_line = True
effect = ReadWriteEffect
@@ -3029,7 +3058,7 @@ primop CatchRetryOp "catchRetry#" GenPrimOp
strictness = { \ _arity -> mkClosedDmdSig [ lazyApply1Dmd
, lazyApply1Dmd
, topDmd ] topDiv }
- -- See Note [Strictness for mask/unmask/catch]
+ -- See Note [Strictness for catch-style primops]
out_of_line = True
effect = ReadWriteEffect
@@ -3041,7 +3070,7 @@ primop CatchSTMOp "catchSTM#" GenPrimOp
strictness = { \ _arity -> mkClosedDmdSig [ lazyApply1Dmd
, lazyApply2Dmd
, topDmd ] topDiv }
- -- See Note [Strictness for mask/unmask/catch]
+ -- See Note [Strictness for catch-style primops]
out_of_line = True
effect = ReadWriteEffect
@@ -3731,6 +3760,7 @@ primop KeepAliveOp "keepAlive#" GenPrimOp
with
out_of_line = True
strictness = { \ _arity -> mkClosedDmdSig [topDmd, topDmd, strictOnceApply1Dmd] topDiv }
+ -- See Note [Strict IO wrappers]
effect = ReadWriteEffect
-- The invoked computation may have side effects
=====================================
testsuite/tests/dmdanal/should_run/T25439.hs
=====================================
@@ -0,0 +1,25 @@
+{-# LANGUAGE MagicHash, UnboxedTuples, BlockArguments #-}
+
+import Prelude hiding (break)
+import GHC.Exts (PromptTag#, newPromptTag#, prompt#, control0#)
+import GHC.IO (IO(..), unIO)
+import Control.Monad (forever)
+
+main :: IO ()
+main = do
+ putStrLn "before"
+ broken >>= putStrLn
+ putStrLn "after"
+
+broken :: IO String
+broken = do
+ loop \l -> do
+ break l "broken"
+
+{-# NOINLINE loop #-}
+loop :: (PromptTag# a -> IO ()) -> IO a
+loop f = IO \rw0 -> case newPromptTag# rw0 of
+ (# rw1, tag #) -> prompt# tag (unIO (forever (f tag))) rw1
+
+break :: PromptTag# a -> a -> IO b
+break tag x = IO (control0# tag \_ rw1 -> (# rw1, x #))
=====================================
testsuite/tests/dmdanal/should_run/T25439.stdout
=====================================
@@ -0,0 +1,3 @@
+before
+broken
+after
=====================================
testsuite/tests/dmdanal/should_run/all.T
=====================================
@@ -33,3 +33,4 @@ test('T22475b', normal, compile_and_run, [''])
# T22549: Do not strictify DFuns, otherwise we will <<loop>>
test('T22549', normal, compile_and_run, ['-fdicts-strict -fno-specialise'])
test('T23208', exit_code(1), multimod_compile_and_run, ['T23208_Lib', 'T23208'])
+test('T25439', normal, compile_and_run, [''])
=====================================
testsuite/tests/ghci/linking/T25240/all.T
=====================================
@@ -1,3 +1,3 @@
# skip on darwin because the leading underscores will make the test fail
-test('T25240', [when(leading_underscore(),skip), req_rts_linker, extra_files(['T25240a.hs'])],
+test('T25240', [when(leading_underscore(),skip), req_interp, extra_files(['T25240a.hs'])],
makefile_test, ['T25240'])
=====================================
testsuite/tests/ghci/linking/all.T
=====================================
@@ -76,4 +76,4 @@ test('big-obj', [extra_files(['big-obj-c.c', 'big-obj.hs']),
unless(doing_ghci, skip), unless(opsys('mingw32'), skip)],
makefile_test, ['big-obj'])
-test('T25155', [req_c, req_th, req_interp, extra_files(['T25155_iserv_main.c', 'T25155_iserv.hs', 'T25155_TH.hs'])], makefile_test, [])
+test('T25155', [req_c, req_th, req_interp, req_rts_linker, extra_files(['T25155_iserv_main.c', 'T25155_iserv.hs', 'T25155_TH.hs'])], makefile_test, [])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/106cb457e38b2ad751e008be43aa77ae80a5b18b...c1e137c3665fe592ffd787bbd2238a4eddd65d52
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/106cb457e38b2ad751e008be43aa77ae80a5b18b...c1e137c3665fe592ffd787bbd2238a4eddd65d52
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/20241114/b2c2235a/attachment-0001.html>
More information about the ghc-commits
mailing list