Skip to content

Add Component::Instance#get_export_index/#get_resource and WIT resour…#620

Open
teleyos wants to merge 1 commit into
bytecodealliance:mainfrom
teleyos:feature/adding-missing-instance-methods
Open

Add Component::Instance#get_export_index/#get_resource and WIT resour…#620
teleyos wants to merge 1 commit into
bytecodealliance:mainfrom
teleyos:feature/adding-missing-instance-methods

Conversation

@teleyos

@teleyos teleyos commented Jul 2, 2026

Copy link
Copy Markdown

…ce support

Instance previously only exposed #get_func, making it impossible to fully drive a component that exports a WIT resource (e.g. a constructor plus instance methods) from Ruby: there was no way to look up the resource's exported type, and Val::Resource/Type::Own/Type::Borrow conversions were hard not_implemented! stubs.

  • Instance#get_export_index / #get_resource wrap wasmtime's own methods of the same name; the shared lookup helper now accepts a previously-resolved ExportIndex (bare or nested in an Array) so lookups can be cached and chained, matching wasmtime's own doc example, and internally prefers get_export_index over get_export since the ComponentItem it discards is never used.
  • New Wasmtime::Component::Resource wraps ResourceAny + its owning Store, requiring an explicit #resource_drop (wasmtime requires every ResourceAny, even borrows, to be explicitly dropped; there's no safe GC finalizer hook for re-entering a Store during collection).
  • New Wasmtime::Component::ExportIndex and ResourceType wrap the matching wasmtime types; both are inert Copy data with no Store dependency, so unlike Resource they need no GC mark.
  • convert.rs now lifts/lowers resource values for the Func::invoke path (calling exported functions), and guards against passing a Resource obtained from one Store into a call on a different Store, which would otherwise silently index into the wrong store's resource table.
  • Host-defined import functions (Linker#root.func_new) still don't support resources in either direction; that path never had a Ruby-visible Store handle to thread through, and stays out of scope here.

…ce support

Instance previously only exposed #get_func, making it impossible to fully
drive a component that exports a WIT `resource` (e.g. a constructor plus
instance methods) from Ruby: there was no way to look up the resource's
exported type, and Val::Resource/Type::Own/Type::Borrow conversions were
hard `not_implemented!` stubs.

- Instance#get_export_index / #get_resource wrap wasmtime's own methods of
  the same name; the shared lookup helper now accepts a previously-resolved
  ExportIndex (bare or nested in an Array) so lookups can be cached and
  chained, matching wasmtime's own doc example, and internally prefers
  get_export_index over get_export since the ComponentItem it discards is
  never used.
- New Wasmtime::Component::Resource wraps ResourceAny + its owning Store,
  requiring an explicit #resource_drop (wasmtime requires every ResourceAny,
  even borrows, to be explicitly dropped; there's no safe GC finalizer hook
  for re-entering a Store during collection).
- New Wasmtime::Component::ExportIndex and ResourceType wrap the matching
  wasmtime types; both are inert Copy data with no Store dependency, so
  unlike Resource they need no GC mark.
- convert.rs now lifts/lowers resource values for the Func::invoke path
  (calling exported functions), and guards against passing a Resource
  obtained from one Store into a call on a different Store, which would
  otherwise silently index into the wrong store's resource table.
- Host-defined import functions (Linker#root.func_new) still don't support
  resources in either direction; that path never had a Ruby-visible Store
  handle to thread through, and stays out of scope here.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@jeffcharles

Copy link
Copy Markdown
Collaborator

Please review the Bytecode Alliance's policy on AI Tool Use

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.

2 participants