Compiled write-captured block-scope shadow shares name-keyed $functionDC (residual of #767/#674)

Abierto
#838 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Ya se ha fusionado un pull request relacionado.

  • #849 de @nickna — fusionado

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
csharp, typescript
Área
compilers

Línea de trabajo

Read Compilation/ClosureAnalyzer.cs and Compilation/LocalVariableResolver.cs alongside the function and suspension emitters listed in the issue. Trace how the inner shadow is renamed for body access and how the arrow resolves its captured r; compare compiled output with the supplied generator repro. Done means compiled mode yields 6,6,100 and the fix covers the listed async and generator contexts.

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

Descripción

Summary

Residual left open by #767. A nested-block let/const that shadows an enclosing binding and is written by a nested closure leaks in compiled mode in all suspension contexts (generator #674, async-gen #725, async function). Read-only captures are fixed by #767 for (async) generators; the write case is off-limits everywhere.

Repro

function* mut(): Generator<number> {
  const r = 100;
  {
    let r = 5;
    const f = () => { r = r + 1; return r; };
    yield f();
    yield r;
  }
  yield r;
}
console.log([...mut()].join(","));
  • Interpreted: 6,6,100 (correct)
  • Compiled: 6,6,6 (wrong — inner and outer r collide on the name-keyed $functionDC field)

Root cause

A captured-AND-mutated local is lifted into the name-keyed $functionDC (#674/#725) so the closure's write and the body share storage. The #711/#767 renamer gives the inner shadow its own storage (<r>__bs0) and routes the body's inner-r access there, but the DC field stays keyed r, so the closure read/write and the outer binding collide. Renaming only the body side would desync the closure, so write-captured shadows are kept off-limits to renaming in every mode.

Suggested fix (Follow-up B)

Make the function DC rename-aware / per-binding: register the DC field under the renamed storage name (<r>__bs0), key CapturedFunctionLocals / FunctionDisplayClassFields by it (body side already retokens via #711), and update the arrow's capture resolution so its capture name r maps to functionDC.<r>__bs0 — the "program-wide ClosureAnalyzer rename awareness" the #767 deferral named. Spans DC registration + body emit + arrow resolver + ClosureAnalyzer/LocalVariableResolver.

Files: Compilation/ILCompiler.Functions.cs, Compilation/ILCompiler.Generators.cs, Compilation/ILCompiler.AsyncGenerators.cs, Compilation/ILCompiler.Async.cs, Compilation/ClosureAnalyzer.cs, Compilation/LocalVariableResolver.cs.

Priority

Low / astronomically rare, but highest blast radius of the closure-residual fixes (edits the capture hub #674/#625/#682/#725 depend on). No TypeScript conformance impact (TSConformance type-checker only; Test262 interpreter already correct). Subsumes #837. Found while implementing #767.

Lenguaje dominante
C#
Estrellas
156
Forks
4
Merge medio
14 h 45 min
PR fusionados (30 d)
40

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.