diff options
author | Andrew Martin <andrew.thaddeus@gmail.com> | 2019-08-19 08:18:19 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-10-26 05:19:38 -0400 |
commit | 8916e64e5437c99b82d5610286430328af1d86bc (patch) | |
tree | 3c9f00fbed65cb725b57acb0ee7b83d776475a89 /includes | |
parent | acedfc8b8706a92127c96f487e3e3b1636451704 (diff) | |
download | haskell-8916e64e5437c99b82d5610286430328af1d86bc.tar.gz |
Implement shrinkSmallMutableArray# and resizeSmallMutableArray#.
This is a part of GHC Proposal #25: "Offer more array resizing primitives".
Resources related to the proposal:
- Discussion: https://github.com/ghc-proposals/ghc-proposals/pull/121
- Proposal: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0025-resize-boxed.rst
Only shrinkSmallMutableArray# is implemented as a primop since a
library-space implementation of resizeSmallMutableArray# (in GHC.Exts)
is no less efficient than a primop would be. This may be replaced by
a primop in the future if someone devises a strategy for growing
arrays in-place. The library-space implementation always copies the
array when growing it.
This commit also tweaks the documentation of the deprecated
sizeofMutableByteArray#, removing the mention of concurrency. That
primop is unsound even in single-threaded applications. Additionally,
the non-negativity assertion on the existing shrinkMutableByteArray#
primop has been removed since this predicate is trivially always true.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/rts/storage/ClosureMacros.h | 13 | ||||
-rw-r--r-- | includes/stg/MiscClosures.h | 1 |
2 files changed, 11 insertions, 3 deletions
diff --git a/includes/rts/storage/ClosureMacros.h b/includes/rts/storage/ClosureMacros.h index 2af50863d0..b5ae2dafc6 100644 --- a/includes/rts/storage/ClosureMacros.h +++ b/includes/rts/storage/ClosureMacros.h @@ -573,13 +573,20 @@ EXTERN_INLINE void overwritingClosure (StgClosure *p) // be less than or equal to closure_sizeW(p), and usually at least as // large as the respective thunk header. // -// Note: As this calls LDV_recordDead() you have to call LDV_RECORD() +// Note: As this calls LDV_recordDead() you have to call LDV_RECORD_CREATE() // on the final state of the closure at the call-site EXTERN_INLINE void overwritingClosureOfs (StgClosure *p, uint32_t offset); EXTERN_INLINE void overwritingClosureOfs (StgClosure *p, uint32_t offset) { - // Set prim = true because only called on ARR_WORDS with the - // shrinkMutableByteArray# primop + // Set prim = true because overwritingClosureOfs is only + // ever called by + // shrinkMutableByteArray# (ARR_WORDS) + // shrinkSmallMutableArray# (SMALL_MUT_ARR_PTRS) + // This causes LDV_recordDead to be invoked. We want this + // to happen because the implementations of the above + // primops both call LDV_RECORD_CREATE after calling this, + // effectively replacing the LDV closure biography. + // See Note [LDV Profiling when Shrinking Arrays] overwritingClosure_(p, offset, closure_sizeW(p), true); } diff --git a/includes/stg/MiscClosures.h b/includes/stg/MiscClosures.h index 7a2ac2ef51..5b2364407f 100644 --- a/includes/stg/MiscClosures.h +++ b/includes/stg/MiscClosures.h @@ -367,6 +367,7 @@ RTS_FUN_DECL(stg_isByteArrayPinnedzh); RTS_FUN_DECL(stg_isMutableByteArrayPinnedzh); RTS_FUN_DECL(stg_shrinkMutableByteArrayzh); RTS_FUN_DECL(stg_resizzeMutableByteArrayzh); +RTS_FUN_DECL(stg_shrinkSmallMutableArrayzh); RTS_FUN_DECL(stg_casIntArrayzh); RTS_FUN_DECL(stg_newArrayzh); RTS_FUN_DECL(stg_newArrayArrayzh); |