Rust codegen internal local bindings shadow TypeScript parameter names

Abierto
#249 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
70/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust, typescript
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
C++
Estrellas
16.4k
Forks
539
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Snapchat/Valdi

Todos los issues de Snapchat/Valdi

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.