[S] Change in dart/sdk[main]: [dart2js] Add a 'FALSE' JS_GET_FLAG.

0 views
Skip to first unread message

Mayank Patke (Gerrit)

unread,
Nov 23, 2022, 6:17:24 PM11/23/22
to Stephen Adams, dart2js-te...@google.com, rev...@dartlang.org

Attention is currently required from: Stephen Adams.

Mayank Patke would like Stephen Adams to review this change.

View Change

[dart2js] Add a 'FALSE' JS_GET_FLAG.

There are a few places in our runtime libraries where we have some code
guarded by `if (false)`. This is to ensure that the guarded code is
marked as used and compiled, but not emitted unless rewritten during
SSA. This pattern is somewhat brittle - a kernel
optimization/transformation which eliminates dead code may discard the
code.

Instead, we can write `if (JS_GET_FLAG('FALSE'))`, which will only be
written to `if (false)` and then discarded during SSA.

Change-Id: I8edc2b24e5fbeece1f042ff3d0c87d58e939bf84
---
M pkg/compiler/lib/src/ssa/builder.dart
M sdk/lib/_internal/js_runtime/lib/interceptors.dart
M sdk/lib/_internal/js_runtime/lib/js_number.dart
3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/pkg/compiler/lib/src/ssa/builder.dart b/pkg/compiler/lib/src/ssa/builder.dart
index c3e3796..eb50233 100644
--- a/pkg/compiler/lib/src/ssa/builder.dart
+++ b/pkg/compiler/lib/src/ssa/builder.dart
@@ -368,6 +368,8 @@
/// concrete SSA builder reports an error.
bool _getFlagValue(String flagName) {
switch (flagName) {
+ case 'FALSE':
+ return false;
case 'DEV_COMPILER':
return false;
case 'MINIFIED':
diff --git a/sdk/lib/_internal/js_runtime/lib/interceptors.dart b/sdk/lib/_internal/js_runtime/lib/interceptors.dart
index bda0ac3..f15041c 100644
--- a/sdk/lib/_internal/js_runtime/lib/interceptors.dart
+++ b/sdk/lib/_internal/js_runtime/lib/interceptors.dart
@@ -8,6 +8,7 @@
show DISPATCH_PROPERTY_NAME, TYPE_TO_INTERCEPTOR_MAP;

import 'dart:collection' hide LinkedList, LinkedListEntry;
+import 'dart:_foreign_helper' show JS_GET_FLAG;
import 'dart:_internal' hide Symbol;
import "dart:_internal" as _symbol_dev show Symbol;
import 'dart:_js_helper'
diff --git a/sdk/lib/_internal/js_runtime/lib/js_number.dart b/sdk/lib/_internal/js_runtime/lib/js_number.dart
index 356a4c0..209a45a 100644
--- a/sdk/lib/_internal/js_runtime/lib/js_number.dart
+++ b/sdk/lib/_internal/js_runtime/lib/js_number.dart
@@ -340,7 +340,7 @@

int operator ~/(num other) {
if (other is! num) throw argumentErrorValue(other);
- if (false) _tdivFast(other); // Ensure resolution.
+ if (JS_GET_FLAG('FALSE')) _tdivFast(other); // Ensure resolution.
if (_isInt32(this)) {
if (other >= 1 || other < -1) {
return JS('int', r'(# / #) | 0', this, other);
@@ -400,7 +400,7 @@
num operator >>(num other) {
if (other is! num) throw argumentErrorValue(other);
if (other < 0) throw argumentErrorValue(other);
- if (false) _shrReceiverPositive(other);
+ if (JS_GET_FLAG('FALSE')) _shrReceiverPositive(other);
return _shrOtherPositive(other);
}


To view, visit change 271800. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I8edc2b24e5fbeece1f042ff3d0c87d58e939bf84
Gerrit-Change-Number: 271800
Gerrit-PatchSet: 3
Gerrit-Owner: Mayank Patke <fishyt...@google.com>
Gerrit-Reviewer: Mayank Patke <fishyt...@google.com>
Gerrit-Reviewer: Stephen Adams <s...@google.com>
Gerrit-Attention: Stephen Adams <s...@google.com>
Gerrit-MessageType: newchange

Mayank Patke (Gerrit)

unread,
Nov 23, 2022, 6:17:26 PM11/23/22
to dart2js-te...@google.com, rev...@dartlang.org, Stephen Adams, CBuild, Commit Queue

Attention is currently required from: Stephen Adams.

Patch set 3:Commit-Queue +1

View Change

    To view, visit change 271800. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sdk
    Gerrit-Branch: main
    Gerrit-Change-Id: I8edc2b24e5fbeece1f042ff3d0c87d58e939bf84
    Gerrit-Change-Number: 271800
    Gerrit-PatchSet: 3
    Gerrit-Owner: Mayank Patke <fishyt...@google.com>
    Gerrit-Reviewer: Mayank Patke <fishyt...@google.com>
    Gerrit-Reviewer: Stephen Adams <s...@google.com>
    Gerrit-Attention: Stephen Adams <s...@google.com>
    Gerrit-Comment-Date: Wed, 23 Nov 2022 23:17:21 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Stephen Adams (Gerrit)

    unread,
    Nov 23, 2022, 7:06:11 PM11/23/22
    to Mayank Patke, dart2js-te...@google.com, rev...@dartlang.org, CBuild, Commit Queue

    Attention is currently required from: Mayank Patke.

    Patch set 3:Code-Review +1

    View Change

      To view, visit change 271800. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: sdk
      Gerrit-Branch: main
      Gerrit-Change-Id: I8edc2b24e5fbeece1f042ff3d0c87d58e939bf84
      Gerrit-Change-Number: 271800
      Gerrit-PatchSet: 3
      Gerrit-Owner: Mayank Patke <fishyt...@google.com>
      Gerrit-Reviewer: Mayank Patke <fishyt...@google.com>
      Gerrit-Reviewer: Stephen Adams <s...@google.com>
      Gerrit-Attention: Mayank Patke <fishyt...@google.com>
      Gerrit-Comment-Date: Thu, 24 Nov 2022 00:06:07 +0000

      Commit Queue (Gerrit)

      unread,
      Feb 7, 2023, 3:08:08 PM2/7/23
      to Mayank Patke, dart2js-te...@google.com, rev...@dartlang.org, Stephen Adams, CBuild

      Commit Queue submitted this change.

      View Change



      3 is the latest approved patch-set.
      No files were changed between the latest approved patch-set and the submitted one.

      Approvals: Stephen Adams: Looks good to me, approved
      [dart2js] Add a 'FALSE' JS_GET_FLAG.

      There are a few places in our runtime libraries where we have some code
      guarded by `if (false)`. This is to ensure that the guarded code is
      marked as used and compiled, but not emitted unless rewritten during
      SSA. This pattern is somewhat brittle - a kernel
      optimization/transformation which eliminates dead code may discard the
      code.

      Instead, we can write `if (JS_GET_FLAG('FALSE'))`, which will only be
      written to `if (false)` and then discarded during SSA.

      Change-Id: I8edc2b24e5fbeece1f042ff3d0c87d58e939bf84
      Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/271800
      Reviewed-by: Stephen Adams <s...@google.com>

      ---
      M pkg/compiler/lib/src/ssa/builder.dart
      M sdk/lib/_internal/js_runtime/lib/interceptors.dart
      M sdk/lib/_internal/js_runtime/lib/js_number.dart
      3 files changed, 26 insertions(+), 2 deletions(-)

      diff --git a/pkg/compiler/lib/src/ssa/builder.dart b/pkg/compiler/lib/src/ssa/builder.dart
      index 9706ced..b134c1d 100644
      --- a/pkg/compiler/lib/src/ssa/builder.dart
      +++ b/pkg/compiler/lib/src/ssa/builder.dart
      @@ -369,6 +369,8 @@

      /// concrete SSA builder reports an error.
         bool? _getFlagValue(String flagName) {

      switch (flagName) {
      + case 'FALSE':
      + return false;
      case 'DEV_COMPILER':
      return false;
      case 'MINIFIED':
      diff --git a/sdk/lib/_internal/js_runtime/lib/interceptors.dart b/sdk/lib/_internal/js_runtime/lib/interceptors.dart
      index becd8b6..5065757 100644

      To view, visit change 271800. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: sdk
      Gerrit-Branch: main
      Gerrit-Change-Id: I8edc2b24e5fbeece1f042ff3d0c87d58e939bf84
      Gerrit-Change-Number: 271800
      Gerrit-PatchSet: 9
      Gerrit-Owner: Mayank Patke <fishyt...@google.com>
      Gerrit-Reviewer: Mayank Patke <fishyt...@google.com>
      Gerrit-Reviewer: Stephen Adams <s...@google.com>
      Gerrit-MessageType: merged

      CBuild (Gerrit)

      unread,
      Feb 7, 2023, 4:28:24 PM2/7/23
      to Mayank Patke, Commit Queue, dart2js-te...@google.com, rev...@dartlang.org, Stephen Adams

      go/dart-cbuild result: SUCCESS

      Details: https://goto.google.com/dart-cbuild/find/b028da6407c0921fd21fc65e7b18197e77dba684

      View Change

        To view, visit change 271800. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: sdk
        Gerrit-Branch: main
        Gerrit-Change-Id: I8edc2b24e5fbeece1f042ff3d0c87d58e939bf84
        Gerrit-Change-Number: 271800
        Gerrit-PatchSet: 9
        Gerrit-Owner: Mayank Patke <fishyt...@google.com>
        Gerrit-Reviewer: Mayank Patke <fishyt...@google.com>
        Gerrit-Reviewer: Stephen Adams <s...@google.com>
        Gerrit-Comment-Date: Tue, 07 Feb 2023 21:28:20 +0000
        Gerrit-HasComments: No
        Gerrit-Has-Labels: No
        Gerrit-MessageType: comment
        Reply all
        Reply to author
        Forward
        0 new messages