Skip to content

fix(bindgen): return state-only handle when async-lowered import resolves eagerly#1434

Merged
vados-cosmonic merged 1 commit intobytecodealliance:mainfrom
andreiltd:fix/p3-canon-lower-eagerly-resolved-subtask
Apr 29, 2026
Merged

fix(bindgen): return state-only handle when async-lowered import resolves eagerly#1434
vados-cosmonic merged 1 commit intobytecodealliance:mainfrom
andreiltd:fix/p3-canon-lower-eagerly-resolved-subtask

Conversation

@andreiltd
Copy link
Copy Markdown
Member

Per CanonicalABI.md an async-lowered import whose callee resolves synchronously returns Subtask.State.RETURNED state only and no subtask handle is packed into the result.

Separateley The CanonicalABI.md packs state into 4 bits so the check bounds are adjusted.

This the relevant spec section:

In the async case, if the callee already called on_resolve, then the RETURNED code is eagerly returned to the core wasm caller without needing to add a Subtask to the current component instance's handles table.

    if subtask.resolved():
      assert(flat_results == [])
      subtask.deliver_resolve()
      return [Subtask.State.RETURNED]
    else:
      subtaski = thread.task.inst.handles.add(subtask)
      def on_progress():
        def subtask_event():
          if subtask.resolved():
            subtask.deliver_resolve()
          return (EventCode.SUBTASK, subtaski, subtask.state)
        subtask.set_pending_event(subtask_event)
      assert(0 < subtaski <= Table.MAX_LENGTH < 2**28)
      assert(0 <= subtask.state < 2**4)
      return [subtask.state | (subtaski << 4)]

…lves eagerly

Per CanonicalABI.md an async-lowered import whose callee resolves
synchronously returns `Subtask.State.RETURNED` state only and no subtask
handle is packed into the result.

Separateley The CanonicalABI.md packs state into 4 bits so the check
bounds are adjusted.
Copy link
Copy Markdown
Collaborator

@vados-cosmonic vados-cosmonic left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@vados-cosmonic vados-cosmonic added this pull request to the merge queue Apr 29, 2026
Merged via the queue into bytecodealliance:main with commit 1608faf Apr 29, 2026
37 checks passed
@jco-release-bot
Copy link
Copy Markdown
Collaborator

🎉 The code in this PR was made available in the following release:
https://github.com/bytecodealliance/jco/releases/tag/js-component-bindgen-v1.18.0

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