Rust codegen internal local bindings shadow TypeScript parameter names
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
callbackproduceslet callback = ...;inside theresultblock, shadowing thecallback: Targument beforecallback.call(...)is invoked. - A parameter named
argumentsproduceslet arguments = ...;before subsequent parameters evaluatearguments.get(index)?, shadowing theMarshallerRefbinding. - A parameter named
marshallerinRef::callis shadowed by the|marshaller|closure argument incall_with, causingValdiPush::push_to(&marshaller, marshaller)to pass&mut Marshallerinstead 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
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Snapchat/Valdi
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
I maintainer di solito rispondono entro 1 giorno
-
Rust codegen: RustMethodResolver fails to unwrap .nullable on optional interface/module methodsAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Snapchat/Valdi
Issue simili
-
RTL-SDR: re-enumerating while streaming removes the in-use entry from the device selection dialogForse già presa @dpc00 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
throneproj/Throne#2227 ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
deepseek-ai/DeepGEMM-Ascend#49 ·
I maintainer di solito rispondono entro 1 giorno