Index: runtime/vm/parser.cc |
diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc |
index 26f2ad7adb095eb5f22a4e1473c56684e15d4ad5..48df56b27c134360ecd54bcec4ce89fa6108a4a5 100644 |
--- a/runtime/vm/parser.cc |
+++ b/runtime/vm/parser.cc |
@@ -10552,6 +10552,18 @@ AstNode* Parser::OptimizeBinaryOpNode(intptr_t op_pos, |
} |
if (binary_op == Token::kIFNULL) { |
// Handle a ?? b. |
+ if (lhs->IsPotentiallyConst()) { |
hausner
2015/12/02 18:29:37
This is a bit more complicated.
You need to use l
Lasse Reichstein Nielsen
2015/12/04 12:11:46
Tried to do that.
Still doesn't work for const co
|
+ // If we know at compile time whether the lhs is null |
+ // and side-effect free, just reduce it to either the lhs or rhs. |
+ // This enables ?? to be compile-time constant. |
+ const Object* left_expr = lhs->EvalConstExpr(); |
+ if (left_expr != NULL) { |
+ if (left_expr->IsNull()) return rhs; |
+ return lhs; |
+ } |
+ } |
+ // Otherwise create a temporary variable for the lhs so we can both |
+ // check it against null and return it if necessary. |
LetNode* result = new(Z) LetNode(op_pos); |
LocalVariable* left_temp = result->AddInitializer(lhs); |
const intptr_t no_pos = Scanner::kNoSourcePos; |