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

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

Issue 2864363002: Remove DartString from constants. (Closed)
Patch Set: Remove toDartString Created 3 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) 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/names.dart' show Selectors;
7 import '../common/tasks.dart' show CompilerTask; 7 import '../common/tasks.dart' show CompilerTask;
8 import '../compiler.dart' show Compiler; 8 import '../compiler.dart' show Compiler;
9 import '../constants/constant_system.dart'; 9 import '../constants/constant_system.dart';
10 import '../constants/values.dart'; 10 import '../constants/values.dart';
11 import '../common_elements.dart' show CommonElements; 11 import '../common_elements.dart' show CommonElements;
12 import '../elements/elements.dart' 12 import '../elements/elements.dart'
13 show ClassElement, FieldElement, MethodElement; 13 show ClassElement, FieldElement, MethodElement;
14 import '../elements/entities.dart'; 14 import '../elements/entities.dart';
15 import '../elements/resolution_types.dart'; 15 import '../elements/resolution_types.dart';
16 import '../js/js.dart' as js; 16 import '../js/js.dart' as js;
17 import '../js_backend/js_backend.dart'; 17 import '../js_backend/js_backend.dart';
18 import '../js_backend/interceptor_data.dart' show InterceptorData; 18 import '../js_backend/interceptor_data.dart' show InterceptorData;
19 import '../js_backend/native_data.dart' show NativeData; 19 import '../js_backend/native_data.dart' show NativeData;
20 import '../native/native.dart' as native; 20 import '../native/native.dart' as native;
21 import '../options.dart'; 21 import '../options.dart';
22 import '../tree/dartstring.dart' as ast;
23 import '../types/types.dart'; 22 import '../types/types.dart';
24 import '../universe/selector.dart' show Selector; 23 import '../universe/selector.dart' show Selector;
25 import '../universe/side_effects.dart' show SideEffects; 24 import '../universe/side_effects.dart' show SideEffects;
26 import '../util/util.dart'; 25 import '../util/util.dart';
27 import '../world.dart' show ClosedWorld; 26 import '../world.dart' show ClosedWorld;
28 import 'interceptor_simplifier.dart'; 27 import 'interceptor_simplifier.dart';
29 import 'nodes.dart'; 28 import 'nodes.dart';
30 import 'types.dart'; 29 import 'types.dart';
31 import 'types_propagation.dart'; 30 import 'types_propagation.dart';
32 import 'value_range_analyzer.dart'; 31 import 'value_range_analyzer.dart';
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 leftString = getString(leftConcat.right); 1127 leftString = getString(leftConcat.right);
1129 if (leftString == null) return node; 1128 if (leftString == null) return node;
1130 } 1129 }
1131 1130
1132 if (leftString.primitiveValue.length + rightString.primitiveValue.length > 1131 if (leftString.primitiveValue.length + rightString.primitiveValue.length >
1133 MAX_SHARED_CONSTANT_FOLDED_STRING_LENGTH) { 1132 MAX_SHARED_CONSTANT_FOLDED_STRING_LENGTH) {
1134 if (node.usedBy.length > 1) return node; 1133 if (node.usedBy.length > 1) return node;
1135 } 1134 }
1136 1135
1137 HInstruction folded = _graph.addConstant( 1136 HInstruction folded = _graph.addConstant(
1138 constantSystem.createString(new ast.DartString.concat( 1137 constantSystem.createString(
1139 leftString.primitiveValue, rightString.primitiveValue)), 1138 leftString.primitiveValue + rightString.primitiveValue),
1140 _closedWorld); 1139 _closedWorld);
1141 if (prefix == null) return folded; 1140 if (prefix == null) return folded;
1142 return new HStringConcat( 1141 return new HStringConcat(
1143 prefix, folded, _closedWorld.commonMasks.stringType); 1142 prefix, folded, _closedWorld.commonMasks.stringType);
1144 } 1143 }
1145 1144
1146 HInstruction visitStringify(HStringify node) { 1145 HInstruction visitStringify(HStringify node) {
1147 HInstruction input = node.inputs[0]; 1146 HInstruction input = node.inputs[0];
1148 if (input.isString(_closedWorld)) return input; 1147 if (input.isString(_closedWorld)) return input;
1149 1148
1150 HInstruction tryConstant() { 1149 HInstruction tryConstant() {
1151 if (!input.isConstant()) return null; 1150 if (!input.isConstant()) return null;
1152 HConstant constant = input; 1151 HConstant constant = input;
1153 if (!constant.constant.isPrimitive) return null; 1152 if (!constant.constant.isPrimitive) return null;
1154 if (constant.constant.isInt) { 1153 if (constant.constant.isInt) {
1155 // Only constant-fold int.toString() when Dart and JS results the same. 1154 // Only constant-fold int.toString() when Dart and JS results the same.
1156 // TODO(18103): We should be able to remove this work-around when issue 1155 // TODO(18103): We should be able to remove this work-around when issue
1157 // 18103 is resolved by providing the correct string. 1156 // 18103 is resolved by providing the correct string.
1158 IntConstantValue intConstant = constant.constant; 1157 IntConstantValue intConstant = constant.constant;
1159 // Very conservative range. 1158 // Very conservative range.
1160 if (!intConstant.isUInt32()) return null; 1159 if (!intConstant.isUInt32()) return null;
1161 } 1160 }
1162 PrimitiveConstantValue primitive = constant.constant; 1161 PrimitiveConstantValue primitive = constant.constant;
1163 return _graph.addConstant( 1162 return _graph.addConstant(
1164 constantSystem.createString(primitive.toDartString()), _closedWorld); 1163 constantSystem.createString('${primitive.primitiveValue}'),
1164 _closedWorld);
1165 } 1165 }
1166 1166
1167 HInstruction tryToString() { 1167 HInstruction tryToString() {
1168 // If the `toString` method is guaranteed to return a string we can call 1168 // If the `toString` method is guaranteed to return a string we can call
1169 // it directly. Keep the stringifier for primitives (since they have fast 1169 // it directly. Keep the stringifier for primitives (since they have fast
1170 // path code in the stringifier) and for classes requiring interceptors 1170 // path code in the stringifier) and for classes requiring interceptors
1171 // (since SsaInstructionSimplifier runs after SsaSimplifyInterceptors). 1171 // (since SsaInstructionSimplifier runs after SsaSimplifyInterceptors).
1172 if (input.canBePrimitive(_closedWorld)) return null; 1172 if (input.canBePrimitive(_closedWorld)) return null;
1173 if (input.canBeNull()) return null; 1173 if (input.canBeNull()) return null;
1174 Selector selector = Selectors.toString_; 1174 Selector selector = Selectors.toString_;
(...skipping 1818 matching lines...) Expand 10 before | Expand all | Expand 10 after
2993 2993
2994 keyedValues.forEach((receiver, values) { 2994 keyedValues.forEach((receiver, values) {
2995 result.keyedValues[receiver] = 2995 result.keyedValues[receiver] =
2996 new Map<HInstruction, HInstruction>.from(values); 2996 new Map<HInstruction, HInstruction>.from(values);
2997 }); 2997 });
2998 2998
2999 result.nonEscapingReceivers.addAll(nonEscapingReceivers); 2999 result.nonEscapingReceivers.addAll(nonEscapingReceivers);
3000 return result; 3000 return result;
3001 } 3001 }
3002 } 3002 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/ssa/nodes.dart ('k') | tests/compiler/dart2js/deferred_follow_constant_dependencies_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698