Rust codegen internal local bindings shadow TypeScript parameter names

オープン
#249 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
70/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust, typescript
領域
backend

調査の方向性

Start by reading the four named generators: RustProxyGenerator.swift, RustCallbackGenerator.swift, RustModuleGenerator.swift, and RustFunctionGenerator.swift, and trace how internal bindings are emitted alongside TypeScript parameters. Check the generated Rust for methods using the listed conflicting parameter names and run the relevant compiler tests. Done means generated bindings use reserved internal names and those cases compile and pass their tests.

索引モデルが issue の本文から書いたものです。

説明

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

Unprefixed internal bindings in RustProxyGenerator collide with TypeScript parameter names

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

When a TypeScript @ExportProxy method has a parameter named function_value, function, or marshaller (or arguments/proxy in invoke), the generated Rust method fails to compile or silently passes the wrong value. RustProxyGenerator.write() binds local variables function_value, function, and closure parameter marshaller in borrowedMethods, and arguments/proxy in invokeCases, using unprefixed names.

Any TypeScript parameter with the same snake-case name is shadowed inside the generated body, causing FunctionRef::call_with or ValdiPush::push_to to reference the local FunctionRef/Marshaller instead of the argument. (The same unprefixed internal bindings marshaller, arguments, callback, and module appear in RustFunctionGenerator, RustCallbackGenerator, and RustModuleGenerator.)

Prefix internal generated bindings with __valdi_ (e.g., __valdi_function, __valdi_marshaller, __valdi_arguments, __valdi_proxy).

Unprefixed internal bindings in RustCallbackGenerator collide with TypeScript parameter names

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

When a TypeScript callback declares a parameter named callback, arguments, or marshaller, the generated Rust callback code fails to compile because internal local bindings shadow those parameters. The problem starts in RustCallbackGenerator.generateDefinition, where resultStatements binds arguments and createCall uses callback inside the same block as createArguments, and call_with binds marshaller around callValues.

In RustCallbackGenerator.generateDefinition:

  • A parameter named callback produces let callback = ...; inside the result block, shadowing the callback: T argument before callback.call(...) is invoked.
  • A parameter named arguments produces let arguments = ...; before subsequent parameters evaluate arguments.get(index)?, shadowing the MarshallerRef binding.
  • A parameter named marshaller in Ref::call is shadowed by the |marshaller| closure argument in call_with, causing ValdiPush::push_to(&marshaller, marshaller) to pass &mut Marshaller instead of the parameter value.

Prefix the internal arguments, callback, and marshaller bindings in RustCallbackGenerator.generateDefinition (for example __valdi_arguments, __valdi_callback, __valdi_marshaller) so they cannot collide with TypeScript parameter names.

Unprefixed module and arguments bindings in RustModuleGenerator collide with TypeScript parameter names

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

When a TypeScript @ExportModule method declares a parameter named module or arguments, the generated Rust FFI invocation handler fails to compile because the deserialized parameter binding shadows the internal variable. The problem starts in RustModuleGenerator.write where invokeCases emits let arguments = unsafe { call.arguments() }; and module.<method>(...) inside the same scope as the deserialized parameter bindings.

A parameter named module generates let module = ...; inside the result block before module.<method>(...) runs, shadowing the &dyn <Name>Module reference bound outside the match; a parameter named arguments followed by another parameter shadows arguments before arguments.get(index)? executes for later parameters.

Rename the internal arguments and module bindings in RustModuleGenerator.write (for example __valdi_arguments and __valdi_module) so TypeScript parameter names cannot shadow them.

Closure binding marshaller in RustFunctionGenerator shadows a TypeScript parameter named marshaller

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

When a TypeScript @ExportFunction declares a parameter named marshaller, the generated Rust call wrapper fails to compile because the closure parameter shadows the function parameter. The problem starts in RustFunctionGenerator.write, where callMarshaller binds "marshaller" for the call_with closure argument while serializedParameters passes parameter.name to ValdiPush::push_to.

Inside self.0.as_borrowed().call_with(|marshaller| { ... }), ValdiPush::push_to(&marshaller, marshaller)?; resolves the first marshaller to the &mut valdi_core_rust::Marshaller<'_> closure parameter rather than the function parameter, which fails trait resolution because Marshaller does not implement ValdiPush.

Change callMarshaller in RustFunctionGenerator.write to use a reserved internal name such as "__valdi_marshaller".

主要言語
C++
スター
16.4k
フォーク
539
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Snapchat/Valdi のほかの issue

Snapchat/Valdi の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。