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

Side by Side Diff: pkg/compiler/lib/src/ssa/codegen.dart

Issue 2674813004: dart2js: Keep refined type for type checks (Closed)
Patch Set: Created 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | pkg/compiler/lib/src/ssa/codegen_helpers.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 import 'dart:math' as math; 5 import 'dart:math' as math;
6 import '../common.dart'; 6 import '../common.dart';
7 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; 7 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem;
8 import '../common/tasks.dart' show CompilerTask; 8 import '../common/tasks.dart' show CompilerTask;
9 import '../compiler.dart' show Compiler; 9 import '../compiler.dart' show Compiler;
10 import '../constants/constant_system.dart'; 10 import '../constants/constant_system.dart';
(...skipping 2789 matching lines...) Expand 10 before | Expand all | Expand 10 after
2800 } 2800 }
2801 2801
2802 void emitIsViaInterceptor( 2802 void emitIsViaInterceptor(
2803 HIsViaInterceptor node, SourceInformation sourceInformation, 2803 HIsViaInterceptor node, SourceInformation sourceInformation,
2804 {bool negative: false}) { 2804 {bool negative: false}) {
2805 checkTypeViaProperty( 2805 checkTypeViaProperty(
2806 node.interceptor, node.typeExpression, sourceInformation, 2806 node.interceptor, node.typeExpression, sourceInformation,
2807 negative: negative); 2807 negative: negative);
2808 } 2808 }
2809 2809
2810 js.Expression generateReceiverOrArgumentTypeTest( 2810 js.Expression generateReceiverOrArgumentTypeTest(HTypeConversion node) {
2811 HInstruction input, TypeMask checkedType) { 2811 HInstruction input = node.checkedInput;
2812 TypeMask inputType = input.instructionType; 2812 TypeMask inputType = node.inputType ?? input.instructionType;
2813 TypeMask checkedType = node.checkedType;
2813 // Figure out if it is beneficial to turn this into a null check. 2814 // Figure out if it is beneficial to turn this into a null check.
2814 // V8 generally prefers 'typeof' checks, but for integers and 2815 // V8 generally prefers 'typeof' checks, but for integers and
2815 // indexable primitives we cannot compile this test into a single 2816 // indexable primitives we cannot compile this test into a single
2816 // typeof check so the null check is cheaper. 2817 // typeof check so the null check is cheaper.
2817 bool isIntCheck = checkedType.containsOnlyInt(closedWorld); 2818 bool isIntCheck = checkedType.containsOnlyInt(closedWorld);
2818 bool turnIntoNumCheck = isIntCheck && input.isIntegerOrNull(closedWorld); 2819 bool turnIntoNumCheck =
2820 isIntCheck && inputType.nonNullable().containsOnlyInt(closedWorld);
Siggi Cherem (dart-lang) 2017/02/03 21:48:16 I think it's fine to keep it nullable here (the an
2819 bool turnIntoNullCheck = !turnIntoNumCheck && 2821 bool turnIntoNullCheck = !turnIntoNumCheck &&
2820 (checkedType.nullable() == inputType) && 2822 (checkedType.nullable() == inputType) &&
2821 (isIntCheck || 2823 (isIntCheck ||
2822 checkedType.satisfies(helpers.jsIndexableClass, closedWorld)); 2824 checkedType.satisfies(helpers.jsIndexableClass, closedWorld));
2823 2825
2824 if (turnIntoNullCheck) { 2826 if (turnIntoNullCheck) {
2825 use(input); 2827 use(input);
2826 return new js.Binary("==", pop(), new js.LiteralNull()) 2828 return new js.Binary("==", pop(), new js.LiteralNull())
2827 .withSourceInformation(input.sourceInformation); 2829 .withSourceInformation(input.sourceInformation);
2828 } else if (isIntCheck && !turnIntoNumCheck) { 2830 } else if (isIntCheck && !turnIntoNumCheck) {
(...skipping 12 matching lines...) Expand all
2841 // input is !string 2843 // input is !string
2842 checkString(input, '!==', input.sourceInformation); 2844 checkString(input, '!==', input.sourceInformation);
2843 return pop(); 2845 return pop();
2844 } 2846 }
2845 reporter.internalError(input, 'Unexpected check: $checkedType.'); 2847 reporter.internalError(input, 'Unexpected check: $checkedType.');
2846 return null; 2848 return null;
2847 } 2849 }
2848 2850
2849 void visitTypeConversion(HTypeConversion node) { 2851 void visitTypeConversion(HTypeConversion node) {
2850 if (node.isArgumentTypeCheck || node.isReceiverTypeCheck) { 2852 if (node.isArgumentTypeCheck || node.isReceiverTypeCheck) {
2851 js.Expression test = generateReceiverOrArgumentTypeTest( 2853 js.Expression test = generateReceiverOrArgumentTypeTest(node);
2852 node.checkedInput, node.checkedType);
2853 js.Block oldContainer = currentContainer; 2854 js.Block oldContainer = currentContainer;
2854 js.Statement body = new js.Block.empty(); 2855 js.Statement body = new js.Block.empty();
2855 currentContainer = body; 2856 currentContainer = body;
2856 if (node.isArgumentTypeCheck) { 2857 if (node.isArgumentTypeCheck) {
2857 generateThrowWithHelper( 2858 generateThrowWithHelper(
2858 helpers.throwIllegalArgumentException, node.checkedInput, 2859 helpers.throwIllegalArgumentException, node.checkedInput,
2859 sourceInformation: node.sourceInformation); 2860 sourceInformation: node.sourceInformation);
2860 } else if (node.isReceiverTypeCheck) { 2861 } else if (node.isReceiverTypeCheck) {
2861 use(node.checkedInput); 2862 use(node.checkedInput);
2862 js.Name methodName = 2863 js.Name methodName =
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
3114 registry.registerStaticUse(new StaticUse.staticInvoke( 3115 registry.registerStaticUse(new StaticUse.staticInvoke(
3115 helper, new CallStructure.unnamed(argumentCount))); 3116 helper, new CallStructure.unnamed(argumentCount)));
3116 return backend.emitter.staticFunctionAccess(helper); 3117 return backend.emitter.staticFunctionAccess(helper);
3117 } 3118 }
3118 3119
3119 @override 3120 @override
3120 void visitRef(HRef node) { 3121 void visitRef(HRef node) {
3121 visit(node.value); 3122 visit(node.value);
3122 } 3123 }
3123 } 3124 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/ssa/codegen_helpers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698