Skip to content
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

Garbage collection happens too early with GHCJS #109

Closed
HeinrichApfelmus opened this issue Oct 7, 2015 · 7 comments

Comments

@HeinrichApfelmus
Copy link
Owner

commented Oct 7, 2015

Currently, GHCJS deviates from the official semantics for weak pointers. Unfortunately, this means that even simple programs that use reactive-banana will not work when compiled with GHCJS.

The ghcjs branch contains an experimental workaround. I currently don't have GHCJS installed, so I have to rely on your feedback. Does commit 211e221 help?

@HeinrichApfelmus

This comment has been minimized.

Copy link
Owner Author

commented Oct 10, 2015

Any luck with commit 5a53683 ?

@luite

This comment has been minimized.

Copy link

commented Oct 27, 2015

I've implemented the semantics to follow those of GHC more accurately, and I've added some tests to the GHCJS testsuite. Do you have a simple (non-interactive, runs in terminal with node.js) example that shows different behaviour with GHCJS? Ideal would be a testcase with thinks like threadDelay and forkIO that prints some results to stdout.

@HeinrichApfelmus

This comment has been minimized.

Copy link
Owner Author

commented Oct 28, 2015

The following example (using the 1.0 API) by Oliver Charles will print consecutive numbers until garbage collection happens, then it will print the same number over and over. It runs in the main thread.

import Reactive.Banana
import Reactive.Banana.Frameworks

main :: IO ()
main = do
    (ah,tick) <- newAddHandler
    network   <- compile $ do
        etick <- fromAddHandler ah
        e     <- accumE 0 (succ <$ etick)
        reactimate $ print <$> e
    actuate network
    mapM_ tick [1..]

Is this what you are looking for?

@luite

This comment has been minimized.

Copy link

commented Oct 28, 2015

Yes. So this example used to give problems?

It appears to do the correct thing with GHCJS master, with reactive-banana compiled from the master branch.

@HeinrichApfelmus

This comment has been minimized.

Copy link
Owner Author

commented Oct 28, 2015

This program used to give problems, indeed. Assuming that garbage collection has happened in your tests, and the program still prints a list of consecutive numbers (instead of always the same number), then it looks like everything is working now.

Thanks Luite!

@luite

This comment has been minimized.

Copy link

commented Oct 28, 2015

Yep, I tested with -DGHCJS_TRACE_GC to verify that GC was indeed happening.

There's a test in the testsuite now to verify the basic weak ref semantics: rts/weak/weak001.hs, but test coverage could still be better. Please report any remaining programs where GHCJS doesn't appear to behave correctly, if you find them. Thanks!

@HeinrichApfelmus

This comment has been minimized.

Copy link
Owner Author

commented Oct 28, 2015

Awesome! I'll report anything that comes up. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.