on develop help sign in
Merge pull request #409 from reflex-frp/ts-fix-fastweakticket-fusion

Add NOINLINE pragma to mkFastWeakTicket

commit77e79c40077b927e346ed1089ca81ae0aa4fee91 authorElliot Cameron <3noch@users.noreply.github.com> dateTue 31 Mar 2020, 10:04 (7 years ago) parent2f5f87a5953c23
2 files changed+10−10
src/Reflex/FastWeak.hs+10 src/Reflex/Spider/Internal.hs−10
src/Reflex/FastWeak.hs+10
@@ -151,6 +151,16 @@ getFastWeakTicket w = do
151151
152152-- | Create a 'FastWeakTicket' directly from a value, creating a 'FastWeak' in the process
153153-- which can be obtained with 'getFastWeakTicketValue'.
154+--
155+-- This function is marked NOINLINE so it is opaque to GHC.
156+-- If we do not do this, then GHC will sometimes fuse the constructor away
157+-- so any weak references that are attached to the ticket will have their
158+-- finalizer run. Using the opaque constructor, GHC does not see the
159+-- constructor application, so it behaves like an IORef and cannot be fused away.
160+--
161+-- The result is also evaluated to WHNF, since forcing a thunk invalidates
162+-- the weak pointer to it in some cases.
163+{-# NOINLINE mkFastWeakTicket #-}
154164mkFastWeakTicket :: a -> IO (FastWeakTicket a)
155165-- I think it's fine if this is lazy - it'll retain the 'a', but so would the output; we just need to make sure it's forced before we start relying on the
156166-- associated FastWeak to actually be weak
src/Reflex/Spider/Internal.hs−10
@@ -450,16 +450,6 @@ data Subscriber x a = Subscriber
450450 , subscriberRecalculateHeight :: !(Height -> IO ())
451451 }
452452
453−--TODO: Move this comment to WeakBag
454−-- These function are constructor functions that are marked NOINLINE so they are
455−-- opaque to GHC. If we do not do this, then GHC will sometimes fuse the constructor away
456−-- so any weak references that are attached to the constructors will have their
457−-- finalizer run. Using the opaque constructor, does not see the
458−-- constructor application, so it behaves like an IORef and cannot be fused away.
459−--
460−-- The result is also evaluated to WHNF, since forcing a thunk invalidates
461−-- the weak pointer to it in some cases.
462−
463453newSubscriberHold :: (HasSpiderTimeline x, Patch p) => Hold x p -> IO (Subscriber x p)
464454newSubscriberHold h = return $ Subscriber
465455 { subscriberPropagate = {-# SCC "traverseHold" #-} propagateSubscriberHold h