You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mpickering> bgamari: Should it be possible to evaluate a thunk using ghc-debug?
5:13 PM <bgamari> Nope
5:13 PM <mpickering> I mean if you unpause
5:13 PM <bgamari> there's no safe way to do this
5:13 PM <mpickering> and repause
5:13 PM <bgamari> ahh
5:13 PM <bgamari> hmm
5:13 PM <bgamari> a good question
5:13 PM <bgamari> I suppose you could spawn a thread to run `evaluate x >> pause`
5:13 PM <bgamari> that would be pretty neat
5:13 PM <mpickering> it seems like it should be possible, and you can implement a "force" request which increases the "pause window" by one and returns the address of the newly evaluated thing
5:14 PM <mpickering> How does the ghci forcing command work?
5:14 PM <bgamari> I would just implement it with an MVar
5:14 PM <mpickering> I want to integrate my rewrite of ghc-vis into ghc-debug somehow you see
5:15 PM <bgamari> forceAndPause :: MVar a -> a -> IO ()
5:15 PM <bgamari> provided in the stub's haskell implementation
5:15 PM <mpickering> Well I'm imagining that you have a GenClosure which happens to be a thunk, and the address of that closure
5:15 PM <mpickering> then you send a message to the RTS to unpause, evaluate the closure, pause again
5:15 PM <bgamari> right
5:16 PM <bgamari> so the stub C implementation would provide a message
5:16 PM <bgamari> which takes a ClosurePtr
5:16 PM <mpickering> because ghc-vis supports this where you click on a thunk and it evaluates
5:16 PM <bgamari> calls forceAndPause on it
5:16 PM <bgamari> and then returns the result
5:16 PM <mpickering> so `forceAndPause` should take a `ClosurePtr` as an argument rather than `a`?
5:17 PM <bgamari> the Message payload should be a ClosurePtr
5:18 PM <bgamari> forceAndPause provided by the Haskell bit should be polymorphic
5:18 PM <bgamari> it would be implemented as
5:19 PM → mdunnio joined ([email protected])
5:19 PM <bgamari> forceAndPause resultVar x = do handleAny (pure . Left) (evaluate x) >>= putMVar resultVar
5:19 PM <bgamari> forceAndPause resultVar x = do handleAny (pure . Left) (fmap Right $ evaluate x) >>= putMVar resultVar
5:19 PM <mpickering> Another thing to think about is that you don't want to actually unpause? because then other computation will happen as well
5:19 PM <bgamari> forceAndPause :: MVar (Either SomeException a) -> a -> IO ()
5:20 PM <bgamari> mpickering, I don't think there is much you can do about that
5:20 PM <bgamari> mpickering, the RTS doesn't really provide any control over scheduling
5:20 PM <mpickering> ok
5:20 PM <bgamari> and indeed it can't
5:20 PM <bgamari> since what if the thunk was unsafePerformIO $ takeMVar someVar
5:20 PM <bgamari> if you forbid any other threads to run then you would deadlock
5:21 PM <bgamari> but the GC would have no way of knowing since someVar is still alive
5:21 PM <mpickering> I suppose it's fine if you pause at a point where the main thread is idle, say, pause >> threadDelay 1000000000
5:21 PM <bgamari> right
5:21 PM <bgamari> mpickering, this is how gdb works as well
5:21 PM <bgamari> if you `print f(x)`
5:22 PM <bgamari> all OS threads other than the one you are looking at will run for a bit while the evaluation occursa
5:22 PM <bgamari> due to limitations in how ptrace works IIRC
5:22 PM <mpickering> ok
5:22 PM <mpickering> seems possible to implement this then
5:22 PM <bgamari> indeed
5:23 PM <mpickering> if you can do this you can answer questions about space usage before/after forcing
5:23 PM <bgamari> sounds like a neat feature
5:23 PM <bgamari> true
5:23 PM <mpickering> which sounds like something you would have found useful recentl
5:23 PM <bgamari> you might also expose a command to force a major GC
5:24 PM <mpickering> as a request?
5:24 PM <mpickering> right now I just do a major gc before pausing
5:24 PM → dennisb joined ([email protected])
5:27 PM <isovector1> i'm trying to solve a stuck tyfam. emitting a wanted `CNonCanonical` of the form `MyTyFam a b c ~ result` works on its own, but won't reduce other families that are stuck on the result of `MyTyFam a b c`
5:31 PM ⇐ mdunnio quit ↔ luke-jr nipped out
5:38 PM <bgamari> mpickering, that also works
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: