Cheng Shao pushed to branch wip/deepseq-primop at Glasgow Haskell Compiler / GHC
Commits:
-
c1a8508d
by Cheng Shao at 2026-01-20T17:23:07+01:00
7 changed files:
- + libraries/ghc-experimental/cbits/DeepSeq.cmm
- libraries/ghc-experimental/ghc-experimental.cabal.in
- + libraries/ghc-experimental/src/GHC/DeepSeq.hs
- testsuite/tests/interface-stability/ghc-experimental-exports.stdout
- + testsuite/tests/primops/should_run/DeepSeqPrimOp.hs
- + testsuite/tests/primops/should_run/DeepSeqPrimOp.stdout
- testsuite/tests/primops/should_run/all.T
Changes:
| 1 | +/* -----------------------------------------------------------------------------
|
|
| 2 | + *
|
|
| 3 | + * (c) The GHC Team, 2025
|
|
| 4 | + *
|
|
| 5 | + * Support for the deepseq# primcall.
|
|
| 6 | + *
|
|
| 7 | + * ---------------------------------------------------------------------------*/
|
|
| 8 | + |
|
| 9 | +#include "Cmm.h"
|
|
| 10 | + |
|
| 11 | +/*
|
|
| 12 | +Note [import CLOSURE annotations]
|
|
| 13 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 14 | +See Note [import CLOSURE annotations] in rts/Apply.cmm.
|
|
| 15 | +*/
|
|
| 16 | + |
|
| 17 | +#if !defined(UnregisterisedCompiler)
|
|
| 18 | +import CLOSURE g0;
|
|
| 19 | +import CLOSURE large_alloc_lim;
|
|
| 20 | +#endif
|
|
| 21 | + |
|
| 22 | +/* -----------------------------------------------------------------------------
|
|
| 23 | + deepseq#
|
|
| 24 | + |
|
| 25 | + Deeply evaluate a value to (approximate) normal form, without requiring an
|
|
| 26 | + NFData constraint. This is used to provide a primitive analogue of
|
|
| 27 | + Control.DeepSeq.force / rnf.
|
|
| 28 | + |
|
| 29 | + See the GHC.DeepSeq documentation for the intended semantics and
|
|
| 30 | + limitations.
|
|
| 31 | + -------------------------------------------------------------------------- */
|
|
| 32 | + |
|
| 33 | +// Worker which performs deep evaluation. This lets us tail-call when traversing
|
|
| 34 | +// the final pointer field, avoiding stack blowup on common spine-recursive
|
|
| 35 | +// structures (e.g. lists).
|
|
| 36 | +//
|
|
| 37 | +// The second argument is a boolean (0/1) accumulator tracking whether any
|
|
| 38 | +// evaluation was forced in the transitive closure so far.
|
|
| 39 | +stg_deepseqWorkzh (P_ p, W_ forced)
|
|
| 40 | +{
|
|
| 41 | + W_ type, info;
|
|
| 42 | + |
|
| 43 | + again: MAYBE_GC(again);
|
|
| 44 | + STK_CHK_GEN();
|
|
| 45 | + |
|
| 46 | + p = UNTAG(p);
|
|
| 47 | + // Values in compact regions are already fully evaluated.
|
|
| 48 | + (W_ in_compact) = call stg_compactContainsAnyzh(p);
|
|
| 49 | + if (in_compact != 0) {
|
|
| 50 | + return (forced);
|
|
| 51 | + }
|
|
| 52 | + info = %INFO_PTR(p);
|
|
| 53 | + type = TO_W_(%INFO_TYPE(%STD_INFO(info)));
|
|
| 54 | + |
|
| 55 | + switch [0 .. N_CLOSURE_TYPES] type {
|
|
| 56 | + |
|
| 57 | + // Unevaluated things must be evaluated first:
|
|
| 58 | + case
|
|
| 59 | + THUNK,
|
|
| 60 | + THUNK_1_0,
|
|
| 61 | + THUNK_0_1,
|
|
| 62 | + THUNK_2_0,
|
|
| 63 | + THUNK_1_1,
|
|
| 64 | + THUNK_0_2,
|
|
| 65 | + THUNK_STATIC,
|
|
| 66 | + AP,
|
|
| 67 | + AP_STACK,
|
|
| 68 | + BLACKHOLE,
|
|
| 69 | + THUNK_SELECTOR : {
|
|
| 70 | + (P_ evald) = call %ENTRY_CODE(info) (p);
|
|
| 71 | + jump stg_deepseqWorkzh(evald, 1);
|
|
| 72 | + }
|
|
| 73 | + |
|
| 74 | + // Follow indirections:
|
|
| 75 | + case IND, IND_STATIC: {
|
|
| 76 | + p = %acquire StgInd_indirectee(p);
|
|
| 77 | + jump stg_deepseqWorkzh(p, forced);
|
|
| 78 | + }
|
|
| 79 | + |
|
| 80 | + // WHITEHOLEs are transient. Yield and try again.
|
|
| 81 | + case WHITEHOLE: {
|
|
| 82 | + goto again;
|
|
| 83 | + }
|
|
| 84 | + |
|
| 85 | + // Arrays of pointers: evaluate elements.
|
|
| 86 | + case
|
|
| 87 | + MUT_ARR_PTRS_DIRTY,
|
|
| 88 | + MUT_ARR_PTRS_CLEAN,
|
|
| 89 | + MUT_ARR_PTRS_FROZEN_DIRTY,
|
|
| 90 | + MUT_ARR_PTRS_FROZEN_CLEAN: {
|
|
| 91 | + W_ i_arr, ptrs_arr;
|
|
| 92 | + ptrs_arr = StgMutArrPtrs_ptrs(p);
|
|
| 93 | + if (ptrs_arr == 0) { return (forced); }
|
|
| 94 | + i_arr = ptrs_arr - 1;
|
|
| 95 | + deepseq_arr_loop0:
|
|
| 96 | + if (i_arr == 0) ( likely: False ) {
|
|
| 97 | + // Tail-call the final element to avoid building up a deep stack
|
|
| 98 | + // when traversing large immutable arrays.
|
|
| 99 | + jump stg_deepseqWorkzh(P_[p + SIZEOF_StgMutArrPtrs], forced);
|
|
| 100 | + }
|
|
| 101 | + (W_ forced_arr) = call stg_deepseqWorkzh(P_[p + SIZEOF_StgMutArrPtrs + WDS(i_arr)], forced);
|
|
| 102 | + forced = forced_arr;
|
|
| 103 | + i_arr = i_arr - 1;
|
|
| 104 | + goto deepseq_arr_loop0;
|
|
| 105 | + }
|
|
| 106 | + |
|
| 107 | + case
|
|
| 108 | + SMALL_MUT_ARR_PTRS_DIRTY,
|
|
| 109 | + SMALL_MUT_ARR_PTRS_CLEAN,
|
|
| 110 | + SMALL_MUT_ARR_PTRS_FROZEN_DIRTY,
|
|
| 111 | + SMALL_MUT_ARR_PTRS_FROZEN_CLEAN: {
|
|
| 112 | + W_ i_sarr, ptrs_sarr;
|
|
| 113 | + ptrs_sarr = StgSmallMutArrPtrs_ptrs(p);
|
|
| 114 | + if (ptrs_sarr == 0) { return (forced); }
|
|
| 115 | + i_sarr = ptrs_sarr - 1;
|
|
| 116 | + deepseq_arr_loop1:
|
|
| 117 | + if (i_sarr == 0) ( likely: False ) {
|
|
| 118 | + // Tail-call the final element to avoid building up a deep stack
|
|
| 119 | + // when traversing large immutable arrays.
|
|
| 120 | + jump stg_deepseqWorkzh(P_[p + SIZEOF_StgSmallMutArrPtrs], forced);
|
|
| 121 | + }
|
|
| 122 | + (W_ forced_sarr) = call stg_deepseqWorkzh(P_[p + SIZEOF_StgSmallMutArrPtrs + WDS(i_sarr)], forced);
|
|
| 123 | + forced = forced_sarr;
|
|
| 124 | + i_sarr = i_sarr - 1;
|
|
| 125 | + goto deepseq_arr_loop1;
|
|
| 126 | + }
|
|
| 127 | + |
|
| 128 | + // Constructors: evaluate their pointer fields.
|
|
| 129 | + case
|
|
| 130 | + CONSTR,
|
|
| 131 | + CONSTR_1_0,
|
|
| 132 | + CONSTR_0_1,
|
|
| 133 | + CONSTR_2_0,
|
|
| 134 | + CONSTR_1_1,
|
|
| 135 | + CONSTR_0_2,
|
|
| 136 | + CONSTR_NOCAF: {
|
|
| 137 | + W_ i_constr, ptrs_constr;
|
|
| 138 | + ptrs_constr = TO_W_(%INFO_PTRS(%STD_INFO(info)));
|
|
| 139 | + if (ptrs_constr == 0) { return (forced); }
|
|
| 140 | + i_constr = 0;
|
|
| 141 | + deepseq_constr_loop:
|
|
| 142 | + if (i_constr < ptrs_constr) {
|
|
| 143 | + // Tail-call the last one. This avoids building up a deep stack
|
|
| 144 | + // when traversing long lists. We count up so the final pointer
|
|
| 145 | + // field (e.g. the tail of a list cell) is tail-called.
|
|
| 146 | + if (i_constr == ptrs_constr - 1) {
|
|
| 147 | + jump stg_deepseqWorkzh(StgClosure_payload(p,i_constr), forced);
|
|
| 148 | + }
|
|
| 149 | + (W_ forced_constr) = call stg_deepseqWorkzh(StgClosure_payload(p,i_constr), forced);
|
|
| 150 | + forced = forced_constr;
|
|
| 151 | + i_constr = i_constr + 1;
|
|
| 152 | + goto deepseq_constr_loop;
|
|
| 153 | + }
|
|
| 154 | + return (forced);
|
|
| 155 | + }
|
|
| 156 | + |
|
| 157 | + case
|
|
| 158 | + MUT_VAR_CLEAN,
|
|
| 159 | + MUT_VAR_DIRTY: {
|
|
| 160 | + p = %relaxed StgMutVar_var(p);
|
|
| 161 | + jump stg_deepseqWorkzh(p, forced);
|
|
| 162 | + }
|
|
| 163 | + |
|
| 164 | + case
|
|
| 165 | + MVAR_CLEAN,
|
|
| 166 | + MVAR_DIRTY: {
|
|
| 167 | + p = %relaxed StgMVar_value(p);
|
|
| 168 | + jump stg_deepseqWorkzh(p, forced);
|
|
| 169 | + }
|
|
| 170 | + |
|
| 171 | + case TVAR: {
|
|
| 172 | + (P_ tvar_val) = call stg_readTVarIOzh(p);
|
|
| 173 | + jump stg_deepseqWorkzh(tvar_val, forced);
|
|
| 174 | + }
|
|
| 175 | + |
|
| 176 | + case WEAK: {
|
|
| 177 | + // Follow the value of a live weak pointer.
|
|
| 178 | + jump stg_deepseqWorkzh(StgWeak_value(p), forced);
|
|
| 179 | + }
|
|
| 180 | + |
|
| 181 | + // Anything else: conservatively stop.
|
|
| 182 | + //
|
|
| 183 | + // This includes (among other closure types) function-like closures and
|
|
| 184 | + // mutable objects which are not plain containers (e.g. TVar#),
|
|
| 185 | + // matching the intended "mimic typical NFData instances" semantics
|
|
| 186 | + // described in the primop documentation.
|
|
| 187 | + //
|
|
| 188 | + // We should never see frames here, but if we do, returning is safer than
|
|
| 189 | + // entering arbitrary things.
|
|
| 190 | + default: {
|
|
| 191 | + return (forced);
|
|
| 192 | + }}
|
|
| 193 | +}
|
|
| 194 | + |
|
| 195 | +// deepseq# primop entry point.
|
|
| 196 | +// deepseq# :: forall a s. a -> State# s -> (# State# s, Int#, a #)
|
|
| 197 | +//
|
|
| 198 | +// The State# argument/result has no runtime representation, so the RTS entry
|
|
| 199 | +// only takes the value being forced.
|
|
| 200 | +stg_deepseqzh (P_ p)
|
|
| 201 | +{
|
|
| 202 | + jump stg_deepseqLoopzh(p, 0);
|
|
| 203 | +}
|
|
| 204 | + |
|
| 205 | +// Worker which evaluates to a root and then delegates to the deep traversal.
|
|
| 206 | +// The second argument is a boolean (0/1) accumulator tracking whether any
|
|
| 207 | +// evaluation was forced in the transitive closure so far.
|
|
| 208 | +stg_deepseqLoopzh (P_ p, W_ forced)
|
|
| 209 | +{
|
|
| 210 | + W_ type, info, tag;
|
|
| 211 | + |
|
| 212 | + again: MAYBE_GC(again);
|
|
| 213 | + STK_CHK_GEN();
|
|
| 214 | + |
|
| 215 | + tag = GETTAG(p);
|
|
| 216 | + p = UNTAG(p);
|
|
| 217 | + info = %INFO_PTR(p);
|
|
| 218 | + type = TO_W_(%INFO_TYPE(%STD_INFO(info)));
|
|
| 219 | + |
|
| 220 | + switch [0 .. N_CLOSURE_TYPES] type {
|
|
| 221 | + |
|
| 222 | + // Unevaluated things must be evaluated first:
|
|
| 223 | + case
|
|
| 224 | + THUNK,
|
|
| 225 | + THUNK_1_0,
|
|
| 226 | + THUNK_0_1,
|
|
| 227 | + THUNK_2_0,
|
|
| 228 | + THUNK_1_1,
|
|
| 229 | + THUNK_0_2,
|
|
| 230 | + THUNK_STATIC,
|
|
| 231 | + AP,
|
|
| 232 | + AP_STACK,
|
|
| 233 | + BLACKHOLE,
|
|
| 234 | + THUNK_SELECTOR : {
|
|
| 235 | + (P_ evald) = call %ENTRY_CODE(info) (p);
|
|
| 236 | + jump stg_deepseqLoopzh(evald, 1);
|
|
| 237 | + }
|
|
| 238 | + |
|
| 239 | + // Follow indirections:
|
|
| 240 | + case IND, IND_STATIC: {
|
|
| 241 | + p = %acquire StgInd_indirectee(p);
|
|
| 242 | + jump stg_deepseqLoopzh(p, forced);
|
|
| 243 | + }
|
|
| 244 | + |
|
| 245 | + // WHITEHOLEs are transient. Yield and try again.
|
|
| 246 | + case WHITEHOLE: {
|
|
| 247 | + goto again;
|
|
| 248 | + }
|
|
| 249 | + |
|
| 250 | + default: {
|
|
| 251 | + P_ root;
|
|
| 252 | + root = tag | p;
|
|
| 253 | + (W_ forced1) = call stg_deepseqWorkzh(root, forced);
|
|
| 254 | + return (forced1, root);
|
|
| 255 | + }}
|
|
| 256 | +} |
| ... | ... | @@ -31,6 +31,7 @@ library |
| 31 | 31 | exposed-modules:
|
| 32 | 32 | Data.Sum.Experimental
|
| 33 | 33 | Data.Tuple.Experimental
|
| 34 | + GHC.DeepSeq
|
|
| 34 | 35 | GHC.PrimOps
|
| 35 | 36 | GHC.Profiling.Eras
|
| 36 | 37 | GHC.TypeLits.Experimental
|
| ... | ... | @@ -46,4 +47,5 @@ library |
| 46 | 47 | build-depends: base >=4.20 && < 4.23,
|
| 47 | 48 | ghc-internal == @ProjectVersionForLib@.*
|
| 48 | 49 | hs-source-dirs: src
|
| 50 | + cmm-sources: cbits/DeepSeq.cmm
|
|
| 49 | 51 | default-language: Haskell2010 |
| 1 | +{-# LANGUAGE ForeignFunctionInterface #-}
|
|
| 2 | +{-# LANGUAGE GHCForeignImportPrim #-}
|
|
| 3 | +{-# LANGUAGE MagicHash #-}
|
|
| 4 | +{-# LANGUAGE UnboxedTuples #-}
|
|
| 5 | +{-# LANGUAGE UnliftedFFITypes #-}
|
|
| 6 | + |
|
| 7 | +module GHC.DeepSeq
|
|
| 8 | + ( force,
|
|
| 9 | + forceIO,
|
|
| 10 | + forceST,
|
|
| 11 | + )
|
|
| 12 | +where
|
|
| 13 | + |
|
| 14 | +import GHC.Internal.Exts
|
|
| 15 | +import GHC.Internal.IO (stToIO)
|
|
| 16 | +import GHC.Internal.ST (ST (..), runST)
|
|
| 17 | + |
|
| 18 | +-- | Pure wrapper around 'forceST'.
|
|
| 19 | +force :: a -> (Bool, a)
|
|
| 20 | +force a = runST (forceST a)
|
|
| 21 | + |
|
| 22 | +-- | Deeply evaluate a value in the 'IO' monad, returning the forced value and
|
|
| 23 | +-- a flag indicating whether any unevaluated closure was forced.
|
|
| 24 | +--
|
|
| 25 | +-- This is a primitive analogue of 'Control.DeepSeq.force' / @rnf@ that does
|
|
| 26 | +-- not require an 'NFData' constraint. It traverses algebraic data (constructor
|
|
| 27 | +-- fields), immutable arrays, and the contents of 'MutVar#', 'MVar#',
|
|
| 28 | +-- 'MutableArray#', 'SmallMutableArray#', 'TVar#', and live 'Weak#' values.
|
|
| 29 | +--
|
|
| 30 | +-- To mimic typical 'Control.DeepSeq.NFData' instances, it stops at
|
|
| 31 | +-- function-like closures (e.g. functions and partial applications) and at
|
|
| 32 | +-- mutable objects which are not plain containers (e.g. 'MutableByteArray#').
|
|
| 33 | +-- Consequently
|
|
| 34 | +-- it is not a drop-in replacement for user-defined 'NFData' instances, which
|
|
| 35 | +-- may choose to force less (or more) depending on semantics.
|
|
| 36 | +--
|
|
| 37 | +-- === Pointer traversal policy
|
|
| 38 | +--
|
|
| 39 | +-- We only follow a pointer when doing so is also possible in Haskell via a
|
|
| 40 | +-- corresponding API. For example, we traverse 'MutVar#', 'MVar#', mutable
|
|
| 41 | +-- arrays, and live weak pointers because you can observe their contents with
|
|
| 42 | +-- operations like @readIORef@, @readMVar@, @readArray@, or @deRefWeak@.
|
|
| 43 | +-- Conversely, we do not peek inside closures whose internals are not
|
|
| 44 | +-- observable from Haskell, such as function closures and their captured free
|
|
| 45 | +-- variables.
|
|
| 46 | +--
|
|
| 47 | +-- Like any deep evaluation, it may not terminate on cyclic structures.
|
|
| 48 | +forceIO :: a -> IO (Bool, a)
|
|
| 49 | +forceIO a = stToIO (forceST a)
|
|
| 50 | + |
|
| 51 | +-- | Deeply evaluate a value in the strict 'ST' monad.
|
|
| 52 | +forceST :: a -> ST s (Bool, a)
|
|
| 53 | +forceST a = ST $ \s0 -> case deepseq# a s0 of
|
|
| 54 | + (# s1, flag#, a' #) -> (# s1, (isTrue# flag#, a') #)
|
|
| 55 | + |
|
| 56 | +foreign import prim "stg_deepseqzh" deepseqzh# :: Any -> State# s -> (# State# s, Int#, Any #)
|
|
| 57 | + |
|
| 58 | +deepseq# :: a -> State# s -> (# State# s, Int#, a #)
|
|
| 59 | +deepseq# x s0 =
|
|
| 60 | + case deepseqzh# (unsafeCoerce# x) s0 of
|
|
| 61 | + (# s1, flag#, x' #) -> (# s1, flag#, unsafeCoerce# x' #) |
| ... | ... | @@ -4454,6 +4454,12 @@ module Data.Tuple.Experimental where |
| 4454 | 4454 | data Unit# = ...
|
| 4455 | 4455 | getSolo :: forall a. Solo a -> a
|
| 4456 | 4456 | |
| 4457 | +module GHC.DeepSeq where
|
|
| 4458 | + -- Safety: None
|
|
| 4459 | + force :: forall a. a -> (GHC.Internal.Types.Bool, a)
|
|
| 4460 | + forceIO :: forall a. a -> GHC.Internal.Types.IO (GHC.Internal.Types.Bool, a)
|
|
| 4461 | + forceST :: forall a s. a -> GHC.Internal.ST.ST s (GHC.Internal.Types.Bool, a)
|
|
| 4462 | + |
|
| 4457 | 4463 | module GHC.PrimOps where
|
| 4458 | 4464 | -- Safety: Unsafe
|
| 4459 | 4465 | (*#) :: Int# -> Int# -> Int#
|
| 1 | +module Main (main) where
|
|
| 2 | + |
|
| 3 | +import Control.Concurrent.MVar (MVar, newEmptyMVar, putMVar)
|
|
| 4 | +import Control.Concurrent.STM (TVar, newTVarIO)
|
|
| 5 | +import Control.Exception (SomeException, evaluate, try)
|
|
| 6 | +import Data.Array (Array, listArray)
|
|
| 7 | +import Data.Array.IO (IOArray, newArray)
|
|
| 8 | +import Data.IORef (IORef, newIORef)
|
|
| 9 | +import GHC.DeepSeq (force, forceIO, forceST)
|
|
| 10 | +import GHC.Compact (compactWithSharing, getCompact)
|
|
| 11 | +import GHC.ST (runST)
|
|
| 12 | +import System.Mem.Weak (mkWeak)
|
|
| 13 | +import System.Timeout (timeout)
|
|
| 14 | + |
|
| 15 | +deepEvaluate :: a -> IO a
|
|
| 16 | +deepEvaluate a = do
|
|
| 17 | + (_, a') <- forceIO a
|
|
| 18 | + pure a'
|
|
| 19 | + |
|
| 20 | +deepEvaluateWithFlag :: a -> IO (Bool, a)
|
|
| 21 | +deepEvaluateWithFlag = forceIO
|
|
| 22 | + |
|
| 23 | +mkThunk :: Int -> Int
|
|
| 24 | +mkThunk x = x + 1
|
|
| 25 | +{-# NOINLINE mkThunk #-}
|
|
| 26 | + |
|
| 27 | +boomVal :: Int
|
|
| 28 | +boomVal = error "boom"
|
|
| 29 | +{-# NOINLINE boomVal #-}
|
|
| 30 | + |
|
| 31 | +funVal :: Int -> Int
|
|
| 32 | +funVal _ = boomVal
|
|
| 33 | +{-# NOINLINE funVal #-}
|
|
| 34 | + |
|
| 35 | +main :: IO ()
|
|
| 36 | +main = do
|
|
| 37 | + r1 <- try (deepEvaluate (1 :: Int, error "boom") >> pure ()) :: IO (Either SomeException ())
|
|
| 38 | + case r1 of
|
|
| 39 | + Left _ -> putStrLn "thunk-forced"
|
|
| 40 | + Right _ -> putStrLn "unexpected-no-exn"
|
|
| 41 | + |
|
| 42 | + r2 <- try (deepEvaluate funVal) :: IO (Either SomeException (Int -> Int))
|
|
| 43 | + case r2 of
|
|
| 44 | + Left _ -> putStrLn "unexpected-exn"
|
|
| 45 | + Right _ -> putStrLn "fun-ok"
|
|
| 46 | + |
|
| 47 | + (forced2, ()) <- deepEvaluateWithFlag ()
|
|
| 48 | + if not forced2
|
|
| 49 | + then putStrLn "noforce-ok"
|
|
| 50 | + else putStrLn "noforce-bad"
|
|
| 51 | + |
|
| 52 | + x <- evaluate (42 :: Int)
|
|
| 53 | + (forced2b, _) <- deepEvaluateWithFlag x
|
|
| 54 | + if not forced2b
|
|
| 55 | + then putStrLn "noforce-int-ok"
|
|
| 56 | + else putStrLn "noforce-int-bad"
|
|
| 57 | + |
|
| 58 | + let (forced2c, _) = force x
|
|
| 59 | + if not forced2c
|
|
| 60 | + then putStrLn "force-int-ok"
|
|
| 61 | + else putStrLn "force-int-bad"
|
|
| 62 | + |
|
| 63 | + let (forced2d, _) = runST (forceST x)
|
|
| 64 | + if not forced2d
|
|
| 65 | + then putStrLn "forcest-int-ok"
|
|
| 66 | + else putStrLn "forcest-int-bad"
|
|
| 67 | + |
|
| 68 | + let v = (1 :: Int, mkThunk 2)
|
|
| 69 | + (forced3, v') <- deepEvaluateWithFlag v
|
|
| 70 | + if forced3 && snd v' == 3
|
|
| 71 | + then putStrLn "thunk-ok"
|
|
| 72 | + else putStrLn "unexpected"
|
|
| 73 | + |
|
| 74 | + let arr :: Array Int Int
|
|
| 75 | + arr = listArray (0, 0) [boomVal]
|
|
| 76 | + r3 <- try (deepEvaluate arr >> pure ()) :: IO (Either SomeException ())
|
|
| 77 | + case r3 of
|
|
| 78 | + Left _ -> putStrLn "array-thunk-forced"
|
|
| 79 | + Right _ -> putStrLn "array-unforced"
|
|
| 80 | + |
|
| 81 | + ioArr <- newArray (0, 0) boomVal :: IO (IOArray Int Int)
|
|
| 82 | + r4 <- try (deepEvaluate ioArr >> pure ()) :: IO (Either SomeException ())
|
|
| 83 | + case r4 of
|
|
| 84 | + Left _ -> putStrLn "ioarray-thunk-forced"
|
|
| 85 | + Right _ -> putStrLn "ioarray-unforced"
|
|
| 86 | + |
|
| 87 | + ref <- newIORef boomVal :: IO (IORef Int)
|
|
| 88 | + r5 <- try (deepEvaluate ref >> pure ()) :: IO (Either SomeException ())
|
|
| 89 | + case r5 of
|
|
| 90 | + Left _ -> putStrLn "ioref-thunk-forced"
|
|
| 91 | + Right _ -> putStrLn "ioref-unforced"
|
|
| 92 | + |
|
| 93 | + mvar <- newEmptyMVar :: IO (MVar Int)
|
|
| 94 | + putMVar mvar boomVal
|
|
| 95 | + r6 <- try (deepEvaluate mvar >> pure ()) :: IO (Either SomeException ())
|
|
| 96 | + case r6 of
|
|
| 97 | + Left _ -> putStrLn "mvar-thunk-forced"
|
|
| 98 | + Right _ -> putStrLn "mvar-unforced"
|
|
| 99 | + |
|
| 100 | + tvar <- newTVarIO boomVal :: IO (TVar Int)
|
|
| 101 | + r6b <- try (deepEvaluate tvar >> pure ()) :: IO (Either SomeException ())
|
|
| 102 | + case r6b of
|
|
| 103 | + Left _ -> putStrLn "tvar-thunk-forced"
|
|
| 104 | + Right _ -> putStrLn "tvar-unforced"
|
|
| 105 | + |
|
| 106 | + keyRef <- newIORef ()
|
|
| 107 | + weak <- mkWeak keyRef boomVal Nothing
|
|
| 108 | + r7 <- try (deepEvaluate weak >> pure ()) :: IO (Either SomeException ())
|
|
| 109 | + case r7 of
|
|
| 110 | + Left _ -> putStrLn "weak-thunk-forced"
|
|
| 111 | + Right _ -> putStrLn "weak-unforced"
|
|
| 112 | + |
|
| 113 | + let cyclic :: [Int]
|
|
| 114 | + cyclic = let xs = 1 : xs in xs
|
|
| 115 | + compacted <- compactWithSharing cyclic
|
|
| 116 | + let cyclic' = getCompact compacted
|
|
| 117 | + _ <- evaluate cyclic'
|
|
| 118 | + r8 <- timeout 2000000 (deepEvaluateWithFlag cyclic')
|
|
| 119 | + case r8 of
|
|
| 120 | + Nothing -> putStrLn "compact-loop-timeout"
|
|
| 121 | + Just _ -> putStrLn "compact-loop-ok" |
| 1 | +thunk-forced
|
|
| 2 | +fun-ok
|
|
| 3 | +noforce-ok
|
|
| 4 | +noforce-int-ok
|
|
| 5 | +force-int-ok
|
|
| 6 | +forcest-int-ok
|
|
| 7 | +thunk-ok
|
|
| 8 | +array-thunk-forced
|
|
| 9 | +ioarray-thunk-forced
|
|
| 10 | +ioref-thunk-forced
|
|
| 11 | +mvar-thunk-forced
|
|
| 12 | +tvar-thunk-forced
|
|
| 13 | +weak-thunk-forced
|
|
| 14 | +compact-loop-ok |
| ... | ... | @@ -17,6 +17,7 @@ test('T13825-compile', normal, compile_and_run, ['']) |
| 17 | 17 | test('T16164', normal, compile_and_run, [''])
|
| 18 | 18 | test('ShowPrim', normal, compile_and_run, [''])
|
| 19 | 19 | test('T12492', normal, compile_and_run, [''])
|
| 20 | +test('DeepSeqPrimOp', [js_skip, extra_ways(['ghci','ghci-opt']), extra_hc_opts('-package ghc-experimental -package ghc-compact')], compile_and_run, [''])
|
|
| 20 | 21 | |
| 21 | 22 | test('ArithInt8', normal, compile_and_run, [''])
|
| 22 | 23 | test('ArithWord8', normal, compile_and_run, [''])
|