Weak.get_copy: copying continuations is unsafe, so don't copy them. - #14988
Weak.get_copy: copying continuations is unsafe, so don't copy them.#14988yallop wants to merge 3 commits into
Conversation
9a56697 to
cf93695
Compare
smuenzel
left a comment
There was a problem hiding this comment.
Copying continuations definitely elides the checks that are built into caml_continuation_use, so preventing copies is a good fix.
|
Seems worth putting the repro in the testsuite? |
|
This is definitely an improvement and we should merge it. However, since there are many other problems with |
FWIW I would be in favor of removing it. I have been bitten a few times by |
|
My understanding is that the main performance argument for This was inefficient, and was fixed 18 years ago, along with other perf bugs in that era's Unfortunately, two years prior to that a hashconsing library was published that became reasonably widely used and got copied into various projects. That library copypasted the old, slow weak hashtable implementation from 2006-era The current release of that library has switched to using |
It's not generally safe to copy continuations. However,
Weak.get_copyshallow-duplicates continuations, which can lead to program crashes. Here's an example program:Running the program produces a segmentation fault.
The problem (identified with Claude's help): duplicating the continuation produces two continuations that share the same fiber, and the mechanism intended to prevent re-execution (setting the fiber to null after execution) only affects one of them. In the example program, the first call to
continuereturns toperform A, and the program then advances toperform B, then the second call tocontinuepasses a unit value back to theperform Bcall, which expects a string.The fix is to treat continuations like custom values in
Weak.get_copy, and not duplicate them.