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

feat: initial resources implementation #128

Merged
merged 14 commits into from
Aug 19, 2023
Merged

feat: initial resources implementation #128

merged 14 commits into from
Aug 19, 2023

Conversation

guybedford
Copy link
Collaborator

@guybedford guybedford commented Aug 10, 2023

Adds support for resources to jco.

There are two main resource cases: host-defined resources and component-defined resources. Host-defined resources are referred to as imported resources.

When lifting and lowering resources, for host-defined resources we capture the resource in the handle itself when assigning the handle index. For component-defined resources we maintain a handle relation via a private resourceHandleSymbol brand for the proxy object created back to the handle.

Component-defined resource "proxy objects" have finalizers attached, finalizers are also unattached when the proxy object lifecycle ends. The private handle symbol is set to null to indicate a dead object so that a lifecycle error instead of an invalid handle lookup can be thrown if they are still used. This is done after all calls to JS that take borrowed resources from the component. Host-defined resources are captured and released so that we do not pin the GC longer than necessary. Own resources are released from import resource instance capture when lifted as that implies they are being transferred to the host code.

Finally, the distinction between the transpilation bindgen and function bindgen is maintained by taking a resource_map into the function bindgen, which provides a mapping from the resource type into its unique table id that can be used for the resource table objects - handleTable{i}, resourceImportInstances{i}, etc. under the assumption that these locals will be present. This allows the separation of instancing concerns from the transpilation bindgen and function bindgen, where only the transpilation bindgen needs to figure out the correct instancing maps (n tables for a resource used by n components).

@guybedford guybedford changed the title resources incremental progress feat: initial resources implementation Aug 15, 2023
@guybedford guybedford merged commit 80881dc into main Aug 19, 2023
4 checks passed
@guybedford guybedford deleted the resources branch August 19, 2023 00:35
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.

1 participant