Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(800)

Unified Diff: lib/src/codegen/js_codegen.dart

Issue 977613002: Make int and double nullable by default (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Optimize away some nonnull checks Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/src/codegen/js_codegen.dart
diff --git a/lib/src/codegen/js_codegen.dart b/lib/src/codegen/js_codegen.dart
index ab8d555d827b05ef5f41e18a4824d46e2e50037d..b952719eaf83fd958ce922f14cda57e66bdbf3f6 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -1047,9 +1047,30 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
bool unaryOperationIsPrimitive(DartType t) => typeIsPrimitiveInJS(t);
+ bool _isNonNullableExpression(Expression expr) {
Jennifer Messerly 2015/03/03 19:14:30 add a TODO that this will go away when we have not
vsm 2015/03/03 19:29:41 Done.
+ if (expr is Literal && expr is! NullLiteral) {
+ return true;
+ }
+ if (expr is ParenthesizedExpression) {
+ return _isNonNullableExpression(expr.expression);
+ }
+ DartType type = null;
+ if (expr is BinaryExpression) {
+ type = rules.getStaticType(expr.leftOperand);
+ } else if (expr is PrefixExpression) {
+ type = rules.getStaticType(expr.operand);
+ } else if (expr is PostfixExpression) {
+ type = rules.getStaticType(expr.operand);
+ }
+ if (type != null && typeIsPrimitiveInJS(type)) {
+ return true;
+ }
+ return false;
+ }
+
JS.Expression notNull(Expression expr) {
var type = rules.getStaticType(expr);
- if (rules.isNonNullableType(type)) {
+ if (rules.isNonNullableType(type) || _isNonNullableExpression(expr)) {
return _visit(expr);
} else {
return js.call('dart.notNull(#)', _visit(expr));
« no previous file with comments | « lib/config.dart ('k') | lib/src/testing.dart » ('j') | test/codegen/expect/BenchmarkBase.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698