Remove unused code from LocalsHandler
+ add test for issue 34993
Change-Id: Icd73c865e80ac9dca0e126c6b7e2c6c5320aef94
Reviewed-on: https://dart-review.googlesource.com/c/85240
Auto-Submit: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
diff --git a/pkg/compiler/lib/src/inferrer/locals_handler.dart b/pkg/compiler/lib/src/inferrer/locals_handler.dart
index a0ad009..5be66e9 100644
--- a/pkg/compiler/lib/src/inferrer/locals_handler.dart
+++ b/pkg/compiler/lib/src/inferrer/locals_handler.dart
@@ -292,27 +292,9 @@
}
void update(InferrerEngine inferrer, Map<Local, FieldEntity> capturedAndBoxed,
- Local local, TypeInformation type, ir.Node node, DartType staticType,
- {bool isSetIfNull: false}) {
+ Local local, TypeInformation type, ir.Node node, DartType staticType) {
assert(type != null);
- if (!inferrer.options.assignmentCheckPolicy.isIgnored) {
- type = inferrer.types.narrowType(type, staticType);
- }
- updateLocal() {
- TypeInformation currentType = locals[local];
-
- if (isSetIfNull && currentType != null) {
- // If-null assignments may return either the new or the original value
- // narrowed to non-null.
- type = inferrer.types.addPhiInput(
- local,
- inferrer.types.allocatePhi(
- locals.block, local, inferrer.types.narrowNotNull(currentType),
- isTry: locals.isTry),
- type);
- }
- locals[local] = type;
- }
+ type = inferrer.types.narrowType(type, staticType);
FieldEntity field = capturedAndBoxed[local];
if (field != null) {
@@ -334,20 +316,18 @@
}
// Update the current handler unconditionally with the new
// type.
- updateLocal();
+ locals[local] = type;
} else {
- updateLocal();
+ locals[local] = type;
}
}
void narrow(InferrerEngine inferrer, Map<Local, FieldEntity> capturedAndBoxed,
- Local local, DartType type, ir.Node node,
- {bool isSetIfNull: false}) {
+ Local local, DartType type, ir.Node node) {
TypeInformation existing = use(inferrer, capturedAndBoxed, local);
TypeInformation newType =
inferrer.types.narrowType(existing, type, isNullable: false);
- update(inferrer, capturedAndBoxed, local, newType, node, type,
- isSetIfNull: isSetIfNull);
+ update(inferrer, capturedAndBoxed, local, newType, node, type);
}
void mergeDiamondFlow(InferrerEngine inferrer, LocalsHandler thenBranch,
diff --git a/pkg/compiler/lib/src/options.dart b/pkg/compiler/lib/src/options.dart
index a915487..0c05a18 100644
--- a/pkg/compiler/lib/src/options.dart
+++ b/pkg/compiler/lib/src/options.dart
@@ -430,18 +430,13 @@
/// Whether the type assertion should be emitted and checked.
final bool isEmitted;
- /// Whether the type assertion should be ignored.
- final bool isIgnored;
-
- const CheckPolicy(
- {this.isTrusted: false, this.isEmitted: false, this.isIgnored: false});
+ const CheckPolicy({this.isTrusted: false, this.isEmitted: false});
static const trusted = const CheckPolicy(isTrusted: true);
static const checked = const CheckPolicy(isEmitted: true);
- static const ignored = const CheckPolicy(isIgnored: true);
String toString() => 'CheckPolicy(isTrusted=$isTrusted,'
- 'isEmitted=$isEmitted,isIgnored=$isIgnored)';
+ 'isEmitted=$isEmitted)';
}
String _extractStringOption(
diff --git a/tests/compiler/dart2js/inference/data/null.dart b/tests/compiler/dart2js/inference/data/null.dart
new file mode 100644
index 0000000..b91c581
--- /dev/null
+++ b/tests/compiler/dart2js/inference/data/null.dart
@@ -0,0 +1,97 @@
+// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/*element: main:[null]*/
+main() {
+ ifThenNullCheck(0);
+ ifThenNullCheck(null);
+ ifThenElseNullCheck(0);
+ ifThenElseNullCheck(null);
+ ifNotThenNullCheck(0);
+ ifNotThenNullCheck(null);
+ ifNotThenElseNullCheck(0);
+ ifNotThenElseNullCheck(null);
+ ifThenNotNullComplexCheck(0, 0);
+ ifThenNotNullComplexCheck(null, null);
+ ifThenElseNotNullComplexCheck(0, 0);
+ ifThenElseNotNullComplexCheck(null, null);
+ ifThenNotNullGradualCheck1(0, 0);
+ ifThenNotNullGradualCheck1(null, 0);
+ ifThenNotNullGradualCheck2(0, 0);
+ ifThenNotNullGradualCheck2(null, 0);
+}
+
+/*element: ifThenNullCheck:[exact=JSUInt31]*/
+ifThenNullCheck(int /*[null|exact=JSUInt31]*/ value) {
+ if (value == null) {
+ return 0;
+ }
+ return value;
+}
+
+/*element: ifThenElseNullCheck:[exact=JSUInt31]*/
+ifThenElseNullCheck(int /*[null|exact=JSUInt31]*/ value) {
+ if (value == null) {
+ return 0;
+ } else {
+ return value;
+ }
+}
+
+/*element: ifNotThenNullCheck:[exact=JSUInt31]*/
+ifNotThenNullCheck(int /*[null|exact=JSUInt31]*/ value) {
+ if (value != null) {
+ return value;
+ }
+ return 0;
+}
+
+/*element: ifNotThenElseNullCheck:[exact=JSUInt31]*/
+ifNotThenElseNullCheck(int /*[null|exact=JSUInt31]*/ value) {
+ if (value != null) {
+ return value;
+ } else {
+ return 0;
+ }
+}
+
+/*element: ifThenNotNullComplexCheck:[null|exact=JSUInt31]*/
+ifThenNotNullComplexCheck(
+ int /*[null|exact=JSUInt31]*/ a, int /*[null|exact=JSUInt31]*/ b) {
+ if (a != null && a /*invoke: [exact=JSUInt31]*/ != b) {
+ return a;
+ }
+ return 0;
+}
+
+/*element: ifThenElseNotNullComplexCheck:[null|exact=JSUInt31]*/
+ifThenElseNotNullComplexCheck(
+ int /*[null|exact=JSUInt31]*/ a, int /*[null|exact=JSUInt31]*/ b) {
+ if (a != null && a /*invoke: [exact=JSUInt31]*/ != b) {
+ return a;
+ }
+ return a;
+}
+
+/*element: ifThenNotNullGradualCheck1:[exact=JSUInt31]*/
+ifThenNotNullGradualCheck1(
+ int /*[null|exact=JSUInt31]*/ a, int /*[exact=JSUInt31]*/ b) {
+ if (a /*invoke: [null|exact=JSUInt31]*/ != b) {
+ if (a != null) {
+ return a;
+ }
+ }
+ return 0;
+}
+
+/*element: ifThenNotNullGradualCheck2:[exact=JSUInt31]*/
+ifThenNotNullGradualCheck2(
+ int /*[null|exact=JSUInt31]*/ a, int /*[exact=JSUInt31]*/ b) {
+ if (a != null) {
+ if (a /*invoke: [exact=JSUInt31]*/ != b) {
+ return a;
+ }
+ }
+ return 0;
+}