@@ -114,7 +114,13 @@ import Reflex.PerformEvent.Base (PerformEventT)
114114import qualified Data.ByteString.Char8 as BS8
115115import System.IO (stderr)
116116import Data.List (isPrefixOf)
117+#endif
118+
119+-- TODO stdout might not be the best channel for debug output
120+debugStrLn :: String -> IO ()
121+debugStrLn = putStrLn
117122
123+#ifdef DEBUG_TRACE_EVENTS
118124withStackOneLine :: (BS8.ByteString -> a) -> a
119125withStackOneLine expr = unsafePerformIO $ do
120126 stack <- currentCallStack
@@ -1299,7 +1305,7 @@ mkWeakPtrWithDebug x debugNote = do
12991305 x' <- evaluate x
13001306 mkWeakPtr x' $
13011307 if debugFinalize
1302− then Just $ putStrLn $ "finalizing: " ++ debugNote
1308+ then Just $ debugStrLn $ "finalizing: " ++ debugNote
13031309 else Nothing
13041310
13051311type WeakList a = [Weak a]
@@ -1321,13 +1327,13 @@ debugSubscriber' description subscribed = Subscriber
13211327 tracePropagate (Proxy :: Proxy x) ("subscriberPropagate: " <> description)
13221328 subscriberPropagate subscribed m
13231329 , subscriberInvalidateHeight = \old -> do
1324− putStrLn $ "invalidateSubscriberHeight: " <> description <> ", old = " <> show (unHeight old)
1330+ traceInvalidateHeight $ "invalidateSubscriberHeight: " <> description <> ", old = " <> show (unHeight old)
13251331 subscriberInvalidateHeight subscribed old
1326− putStrLn $ "invalidateSubscriberHeight: " <> description <> ", done"
1332+ traceInvalidateHeight $ "invalidateSubscriberHeight: " <> description <> ", done"
13271333 , subscriberRecalculateHeight = \new -> do
1328− putStrLn $ "subscriberRecalculateHeight: " <> description <> ", new = " <> show (unHeight new)
1334+ traceInvalidateHeight $ "subscriberRecalculateHeight: " <> description <> ", new = " <> show (unHeight new)
13291335 subscriberRecalculateHeight subscribed new
1330− putStrLn $ "subscriberRecalculateHeight: " <> description <> ", done"
1336+ traceInvalidateHeight $ "subscriberRecalculateHeight: " <> description <> ", done"
13311337 }
13321338
13331339
@@ -1341,11 +1347,15 @@ withIncreasedDepth _ a = do
13411347
13421348{-# INLINE tracePropagate #-}
13431349tracePropagate :: (CanTrace x m) => proxy x -> String -> m ()
1344−tracePropagate p = trace p
1350+tracePropagate p = when debugPropagate . trace p
13451351
13461352{-# INLINE traceInvalidate #-}
13471353traceInvalidate :: String -> IO ()
1348−traceInvalidate = liftIO . putStrLn
1354+traceInvalidate = liftIO . debugStrLn
1355+
1356+{-# INLINE traceInvalidateHeight #-}
1357+traceInvalidateHeight :: String -> IO ()
1358+traceInvalidateHeight = liftIO . debugStrLn
13491359
13501360{-# INLINE trace #-}
13511361trace :: (CanTrace x m) => proxy x -> String -> m ()
@@ -1356,7 +1366,7 @@ traceM :: forall x proxy m. (CanTrace x m) => proxy x -> m String -> m ()
13561366traceM _ getMessage = do
13571367 message <- getMessage
13581368 d <- liftIO $ readIORef $ _spiderTimeline_depth $ unSTE (spiderTimeline :: SpiderTimelineEnv x)
1359− liftIO $ putStrLn $ replicate d ' ' <> message
1369+ liftIO $ debugStrLn $ replicate d ' ' <> message
13601370
13611371#else
13621372
@@ -1372,6 +1382,10 @@ tracePropagate _ _ = return ()
13721382traceInvalidate :: String -> IO ()
13731383traceInvalidate _ = return ()
13741384
1385+{-# INLINE traceInvalidateHeight #-}
1386+traceInvalidateHeight :: String -> IO ()
1387+traceInvalidateHeight _ = return ()
1388+
13751389{-# INLINE debugSubscriber #-}
13761390debugSubscriber :: String -> Subscriber x a -> IO (Subscriber x a)
13771391debugSubscriber _ = return
@@ -2327,7 +2341,7 @@ runFrame a = SpiderHost $ do
23272341 subscription <- unSpiderHost $ runFrame $ {-# SCC "subscribeSwitch" #-} subscribe e sub --TODO: Assert that the event isn't firing --TODO: This should not loop because none of the events should be firing, but still, it is inefficient
23282342 {-
23292343 stackTrace <- liftIO $ fmap renderStack $ ccsToStrings =<< (getCCSOf $! switchSubscribedParent subscribed)
2330− liftIO $ putStrLn $ (++stackTrace) $ "subd' subscribed to " ++ case e of
2344+ liftIO $ debugStrLn $ (++stackTrace) $ "subd' subscribed to " ++ case e of
23312345 EventRoot _ -> "EventRoot"
23322346 EventNever -> "EventNever"
23332347 _ -> "something else"