[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 <sra@google.com>
This commit is contained in:
Mayank Patke 2023-02-07 20:07:57 +00:00 committed by Commit Queue
parent ff01414b8f
commit b028da6407
3 changed files with 5 additions and 2 deletions

View file

@ -369,6 +369,8 @@ class KernelSsaGraphBuilder extends ir.Visitor<void> with ir.VisitorVoidMixin {
/// concrete SSA builder reports an error.
bool? _getFlagValue(String flagName) {
switch (flagName) {
case 'FALSE':
return false;
case 'DEV_COMPILER':
return false;
case 'MINIFIED':

View file

@ -8,6 +8,7 @@ import 'dart:_js_embedded_names'
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'

View file

@ -340,7 +340,7 @@ class JSNumber extends Interceptor implements double {
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 @@ class JSNumber extends Interceptor implements double {
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);
}