Rust codegen internal local bindings shadow TypeScript parameter names

Aperta
#249 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
70/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust, typescript
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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".

Lingua principale
C++
Stelle
16.4k
Fork
539
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Snapchat/Valdi

Tutte le issue di Snapchat/Valdi

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.