on develop help sign in
Some more random cleanups
commit677ce27c827c1a4f8370c79e24d01e4e32ca52f8 authorRyan Trinkle <ryan.trinkle@gmail.com> dateFri 20 Sep 2019, 19:49 (7 years ago) parente39c56c
4 files changed+24−22
reflex.cabal+5 src/Reflex/Class.hs+16−13 src/Reflex/PerformEvent/Base.hs+3−3 src/Reflex/Requester/Base/Internal.hs−6
reflex.cabal+5
@@ -144,6 +144,7 @@ library
144144 Reflex.Workflow
145145
146146 ghc-options: -Wall -fwarn-redundant-constraints -fwarn-tabs -funbox-strict-fields -O2 -fspecialise-aggressively
147+ ghc-prof-options: -fprof-auto-calls
147148
148149 if flag(debug-trace-events)
149150 cpp-options: -DDEBUG_TRACE_EVENTS
@@ -179,6 +180,7 @@ test-suite semantics
179180 main-is: semantics.hs
180181 hs-source-dirs: test
181182 ghc-options: -O2 -Wall -rtsopts
183+ ghc-prof-options: -fprof-auto-calls
182184 build-depends:
183185 base,
184186 bifunctors,
@@ -204,6 +206,7 @@ test-suite CrossImpl
204206 main-is: Reflex/Test/CrossImpl.hs
205207 hs-source-dirs: test
206208 ghc-options: -O2 -Wall -rtsopts
209+ ghc-prof-options: -fprof-auto-calls
207210 build-depends:
208211 base,
209212 containers,
@@ -356,6 +359,7 @@ benchmark spider-bench
356359 hs-source-dirs: bench test
357360 main-is: Main.hs
358361 ghc-options: -Wall -O2 -rtsopts
362+ ghc-prof-options: -fprof-auto-calls
359363 build-depends:
360364 base,
361365 containers,
@@ -381,6 +385,7 @@ benchmark saulzar-bench
381385 c-sources: bench-cbits/checkCapability.c
382386 main-is: RunAll.hs
383387 ghc-options: -Wall -O2 -rtsopts -threaded
388+ ghc-prof-options: -fprof-auto-calls
384389 build-depends:
385390 base,
386391 containers,
src/Reflex/Class.hs+16−13
@@ -944,10 +944,6 @@ unsafeMapIncremental f g a = unsafeBuildIncremental (fmap f $ sample $ currentIn
944944mergeMap :: (Reflex t, Ord k) => Map k (Event t a) -> Event t (Map k a)
945945mergeMap = fmap dmapToMap . merge . mapWithFunctorToDMap
946946
947−-- | Like 'mergeMap' but for 'IntMap'.
948−mergeIntMap :: Reflex t => IntMap (Event t a) -> Event t (IntMap a)
949−mergeIntMap = fmap dmapToIntMap . merge . intMapWithFunctorToDMap
950−
951947-- | Create a merge whose parents can change over time
952948mergeMapIncremental :: (Reflex t, Ord k) => Incremental t (PatchMap k (Event t a)) -> Event t (Map k a)
953949mergeMapIncremental = fmap dmapToMap . mergeIncremental . unsafeMapIncremental mapWithFunctorToDMap (const2PatchDMapWith id)
@@ -1032,19 +1028,19 @@ switchHoldPromptOnly e0 e' = do
10321028
10331029-- | When the given outer event fires, condense the inner events into the contained patch. Non-firing inner events will be replaced with deletions.
10341030coincidencePatchMap :: (Reflex t, Ord k) => Event t (PatchMap k (Event t v)) -> Event t (PatchMap k v)
1035−coincidencePatchMap e = fmapCheap PatchMap $ coincidence $ ffor e $ \(PatchMap m) -> mergeMap $ ffor m $ \case
1031+coincidencePatchMap e = fmapCheap PatchMap $ coincidence $ fforCheap e $ \(PatchMap m) -> mergeMap $ ffor m $ \case
10361032 Nothing -> fmapCheap (const Nothing) e
10371033 Just ev -> leftmost [fmapCheap Just ev, fmapCheap (const Nothing) e]
10381034
10391035-- | See 'coincidencePatchMap'
10401036coincidencePatchIntMap :: Reflex t => Event t (PatchIntMap (Event t v)) -> Event t (PatchIntMap v)
1041−coincidencePatchIntMap e = fmapCheap PatchIntMap $ coincidence $ ffor e $ \(PatchIntMap m) -> mergeIntMap $ ffor m $ \case
1037+coincidencePatchIntMap e = fmapCheap PatchIntMap $ coincidence $ fforCheap e $ \(PatchIntMap m) -> mergeIntMap $ ffor m $ \case
10421038 Nothing -> fmapCheap (const Nothing) e
10431039 Just ev -> leftmost [fmapCheap Just ev, fmapCheap (const Nothing) e]
10441040
10451041-- | See 'coincidencePatchMap'
10461042coincidencePatchMapWithMove :: (Reflex t, Ord k) => Event t (PatchMapWithMove k (Event t v)) -> Event t (PatchMapWithMove k v)
1047−coincidencePatchMapWithMove e = fmapCheap unsafePatchMapWithMove $ coincidence $ ffor e $ \p -> mergeMap $ ffor (unPatchMapWithMove p) $ \ni -> case PatchMapWithMove._nodeInfo_from ni of
1043+coincidencePatchMapWithMove e = fmapCheap unsafePatchMapWithMove $ coincidence $ fforCheap e $ \p -> mergeMap $ ffor (unPatchMapWithMove p) $ \ni -> case PatchMapWithMove._nodeInfo_from ni of
10481044 PatchMapWithMove.From_Delete -> fforCheap e $ \_ ->
10491045 ni { PatchMapWithMove._nodeInfo_from = PatchMapWithMove.From_Delete }
10501046 PatchMapWithMove.From_Move k -> fforCheap e $ \_ ->
@@ -1304,7 +1300,7 @@ accumMaybeMDyn
13041300 -> Event t b
13051301 -> m (Dynamic t a)
13061302accumMaybeMDyn f z e = do
1307− rec let e' = flip push e $ \o -> do
1303+ rec let e' = flip pushCheap e $ \o -> do
13081304 v <- sample $ current d'
13091305 f v o
13101306 d' <- holdDyn z e'
@@ -1360,8 +1356,8 @@ mapAccumMaybeMDyn f z e = do
13601356 return $ case result of
13611357 (Nothing, Nothing) -> Nothing
13621358 _ -> Just result
1363− d' <- holdDyn z $ mapMaybe fst e'
1364− return (d', mapMaybe snd e')
1359+ d' <- holdDyn z $ fmapMaybeCheap fst e'
1360+ return (d', fmapMaybeCheap snd e')
13651361
13661362-- | Accumulate a 'Behavior' by folding occurrences of an 'Event'
13671363-- with the provided function.
@@ -1399,7 +1395,7 @@ accumMaybeB f = accumMaybeMB $ \v o -> return $ f v o
13991395{-# INLINE accumMaybeMB #-}
14001396accumMaybeMB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Behavior t a)
14011397accumMaybeMB f z e = do
1402− rec let e' = flip push e $ \o -> do
1398+ rec let e' = flip pushCheap e $ \o -> do
14031399 v <- sample d'
14041400 f v o
14051401 d' <- hold z e'
@@ -1449,8 +1445,8 @@ mapAccumMaybeMB f z e = do
14491445 return $ case result of
14501446 (Nothing, Nothing) -> Nothing
14511447 _ -> Just result
1452− d' <- hold z $ mapMaybe fst e'
1453− return (d', mapMaybe snd e')
1448+ d' <- hold z $ fmapMaybeCheap fst e'
1449+ return (d', fmapMaybeCheap snd e')
14541450
14551451-- | Accumulate occurrences of an 'Event', producing an output occurrence each
14561452-- time. Discard the underlying 'Accumulator'.
@@ -1676,7 +1672,14 @@ mergeWithFoldCheap' f es =
16761672-- | See 'switchHoldPromptly'
16771673switchPromptly :: (Reflex t, MonadHold t m) => Event t a -> Event t (Event t a) -> m (Event t a)
16781674switchPromptly = switchHoldPromptly
1675+
16791676{-# DEPRECATED switchPromptOnly "Use 'switchHoldPromptOnly' instead. The 'switchHold*' naming convention was chosen because those functions are more closely related to each other than they are to 'switch'. " #-}
16801677-- | See 'switchHoldPromptOnly'
16811678switchPromptOnly :: (Reflex t, MonadHold t m) => Event t a -> Event t (Event t a) -> m (Event t a)
16821679switchPromptOnly = switchHoldPromptOnly
1680+
1681+{-# DEPRECATED mergeIntMap "Use 'mergeInt' instead" #-}
1682+-- | Like 'mergeMap' but for 'IntMap'.
1683+mergeIntMap :: Reflex t => IntMap (Event t a) -> Event t (IntMap a)
1684+mergeIntMap = mergeInt
1685+
src/Reflex/PerformEvent/Base.hs+3−3
@@ -110,7 +110,7 @@ instance (ReflexHost t, PrimMonad (HostFrame t)) => Adjustable t (PerformEventT
110110 requests0 = fmap snd children0
111111 results' = fmap fst <$> children'
112112 requests' = fmap snd `fmapCheap` children'
113− requests <- switchHoldPromptOnlyIncremental mergeIntIncremental coincidencePatchIntMap requests0 $ requests'
113+ requests <- switchHoldPromptOnlyIncremental mergeIntIncremental coincidencePatchIntMap requests0 requests'
114114 --TODO: promptly *prevent* events, then sign up the new ones; this is a serious breaking change to PerformEvent
115115 RequesterInternalT $ tellEvent $ fforMaybeCheap requests concatIntMapMaybe
116116 pure (results0, results')
@@ -125,7 +125,7 @@ instance (ReflexHost t, PrimMonad (HostFrame t)) => Adjustable t (PerformEventT
125125 requests0 = weakenDMapWith (fst . getCompose) children0
126126 results' = mapPatchDMap (snd . getCompose) <$> children'
127127 requests' = weakenPatchDMapWith (fst . getCompose) `fmapCheap` children'
128− requests <- switchHoldPromptOnlyIncremental mergeMapIncremental coincidencePatchMap requests0 $ requests'
128+ requests <- switchHoldPromptOnlyIncremental mergeMapIncremental coincidencePatchMap requests0 requests'
129129 --TODO: promptly *prevent* events, then sign up the new ones; this is a serious breaking change to PerformEvent
130130 RequesterInternalT $ tellEvent $ fforMaybeCheap requests concatMapMaybe
131131 pure (results0, results')
@@ -140,7 +140,7 @@ instance (ReflexHost t, PrimMonad (HostFrame t)) => Adjustable t (PerformEventT
140140 requests0 = weakenDMapWith (fst . getCompose) children0
141141 results' = mapPatchDMapWithMove (snd . getCompose) <$> children'
142142 requests' = weakenPatchDMapWithMoveWith (fst . getCompose) `fmapCheap` children'
143− requests <- switchHoldPromptOnlyIncremental mergeMapIncrementalWithMove coincidencePatchMapWithMove requests0 $ requests'
143+ requests <- switchHoldPromptOnlyIncremental mergeMapIncrementalWithMove coincidencePatchMapWithMove requests0 requests'
144144 --TODO: promptly *prevent* events, then sign up the new ones; this is a serious breaking change to PerformEvent
145145 RequesterInternalT $ tellEvent $ fforMaybeCheap requests concatMapMaybe
146146 pure (results0, results')
src/Reflex/Requester/Base/Internal.hs−6
@@ -68,12 +68,6 @@ import Data.Foldable
6868
6969import Debug.Trace
7070
71−--TODO: The use of Seq in this module could probably be replaced with something
72−--even cheaper. We do need O(1) append, but we don't need associativity until
73−--the very end, when we're smashing everything together. This could be
74−--implemented as a binary tree whose representation isn't associative, but which
75−--doesn't allow any external party to observe the lack of associativity.
76−
7771data RequestData ps request = forall s. RequestData !(TagGen ps s) !(NonEmptyDeferred (RequestEnvelope s request))
7872data ResponseData ps response = forall s. ResponseData !(TagGen ps s) !(TagMap s response)
7973