Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

TupleOptimization: tuple swap is miscompiled

Cerrado
#9,210 0 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@tlively ya está trabajando en esto.

Desde el 5/10/2026.

  • #9213 de @tlively — fusionado

Evaluación

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

Línea de trabajo

Start by running the provided test.wat reproducer with and without --tuple-optimization, then locate the TupleOptimization pass in Binaryen. The issue suggests comparing its lowering with Heap2Local's handling of struct.new. Done means the optimized swap returns 16, matching the unoptimized module; add a regression test for the reproducer.

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

Descripción

Summary

--tuple-optimization splits a tuple local into scalar locals and lowers local.set $t (tuple.make a0 a1) to $t0 = a0; $t1 = a1, in order. If an operand reads an element of $t that was already overwritten (a1 = tuple.extract 0 $t), it reads the new value:

t = (t.1, t.0)   ==>   $t0 = $t1; $t1 = $t0;   // $t0 is already overwritten

The pass is in -O1 and above; a multivalue loop that swaps its parameters (plain wasm) is miscompiled by -O3, -Os, -Oz and -O4.

Evaluating the operands into temporaries first (as Heap2Local does for struct.new) would fix it.

Reproducer

test.wat:

(module
 (func (export "f") (param $x i32) (param $y i32) (result i32)
  (local $t (tuple i32 i32))
  (local.set $t (tuple.make 2 (local.get $x) (local.get $y)))
  (local.set $t (tuple.make 2 (tuple.extract 2 1 (local.get $t)) (tuple.extract 2 0 (local.get $t))))
  (tuple.extract 2 1 (local.get $t))))
$ wasm-opt test.wat --enable-multivalue -o in.wasm
$ wasm-opt test.wat --enable-multivalue --tuple-optimization -o out.wasm
$ wasmtime run --invoke f in.wasm 16 1000
16
$ wasmtime run --invoke f out.wasm 16 1000
1000

f swaps the elements of t and returns t.1, which is the original x, so the correct result is 16. V8 gives the same results.

AI was used as part of the process of finding this issue. I have manually checked and reproduced it.

Lenguaje dominante
WebAssembly
Estrellas
8.7k
Forks
893
Merge medio
1 d 18 h
PR fusionados (30 d)
95

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 WebAssembly/binaryen

Todos los issues de WebAssembly/binaryen

Issues similares

Más issues de Compilers

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.