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

Side by Side Diff: pkg/compiler/lib/src/deferred_load.dart

Issue 2194173002: Include constants in deferred computation. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 deferred_load; 5 library deferred_load;
6 6
7 import 'common/backend_api.dart' show Backend; 7 import 'common/backend_api.dart' show Backend;
8 import 'common/tasks.dart' show CompilerTask; 8 import 'common/tasks.dart' show CompilerTask;
9 import 'common.dart'; 9 import 'common.dart';
10 import 'compiler.dart' show Compiler; 10 import 'compiler.dart' show Compiler;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // assign every element to its output unit). 175 // assign every element to its output unit).
176 if (element.enclosingElement == null) { 176 if (element.enclosingElement == null) {
177 _elementToOutputUnit[element] = mainOutputUnit; 177 _elementToOutputUnit[element] = mainOutputUnit;
178 break; 178 break;
179 } 179 }
180 element = element.enclosingElement.implementation; 180 element = element.enclosingElement.implementation;
181 } 181 }
182 return _elementToOutputUnit[element]; 182 return _elementToOutputUnit[element];
183 } 183 }
184 184
185 /// Direct access to the output-unit to element relation used for testing.
186 OutputUnit getOutputUnitForElementForTesting(Element element) {
187 return _elementToOutputUnit[element];
188 }
189
185 /// Returns the [OutputUnit] where [constant] belongs. 190 /// Returns the [OutputUnit] where [constant] belongs.
186 OutputUnit outputUnitForConstant(ConstantValue constant) { 191 OutputUnit outputUnitForConstant(ConstantValue constant) {
187 if (!isProgramSplit) return mainOutputUnit; 192 if (!isProgramSplit) return mainOutputUnit;
188 return _constantToOutputUnit[constant]; 193 return _constantToOutputUnit[constant];
189 } 194 }
190 195
196 /// Direct access to the output-unit to constants map used for testing.
197 Map<ConstantValue, OutputUnit> get outputUnitForConstantsForTesting {
198 return _constantToOutputUnit;
199 }
200
191 bool isDeferred(Element element) { 201 bool isDeferred(Element element) {
192 return outputUnitForElement(element) != mainOutputUnit; 202 return outputUnitForElement(element) != mainOutputUnit;
193 } 203 }
194 204
195 /// Returns the unique name for the deferred import of [prefix]. 205 /// Returns the unique name for the deferred import of [prefix].
196 String getImportDeferName(Spannable node, PrefixElement prefix) { 206 String getImportDeferName(Spannable node, PrefixElement prefix) {
197 String name = 207 String name =
198 importDeferName[new _DeclaredDeferredImport(prefix.deferredImport)]; 208 importDeferName[new _DeclaredDeferredImport(prefix.deferredImport)];
199 if (name == null) { 209 if (name == null) {
200 reporter.internalError(node, "No deferred name for $prefix."); 210 reporter.internalError(node, "No deferred name for $prefix.");
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 // TODO(johnniwinther): Add only expressions that are actually needed. 353 // TODO(johnniwinther): Add only expressions that are actually needed.
344 // Currently we have some noise here: Some potential expressions are 354 // Currently we have some noise here: Some potential expressions are
345 // seen that should never be added (for instance field initializers 355 // seen that should never be added (for instance field initializers
346 // in constant constructors, like `this.field = parameter`). And some 356 // in constant constructors, like `this.field = parameter`). And some
347 // implicit constant expression are seen that we should be able to add 357 // implicit constant expression are seen that we should be able to add
348 // (like primitive constant literals like `true`, `"foo"` and `0`). 358 // (like primitive constant literals like `true`, `"foo"` and `0`).
349 // See dartbug.com/26406 for context. 359 // See dartbug.com/26406 for context.
350 treeElements 360 treeElements
351 .forEachConstantNode((Node node, ConstantExpression expression) { 361 .forEachConstantNode((Node node, ConstantExpression expression) {
352 if (compiler.serialization.isDeserialized(analyzableElement)) { 362 if (compiler.serialization.isDeserialized(analyzableElement)) {
353 if (!expression.isImplicit && !expression.isPotential) { 363 if (!expression.isPotential) {
354 // Enforce evaluation of [expression]. 364 // Enforce evaluation of [expression].
355 backend.constants.getConstantValue(expression); 365 backend.constants.getConstantValue(expression);
356 } 366 }
357 } 367 }
358 368
359 // Explicitly depend on the backend constants. 369 // Explicitly depend on the backend constants.
360 if (backend.constants.hasConstantValue(expression)) { 370 if (backend.constants.hasConstantValue(expression)) {
361 ConstantValue value = 371 ConstantValue value =
362 backend.constants.getConstantValue(expression); 372 backend.constants.getConstantValue(expression);
363 assert(invariant(node, value != null, 373 assert(invariant(node, value != null,
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 elementMap.putIfAbsent(output, () => <String>[]).add('$element'); 931 elementMap.putIfAbsent(output, () => <String>[]).add('$element');
922 }); 932 });
923 _constantToOutputUnit.forEach((ConstantValue value, OutputUnit output) { 933 _constantToOutputUnit.forEach((ConstantValue value, OutputUnit output) {
924 constantMap 934 constantMap
925 .putIfAbsent(output, () => <String>[]) 935 .putIfAbsent(output, () => <String>[])
926 .add(value.toStructuredText()); 936 .add(value.toStructuredText());
927 }); 937 });
928 938
929 StringBuffer sb = new StringBuffer(); 939 StringBuffer sb = new StringBuffer();
930 for (OutputUnit outputUnit in allOutputUnits) { 940 for (OutputUnit outputUnit in allOutputUnits) {
931 sb.write(outputUnit.name); 941 sb.write('\n-------------------------------\n');
942 sb.write('Output unit: ${outputUnit.name}');
932 List<String> elements = elementMap[outputUnit]; 943 List<String> elements = elementMap[outputUnit];
933 if (elements != null) { 944 if (elements != null) {
934 sb.write('\n elements:'); 945 sb.write('\n elements:');
935 for (String element in elements..sort()) { 946 for (String element in elements..sort()) {
936 sb.write('\n $element'); 947 sb.write('\n $element');
937 } 948 }
938 } 949 }
939 List<String> constants = constantMap[outputUnit]; 950 List<String> constants = constantMap[outputUnit];
940 if (constants != null) { 951 if (constants != null) {
941 sb.write('\n constants:'); 952 sb.write('\n constants:');
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 1035
1025 bool operator ==(other) { 1036 bool operator ==(other) {
1026 if (other is! _DeclaredDeferredImport) return false; 1037 if (other is! _DeclaredDeferredImport) return false;
1027 return declaration == other.declaration; 1038 return declaration == other.declaration;
1028 } 1039 }
1029 1040
1030 int get hashCode => declaration.hashCode * 17; 1041 int get hashCode => declaration.hashCode * 17;
1031 1042
1032 String toString() => '$declaration'; 1043 String toString() => '$declaration';
1033 } 1044 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698