OptimizeInstructions: `--tnh` makes `ref.cast` non-nullable before a possibly infinite loop
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
- 45/100
Línea de trabajo
The check is in src/passes/OptimizeInstructions.cpp around lines 1843-1853, where a ref.cast is made non-nullable when a later sibling transfersControlFlow(). Read the effects code for mayNotReturn and how loops are marked after #5711. Run the reproducer with --traps-never-happen to see the cast turn into ref.cast (ref $S). Done when a sibling that may not return keeps the nullable cast, and the existing tests still pass.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Reproducer
(module
(type $S (struct (field (mut i32))))
(func (export "f") (param $a anyref) (param $n i32)
(struct.set $S 0
(ref.cast (ref null $S) (local.get $a))
(loop $l (result i32) (br_if $l (local.get $n)) (i32.const 0)))))
wasm-opt -all in.wat --optimize-instructions --traps-never-happen (also -O3) turns the cast into (ref.cast (ref $S) ...). In pseudocode:
// input
x = cast_or_null<S>(a)
while (n != 0) {}
x.field0 = 0 // traps if x is null
// output
x = cast_nonnull<S>(a) // traps if a is null
while (n != 0) {}
x.field0 = 0
With a = null and n = 1, the input loops forever without reaching the struct.set, so nothing traps; the output traps before the loop.
Cause
This check excludes a later sibling that transfersControlFlow(), since then "we might not reach the parent". A sibling that may not return (an infinite loop) also means we might not reach the parent, but transfersControlFlow() does not include mayNotReturn, so the check misses it. The same applies to array.get, array.set and array.copy.
This check predates #5711. Before #5711 a loop had the effect "may trap (timeout)", which traps-never-happen ignores, so assuming the loop terminates was consistent. #5711 changed loops to mayNotReturn so that traps-never-happen keeps infinite loops, but this check was not updated.
Possible fix
Add || effects(child).mayNotReturn to that check.
If traps-never-happen is meant to allow this, please let us know.
- Lenguaje dominante
- WebAssembly
- Estrellas
- 8.7k
- Forks
- 895
- Merge medio
- 1 d 23 h
- PR fusionados (30 d)
- 105
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de WebAssembly/binaryen
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
WebAssembly/binaryen#9135 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 Medio día Aptitud para principiantes 76/100
WebAssembly/binaryen#9018 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
Memory64Lowering: table.get/table.set keep i64 index on lowered table64, output fails validationAbierto
Dificultad 3/5 Medio día Aptitud para principiantes 66/100
WebAssembly/binaryen#9245 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 65/100
WebAssembly/binaryen#9244 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 62/100
WebAssembly/binaryen#9243 ·
Los mantenedores suelen responder en 1 día
Todos los issues de WebAssembly/binaryen
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
jaseci-labs/jac#9934 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
rescript-lang/rescript#8763 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
flagos-ai/FlagTree#1344 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 5 días