[array] Add Torque fast path for Array.prototype.flat [v8/v8 : main]

0 views
Skip to first unread message

Amemiya Riya (Gerrit)

unread,
Jan 29, 2026, 4:01:15 AMJan 29
to Leszek Swirski, v8-re...@googlegroups.com
Attention needed from Leszek Swirski

Amemiya Riya added 1 comment

File src/builtins/array-flat.tq
Line 240, Patchset 1: const fastResult = runtime::ArrayFastFlat(fastO, len, depthSmi);
Leszek Swirski . resolved

it would be good to implement this fast path in torque/CSA rather than a runtime function, so that we don't have to pay the runtime call overheads. This is true in general, we usually have the fast paths written in torque/CSA and only call out to the runtime in slow paths.

Amemiya Riya

Thanks for the feedback! I've updated the implementation to use Torque/CSA instead of a runtime function.

Open in Gerrit

Related details

Attention is currently required from:
  • Leszek Swirski
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: v8/v8
Gerrit-Branch: main
Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
Gerrit-Change-Number: 7526287
Gerrit-PatchSet: 4
Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
Gerrit-Attention: Leszek Swirski <les...@chromium.org>
Gerrit-Comment-Date: Thu, 29 Jan 2026 09:01:10 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Leszek Swirski <les...@chromium.org>
unsatisfied_requirement
open
diffy

Amemiya Riya (Gerrit)

unread,
Feb 5, 2026, 10:21:45 AMFeb 5
to Leszek Swirski, v8-re...@googlegroups.com
Attention needed from Leszek Swirski

Amemiya Riya added 1 comment

Patchset-level comments
File-level comment, Patchset 4 (Latest):
Amemiya Riya . resolved

@les...@chromium.org

Could you please take a look when you have a chance?

Open in Gerrit

Related details

Attention is currently required from:
  • Leszek Swirski
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: v8/v8
Gerrit-Branch: main
Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
Gerrit-Change-Number: 7526287
Gerrit-PatchSet: 4
Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
Gerrit-Attention: Leszek Swirski <les...@chromium.org>
Gerrit-Comment-Date: Thu, 05 Feb 2026 15:21:39 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
unsatisfied_requirement
open
diffy

Amemiya Riya (Gerrit)

unread,
Feb 11, 2026, 10:16:11 AM (13 days ago) Feb 11
to Olivier Flückiger, Igor Sheludko, Leszek Swirski, v8-re...@googlegroups.com
Attention needed from Igor Sheludko, Leszek Swirski and Olivier Flückiger

Amemiya Riya added 1 comment

Patchset-level comments
Amemiya Riya . resolved

Since you seem busy at the moment, I've added additional reviewers as suggested by the guidelines. I would appreciate it if you could take a look when you have a chance.

Open in Gerrit

Related details

Attention is currently required from:
  • Igor Sheludko
  • Leszek Swirski
  • Olivier Flückiger
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: v8/v8
Gerrit-Branch: main
Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
Gerrit-Change-Number: 7526287
Gerrit-PatchSet: 4
Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
Gerrit-Reviewer: Igor Sheludko <ish...@chromium.org>
Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
Gerrit-Reviewer: Olivier Flückiger <ol...@chromium.org>
Gerrit-Attention: Igor Sheludko <ish...@chromium.org>
Gerrit-Attention: Olivier Flückiger <ol...@chromium.org>
Gerrit-Attention: Leszek Swirski <les...@chromium.org>
Gerrit-Comment-Date: Wed, 11 Feb 2026 15:16:05 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
unsatisfied_requirement
open
diffy

Leszek Swirski (Gerrit)

unread,
Feb 11, 2026, 10:39:37 AM (13 days ago) Feb 11
to Amemiya Riya, Olivier Flückiger, Igor Sheludko, v8-re...@googlegroups.com
Attention needed from Amemiya Riya, Igor Sheludko and Olivier Flückiger

Leszek Swirski added 1 comment

Patchset-level comments
Leszek Swirski . resolved

sorry for being slow, it's a large commit and needs some dedicated time to review

Open in Gerrit

Related details

Attention is currently required from:
  • Amemiya Riya
  • Igor Sheludko
  • Olivier Flückiger
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: v8/v8
Gerrit-Branch: main
Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
Gerrit-Change-Number: 7526287
Gerrit-PatchSet: 4
Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
Gerrit-Reviewer: Igor Sheludko <ish...@chromium.org>
Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
Gerrit-Reviewer: Olivier Flückiger <ol...@chromium.org>
Gerrit-Attention: Amemiya Riya <riyaa...@gmail.com>
Gerrit-Attention: Igor Sheludko <ish...@chromium.org>
Gerrit-Attention: Olivier Flückiger <ol...@chromium.org>
Gerrit-Comment-Date: Wed, 11 Feb 2026 15:39:33 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
unsatisfied_requirement
open
diffy

Amemiya Riya (Gerrit)

unread,
Feb 11, 2026, 11:50:51 AM (13 days ago) Feb 11
to Olivier Flückiger, Igor Sheludko, Leszek Swirski, v8-re...@googlegroups.com
Attention needed from Igor Sheludko, Leszek Swirski and Olivier Flückiger

Amemiya Riya added 1 comment

Patchset-level comments
Leszek Swirski . resolved

sorry for being slow, it's a large commit and needs some dedicated time to review

Amemiya Riya

Thanks for getting back to me. If anything, I'm sorry for the nudge. I appreciate you taking the time to review such a large change.

Open in Gerrit

Related details

Attention is currently required from:
  • Igor Sheludko
  • Leszek Swirski
  • Olivier Flückiger
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: v8/v8
Gerrit-Branch: main
Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
Gerrit-Change-Number: 7526287
Gerrit-PatchSet: 4
Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
Gerrit-Reviewer: Igor Sheludko <ish...@chromium.org>
Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
Gerrit-Reviewer: Olivier Flückiger <ol...@chromium.org>
Gerrit-Attention: Igor Sheludko <ish...@chromium.org>
Gerrit-Attention: Olivier Flückiger <ol...@chromium.org>
Gerrit-Attention: Leszek Swirski <les...@chromium.org>
Gerrit-Comment-Date: Wed, 11 Feb 2026 16:50:45 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Leszek Swirski <les...@chromium.org>
unsatisfied_requirement
open
diffy

Leszek Swirski (Gerrit)

unread,
Feb 18, 2026, 7:14:47 AM (6 days ago) Feb 18
to Amemiya Riya, Olivier Flückiger, Igor Sheludko, v8-re...@googlegroups.com
Attention needed from Amemiya Riya, Igor Sheludko and Olivier Flückiger

Leszek Swirski added 5 comments

Patchset-level comments
Leszek Swirski . resolved

Sorry again for the slow review. Overall the idea looks very nice, here's some comments and ideas.

