
#14375: Implement with# primop -------------------------------------+------------------------------------- Reporter: simonpj | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.8.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: JoinPoints Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #14346 | Differential Rev(s): ​Phab:D4110, Wiki Page: | Phab:D4189 -------------------------------------+------------------------------------- Comment (by tdammers): Updated Phab:D4110 with the original patch rebased onto master. Also added two tests. The first one, `T14375`, is a slightly modified version of the small test case from comment:14:ticket:14346; the original reproduction case is unsuitable for testsuite use due to the crucially important use of `forever`, but by throwing an exception, we can stop execution while still tricking the optimizer into considering the code after `forever` unreachable. I have verified that this test fails on GHC 8.2 and passes after this patch. However, due to other changes in the meantime, it also passes on GHC versions just before the patch, even when we disable the obvious suspect (`NOINLINE` pragmas on the `alloca...` functions, the previous workaround), so there must be yet something else going on. The second test case, `T14375-2`, was suggested by bgamari in a private chat. The idea is to verify the correct operation of the new `with#` primop by using it on a binding that is also the key of a weak pointer, using its finalizer to attach observable behavior to its deallocation. This way, we can tell from the test output whether the finalizer runs before or after the end of the block wrapped in `with#`. Unfortunately, finalizers are somewhat unpredictable creatures, and so the test case is somewhat brittle - in order to actually see the finalizer running, the test has to be compiled unoptimized, and the `threadDelay` calls in strategic locations are needed to trigger GC. Obviously, since we're using the new `with#` primop directly in this second test, it is impossible to verify that it fixes anything; it just tells us that `with#` behaves as expected in this case. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14375#comment:22 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler