Files
Liam Murphy 88f8917efb Fix Rust values getting GC'd while still borrowed and not getting GC'd if created via. constructor (#3940)
* Add a failing test

* Force tests to run sequentially

At first I tried fixing them so that they didn't need to (giving each of them
their own `dropCount`), but running multiple GCs in parallel seems to be flaky.

* Add objects created via. constructors to the FinalizationRegistry

* Add a failing test

* Fix exported Rust types being GC'd while still borrowed

I also discovered and fixed an extra bug while working on this, which
was that `LongRefFromWasmAbi` wasn't getting used for `self`: this bug
didn't cause any problems before, because the only type that had a
different `LongRefFromWasmAbi` impl than its `RefFromWasmAbi` impl was
`JsValue` which can't be the type of `self`.

It became a problem here because I made the new `LongRefFromWasmAbi`
impl for exported Rust types clone the `Rc`, whereas the
`RefFromWasmAbi` impl doesn't because garbage collection can't occur
during the synchronous call that the value has to live for.

I might actually change it so that both of the impls behave like the
current `LongRefFromWasmAbi` impl, though: cloning an `Rc` isn't
expensive and so having the second different impl just makes things more
complicated for no good reason. I just left it in this commit as
explanation for how I discovered the `LongRefFromWasmAbi` issue.

* Unify RefFromWasmAbi and LongRefFromWasmAbi impls

* Get rid of needless looping

* Get rid of outdated `borrow_mut`

Now that borrowing a Rust value always clones its `Rc`, `Rc::into_inner`
is a sufficient check that the value isn't borrowed.

* Get rid of needless `mut`

For some reason I was getting errors before without it, but that seems
to be fixed now. (It's probably something to do with having removed the
`borrow_mut`, but that only takes `&self`, so I still don't get it.)

* Update reference tests

* Add changelog entry

* Update schema hash

* Use Rc::try_unwrap instead of Rc::into_inner

* Skip GC tests

They seem to be far flakier in CI than locally for some reason, and I
don't see any way to solve it; so just turn them off. :(

I also got rid of the weird GC warmup hack because it doesn't do
anything anymore; I could've sworn it was a reproducible effect before,
but it seems to make no difference now.
2024-06-01 22:18:14 +10:00
..
2024-03-04 11:25:46 +01:00