File src/builtins/array-flat.tq
Line 40, Patchset 4 (Latest): a = NewJSArray(map, this.fixedArray);
Leszek Swirski . unresolved

why not immediately initialise this with `elements`?

Line 51, Patchset 4 (Latest): case (TheHole): {
}
Leszek Swirski . unresolved

I think you have to set `undefined` values for incoming holes too, because the flattened result will `Get` from the input and read `undefined`, not `hole`.

You can test this by adding a test case like:

```
let a = [,,];
let b = [a].flat();
assertEquals(a[0], undefined);
assertEquals(b[0], undefined);
Array.prototype[0] = 42;
assertEquals(a[0], 42);
assertEquals(b[0], undefined);
```

Please double check current behaviour when you do this just to make sure I'm right.

Line 208, Patchset 4 (Latest): let stack = growable_fixed_array::NewGrowableFixedArray();
Leszek Swirski . unresolved

rather than an allocated stack, what about using the machine stack by having a recursive call to a helper?

Line 223, Patchset 4 (Latest): element = fastOW.LoadElementNoHole(index) otherwise FoundHole;
Leszek Swirski . unresolved

if the inputs are DOUBLE_ELEMENTS, this will need to materialize a new Number. It would be nice if `CalculateFlattenedLengthFast` also calculated whether _all_ input arrays are DOUBLE_ELEMENTS, and if yes, you could have a separate fast path that avoids this allocation and preallocates the FlatVector already as a `FixedDoubleArray`.

Open in Gerrit

Related details

