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

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: Rebased 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // assign every element to its output unit). 173 // assign every element to its output unit).
174 if (element.enclosingElement == null) { 174 if (element.enclosingElement == null) {
175 _elementToOutputUnit[element] = mainOutputUnit; 175 _elementToOutputUnit[element] = mainOutputUnit;
176 break; 176 break;
177 } 177 }
178 element = element.enclosingElement.implementation; 178 element = element.enclosingElement.implementation;
179 } 179 }
180 return _elementToOutputUnit[element]; 180 return _elementToOutputUnit[element];
181 } 181 }
182 182
183 /// Direct access to the output-unit to element relation used for testing.
184 OutputUnit getOutputUnitForElementForTesting(Element element) {
185 return _elementToOutputUnit[element];
186 }
187
183 /// Returns the [OutputUnit] where [constant] belongs. 188 /// Returns the [OutputUnit] where [constant] belongs.
184 OutputUnit outputUnitForConstant(ConstantValue constant) { 189 OutputUnit outputUnitForConstant(ConstantValue constant) {
185 if (!isProgramSplit) return mainOutputUnit; 190 if (!isProgramSplit) return mainOutputUnit;
186 return _constantToOutputUnit[constant]; 191 return _constantToOutputUnit[constant];
187 } 192 }
188 193
194 /// Direct access to the output-unit to constants map used for testing.
195 Map<ConstantValue, OutputUnit> get outputUnitForConstantsForTesting {
196 return _constantToOutputUnit;
197 }
198
189 bool isDeferred(Element element) { 199 bool isDeferred(Element element) {
190 return outputUnitForElement(element) != mainOutputUnit; 200 return outputUnitForElement(element) != mainOutputUnit;
191 } 201 }
192 202
193 /// Returns the unique name for the deferred import of [prefix]. 203 /// Returns the unique name for the deferred import of [prefix].
194 String getImportDeferName(Spannable node, PrefixElement prefix) { 204 String getImportDeferName(Spannable node, PrefixElement prefix) {
195 String name = 205 String name =
196 importDeferName[new _DeclaredDeferredImport(prefix.deferredImport)]; 206 importDeferName[new _DeclaredDeferredImport(prefix.deferredImport)];
197 if (name == null) { 207 if (name == null) {
198 reporter.internalError(node, "No deferred name for $prefix."); 208 reporter.internalError(node, "No deferred name for $prefix.");
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 // TODO(johnniwinther): Add only expressions that are actually needed. 351 // TODO(johnniwinther): Add only expressions that are actually needed.
342 // Currently we have some noise here: Some potential expressions are 352 // Currently we have some noise here: Some potential expressions are
343 // seen that should never be added (for instance field initializers 353 // seen that should never be added (for instance field initializers
344 // in constant constructors, like `this.field = parameter`). And some 354 // in constant constructors, like `this.field = parameter`). And some
345 // implicit constant expression are seen that we should be able to add 355 // implicit constant expression are seen that we should be able to add
346 // (like primitive constant literals like `true`, `"foo"` and `0`). 356 // (like primitive constant literals like `true`, `"foo"` and `0`).
347 // See dartbug.com/26406 for context. 357 // See dartbug.com/26406 for context.
348 treeElements.forEachConstantNode( 358 treeElements.forEachConstantNode(
349 (ast.Node node, ConstantExpression expression) { 359 (ast.Node node, ConstantExpression expression) {
350 if (compiler.serialization.isDeserialized(analyzableElement)) { 360 if (compiler.serialization.isDeserialized(analyzableElement)) {
351 if (!expression.isImplicit && !expression.isPotential) { 361 if (!expression.isPotential) {
352 // Enforce evaluation of [expression]. 362 // Enforce evaluation of [expression].
353 backend.constants.getConstantValue(expression); 363 backend.constants.getConstantValue(expression);
354 } 364 }
355 } 365 }
356 366
357 // Explicitly depend on the backend constants. 367 // Explicitly depend on the backend constants.
358 if (backend.constants.hasConstantValue(expression)) { 368 if (backend.constants.hasConstantValue(expression)) {
359 ConstantValue value = 369 ConstantValue value =
360 backend.constants.getConstantValue(expression); 370 backend.constants.getConstantValue(expression);
361 assert(invariant(node, value != null, 371 assert(invariant(node, value != null,
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 elementMap.putIfAbsent(output, () => <String>[]).add('$element'); 929 elementMap.putIfAbsent(output, () => <String>[]).add('$element');
920 }); 930 });
921 _constantToOutputUnit.forEach((ConstantValue value, OutputUnit output) { 931 _constantToOutputUnit.forEach((ConstantValue value, OutputUnit output) {
922 constantMap 932 constantMap
923 .putIfAbsent(output, () => <String>[]) 933 .putIfAbsent(output, () => <String>[])
924 .add(value.toStructuredText()); 934 .add(value.toStructuredText());
925 }); 935 });
926 936
927 StringBuffer sb = new StringBuffer(); 937 StringBuffer sb = new StringBuffer();
928 for (OutputUnit outputUnit in allOutputUnits) { 938 for (OutputUnit outputUnit in allOutputUnits) {
929 sb.write(outputUnit.name); 939 sb.write('\n-------------------------------\n');
940 sb.write('Output unit: ${outputUnit.name}');
930 List<String> elements = elementMap[outputUnit]; 941 List<String> elements = elementMap[outputUnit];
931 if (elements != null) { 942 if (elements != null) {
932 sb.write('\n elements:'); 943 sb.write('\n elements:');
933 for (String element in elements..sort()) { 944 for (String element in elements..sort()) {
934 sb.write('\n $element'); 945 sb.write('\n $element');
935 } 946 }
936 } 947 }
937 List<String> constants = constantMap[outputUnit]; 948 List<String> constants = constantMap[outputUnit];
938 if (constants != null) { 949 if (constants != null) {
939 sb.write('\n constants:'); 950 sb.write('\n constants:');
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 1033
1023 bool operator ==(other) { 1034 bool operator ==(other) {
1024 if (other is! _DeclaredDeferredImport) return false; 1035 if (other is! _DeclaredDeferredImport) return false;
1025 return declaration == other.declaration; 1036 return declaration == other.declaration;
1026 } 1037 }
1027 1038
1028 int get hashCode => declaration.hashCode * 17; 1039 int get hashCode => declaration.hashCode * 17;
1029 1040
1030 String toString() => '$declaration'; 1041 String toString() => '$declaration';
1031 } 1042 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/constants/expressions.dart ('k') | pkg/compiler/lib/src/serialization/equivalence.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698