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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart

Issue 1160763002: dart2js cps: 'is'-check directly against type variables. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dart2js.ir_builder; 5 library dart2js.ir_builder;
6 6
7 import '../constants/constant_system.dart'; 7 import '../constants/constant_system.dart';
8 import '../constants/expressions.dart'; 8 import '../constants/expressions.dart';
9 import '../constants/values.dart' show PrimitiveConstantValue; 9 import '../constants/values.dart' show PrimitiveConstantValue;
10 import '../dart_types.dart'; 10 import '../dart_types.dart';
(...skipping 2652 matching lines...) Expand 10 before | Expand all | Expand 10 after
2663 List<ir.Primitive> arguments) { 2663 List<ir.Primitive> arguments) {
2664 return addPrimitive(new ir.CreateInvocationMirror(selector, arguments)); 2664 return addPrimitive(new ir.CreateInvocationMirror(selector, arguments));
2665 } 2665 }
2666 2666
2667 @override 2667 @override
2668 ir.Primitive buildTypeOperator(ir.Primitive value, 2668 ir.Primitive buildTypeOperator(ir.Primitive value,
2669 DartType type, 2669 DartType type,
2670 {bool isTypeTest}) { 2670 {bool isTypeTest}) {
2671 assert(isOpen); 2671 assert(isOpen);
2672 assert(isTypeTest != null); 2672 assert(isTypeTest != null);
2673 // For type tests, we must treat specially the rare cases where `null`
karlklose 2015/05/28 07:42:30 Move comment back into the if branch? Also, the t
asgerf 2015/05/28 08:52:55 It should be clear that this is not an optimizatio
2674 // satisfies the test (which otherwise never satisfies a type test).
2673 if (isTypeTest) { 2675 if (isTypeTest) {
2674 // The TypeOperator node does not allow the Object, dynamic, and Null type s,
2675 // because the null value satisfies them. These must be handled here.
2676 if (type.isObject || type.isDynamic) { 2676 if (type.isObject || type.isDynamic) {
2677 // `x is Object` and `x is dynamic` are always true, even if x is null. 2677 // `x is Object` and `x is dynamic` are always true, even if x is null.
2678 return buildBooleanConstant(true); 2678 return buildBooleanConstant(true);
2679 } 2679 }
2680 if (type is InterfaceType && type.element == program.nullClass) { 2680 if (type is InterfaceType && type.element == program.nullClass) {
2681 // `x is Null` is true if and only if x is null. 2681 // `x is Null` is true if and only if x is null.
2682 return addPrimitive(new ir.Identical(value, buildNullConstant())); 2682 return addPrimitive(new ir.Identical(value, buildNullConstant()));
2683 } 2683 }
2684 } 2684 }
2685 // Null cannot not satisfy the check. Use a standard subtype check.
2686 List<ir.Primitive> typeArguments = const <ir.Primitive>[]; 2685 List<ir.Primitive> typeArguments = const <ir.Primitive>[];
2687 if (type is GenericType && type.typeArguments.isNotEmpty) { 2686 if (type is GenericType && type.typeArguments.isNotEmpty) {
2688 typeArguments = type.typeArguments.map(buildTypeExpression).toList(); 2687 typeArguments = type.typeArguments.map(buildTypeExpression).toList();
2688 } else if (type is TypeVariableType) {
2689 typeArguments = <ir.Primitive>[buildTypeVariableAccess(type)];
2689 } 2690 }
2690 ir.Primitive check = _continueWithExpression( 2691 ir.Primitive check = _continueWithExpression(
2691 (k) => new ir.TypeOperator(value, 2692 (k) => new ir.TypeOperator(value,
2692 type, typeArguments, k, isTypeTest: isTypeTest)); 2693 type, typeArguments, k, isTypeTest: isTypeTest));
2693 return check; 2694 return check;
2694 } 2695 }
2695 } 2696 }
2696 2697
2697 2698
2698 /// Location of a variable relative to a given closure. 2699 /// Location of a variable relative to a given closure.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2766 } 2767 }
2767 2768
2768 /// Synthetic parameter to a JavaScript factory method that takes the type 2769 /// Synthetic parameter to a JavaScript factory method that takes the type
2769 /// argument given for the type variable [variable]. 2770 /// argument given for the type variable [variable].
2770 class TypeInformationParameter implements Local { 2771 class TypeInformationParameter implements Local {
2771 final TypeVariableElement variable; 2772 final TypeVariableElement variable;
2772 final ExecutableElement executableContext; 2773 final ExecutableElement executableContext;
2773 TypeInformationParameter(this.variable, this.executableContext); 2774 TypeInformationParameter(this.variable, this.executableContext);
2774 String get name => variable.name; 2775 String get name => variable.name;
2775 } 2776 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart » ('j') | pkg/compiler/lib/src/js_backend/codegen/codegen.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698