[P2] Compiler: Array.prototype.flat reads arguments indices before evaluating depth

クローズ
#3,535 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

関連するプルリクエストがすでにマージされています。

  • #3510 @nickna による — マージ済み

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
csharp, typescript
領域
compilers

調査の方向性

Start by reading the inline Array.prototype.flat dispatch and the mapped arguments changes in #3510; compare their evaluation order with JavaScript’s call argument evaluation. Compile the sample as an unchecked classic .js program using --no-tsconfig --noLib --verify and check the trace against Node v22.23.2. Done means the depth expression runs before indexed access, while the result remains 7.

索引モデルが issue の本文から書いたものです。

説明

An indexed arguments accessor runs before the depth expression when compiled JavaScript invokes Array.prototype.flat.call. JavaScript evaluates the call arguments before entering the builtin.

function run(first) {
    const args = arguments;
    const trace = [];
    Object.defineProperty(args, "0", { get() { trace.push("index"); return 7; } });
    const result = Array.prototype.flat.call(args, (trace.push("depth expression"), 1));
    console.log(result.join(","), trace.join(","));
}
run(1);

Node v22.23.2 prints 7 depth expression,index. The compiler with the mapped arguments changes in #3510 prints 7 index,depth expression and passes full saved IL verification. Clean main at cabb41636 prints an empty result with depth expression, since the former arguments snapshot skipped indexed accessors entirely. Compile the sample as an unchecked classic .js program with --no-tsconfig --noLib --verify.

Inline flat prepares its array-like input before evaluating the depth expression. The mapped arguments work makes indexed accessors observable, which exposes this pre-existing dispatch order. Related to #3533, which covers duplicate length reads.

主要言語
C#
スター
156
フォーク
4
平均マージ
15時間 35分
マージ済み PR(30日)
43

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nickna/SharpTS のほかの issue

nickna/SharpTS の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。