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

Add Thread-Bound Data to the documented JS API #53

Merged
merged 2 commits into from
May 21, 2024
Merged

Conversation

tlively
Copy link
Member

@tlively tlively commented Apr 15, 2024

As discussed in #30 and #37, add a JS API that allows arbitrary objects to be wrapped and converted to shared externrefs with dynamic checks ensuring the wrapped object is only ever observed on the original thread. Refer to the existing FAQ entry for discussion on how the lifetimes of the wrapper and wrapped object might interact.

Resolves #37.

As discussed in #30 and #37, add a JS API that allows arbitrary objects to be
wrapped and converted to shared externrefs with dynamic checks ensuring the
wrapped object is only ever observed on the original thread. Refer to the
existing FAQ entry for discussion on how the lifetimes of the wrapper and
wrapped object might interact.

Resolves #37.
@tlively tlively requested review from abrown and conrad-watt April 15, 2024 19:33
@tlively
Copy link
Member Author

tlively commented Apr 15, 2024

cc @eqrion and @syg for comments as well.

Copy link
Collaborator

@abrown abrown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just reviewed for wording choice. Should we bring this up in the next threads subgroup meeting?

@@ -589,6 +589,26 @@ entire thread or agent.
[jspi]: https://github.com/WebAssembly/js-promise-integration
[realm]: https://tc39.es/ecma262/#realm

#### Thread-Bound Data

Just as WebAssembly produces expect to be able to call JS functions, they also expect to be able to
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users?

Suggested change
Just as WebAssembly produces expect to be able to call JS functions, they also expect to be able to
Just as WebAssembly users expect to be able to call JS functions, they also expect to be able to

references to DOM nodes in some of its shared objects. Normally this would be disallowed because DOM
nodes are not shareable and shared-to-unshared references are disallowed. To bridge this gap, we
need a utility that allows shared-to-unshared objects as an exception to the general rule, assuming
that Web GCs can support such an exception (see the discussion in the FAQ below). To avoid
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
that Web GCs can support such an exception (see the discussion in the FAQ below). To avoid
that browser GCs can support such an exception (see the discussion in the FAQ below). To avoid


`ThreadBoundData` is a shared JS object that wraps any other arbitrary JS object. `ThreadBoundData`
provides access to the wrapped object via a `get` method that throws an exception when called on any
thread besides the thread that owns the wrapped object, ensuring that the wrapped object can be
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we say "thread" here, do we really just mean web workers? It might be worthwhile clarifying that...

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 we should be more precise. In specese that would be "agent".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a function called on an agent or called by an agent?

#### Thread-Bound Data

Just as WebAssembly produces expect to be able to call JS functions, they also expect to be able to
hold handles to JS objects. For example, a language compiled to shared WasmGC may need to hold
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hold handles to JS objects. For example, a language compiled to shared WasmGC may need to hold
reference JS objects. For example, a language compiled to shared WasmGC may need to hold

nodes are not shareable and shared-to-unshared references are disallowed. To bridge this gap, we
need a utility that allows shared-to-unshared objects as an exception to the general rule, assuming
that Web GCs can support such an exception (see the discussion in the FAQ below). To avoid
complicating the core language and forcing every non-Web engine to support shared-to-unshared edges,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
complicating the core language and forcing every non-Web engine to support shared-to-unshared edges,
complicating the core language and forcing every engine to support shared-to-unshared edges,


`ThreadBoundData` is a shared JS object that wraps any other arbitrary JS object. `ThreadBoundData`
provides access to the wrapped object via a `get` method that throws an exception when called on any
thread besides the thread that owns the wrapped object, ensuring that the wrapped object can be
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear what "owns" means. I'm guessing you mean "created"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will clarify that it is the agent on which the ThreadBoundData wrapper is created. (As opposed to the agent on which the wrapped object was created, in case someone wants to wrap a shared object for some reason.)


`ThreadBoundData` is a shared JS object that wraps any other arbitrary JS object. `ThreadBoundData`
provides access to the wrapped object via a `get` method that throws an exception when called on any
thread besides the thread that owns the wrapped object, ensuring that the wrapped object can be
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 we should be more precise. In specese that would be "agent".

@tlively
Copy link
Member Author

tlively commented Apr 23, 2024

Thank you both for the review. I've addressed all the feedback. I'll also add this as an agenda item for the next subgroup meeting.

@tlively
Copy link
Member Author

tlively commented Apr 30, 2024

The text here already includes "... assuming that browser GCs can support such an exception (see the discussion in the FAQ below)" so I think it's sufficiently clear that this is not set in stone and depends on architectural constraints from browsers.

@abrown
Copy link
Collaborator

abrown commented May 1, 2024

Talked to @eqrion: he has opinions on this but is on leave for a few more weeks. Why don't we leave it open until he gets back?

@eqrion
Copy link
Contributor

eqrion commented May 21, 2024

(sorry for the delay, just got back). My comment was only just ensuring that this is suitably marked as depending on browsers supporting shared-to-unshared references, which is an open question at this point. It looks like that's marked out well enough, so I think this can be merged.

@tlively tlively requested a review from abrown May 21, 2024 15:20
@tlively
Copy link
Member Author

tlively commented May 21, 2024

Thanks, @eqrion! @abrown, want to flip the approve bit?

@abrown abrown merged commit 70389cd into main May 21, 2024
@abrown abrown deleted the thread-bound-data branch May 21, 2024 23:18
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.

Dynamic sharedness checks as an escape hatch
4 participants