Rust codegen: Non-function properties on @ExportProxy or @ExportModule fail at runtime due to unconditional function dispatch

Open
#251 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp, rust, typescript
Domain
api, backend

Research direction

Start with compiler/compiler/Compiler/Sources/Generation/Rust/RustMethodResolver.swift and trace how RustProxyGenerator and RustModuleGenerator handle resolved entries; then inspect RustSchemaWriter.appendInterface and the proxy and module registration paths in RustValdi.cpp. Check how generated JS-backed proxy getters and Rust-implemented proxy or module values match their schema slots. Done means non-function properties are read as values or rejected consistently, with runtime dispatch matching the schema.

Written by the indexing model from the issue text.

Description

Found while reviewing https://github.com/Snapchat/Valdi/pull/211 (native Rust code generation). Not blocking that PR.

Non-function properties on @ExportProxy or @ExportModule fail at runtime due to unconditional function dispatch

File: compiler/compiler/Compiler/Sources/Generation/Rust/RustMethodResolver.swift

When a TypeScript @ExportProxy interface declares a non-function property (such as a readonly field), calling the generated Rust getter on a JS-backed proxy fails at runtime, and passing a Rust-implemented proxy to JS puts a function object in a non-function schema slot. The mismatch starts in RustMethodResolver.resolve, where the default: branch lowers non-function properties into zero-parameter RustResolvedMethod entries while RustProxyGenerator still emits function-call dispatch for every resolved method.

For a JS-backed proxy, the generated borrowedMethods implementation fetches the property via self.0.property(...), deserializes it as valdi_core_rust::FunctionRef<'_>, and invokes call_with, which fails because the JS value is not a function; for a Rust-implemented proxy (or @ExportModule), RustSchemaWriter.appendInterface emits a non-function schema field while valdi_rust_value_new_proxy / valdi_rust_register_module in RustValdi.cpp populates every slot with a RustModuleMethod function.

Separate non-function properties from methods in RustMethodResolver.resolve (for instance with an isMethod flag) so RustProxyGenerator reads value properties directly via ValdiDeserialize on JS proxies and RustProxyGenerator / RustModuleGenerator either disallow non-function properties or expose a property-read path that matches the schema.

Dominant language
C++
Stars
16.4k
Forks
539
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Snapchat/Valdi

All issues in Snapchat/Valdi

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.