-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid boxing arrays (#230 rebased) #375
Conversation
Let's make sure this works decently with recent GHC. Some things have gotten harder. Sigh |
#if MIN_VERSION_base(4,9,0) | ||
-- GHC can't unbox across the runRW# boundary, so we apply the Array constructor | ||
-- on the outside. | ||
run (ST act) = | ||
case runRW# $ \s -> | ||
case act s of { (# s', MArray mary #) -> | ||
unsafeFreezeSmallArray# mary s' } of | ||
(# _, ary #) -> Array ary | ||
#else | ||
run act = runST (act >>= unsafeFreeze) | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like what I've seen so far in the Core. The only inner I probably won't bother to look at Core diffs across GHC versions, so if you're suspecting that some things that this patch used to do don't work anymore with recent GHCs, you'll have to figure this out yourself. |
Previously, we used a lot of things that looked like runST (act >>= unsafeFreeze) The trouble is that GHC can't unbox past the `runRW#` primitive that `runST` is based on. So this actually allocates an `Array` constructor which we will then throw away immediately. The way to avoid this is to call `runRW#` manually to produce a raw `SmallArray#`, then apply the `Array` constructor on the outside.
5636f09
to
adbf88e
Compare
Previously, we used a lot of things that looked like
The trouble is that GHC can't unbox past the
runRW#
primitivethat
runST
is based on. So this actually allocates anArray
constructor which we will then throw away immediately.
The way to avoid this is to call
runRW#
manually to producea raw
SmallArray#
, then apply theArray
constructor on theoutside.