Skip to content

Commit 8e70d3b

Browse files
committed
Avoid use of NonConstantValue in SSA
BUG= Review URL: https://codereview.chromium.org/1934553002 .
1 parent b361d8c commit 8e70d3b

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

pkg/compiler/lib/src/constants/expressions.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,8 +1450,7 @@ class DeferredConstantExpression extends ConstantExpression {
14501450
ConstantValue evaluate(
14511451
Environment environment, ConstantSystem constantSystem) {
14521452
return new DeferredConstantValue(
1453-
expression.evaluate(environment, constantSystem),
1454-
prefix);
1453+
expression.evaluate(environment, constantSystem), prefix);
14551454
}
14561455

14571456
@override

pkg/compiler/lib/src/constants/values.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class NullConstantValue extends PrimitiveConstantValue {
159159
/** The value a Dart null is compiled to in JavaScript. */
160160
static const String JsNull = "null";
161161

162-
factory NullConstantValue() => const NullConstantValue._internal();
162+
const factory NullConstantValue() = NullConstantValue._internal;
163163

164164
const NullConstantValue._internal();
165165

pkg/compiler/lib/src/deferred_load.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import 'common/tasks.dart' show CompilerTask;
99
import 'common.dart';
1010
import 'compiler.dart' show Compiler;
1111
import 'constants/expressions.dart'
12-
show
13-
ConstantExpression,
14-
ConstantExpressionKind;
12+
show ConstantExpression, ConstantExpressionKind;
1513
import 'constants/values.dart'
1614
show
1715
ConstantValue,
@@ -338,12 +336,13 @@ class DeferredLoadTask extends CompilerTask {
338336
TreeElements treeElements = analyzableElement.resolvedAst.elements;
339337
assert(treeElements != null);
340338

341-
treeElements.forEachConstantNode(
342-
(Node node, ConstantExpression expression) {
339+
treeElements
340+
.forEachConstantNode((Node node, ConstantExpression expression) {
343341
// Explicitly depend on the backend constants.
344342
ConstantValue value = backend.constants.getConstantValue(expression);
345343
assert(invariant(node, value != null,
346-
message: "No constant value for ${expression.toStructuredText()}."));
344+
message:
345+
"No constant value for ${expression.toStructuredText()}."));
347346
constants.add(value);
348347
});
349348
}

pkg/compiler/lib/src/ssa/nodes.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ class HGraph {
198198
HConstant result = constants[constant];
199199
// TODO(johnniwinther): Support source information per constant reference.
200200
if (result == null) {
201+
if (!constant.isConstant) {
202+
// We use `null` as the value for invalid constant expressions.
203+
constant = const NullConstantValue();
204+
}
201205
TypeMask type = computeTypeMask(compiler, constant);
202206
result = new HConstant.internal(constant, type)
203207
..sourceInformation = sourceInformation;

0 commit comments

Comments
 (0)