[P2] Compiler: Array prototype calls read arguments.length twice

Cerrado
#3,533 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Ya se ha fusionado un pull request relacionado.

  • #3510 de @nickna — fusionado

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
csharp, typescript
Área
compilers

Línea de trabajo

Start by reading the descriptor-aware compiled arguments work in pull request #3510 and compare its standalone assembly at 66d78c4ff with clean main at cabb41636. Trace the inline calls to Array.prototype.map, filter, flat, and toReversed, then run the supplied reproducer and the related compiler tests. Done means each method reads the live arguments length once while preserving its result length validation and element-read order.

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

Descripción

The descriptor-aware compiled arguments work in #3510 introduced a second read of arguments.length in inline calls to Array.prototype.map, filter, flat, and toReversed. The precheck reads the length, then the arguments materializer reads it again. A getter can observe both reads and return different lengths.

function read(method) {
    function f(a, b) {
        const args = arguments;
        let count = 0;
        Object.defineProperty(args, "length", {
            get() { count++; return count === 1 ? 2 : 1; }
        });
        let result;
        if (method === "map") result = Array.prototype.map.call(args, value => value);
        if (method === "filter") result = Array.prototype.filter.call(args, value => true);
        if (method === "flat") result = Array.prototype.flat.call(args);
        if (method === "toReversed") result = Array.prototype.toReversed.call(args);
        console.log(method, count, result.join(","));
    }
    f(2, 1);
}
for (const method of ["map", "filter", "flat", "toReversed"]) read(method);

Node v22.23.2 reads the length once for each method. The outputs contain both entries (2,1 for map/filter/flat and 1,2 for toReversed). The verified standalone assembly on #3510 at 66d78c4ff reads it twice and uses the second length. Clean main at cabb41636 reads it once but falls back to backing storage, which separately loses descriptor-backed values.

Expected: use one live length read and preserve method-specific result length validation and element-read order. The distinct Array.prototype.with index validation and allocation failure is tracked in #3531.

Lenguaje dominante
C#
Estrellas
156
Forks
4
Merge medio
15 h 35 min
PR fusionados (30 d)
43

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 nickna/SharpTS

Todos los issues de nickna/SharpTS

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.