diff options
author | Ben Gamari <ben@smart-cactus.org> | 2022-06-30 15:06:25 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-07-16 07:21:51 -0400 |
commit | 4ef1c65d76ef4aeb0fbd6a3667be628571c86f54 (patch) | |
tree | ae40e58d4f3c414efa1db2d73ff58822d744420e /compiler/GHC | |
parent | 4beb9f3c367e1f7ee80b5458318d9f91622e4568 (diff) | |
download | haskell-4ef1c65d76ef4aeb0fbd6a3667be628571c86f54.tar.gz |
Make keepAlive# out-of-line
This is a naive approach to fixing the unsoundness noticed in #21708.
Specifically, we remove the lowering of `keepAlive#` via CorePrep and
instead turn it into an out-of-line primop.
This is simple, inefficient (since the continuation must now be heap
allocated), but good enough for 9.4.1. We will revisit this
(particiularly via #16098) in a future release.
Metric Increase:
T4978
T7257
T9203
Diffstat (limited to 'compiler/GHC')
-rw-r--r-- | compiler/GHC/Builtin/primops.txt.pp | 1 | ||||
-rw-r--r-- | compiler/GHC/CoreToStg/Prep.hs | 33 | ||||
-rw-r--r-- | compiler/GHC/StgToCmm/Prim.hs | 4 |
3 files changed, 2 insertions, 36 deletions
diff --git a/compiler/GHC/Builtin/primops.txt.pp b/compiler/GHC/Builtin/primops.txt.pp index d81dd3bc92..ac03c20dbd 100644 --- a/compiler/GHC/Builtin/primops.txt.pp +++ b/compiler/GHC/Builtin/primops.txt.pp @@ -3307,6 +3307,7 @@ primop KeepAliveOp "keepAlive#" GenPrimOp polymorphic type might suggest; see the section \"RuntimeRep polymorphism in continuation-style primops\" for details. } with + out_of_line = True strictness = { \ _arity -> mkClosedDmdSig [topDmd, topDmd, strictOnceApply1Dmd] topDiv } diff --git a/compiler/GHC/CoreToStg/Prep.hs b/compiler/GHC/CoreToStg/Prep.hs index 583badce52..d03df0eedb 100644 --- a/compiler/GHC/CoreToStg/Prep.hs +++ b/compiler/GHC/CoreToStg/Prep.hs @@ -28,10 +28,7 @@ import GHC.Tc.Utils.Env import GHC.Unit import GHC.Builtin.Names -import GHC.Builtin.PrimOps -import GHC.Builtin.PrimOps.Ids (primOpId) import GHC.Builtin.Types -import GHC.Builtin.Types.Prim ( realWorldStatePrimTy ) import GHC.Core.Utils import GHC.Core.Opt.Arity @@ -1072,36 +1069,6 @@ cpeApp top_env expr = let (terminal, args') = collect_args arg in cpe_app env terminal (args' ++ args) - -- See Note [keepAlive# magic]. - cpe_app env - (Var f) - args - | Just KeepAliveOp <- isPrimOpId_maybe f - , CpeApp (Type arg_lev) - : CpeApp (Type _result_rep) - : CpeApp (Type arg_ty) - : CpeApp (Type result_ty) - : CpeApp arg - : CpeApp s0 - : CpeApp k - : rest <- args - = do { y <- newVar (cpSubstTy env result_ty) - ; s2 <- newVar realWorldStatePrimTy - ; -- beta reduce if possible - ; (floats, k') <- case k of - Lam s body -> cpe_app (extendCorePrepEnvExpr env s s0) body rest - _ -> cpe_app env k (CpeApp s0 : rest) - ; let touchId = primOpId TouchOp - expr = Case k' y result_ty [Alt DEFAULT [] rhs] - rhs = let scrut = mkApps (Var touchId) [Type arg_lev, Type arg_ty, arg, Var realWorldPrimId] - in Case scrut s2 result_ty [Alt DEFAULT [] (Var y)] - ; (floats', expr') <- cpeBody env expr - ; return (floats `appendFloats` floats', expr') - } - | Just KeepAliveOp <- isPrimOpId_maybe f - = pprPanic "invalid keepAlive# application" $ - vcat [ text "args:" <+> ppr args ] - -- runRW# magic cpe_app env (Var f) (CpeApp _runtimeRep@Type{} : CpeApp _type@Type{} : CpeApp arg : rest) | f `hasKey` runRWKey diff --git a/compiler/GHC/StgToCmm/Prim.hs b/compiler/GHC/StgToCmm/Prim.hs index 22367e48ff..5d459ba7ad 100644 --- a/compiler/GHC/StgToCmm/Prim.hs +++ b/compiler/GHC/StgToCmm/Prim.hs @@ -1632,9 +1632,7 @@ emitPrimOp cfg primop = TraceEventBinaryOp -> alwaysExternal TraceMarkerOp -> alwaysExternal SetThreadAllocationCounter -> alwaysExternal - - -- See Note [keepAlive# magic] in GHC.CoreToStg.Prep. - KeepAliveOp -> panic "keepAlive# should have been eliminated in CorePrep" + KeepAliveOp -> alwaysExternal where profile = stgToCmmProfile cfg |