OLD | NEW |
---|---|
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 '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; | 5 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; |
6 import '../common/names.dart' show Selectors; | |
6 import '../common/tasks.dart' show CompilerTask; | 7 import '../common/tasks.dart' show CompilerTask; |
7 import '../compiler.dart' show Compiler; | 8 import '../compiler.dart' show Compiler; |
8 import '../constants/constant_system.dart'; | 9 import '../constants/constant_system.dart'; |
9 import '../constants/values.dart'; | 10 import '../constants/values.dart'; |
10 import '../core_types.dart' show CoreClasses; | 11 import '../core_types.dart' show CoreClasses; |
11 import '../dart_types.dart'; | 12 import '../dart_types.dart'; |
12 import '../elements/elements.dart'; | 13 import '../elements/elements.dart'; |
13 import '../js/js.dart' as js; | 14 import '../js/js.dart' as js; |
14 import '../js_backend/backend_helpers.dart' show BackendHelpers; | 15 import '../js_backend/backend_helpers.dart' show BackendHelpers; |
15 import '../js_backend/js_backend.dart'; | 16 import '../js_backend/js_backend.dart'; |
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1006 constantSystem.createString(new ast.DartString.concat( | 1007 constantSystem.createString(new ast.DartString.concat( |
1007 leftString.primitiveValue, rightString.primitiveValue)), | 1008 leftString.primitiveValue, rightString.primitiveValue)), |
1008 compiler); | 1009 compiler); |
1009 if (prefix == null) return folded; | 1010 if (prefix == null) return folded; |
1010 return new HStringConcat(prefix, folded, backend.stringType); | 1011 return new HStringConcat(prefix, folded, backend.stringType); |
1011 } | 1012 } |
1012 | 1013 |
1013 HInstruction visitStringify(HStringify node) { | 1014 HInstruction visitStringify(HStringify node) { |
1014 HInstruction input = node.inputs[0]; | 1015 HInstruction input = node.inputs[0]; |
1015 if (input.isString(compiler)) return input; | 1016 if (input.isString(compiler)) return input; |
1016 if (input.isConstant()) { | 1017 |
1018 HInstruction tryConstant() { | |
1019 if (!input.isConstant()) return null; | |
1017 HConstant constant = input; | 1020 HConstant constant = input; |
1018 if (!constant.constant.isPrimitive) return node; | 1021 if (!constant.constant.isPrimitive) return null; |
1019 if (constant.constant.isInt) { | 1022 if (constant.constant.isInt) { |
1020 // Only constant-fold int.toString() when Dart and JS results the same. | 1023 // Only constant-fold int.toString() when Dart and JS results the same. |
1021 // TODO(18103): We should be able to remove this work-around when issue | 1024 // TODO(18103): We should be able to remove this work-around when issue |
1022 // 18103 is resolved by providing the correct string. | 1025 // 18103 is resolved by providing the correct string. |
1023 IntConstantValue intConstant = constant.constant; | 1026 IntConstantValue intConstant = constant.constant; |
1024 // Very conservative range. | 1027 // Very conservative range. |
1025 if (!intConstant.isUInt32()) return node; | 1028 if (!intConstant.isUInt32()) return null; |
1026 } | 1029 } |
1027 PrimitiveConstantValue primitive = constant.constant; | 1030 PrimitiveConstantValue primitive = constant.constant; |
1028 return graph.addConstant( | 1031 return graph.addConstant( |
1029 constantSystem.createString(primitive.toDartString()), compiler); | 1032 constantSystem.createString(primitive.toDartString()), compiler); |
1030 } | 1033 } |
1031 return node; | 1034 |
1035 HInstruction tryToString() { | |
Harry Terkelsen
2016/09/23 17:49:25
Will this only be called in the kernel->ssa case?
sra1
2016/09/23 18:15:39
There are a few in the old builder case.
There are
| |
1036 // If the `toString` method is guaranteed to return a string we can call | |
1037 // it directly. Keep the stringifier for primitives (since they have fast | |
1038 // path code in the stringifier) and for classes requiring interceptors | |
1039 // (since SsaInstructionSimplifier runs after SsaSimplifyInterceptors). | |
1040 if (input.canBePrimitive(compiler)) return null; | |
1041 if (input.canBeNull()) return null; | |
1042 Selector selector = Selectors.toString_; | |
1043 TypeMask toStringType = TypeMaskFactory.inferredTypeForSelector( | |
1044 selector, input.instructionType, compiler); | |
1045 ClassWorld classWorld = compiler.closedWorld; | |
1046 if (!toStringType.containsOnlyString(classWorld)) return null; | |
1047 // All intercepted classes extend `Interceptor`, so if the receiver can't | |
1048 // be a class extending `Interceptor` then it can be called directly. | |
1049 if (new TypeMask.nonNullSubclass(helpers.jsInterceptorClass, classWorld) | |
1050 .isDisjoint(input.instructionType, classWorld)) { | |
1051 HInstruction result = new HInvokeDynamicMethod( | |
1052 selector, | |
1053 input.instructionType, // receiver mask. | |
1054 <HInstruction>[input, input], // [interceptor, receiver]. | |
1055 toStringType)..sourceInformation = node.sourceInformation; | |
1056 return result; | |
1057 } | |
1058 return null; | |
1059 } | |
1060 | |
1061 return tryConstant() ?? tryToString() ?? node; | |
1032 } | 1062 } |
1033 | 1063 |
1034 HInstruction visitOneShotInterceptor(HOneShotInterceptor node) { | 1064 HInstruction visitOneShotInterceptor(HOneShotInterceptor node) { |
1035 return handleInterceptedCall(node); | 1065 return handleInterceptedCall(node); |
1036 } | 1066 } |
1037 | 1067 |
1038 bool needsSubstitutionForTypeVariableAccess(ClassElement cls) { | 1068 bool needsSubstitutionForTypeVariableAccess(ClassElement cls) { |
1039 ClassWorld classWorld = compiler.closedWorld; | 1069 ClassWorld classWorld = compiler.closedWorld; |
1040 if (classWorld.isUsedAsMixin(cls)) return true; | 1070 if (classWorld.isUsedAsMixin(cls)) return true; |
1041 | 1071 |
(...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2621 | 2651 |
2622 keyedValues.forEach((receiver, values) { | 2652 keyedValues.forEach((receiver, values) { |
2623 result.keyedValues[receiver] = | 2653 result.keyedValues[receiver] = |
2624 new Map<HInstruction, HInstruction>.from(values); | 2654 new Map<HInstruction, HInstruction>.from(values); |
2625 }); | 2655 }); |
2626 | 2656 |
2627 result.nonEscapingReceivers.addAll(nonEscapingReceivers); | 2657 result.nonEscapingReceivers.addAll(nonEscapingReceivers); |
2628 return result; | 2658 return result; |
2629 } | 2659 } |
2630 } | 2660 } |
OLD | NEW |