Skip to content

[26488] Implement Droppable struct for gpubuffer - #36897

Closed
willypuzzle wants to merge 1 commit into
servo:mainfrom
willypuzzle:26488-Drop-impls-for-DOM-types-should-be-forbidden-gpubuffer-2
Closed

willypuzzle wants to merge 1 commit into
servo:mainfrom
willypuzzle:26488-Drop-impls-for-DOM-types-should-be-forbidden-gpubuffer-2

Conversation

@willypuzzle

Copy link
Copy Markdown
Contributor

Implemented Droppable struct for GPUBuffer in order to accomplish incremental satisfatcion of #26488

Testing: The code is just covered by tests
Fixes (partially): #26488

@willypuzzle
willypuzzle requested a review from gterzian as a code owner May 7, 2025 15:54
@sagudev

sagudev commented May 7, 2025

Copy link
Copy Markdown
Member

Just heads up that default wpt run does not cover webgpu tests. We have special webgpu label/preset for it.

@willypuzzle
willypuzzle force-pushed the 26488-Drop-impls-for-DOM-types-should-be-forbidden-gpubuffer-2 branch from 82e90d3 to 9ab53bf Compare May 7, 2025 21:23
@jdm

jdm commented May 7, 2025

Copy link
Copy Markdown
Member

I haven't looked at this carefully yet, but the use of the Promise in the code that runs in the drop implementation is a problem, since that uses the JS engine. We need to figure out what to do about that.

@willypuzzle
willypuzzle force-pushed the 26488-Drop-impls-for-DOM-types-should-be-forbidden-gpubuffer-2 branch 2 times, most recently from 9fa13a0 to c31ef97 Compare May 8, 2025 08:29
Signed-off-by: Domenico Rizzo <[email protected]>

Corrected member access

Signed-off-by: Domenico Rizzo <[email protected]>

removing unwanted macro

Signed-off-by: Domenico Rizzo <[email protected]>

Corrected methods' name

Signed-off-by: Domenico Rizzo <[email protected]>

applied mach fmt

Signed-off-by: Domenico Rizzo <[email protected]>
@willypuzzle
willypuzzle force-pushed the 26488-Drop-impls-for-DOM-types-should-be-forbidden-gpubuffer-2 branch from c31ef97 to 627834f Compare May 8, 2025 08:51
@willypuzzle

willypuzzle commented May 8, 2025 •

Copy link
Copy Markdown
Contributor Author

I haven't looked at this carefully yet, but the use of the Promise in the code that runs in the drop implementation is a problem, since that uses the JS engine. We need to figure out what to do about that.

@jdm the tests passed, tough.

@jdm

jdm commented May 8, 2025

Copy link
Copy Markdown
Member

@willypuzzle The problem these changes are trying to solve only appears intermittently. The risk is that when the GPUBuffer is garbage collected and runs it's Drop code, the Promise object has already been garbage collected and will trigger a crash. This can happen when shutting down the JS engine while closing a tab.

@willypuzzle

willypuzzle commented May 8, 2025 •

Copy link
Copy Markdown
Contributor Author

@willypuzzle The problem these changes are trying to solve only appears intermittently. The risk is that when the GPUBuffer is garbage collected and runs it's Drop code, the Promise object has already been garbage collected and will trigger a crash. This can happen when shutting down the JS engine while closing a tab.

@jdm could any solution exist?

@willypuzzle

Copy link
Copy Markdown
Contributor Author

@jdm maybe we can check if the promise has been just garbage collected and, in case, doing nothing.

@jdm

jdm commented May 10, 2025

Copy link
Copy Markdown
Member

@jdm maybe we can check if the promise has been just garbage collected and, in case, doing nothing.

Unfortunately I don't yet know how to do this. Unlike other DOM objects that Servo implements, Promises are implemented in the JS engine and I don't know of a way to learn when a particular promise has been GCed.

@willypuzzle

Copy link
Copy Markdown
Contributor Author

Unfortunately I don't yet know how to do this. Unlike other DOM objects that Servo implements, Promises are implemented in the JS engine and I don't know of a way to learn when a particular promise has been GCed.

@jdm so should we give up the task? 😔

@jdm

jdm commented May 10, 2025

Copy link
Copy Markdown
Member

Unfortunately I don't yet know how to do this. Unlike other DOM objects that Servo implements, Promises are implemented in the JS engine and I don't know of a way to learn when a particular promise has been GCed.

@jdm so should we give up the task? 😔

I suggest leaving this PR for now and working on other structs that implement Drop while we figure out what to do here.

@willypuzzle

Copy link
Copy Markdown
Contributor Author

@jdm any ideas for this?

@jdm

jdm commented Jan 19, 2026

Copy link
Copy Markdown
Member

I have a plan. I'm creating a new PromiseFinalizerRegistry that stores Vec<Weak<RefCell<Option<Rc<Promise>>>>. That is a list of pieces of memory that store promise values that can be cleared. This will allow code like GPUBuffer to register an empty storage slot in its constructor, store promises in it during normal operation, and use it from its Drop implementation. Meanwhile, when the JS runtime is shut down we can clear out all of the registered storage slots, so when the final GC happens and the Drop implementations run, the slots will be empty and there's no risk of interacting with a promise object that was already GC'd.

I'll make a PR once I've finished the implementation.

@jdm

jdm commented Aug 17, 2026

Copy link
Copy Markdown
Member

This was addressed by #46415.

@jdm jdm closed this Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants