Skip to content

fix: async adapter string params + shim routing#96

Open
avrabe wants to merge 6 commits intomainfrom
fix/async-string-params-and-issue-92
Open

fix: async adapter string params + shim routing#96
avrabe wants to merge 6 commits intomainfrom
fix/async-string-params-and-issue-92

Conversation

@avrabe
Copy link
Copy Markdown
Contributor

@avrabe avrabe commented Apr 14, 2026

Summary

Follow-up to PR #95. Fixes task.return shim routing for the component wrapper and adds infrastructure for string param cross-memory copy.

Changes

  • Export task.return shims from fused module ($task_return_shim_N)
  • Component wrapper aliases shim exports instead of canonical task.return for shimmed imports (fixes intra-component forwarding through indirect table)
  • Add string param cross-memory copy via cabi_realloc + memory.copy
  • Fix component_realloc_index to prefer module 0's realloc

Status

P3 compute functions (prime, fibonacci, factorial, collatz) produce correct results on stock wasmtime. String-returning functions need a resolver-level fix for pointer_pair_positions offset mapping with mixed-type params.

73/73 P2 runtime tests pass.

🤖 Generated with Claude Code

avrabe and others added 6 commits April 13, 2026 21:25
Add cross-memory copy for string/list INPUT params in the async
callback adapter. When the call crosses a memory boundary, the
adapter allocates in callee memory via cabi_realloc and copies
string data from caller memory before calling [async-lift].

Text functions still fail because the text_processor uses intra-
component forwarding functions (call_indirect through fixup table)
that route to canonical task.return. These forwarding functions
bypass our shim. Fix requires the component wrapper to provide
shim functions instead of canonical task.return for shimmed imports.

73/73 P2 runtime tests pass. P3 compute functions correct.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Export task.return shims from fused module ($task_return_shim_N)
- Component wrapper aliases shim exports instead of using canonical
  task.return for shimmed imports (fixes intra-component forwarding)
- Fix component_realloc_index to prefer module 0's realloc

Text functions: shim routing works (no more "invalid task.return
signature") but param copy uses wrong pointer_pair_positions for
mixed-type params (copies shift instead of text_ptr). Needs the
sync adapter's position mapping logic.

73/73 P2 tests pass. P3 compute functions correct.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Export task.return shims ($task_return_shim_N) from fused module
- Component wrapper aliases shim exports instead of canonical task.return
- Add string param cross-memory copy (caller→callee via cabi_realloc)
- Fix component_realloc_index to prefer module 0
- Debug logging for param copy positions

Text functions: shim routing works but pointer_pair_positions has
wrong offsets for mixed-type params (e.g., caesar(u32, string) reports
position [0] instead of [1]). Needs resolver-level fix for async
adapter param flattening.

73/73 P2 tests pass. P3 compute functions correct.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Compute pointer pair positions from CALLER's flat param types
instead of the CALLEE's component type order. The caller's locals
are in canon-lower order which may differ from the callee's
component type param order.

Results:
  caesar 3 "hello" → runs without crash (param copy works!)
    but result not printed (string result delivery incomplete)
  analyze "hello world" → partial output with garbage pointers
    (complex record type not fully handled)
  prime/fibonacci/factorial/collatz → all correct

73/73 P2 tests pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Reverting the forwarding function body replacement approach — the
forwarding functions have different types than the shims (dispatch
type (i32,i32) vs actual task.return type). The wrapper-level shim
routing handles the import table correctly.

The forwarding function's call_indirect table[N] resolves to the
import function, which the wrapper provides as the shim export.
The types match for (i32,i32) → () shims (string results).

Caesar runs without crash but produces empty output — the shim
globals may not be receiving values. Needs deeper table/import
tracing.

73/73 P2 tests pass. Compute functions correct.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Patch element segments to replace task.return import references with
shim function references. This ensures call_indirect through
element-segment-initialized tables calls the shim instead of the
stub import.

Root cause identified for remaining string function issue: the
forwarding function's table index (i32.const 2) uses ORIGINAL
component import numbering, but the element segment uses MERGED
import numbering. Position 2 in the merged element segment is
'analyze', not 'caesar-cipher' as the forwarding function expects.
This is a merger-level table index remapping issue.

73/73 P2 tests pass. Compute functions correct.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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