Attention is currently required from:
  • Amemiya Riya
  • Igor Sheludko
  • Olivier Flückiger
Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: v8/v8
    Gerrit-Branch: main
    Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
    Gerrit-Change-Number: 7526287
    Gerrit-PatchSet: 4
    Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
    Gerrit-Reviewer: Igor Sheludko <ish...@chromium.org>
    Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
    Gerrit-Reviewer: Olivier Flückiger <ol...@chromium.org>
    Gerrit-Attention: Amemiya Riya <riyaa...@gmail.com>
    Gerrit-Attention: Igor Sheludko <ish...@chromium.org>
    Gerrit-Attention: Olivier Flückiger <ol...@chromium.org>
    Gerrit-Comment-Date: Wed, 18 Feb 2026 12:14:42 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Amemiya Riya (Gerrit)

    unread,
    Feb 19, 2026, 5:08:21 AM (5 days ago) Feb 19
    to Olivier Flückiger, Igor Sheludko, Leszek Swirski, v8-re...@googlegroups.com
    Attention needed from Igor Sheludko, Leszek Swirski and Olivier Flückiger

    Amemiya Riya added 4 comments

    File src/builtins/array-flat.tq
    Line 40, Patchset 4: a = NewJSArray(map, this.fixedArray);
    Leszek Swirski . resolved

    why not immediately initialise this with `elements`?

    Amemiya Riya

    Thank you for pointing this out. There was no particular reason for the two-step initialization — I simply hadn't considered passing elements directly. I've updated it to initialize with elements immediately after allocation.

    Line 51, Patchset 4: case (TheHole): {
    }
    Leszek Swirski . unresolved

    I think you have to set `undefined` values for incoming holes too, because the flattened result will `Get` from the input and read `undefined`, not `hole`.

    You can test this by adding a test case like:

    ```
    let a = [,,];
    let b = [a].flat();
    assertEquals(a[0], undefined);
    assertEquals(b[0], undefined);
    Array.prototype[0] = 42;
    assertEquals(a[0], 42);
    assertEquals(b[0], undefined);
    ```

    Please double check current behaviour when you do this just to make sure I'm right.

    Amemiya Riya

    Thank you, I double-checked this. Holes in nested arrays should be correctly skipped since HasProperty returns false for them, so [,,].flat() produces [] (length=0). After setting Array.prototype[0] = 42, b[0] returns 42 via the prototype chain, which appears to match the slow path behaviour. Let me know if I'm missing something.

    Line 208, Patchset 4: let stack = growable_fixed_array::NewGrowableFixedArray();
    Leszek Swirski . unresolved

    rather than an allocated stack, what about using the machine stack by having a recursive call to a helper?

    Amemiya Riya

    Thank you for the suggestion. I tried converting this to a recursive builtin, but ran into a Torque compiler limitation — inlining complex macros (FastJSArrayWitness + try/label FoundHole + continue) into a builtin body causes the compiler to crash with a stack overflow (SIGSEGV). Additionally, FastJSArray is a transient type and cannot be used as a builtin argument. I've kept the allocated stack approach for now, but happy to revisit if there's a workaround I'm missing.

    Line 223, Patchset 4: element = fastOW.LoadElementNoHole(index) otherwise FoundHole;
    Leszek Swirski . resolved

    if the inputs are DOUBLE_ELEMENTS, this will need to materialize a new Number. It would be nice if `CalculateFlattenedLengthFast` also calculated whether _all_ input arrays are DOUBLE_ELEMENTS, and if yes, you could have a separate fast path that avoids this allocation and preallocates the FlatVector already as a `FixedDoubleArray`.

    Amemiya Riya

    Thank you for the suggestion. I've added an allDouble flag to CalculateFlattenedLengthFast that tracks whether all leaf elements are Numbers. When true, TryFastFlat now writes directly into a FixedDoubleArray,avoiding the FlatVector intermediate step and the HeapNumber allocation overhead.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Igor Sheludko
    • Leszek Swirski
    • Olivier Flückiger
    Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: v8/v8
    Gerrit-Branch: main
    Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
    Gerrit-Change-Number: 7526287
    Gerrit-PatchSet: 5
    Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
    Gerrit-Reviewer: Igor Sheludko <ish...@chromium.org>
    Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
    Gerrit-Reviewer: Olivier Flückiger <ol...@chromium.org>
    Gerrit-Attention: Igor Sheludko <ish...@chromium.org>
    Gerrit-Attention: Olivier Flückiger <ol...@chromium.org>
    Gerrit-Attention: Leszek Swirski <les...@chromium.org>
    Gerrit-Comment-Date: Thu, 19 Feb 2026 10:08:14 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Leszek Swirski <les...@chromium.org>
    unsatisfied_requirement
    open
    diffy

    Leszek Swirski (Gerrit)

    unread,
    Feb 19, 2026, 5:18:31 AM (5 days ago) Feb 19
    to Amemiya Riya, Olivier Flückiger, Igor Sheludko, v8-re...@googlegroups.com
    Attention needed from Amemiya Riya, Igor Sheludko and Olivier Flückiger

    Leszek Swirski added 2 comments

    File src/builtins/array-flat.tq
    Line 51, Patchset 4: case (TheHole): {
    }
    Leszek Swirski . unresolved

    I think you have to set `undefined` values for incoming holes too, because the flattened result will `Get` from the input and read `undefined`, not `hole`.

    You can test this by adding a test case like:

    ```
    let a = [,,];
    let b = [a].flat();
    assertEquals(a[0], undefined);
    assertEquals(b[0], undefined);
    Array.prototype[0] = 42;
    assertEquals(a[0], 42);
    assertEquals(b[0], undefined);
    ```

    Please double check current behaviour when you do this just to make sure I'm right.

    Amemiya Riya

    Thank you, I double-checked this. Holes in nested arrays should be correctly skipped since HasProperty returns false for them, so [,,].flat() produces [] (length=0). After setting Array.prototype[0] = 42, b[0] returns 42 via the prototype chain, which appears to match the slow path behaviour. Let me know if I'm missing something.

    Leszek Swirski

    Thanks, I missed the `Has` in the `flat` spec. In that case, I think you're already skipping holes before calling `StoreResult`, which means you should be able to mark the Hole case here unreachable.

    Line 208, Patchset 4: let stack = growable_fixed_array::NewGrowableFixedArray();
    Leszek Swirski . resolved

    rather than an allocated stack, what about using the machine stack by having a recursive call to a helper?

    Amemiya Riya

    Thank you for the suggestion. I tried converting this to a recursive builtin, but ran into a Torque compiler limitation — inlining complex macros (FastJSArrayWitness + try/label FoundHole + continue) into a builtin body causes the compiler to crash with a stack overflow (SIGSEGV). Additionally, FastJSArray is a transient type and cannot be used as a builtin argument. I've kept the allocated stack approach for now, but happy to revisit if there's a workaround I'm missing.

    Leszek Swirski

    let's keep it as-is and revisit separately then, thanks for checking.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Amemiya Riya
    • Igor Sheludko
    • Olivier Flückiger
    Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: v8/v8
    Gerrit-Branch: main
    Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
    Gerrit-Change-Number: 7526287
    Gerrit-PatchSet: 5
    Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
    Gerrit-Reviewer: Igor Sheludko <ish...@chromium.org>
    Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
    Gerrit-Reviewer: Olivier Flückiger <ol...@chromium.org>
    Gerrit-Attention: Amemiya Riya <riyaa...@gmail.com>
    Gerrit-Attention: Igor Sheludko <ish...@chromium.org>
    Gerrit-Attention: Olivier Flückiger <ol...@chromium.org>
    Gerrit-Comment-Date: Thu, 19 Feb 2026 10:18:26 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Amemiya Riya <riyaa...@gmail.com>
    Comment-In-Reply-To: Leszek Swirski <les...@chromium.org>
    unsatisfied_requirement
    open
    diffy

    Amemiya Riya (Gerrit)

    unread,
    Feb 19, 2026, 8:28:38 AM (5 days ago) Feb 19
    to Olivier Flückiger, Igor Sheludko, Leszek Swirski, v8-re...@googlegroups.com
    Attention needed from Igor Sheludko, Leszek Swirski and Olivier Flückiger

    Amemiya Riya added 1 comment

    File src/builtins/array-flat.tq
    Line 51, Patchset 4: case (TheHole): {
    }
    Leszek Swirski . resolved

    I think you have to set `undefined` values for incoming holes too, because the flattened result will `Get` from the input and read `undefined`, not `hole`.

    You can test this by adding a test case like:

    ```
    let a = [,,];
    let b = [a].flat();
    assertEquals(a[0], undefined);
    assertEquals(b[0], undefined);
    Array.prototype[0] = 42;
    assertEquals(a[0], 42);
    assertEquals(b[0], undefined);
    ```

    Please double check current behaviour when you do this just to make sure I'm right.

    Amemiya Riya

    Thank you, I double-checked this. Holes in nested arrays should be correctly skipped since HasProperty returns false for them, so [,,].flat() produces [] (length=0). After setting Array.prototype[0] = 42, b[0] returns 42 via the prototype chain, which appears to match the slow path behaviour. Let me know if I'm missing something.

    Leszek Swirski

    Thanks, I missed the `Has` in the `flat` spec. In that case, I think you're already skipping holes before calling `StoreResult`, which means you should be able to mark the Hole case here unreachable.

    Amemiya Riya

    Thank you for confirming. I've marked the Hole cases as unreachable.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Igor Sheludko
    • Leszek Swirski
    • Olivier Flückiger
    Submit Requirements:
      • requirement is not satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: v8/v8
      Gerrit-Branch: main
      Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
      Gerrit-Change-Number: 7526287
      Gerrit-PatchSet: 6
      Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
      Gerrit-Reviewer: Igor Sheludko <ish...@chromium.org>
      Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
      Gerrit-Reviewer: Olivier Flückiger <ol...@chromium.org>
      Gerrit-Attention: Igor Sheludko <ish...@chromium.org>
      Gerrit-Attention: Olivier Flückiger <ol...@chromium.org>
      Gerrit-Attention: Leszek Swirski <les...@chromium.org>
      Gerrit-Comment-Date: Thu, 19 Feb 2026 13:28:33 +0000
      unsatisfied_requirement
      open
      diffy

      Leszek Swirski (Gerrit)

      unread,
      Feb 19, 2026, 8:29:34 AM (5 days ago) Feb 19
      to Amemiya Riya, Olivier Flückiger, Igor Sheludko, v8-re...@googlegroups.com
      Attention needed from Amemiya Riya, Igor Sheludko and Olivier Flückiger

      Leszek Swirski voted Code-Review+1

      Code-Review+1
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Amemiya Riya
      • Igor Sheludko
      • Olivier Flückiger
      Submit Requirements:
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: v8/v8
      Gerrit-Branch: main
      Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
      Gerrit-Change-Number: 7526287
      Gerrit-PatchSet: 6
      Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
      Gerrit-Reviewer: Igor Sheludko <ish...@chromium.org>
      Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
      Gerrit-Reviewer: Olivier Flückiger <ol...@chromium.org>
      Gerrit-Attention: Amemiya Riya <riyaa...@gmail.com>
      Gerrit-Attention: Igor Sheludko <ish...@chromium.org>
      Gerrit-Attention: Olivier Flückiger <ol...@chromium.org>
      Gerrit-Comment-Date: Thu, 19 Feb 2026 13:29:30 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Amemiya Riya (Gerrit)

      unread,
      Feb 19, 2026, 9:37:55 AM (5 days ago) Feb 19
      to Leszek Swirski, Olivier Flückiger, Igor Sheludko, v8-re...@googlegroups.com
      Attention needed from Igor Sheludko and Olivier Flückiger

      Amemiya Riya added 1 comment

      Patchset-level comments
      File-level comment, Patchset 6 (Latest):
      Amemiya Riya . resolved

      @ish...@chromium.org @ol...@chromium.org

      Hello. I would need one more review to merge this, so would you be able to take a look when you have a chance? I also don't have the permission to submit to CQ, so I would really appreciate it if you could do that after review. Thank you very much!

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Igor Sheludko
      • Olivier Flückiger
      Submit Requirements:
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: v8/v8
      Gerrit-Branch: main
      Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
      Gerrit-Change-Number: 7526287
      Gerrit-PatchSet: 6
      Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
      Gerrit-Reviewer: Igor Sheludko <ish...@chromium.org>
      Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
      Gerrit-Reviewer: Olivier Flückiger <ol...@chromium.org>
      Gerrit-Attention: Igor Sheludko <ish...@chromium.org>
      Gerrit-Attention: Olivier Flückiger <ol...@chromium.org>
      Gerrit-Comment-Date: Thu, 19 Feb 2026 14:37:47 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Amemiya Riya (Gerrit)

      unread,
      Feb 19, 2026, 1:36:11 PM (5 days ago) Feb 19
      to V8 LUCI CQ, Leszek Swirski, Olivier Flückiger, Igor Sheludko, v8-re...@googlegroups.com
      Attention needed from Igor Sheludko, Leszek Swirski and Olivier Flückiger

      Amemiya Riya added 1 comment

      Patchset-level comments
      File-level comment, Patchset 7 (Latest):
      Amemiya Riya . resolved

      @les...@chromium.org

      I have fixed the test failures. Could you please take a look when you have a chance?

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Igor Sheludko
      • Leszek Swirski
      • Olivier Flückiger
      Submit Requirements:
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: v8/v8
      Gerrit-Branch: main
      Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
      Gerrit-Change-Number: 7526287
      Gerrit-PatchSet: 7
      Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
      Gerrit-Reviewer: Igor Sheludko <ish...@chromium.org>
      Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
      Gerrit-Reviewer: Olivier Flückiger <ol...@chromium.org>
      Gerrit-Attention: Igor Sheludko <ish...@chromium.org>
      Gerrit-Attention: Olivier Flückiger <ol...@chromium.org>
      Gerrit-Attention: Leszek Swirski <les...@chromium.org>
      Gerrit-Comment-Date: Thu, 19 Feb 2026 18:36:03 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Leszek Swirski (Gerrit)

      unread,
      Feb 20, 2026, 3:49:22 AM (4 days ago) Feb 20
      to Amemiya Riya, V8 LUCI CQ, Olivier Flückiger, Igor Sheludko, v8-re...@googlegroups.com
      Attention needed from Amemiya Riya, Igor Sheludko and Olivier Flückiger

      Leszek Swirski voted Code-Review+1

      Code-Review+1
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Amemiya Riya
      • Igor Sheludko
      • Olivier Flückiger
      Submit Requirements:
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: v8/v8
      Gerrit-Branch: main
      Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
      Gerrit-Change-Number: 7526287
      Gerrit-PatchSet: 7
      Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
      Gerrit-Reviewer: Igor Sheludko <ish...@chromium.org>
      Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
      Gerrit-Reviewer: Olivier Flückiger <ol...@chromium.org>
      Gerrit-Attention: Amemiya Riya <riyaa...@gmail.com>
      Gerrit-Attention: Igor Sheludko <ish...@chromium.org>
      Gerrit-Attention: Olivier Flückiger <ol...@chromium.org>
      Gerrit-Comment-Date: Fri, 20 Feb 2026 08:49:17 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Amemiya Riya (Gerrit)

      unread,
      Feb 20, 2026, 4:42:21 AM (4 days ago) Feb 20
      to Leszek Swirski, V8 LUCI CQ, Olivier Flückiger, Igor Sheludko, v8-re...@googlegroups.com
      Attention needed from Igor Sheludko, Leszek Swirski and Olivier Flückiger

      Amemiya Riya added 1 comment

      Patchset-level comments
      Amemiya Riya . resolved

      Thank you for taking the time to review this multiple times.

      Since I do not have try job permissions, could you please trigger a CQ Dry Run again?

      Once the tests pass, it would be great to get a review from one more person, as I need a second +1 to merge this.

      Additionally, as I don't have permission to click "SUBMIT TO CQ", could you please submit it for me when it's ready?

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Igor Sheludko
      • Leszek Swirski
      • Olivier Flückiger
      Submit Requirements:
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: v8/v8
      Gerrit-Branch: main
      Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
      Gerrit-Change-Number: 7526287
      Gerrit-PatchSet: 7
      Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
      Gerrit-Reviewer: Igor Sheludko <ish...@chromium.org>
      Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
      Gerrit-Reviewer: Olivier Flückiger <ol...@chromium.org>
      Gerrit-Attention: Igor Sheludko <ish...@chromium.org>
      Gerrit-Attention: Olivier Flückiger <ol...@chromium.org>
      Gerrit-Attention: Leszek Swirski <les...@chromium.org>
      Gerrit-Comment-Date: Fri, 20 Feb 2026 09:42:15 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Amemiya Riya (Gerrit)

      unread,
      Feb 20, 2026, 5:33:18 AM (4 days ago) Feb 20
      to Leszek Swirski, V8 LUCI CQ, Olivier Flückiger, Igor Sheludko, v8-re...@googlegroups.com
      Attention needed from Igor Sheludko and Olivier Flückiger

      Amemiya Riya added 1 comment

      Patchset-level comments
      Amemiya Riya . resolved

      Thank you for triggering the dry run. The tests have passed!

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Igor Sheludko
      • Olivier Flückiger
      Submit Requirements:
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: v8/v8
      Gerrit-Branch: main
      Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
      Gerrit-Change-Number: 7526287
      Gerrit-PatchSet: 7
      Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
      Gerrit-Reviewer: Igor Sheludko <ish...@chromium.org>
      Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
      Gerrit-Reviewer: Olivier Flückiger <ol...@chromium.org>
      Gerrit-Attention: Igor Sheludko <ish...@chromium.org>
      Gerrit-Attention: Olivier Flückiger <ol...@chromium.org>
      Gerrit-Comment-Date: Fri, 20 Feb 2026 10:33:12 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Olivier Flückiger (Gerrit)

      unread,
      Feb 20, 2026, 8:14:43 AM (4 days ago) Feb 20
      to Amemiya Riya, Leszek Swirski, V8 LUCI CQ, Igor Sheludko, v8-re...@googlegroups.com
      Attention needed from Igor Sheludko

      Olivier Flückiger added 5 comments

      Patchset-level comments
      Olivier Flückiger . resolved

      Thanks for the contribution. This is a nice improvement indeed.

      My high-level comment here is that we should be weary of introducing too much polymorphism. On the one hand from generalizing where not needed (smi -> double) but also from specializing where we don't have a witness that this is a stable situation and a target elements kind which is expensive to get out of again (normal -> double)

      Wdyt about lower bounding the target elements kind by the max leaf elements kind (modulo holey)?

      File src/builtins/array-flat.tq
      Line 37, Patchset 7 (Latest): if (IsDoubleElementsKind(kind)) {
      Olivier Flückiger . unresolved

      I am not sure I like the idea of converting something that was not a double array to a double array. This has the potential of causing additional polymorphism and expensive conversions. E.g., if we have code that is repeatedly calling `flat()` on an array and then adding more arrays to the result.

      Line 159, Patchset 7 (Latest): const elementArray: FastJSArray =
      Olivier Flückiger . unresolved

      in general if the the array is packed or holey smi oder double, then there is no need to scan it, because we already know it won't contain any arrays! same for typed arrays. (and ofc same for the source array itself).

      Line 179, Patchset 7 (Latest): if (allDouble && !Is<Number>(element)) allDouble = false;
      Olivier Flückiger . unresolved

      This will convert SMI arrays to DOUBLE arrays. I don't think this is what we want.

      Line 301, Patchset 7 (Latest): return NewJSArray(doubleMap, doubleElements);
      Olivier Flückiger . unresolved

      I find it a bit confusing that this case does not use the NewFlatVector helper. It took me a while to understand why we have this, and the ToDouble conversion case in the helper.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Igor Sheludko
      Submit Requirements:
        • requirement satisfiedCode-Owners
        • requirement is not satisfiedCode-Review
        • requirement is not satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: v8/v8
        Gerrit-Branch: main
        Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
        Gerrit-Change-Number: 7526287
        Gerrit-PatchSet: 7
        Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
        Gerrit-Reviewer: Igor Sheludko <ish...@chromium.org>
        Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
        Gerrit-Reviewer: Olivier Flückiger <ol...@chromium.org>
        Gerrit-Attention: Igor Sheludko <ish...@chromium.org>
        Gerrit-Comment-Date: Fri, 20 Feb 2026 13:14:38 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Olivier Flückiger (Gerrit)

        unread,
        Feb 20, 2026, 8:46:55 AM (4 days ago) Feb 20
        to Amemiya Riya, Leszek Swirski, V8 LUCI CQ, Igor Sheludko, v8-re...@googlegroups.com
        Attention needed from Amemiya Riya and Igor Sheludko

        Olivier Flückiger added 1 comment

        File src/builtins/array-flat.tq
        Line 160, Patchset 7 (Latest): Cast<FastJSArray>(element) otherwise goto Bailout;
        Olivier Flückiger . unresolved

        Here (and probably most similar casts) you could use `Cast<FastJSArrayForRead>` instead.

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Amemiya Riya
        • Igor Sheludko
        Submit Requirements:
        • requirement satisfiedCode-Owners
        • requirement is not satisfiedCode-Review
        • requirement is not satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: v8/v8
        Gerrit-Branch: main
        Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
        Gerrit-Change-Number: 7526287
        Gerrit-PatchSet: 7
        Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
        Gerrit-Reviewer: Igor Sheludko <ish...@chromium.org>
        Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
        Gerrit-Reviewer: Olivier Flückiger <ol...@chromium.org>
        Gerrit-Attention: Amemiya Riya <riyaa...@gmail.com>
        Gerrit-Attention: Igor Sheludko <ish...@chromium.org>
        Gerrit-Comment-Date: Fri, 20 Feb 2026 13:46:49 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Amemiya Riya (Gerrit)

        unread,
        Feb 21, 2026, 11:49:22 PM (2 days ago) Feb 21
        to Leszek Swirski, V8 LUCI CQ, Olivier Flückiger, Igor Sheludko, v8-re...@googlegroups.com
        Attention needed from Igor Sheludko, Leszek Swirski and Olivier Flückiger

        Amemiya Riya added 5 comments

        File src/builtins/array-flat.tq
        Line 37, Patchset 7: if (IsDoubleElementsKind(kind)) {
        Olivier Flückiger . resolved

        I am not sure I like the idea of converting something that was not a double array to a double array. This has the potential of causing additional polymorphism and expensive conversions. E.g., if we have code that is repeatedly calling `flat()` on an array and then adding more arrays to the result.

        Amemiya Riya

        Thanks for the suggestion. I've introduced a targetKind variable derived from the elements kind of each array using GetPackedElementsKind and GetMoreGeneralElementsKind. This tracks the most general input kind and avoids spurious widening.

        Line 159, Patchset 7: const elementArray: FastJSArray =
        Olivier Flückiger . resolved

        in general if the the array is packed or holey smi oder double, then there is no need to scan it, because we already know it won't contain any arrays! same for typed arrays. (and ofc same for the source array itself).

        Amemiya Riya

        I updated the code to add the length directly for PACKED_SMI_ELEMENTS and PACKED_DOUBLE_ELEMENTS without scanning. I excluded holey variants because holes are skipped during flattening, so using array.length would overcount the actual elements.

        Line 160, Patchset 7: Cast<FastJSArray>(element) otherwise goto Bailout;
        Olivier Flückiger . resolved

        Here (and probably most similar casts) you could use `Cast<FastJSArrayForRead>` instead.

        Amemiya Riya

        I've updated the internal sub-array casts and traversal variables to use FastJSArrayForRead. The entry parameter remains FastJSArrayForCopy for compatibility with the caller.

        Line 179, Patchset 7: if (allDouble && !Is<Number>(element)) allDouble = false;
        Olivier Flückiger . resolved

        This will convert SMI arrays to DOUBLE arrays. I don't think this is what we want.

        Amemiya Riya

        This is resolved by the targetKind refactoring mentioned in #37. An all-Smi input now correctly produces a PACKED_SMI_ELEMENTS result.

        Line 301, Patchset 7: return NewJSArray(doubleMap, doubleElements);
        Olivier Flückiger . resolved

        I find it a bit confusing that this case does not use the NewFlatVector helper. It took me a while to understand why we have this, and the ToDouble conversion case in the helper.

        Amemiya Riya

        The double path writes directly to a FixedDoubleArray to avoid an intermediate FixedArray allocation and copy, which is why it bypasses FlatVector. To make this clearer, I simplified FlatVector by removing type tracking fields and removed the now-unreachable ToDouble conversion branch.

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Igor Sheludko
        • Leszek Swirski
        • Olivier Flückiger
        Submit Requirements:
          • requirement satisfiedCode-Owners
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedReview-Enforcement
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: v8/v8
          Gerrit-Branch: main
          Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
          Gerrit-Change-Number: 7526287
          Gerrit-PatchSet: 8
          Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
          Gerrit-Reviewer: Igor Sheludko <ish...@chromium.org>
          Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
          Gerrit-Reviewer: Olivier Flückiger <ol...@chromium.org>
          Gerrit-Attention: Igor Sheludko <ish...@chromium.org>
          Gerrit-Attention: Olivier Flückiger <ol...@chromium.org>
          Gerrit-Attention: Leszek Swirski <les...@chromium.org>
          Gerrit-Comment-Date: Sun, 22 Feb 2026 04:49:14 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: No
          Comment-In-Reply-To: Olivier Flückiger <ol...@chromium.org>
          satisfied_requirement
          unsatisfied_requirement
          open
          diffy

          Olivier Flückiger (Gerrit)

          unread,
          Feb 23, 2026, 4:07:12 AM (yesterday) Feb 23
          to Amemiya Riya, Leszek Swirski, V8 LUCI CQ, Igor Sheludko, v8-re...@googlegroups.com
          Attention needed from Amemiya Riya, Igor Sheludko and Leszek Swirski

          Olivier Flückiger added 8 comments

          Patchset-level comments
          File-level comment, Patchset 8 (Latest):
          Olivier Flückiger . unresolved

          Thanks, this looks a lot simpler now. This is going in the right direction.

          However, if I understand the changes correctly, we will almost never generate smi/double elements. Basically `[[1]].flat()` will see PACKED_ELEMENTS on the outer array and already generalize to the max.

          My suggestion was actually to only look at the elements kind of leaf arrays (i.e. arrays which do not contain more arrays).

          I tried to add some suggested edits on how I would fix this. No guarantees that it actually works 😊

          To make sure it does work, let's actually add some mjsunit tests. E.g. something like:
          ```
          assertSmiElementsKind([1].flat());
          assertSmiElementsKind([[1]].flat());
          assertSmiElementsKind([[1],[1]].flat());
          assertDoubleElementsKind([1.1].flat());
          assertDoubleElementsKind([[1.1]].flat());
          assertDoubleElementsKind([[1.1],[[1.1]]].flat());
          assertObjectElementsKind([[1],[[1.1]]].flat());
          let generic = [{}];
          generic[0] = 1;
          assertObjectElementsKind(generic.flat());
          assertObjectElementsKind([generic].flat());
          etc...
          ```

          File src/builtins/array-flat.tq
          Line 31, Patchset 8 (Latest):// Order: PACKED_SMI_ELEMENTS < PACKED_DOUBLE_ELEMENTS < PACKED_ELEMENTS.
          Olivier Flückiger . unresolved

          please add a static_assert for that.

          Line 36, Patchset 8 (Latest): if (a == ElementsKind::PACKED_DOUBLE_ELEMENTS ||
          Olivier Flückiger . unresolved

          I would generalize `(SMI v DOUBLE)` to `PACKED`. We typically do so, otherwise e.g., `[huge-smi-array, [1.1]].flat()` doubles the memory consumption.

          Line 83, Patchset 8 (Latest): GetPackedElementsKind(source.map.elements_kind);
          Olivier Flückiger . unresolved
          ```suggestion
          GetPackedElementsKind(source.map.elements_kind);
          let leafArrayNeedsElementsKindUpdate = false;
          if (subKind == ElementsKind::PACKED_ELEMENTS) {
          leafArrayNeedsElementsKindUpdate = true;
          targetKind = ElementsKind::PACKED_SMI_ELEMENTS;
          }
          ```
          Line 87, Patchset 8 (Latest): let currentDepth: Smi = depth;
          Olivier Flückiger . unresolved

          I would also add the packed elements kind check from line 115 here to have a fast-case for users passing already flat numeric arrays to the builtin.

          Line 111, Patchset 8 (Latest): targetKind = GetMoreGeneralElementsKind(targetKind, subKind);
          Olivier Flückiger . unresolved
          ```suggestion
          if (subKind == ElementsKind::PACKED_ELEMENTS) {
          leafArrayNeedsElementsKindUpdate = true;
          subKind = ElementsKind::PACKED_SMI_ELEMENTS;
          }
          targetKind = GetMoreGeneralElementsKind(targetKind, subKind);
          ```
          Line 143, Patchset 8 (Latest): }
          Olivier Flückiger . unresolved
          ```suggestion
          } else if (!IsNumber(element)) {
          targetKind = GetMoreGeneralElementsKind(targetKind,
          ElementsKind::PACKED_ELEMENTS);
          } else if (TaggedIsSmi(element)) {
          targetKind = GetMoreGeneralElementsKind(targetKind,
          ElementsKind::PACKED_DOUBLE_ELEMENTS);
          }
          ```
          Line 154, Patchset 8 (Latest): if (stack.length == 0) break;
          Olivier Flückiger . unresolved
          ```suggestion
          if (leafArrayNeedsElementsKindUpdate) {
          const rawKind: ElementsKind = elementArray.map.elements_kind;
          const subKind: ElementsKind = GetPackedElementsKind(rawKind);
          targetKind = GetMoreGeneralElementsKind(targetKind, subKind);
          }
          leafArrayNeedsElementsKindUpdate = false;
          if (stack.length == 0) break;
          ```
          Open in Gerrit

          Related details

          Attention is currently required from:
          • Amemiya Riya
          • Igor Sheludko
          • Leszek Swirski
          Submit Requirements:
            • requirement satisfiedCode-Owners
            • requirement is not satisfiedCode-Review
            • requirement is not satisfiedNo-Unresolved-Comments
            • requirement is not satisfiedReview-Enforcement
            Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
            Gerrit-MessageType: comment
            Gerrit-Project: v8/v8
            Gerrit-Branch: main
            Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
            Gerrit-Change-Number: 7526287
            Gerrit-PatchSet: 8
            Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
            Gerrit-Reviewer: Igor Sheludko <ish...@chromium.org>
            Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
            Gerrit-Reviewer: Olivier Flückiger <ol...@chromium.org>
            Gerrit-Attention: Amemiya Riya <riyaa...@gmail.com>
            Gerrit-Attention: Igor Sheludko <ish...@chromium.org>
            Gerrit-Attention: Leszek Swirski <les...@chromium.org>
            Gerrit-Comment-Date: Mon, 23 Feb 2026 09:07:06 +0000
            Gerrit-HasComments: Yes
            Gerrit-Has-Labels: No
            satisfied_requirement
            unsatisfied_requirement
            open
            diffy

            Olivier Flückiger (Gerrit)

            unread,
            Feb 23, 2026, 4:09:21 AM (yesterday) Feb 23
            to Amemiya Riya, Leszek Swirski, V8 LUCI CQ, Igor Sheludko, v8-re...@googlegroups.com
            Attention needed from Amemiya Riya, Igor Sheludko and Leszek Swirski

            Olivier Flückiger added 1 comment

            File src/builtins/array-flat.tq
            Olivier Flückiger . unresolved
            ```suggestion
            } else if (!IsNumber(element)) {
            targetKind = GetMoreGeneralElementsKind(targetKind,
            ElementsKind::PACKED_ELEMENTS);
            } else if (TaggedIsSmi(element)) {
            targetKind = GetMoreGeneralElementsKind(targetKind,
            ElementsKind::PACKED_DOUBLE_ELEMENTS);
            }
            ```
            Olivier Flückiger

            `!TaggedIsSmi` of course

            Gerrit-Comment-Date: Mon, 23 Feb 2026 09:09:16 +0000
            Gerrit-HasComments: Yes
            Gerrit-Has-Labels: No
            Comment-In-Reply-To: Olivier Flückiger <ol...@chromium.org>
            satisfied_requirement
            unsatisfied_requirement
            open
            diffy

            Amemiya Riya (Gerrit)

            unread,
            4:17 AM (5 hours ago) 4:17 AM
            to Leszek Swirski, V8 LUCI CQ, Olivier Flückiger, Igor Sheludko, v8-re...@googlegroups.com
            Attention needed from Igor Sheludko, Leszek Swirski and Olivier Flückiger

            Amemiya Riya added 8 comments

            Patchset-level comments
            Olivier Flückiger . unresolved

            Thanks, this looks a lot simpler now. This is going in the right direction.

            However, if I understand the changes correctly, we will almost never generate smi/double elements. Basically `[[1]].flat()` will see PACKED_ELEMENTS on the outer array and already generalize to the max.

            My suggestion was actually to only look at the elements kind of leaf arrays (i.e. arrays which do not contain more arrays).

            I tried to add some suggested edits on how I would fix this. No guarantees that it actually works 😊

            To make sure it does work, let's actually add some mjsunit tests. E.g. something like:
            ```
            assertSmiElementsKind([1].flat());
            assertSmiElementsKind([[1]].flat());
            assertSmiElementsKind([[1],[1]].flat());
            assertDoubleElementsKind([1.1].flat());
            assertDoubleElementsKind([[1.1]].flat());
            assertDoubleElementsKind([[1.1],[[1.1]]].flat());
            assertObjectElementsKind([[1],[[1.1]]].flat());
            let generic = [{}];
            generic[0] = 1;
            assertObjectElementsKind(generic.flat());
            assertObjectElementsKind([generic].flat());
            etc...
            ```

            Amemiya Riya

            Thank you for the detailed review and the suggested edits. I've implemented the leaf array inspection approach, but used boolean flags (seenSmi, seenDouble, seenObject) instead of the merge-based approach in the suggested edits.

            The reason is that resetting PACKED_ELEMENTS sub-array kind to SMI as a placeholder causes incorrect merges at deeper nesting levels — for example, [[[1.1],[2.2]]].flat(2) would produce PACKED_ELEMENTS instead of PACKED_DOUBLE_ELEMENTS because the placeholder SMI gets merged with the first DOUBLE sub-array.

            The boolean flags approach avoids this by tracking seen types directly.
            All the test cases you suggested are added, except for assertDoubleElementsKind([[1.1],[[1.1]]].flat()) — the default flat depth is 1, so the result is [1.1, [1.1]] which contains an array reference, meaning PACKED_DOUBLE_ELEMENTS is not achievable. Was this intended for a different input or a depth of 2?

            File src/builtins/array-flat.tq
            Line 31, Patchset 8:// Order: PACKED_SMI_ELEMENTS < PACKED_DOUBLE_ELEMENTS < PACKED_ELEMENTS.
            Olivier Flückiger . resolved

            please add a static_assert for that.

            Amemiya Riya

            The macro GetMoreGeneralElementsKind was removed in this patchset since the boolean flags approach replaces the merge logic entirely, so there is no longer a place where the static_assert would apply.

            Line 36, Patchset 8: if (a == ElementsKind::PACKED_DOUBLE_ELEMENTS ||
            Olivier Flückiger . resolved

            I would generalize `(SMI v DOUBLE)` to `PACKED`. We typically do so, otherwise e.g., `[huge-smi-array, [1.1]].flat()` doubles the memory consumption.

            Amemiya Riya

            Thank you for the suggestion. The SMI+DOUBLE → PACKED_ELEMENTS behavior is preserved in the final kind determination using boolean flags. GetMoreGeneralElementsKind itself was removed since the boolean flags approach does not need a merge function.

            Line 83, Patchset 8: GetPackedElementsKind(source.map.elements_kind);
            Olivier Flückiger . resolved
            ```suggestion
            GetPackedElementsKind(source.map.elements_kind);
            let leafArrayNeedsElementsKindUpdate = false;
            if (subKind == ElementsKind::PACKED_ELEMENTS) {
            leafArrayNeedsElementsKindUpdate = true;
            targetKind = ElementsKind::PACKED_SMI_ELEMENTS;
            }
            ```
            Amemiya Riya

            Thank you for the suggested edit. I took a slightly different approach — packed numeric sources return early with their kind, and PACKED_ELEMENTS sources fall through to the full scan using boolean flags. The merge-based initialization with a SMI placeholder caused incorrect results at deeper nesting levels (see top-level comment for details).

            Line 87, Patchset 8: let currentDepth: Smi = depth;
            Olivier Flückiger . resolved

            I would also add the packed elements kind check from line 115 here to have a fast-case for users passing already flat numeric arrays to the builtin.

            Amemiya Riya

            Thank you for the suggestion. Implemented as an early return for PACKED_SMI_ELEMENTS and PACKED_DOUBLE_ELEMENTS sources.

            Line 111, Patchset 8: targetKind = GetMoreGeneralElementsKind(targetKind, subKind);
            Olivier Flückiger . resolved
            ```suggestion
            if (subKind == ElementsKind::PACKED_ELEMENTS) {
            leafArrayNeedsElementsKindUpdate = true;
            subKind = ElementsKind::PACKED_SMI_ELEMENTS;
            }
            targetKind = GetMoreGeneralElementsKind(targetKind, subKind);
            ```
            Amemiya Riya

            Thank you for the suggested edit. I took a slightly different approach here — packed numeric sub-arrays set the corresponding boolean flag and add their length directly, while PACKED_ELEMENTS sub-arrays are descended into so their leaf elements are inspected individually. Resetting PACKED_ELEMENTS to SMI and merging it as a placeholder caused incorrect results at depth > 1, e.g. [[[1.1],[2.2]]].flat(2) produced PACKED_ELEMENTS instead of PACKED_DOUBLE_ELEMENTS.

            Line 143, Patchset 8: }
            Olivier Flückiger . resolved
            ```suggestion
            } else if (!IsNumber(element)) {
            targetKind = GetMoreGeneralElementsKind(targetKind,
            ElementsKind::PACKED_ELEMENTS);
            } else if (TaggedIsSmi(element)) {
            targetKind = GetMoreGeneralElementsKind(targetKind,
            ElementsKind::PACKED_DOUBLE_ELEMENTS);
            }
            ```
            Olivier Flückiger

            `!TaggedIsSmi` of course

            Amemiya Riya

            Done

            Line 154, Patchset 8: if (stack.length == 0) break;
            Olivier Flückiger . resolved
            ```suggestion
            if (leafArrayNeedsElementsKindUpdate) {
            const rawKind: ElementsKind = elementArray.map.elements_kind;
            const subKind: ElementsKind = GetPackedElementsKind(rawKind);
            targetKind = GetMoreGeneralElementsKind(targetKind, subKind);
            }
            leafArrayNeedsElementsKindUpdate = false;
            if (stack.length == 0) break;
            ```
            Amemiya Riya

            This is no longer needed with the current approach. Since PACKED_ELEMENTS sub-arrays are descended into rather than merged, there is no placeholder kind to correct during ascending.

            Open in Gerrit

            Related details

            Attention is currently required from:
            • Igor Sheludko
            • Leszek Swirski
            • Olivier Flückiger
            Submit Requirements:
            • requirement is not satisfiedCode-Owners
            • requirement is not satisfiedCode-Review
            • requirement is not satisfiedNo-Unresolved-Comments
            • requirement is not satisfiedReview-Enforcement
            Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
            Gerrit-MessageType: comment
            Gerrit-Project: v8/v8
            Gerrit-Branch: main
            Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
            Gerrit-Change-Number: 7526287
            Gerrit-PatchSet: 11
            Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
            Gerrit-Reviewer: Igor Sheludko <ish...@chromium.org>
            Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
            Gerrit-Reviewer: Olivier Flückiger <ol...@chromium.org>
            Gerrit-Attention: Igor Sheludko <ish...@chromium.org>
            Gerrit-Attention: Olivier Flückiger <ol...@chromium.org>
            Gerrit-Attention: Leszek Swirski <les...@chromium.org>
            Gerrit-Comment-Date: Tue, 24 Feb 2026 09:17:41 +0000
            unsatisfied_requirement
            open
            diffy

            Olivier Flückiger (Gerrit)

            unread,
            5:47 AM (3 hours ago) 5:47 AM
            to Amemiya Riya, Leszek Swirski, V8 LUCI CQ, Igor Sheludko, v8-re...@googlegroups.com
            Attention needed from Amemiya Riya, Igor Sheludko and Leszek Swirski

            Olivier Flückiger voted and added 2 comments

            Votes added by Olivier Flückiger

            Code-Review+1

            2 comments

            Patchset-level comments
            File-level comment, Patchset 8:
            Olivier Flückiger . resolved

            Thanks, this looks a lot simpler now. This is going in the right direction.

            However, if I understand the changes correctly, we will almost never generate smi/double elements. Basically `[[1]].flat()` will see PACKED_ELEMENTS on the outer array and already generalize to the max.

            My suggestion was actually to only look at the elements kind of leaf arrays (i.e. arrays which do not contain more arrays).

            I tried to add some suggested edits on how I would fix this. No guarantees that it actually works 😊

            To make sure it does work, let's actually add some mjsunit tests. E.g. something like:
            ```
            assertSmiElementsKind([1].flat());
            assertSmiElementsKind([[1]].flat());
            assertSmiElementsKind([[1],[1]].flat());
            assertDoubleElementsKind([1.1].flat());
            assertDoubleElementsKind([[1.1]].flat());
            assertDoubleElementsKind([[1.1],[[1.1]]].flat());
            assertObjectElementsKind([[1],[[1.1]]].flat());
            let generic = [{}];
            generic[0] = 1;
            assertObjectElementsKind(generic.flat());
            assertObjectElementsKind([generic].flat());
            etc...
            ```

            Amemiya Riya

            Thank you for the detailed review and the suggested edits. I've implemented the leaf array inspection approach, but used boolean flags (seenSmi, seenDouble, seenObject) instead of the merge-based approach in the suggested edits.

            The reason is that resetting PACKED_ELEMENTS sub-array kind to SMI as a placeholder causes incorrect merges at deeper nesting levels — for example, [[[1.1],[2.2]]].flat(2) would produce PACKED_ELEMENTS instead of PACKED_DOUBLE_ELEMENTS because the placeholder SMI gets merged with the first DOUBLE sub-array.

            The boolean flags approach avoids this by tracking seen types directly.
            All the test cases you suggested are added, except for assertDoubleElementsKind([[1.1],[[1.1]]].flat()) — the default flat depth is 1, so the result is [1.1, [1.1]] which contains an array reference, meaning PACKED_DOUBLE_ELEMENTS is not achievable. Was this intended for a different input or a depth of 2?

            Olivier Flückiger

            Was this intended for a different input or a depth of 2?

            yes, of course.

            File-level comment, Patchset 11 (Latest):
            Olivier Flückiger . resolved

            lgtm, thanks for the additional improvements.

            Open in Gerrit

            Related details

            Attention is currently required from:
            • Amemiya Riya
            • Igor Sheludko
            • Leszek Swirski
            Submit Requirements:
            • requirement satisfiedCode-Owners
            • requirement is not satisfiedCode-Review
            • requirement is not satisfiedReview-Enforcement
            Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
            Gerrit-MessageType: comment
            Gerrit-Project: v8/v8
            Gerrit-Branch: main
            Gerrit-Change-Id: I2eea8c149b5c6a522fef086f36df108ca7a0a2e2
            Gerrit-Change-Number: 7526287
            Gerrit-PatchSet: 11
            Gerrit-Owner: Amemiya Riya <riyaa...@gmail.com>
            Gerrit-Reviewer: Igor Sheludko <ish...@chromium.org>
            Gerrit-Reviewer: Leszek Swirski <les...@chromium.org>
            Gerrit-Reviewer: Olivier Flückiger <ol...@chromium.org>
            Gerrit-Attention: Amemiya Riya <riyaa...@gmail.com>
            Gerrit-Attention: Igor Sheludko <ish...@chromium.org>
            Gerrit-Attention: Leszek Swirski <les...@chromium.org>
            Gerrit-Comment-Date: Tue, 24 Feb 2026 10:47:33 +0000
            Gerrit-HasComments: Yes
            Gerrit-Has-Labels: Yes
            Comment-In-Reply-To: Amemiya Riya <riyaa...@gmail.com>
            Comment-In-Reply-To: Olivier Flückiger <ol...@chromium.org>
            satisfied_requirement
            unsatisfied_requirement
            open
            diffy
            Reply all
            Reply to author
            Forward
            0 new messages