Rust codegen: Callbacks and futures passed as generic model arguments are dropped before definition generation

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

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
compilers

Research direction

Start in RustTypeResolver.swift at resolve(_:namePath:) and trace how generic model arguments are represented in RustTypes.swift. Then inspect RustReferencedTypeGenerator.swift at collectTypes and the Rust code generation tests for generic models containing callbacks or Promise values. Done means the generated definitions include those callback or future types and the generated Rust compiles.

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.

Callbacks and futures passed as generic model arguments are dropped before definition generation

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

When a callback or Promise is passed as a type argument to a generic model (such as Boxed<(x: number) => void> or Boxed<Promise<number>>), the generated Rust code fails to compile because the callback or future type is never defined. In resolve(_:namePath:), the .genericObject branch formats resolvedArguments into strings and discards the resolved RustType values by returning .model(rust:borrowed:).

Because RustReferencedTypeGenerator.collectTypes in compiler/compiler/Compiler/Sources/Generation/Rust/RustReferencedTypeGenerator.swift only recurses into .callback, .future, .valueArray, and .nullable, callbacks and futures inside generic model arguments are never collected or emitted, leaving undefined type references in the generated module or function signatures.

Preserve the resolved generic argument RustType values on a .genericModel (or .model) case in compiler/compiler/Compiler/Sources/Generation/Rust/RustTypes.swift and traverse them in RustReferencedTypeGenerator.collectTypes.

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.