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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/deferred_load.dart

Issue 220203004: Improve the mirror support for deferred loading. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
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 'dart2jslib.dart' show 7 import 'dart2jslib.dart' show
8 Compiler, 8 Compiler,
9 CompilerTask, 9 CompilerTask,
10 Constant, 10 Constant,
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 elementDependencies.addAll(elements.otherDependencies); 296 elementDependencies.addAll(elements.otherDependencies);
297 } 297 }
298 298
299 /// Finds all elements and constants that [element] depends directly on. 299 /// Finds all elements and constants that [element] depends directly on.
300 /// (not the transitive closure.) 300 /// (not the transitive closure.)
301 /// 301 ///
302 /// Adds the results to [elements] and [constants]. 302 /// Adds the results to [elements] and [constants].
303 void _collectAllElementsAndConstantsResolvedFrom(Element element, 303 void _collectAllElementsAndConstantsResolvedFrom(Element element,
304 Set<Element> elements, 304 Set<Element> elements,
305 Set<Constant> constants) { 305 Set<Constant> constants) {
306 element = element.implementation; 306 // TODO(sigurdm): How is metadata on a patch-class handled?
307 for (MetadataAnnotation metadata in element.metadata) { 307 for (MetadataAnnotation metadata in element.metadata) {
308 if (metadata.value != null) { 308 if (metadata.value != null) {
309 constants.add(metadata.value); 309 constants.add(metadata.value);
310 elements.add(metadata.value.computeType(compiler).element); 310 elements.add(metadata.value.computeType(compiler).element);
311 } 311 }
312 } 312 }
313 if (element.isClass()) { 313 if (element.isClass()) {
314 // If we see a class, add everything its instance members refer 314 // If we see a class, add everything its instance members refer
315 // to. Static members are not relevant. 315 // to. Static members are not relevant.
316 ClassElement cls = element.declaration; 316 ClassElement cls = element.declaration;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 435
436 if (mirrorTask.librariesWithUsage.contains(library)) { 436 if (mirrorTask.librariesWithUsage.contains(library)) {
437 437
438 Map<LibraryElement, List<MirrorUsage>> mirrorsResult = 438 Map<LibraryElement, List<MirrorUsage>> mirrorsResult =
439 mirrorTask.analyzer.collectMirrorsUsedAnnotation(); 439 mirrorTask.analyzer.collectMirrorsUsedAnnotation();
440 440
441 // If there is a MirrorsUsed annotation we add only the needed 441 // If there is a MirrorsUsed annotation we add only the needed
442 // things to the output units for the library. 442 // things to the output units for the library.
443 List<MirrorUsage> mirrorUsages = mirrorsResult[library]; 443 List<MirrorUsage> mirrorUsages = mirrorsResult[library];
444 if (mirrorUsages == null) continue; 444 if (mirrorUsages == null) continue;
445
446 void mapDependenciesIfResolved(Element element) {
447 // If there is a target for this class, but no use of mirrors the
448 // class will not be resolved. We just skip it.
449 if (element is ClassElement &&
450 !(element as ClassElement).isResolved) {
451 return;
452 }
453 _mapDependencies(element, deferredImport);
454 }
455
445 for (MirrorUsage usage in mirrorUsages) { 456 for (MirrorUsage usage in mirrorUsages) {
446 if (usage.targets != null) { 457 if (usage.targets != null) {
447 for (Element dependency in usage.targets) { 458 for (Element dependency in usage.targets) {
448 _mapDependencies(dependency, deferredImport); 459 if (dependency.isLibrary()) {
460 LibraryElement library = dependency;
461 library.forEachLocalMember(mapDependenciesIfResolved);
462 } else {
463 mapDependenciesIfResolved(dependency);
464 }
449 } 465 }
450 } 466 }
451 if (usage.metaTargets != null) { 467 if (usage.metaTargets != null) {
452 for (Element dependency in usage.metaTargets) { 468 for (Element dependency in usage.metaTargets) {
453 _mapDependencies(dependency, deferredImport); 469 _mapDependencies(dependency, deferredImport);
454 } 470 }
455 } 471 }
456 } 472 }
457 } else { 473 } else {
458 // If there is no MirrorsUsed annotation we add _everything_ to 474 // If there is no MirrorsUsed annotation we add _everything_ to
(...skipping 18 matching lines...) Expand all
477 // deferred libraries at the same time. 493 // deferred libraries at the same time.
478 bool usesMirrors = false; 494 bool usesMirrors = false;
479 for (LibraryTag tag in library.tags) { 495 for (LibraryTag tag in library.tags) {
480 if (tag is! Import) continue; 496 if (tag is! Import) continue;
481 if (library.getLibraryFromTag(tag) == compiler.mirrorsLibrary) { 497 if (library.getLibraryFromTag(tag) == compiler.mirrorsLibrary) {
482 usesMirrors = true; 498 usesMirrors = true;
483 break; 499 break;
484 } 500 }
485 } 501 }
486 if (usesMirrors) { 502 if (usesMirrors) {
487 for (Link link in compiler.enqueuer.allElementsByName.values) { 503 // Add all resolved elements to the output unit.
488 for (Element dependency in link) { 504 for (Element element in
489 _mapDependencies(dependency, deferredImport); 505 compiler.enqueuer.resolution.resolvedElements.keys) {
490 } 506 _mapDependencies(element, deferredImport);
507 }
508 for (Element element in
509 compiler.mirrorDependencies.otherDependencies) {
510 _mapDependencies(element, deferredImport);
491 } 511 }
492 } 512 }
493 } 513 }
494 } 514 }
495 } 515 }
496 } 516 }
497 517
498 /// Goes through [allConstants] and adjusts their outputUnits. 518 /// Goes through [allConstants] and adjusts their outputUnits.
499 void _adjustConstantsOutputUnit(Set<Constant> allConstants) { 519 void _adjustConstantsOutputUnit(Set<Constant> allConstants) {
500 // A constant has three dependencies: 520 // A constant has three dependencies:
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 } 768 }
749 if (splitProgram && compiler.backend is DartBackend) { 769 if (splitProgram && compiler.backend is DartBackend) {
750 // TODO(sigurdm): Implement deferred loading for dart2dart. 770 // TODO(sigurdm): Implement deferred loading for dart2dart.
751 splitProgram = false; 771 splitProgram = false;
752 compiler.reportInfo( 772 compiler.reportInfo(
753 lastDeferred, 773 lastDeferred,
754 MessageKind.DEFERRED_LIBRARY_DART_2_DART); 774 MessageKind.DEFERRED_LIBRARY_DART_2_DART);
755 } 775 }
756 } 776 }
757 } 777 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/compiler.dart ('k') | sdk/lib/_internal/compiler/implementation/enqueue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698