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

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,
11 ConstructedConstant, 11 ConstructedConstant,
12 MessageKind, 12 MessageKind,
13 StringConstant, 13 StringConstant,
14 invariant; 14 invariant;
15 15
16 import 'dart_backend/dart_backend.dart' show 16 import 'dart_backend/dart_backend.dart' show
17 DartBackend; 17 DartBackend;
18 18
19 import 'elements/elements.dart' show 19 import 'elements/elements.dart' show
20 Element, 20 Element,
21 ClassElement, 21 ClassElement,
22 ElementKind, 22 ElementKind,
23 Elements, 23 Elements,
24 FunctionElement, 24 FunctionElement,
25 LibraryElement, 25 LibraryElement,
26 MetadataAnnotation, 26 MetadataAnnotation,
27 ScopeContainerElement, 27 ScopeContainerElement,
28 PrefixElement, 28 PrefixElement,
29 ClosureContainer; 29 ClosureContainer,
30 STATE_DONE;
30 31
31 import 'util/util.dart' show 32 import 'util/util.dart' show
32 Link; 33 Link;
33 34
34 import 'util/setlet.dart' show 35 import 'util/setlet.dart' show
35 Setlet; 36 Setlet;
36 37
37 import 'tree/tree.dart' show 38 import 'tree/tree.dart' show
38 LibraryTag, 39 LibraryTag,
39 Node, 40 Node,
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 elementDependencies.addAll(elements.otherDependencies); 297 elementDependencies.addAll(elements.otherDependencies);
297 } 298 }
298 299
299 /// Finds all elements and constants that [element] depends directly on. 300 /// Finds all elements and constants that [element] depends directly on.
300 /// (not the transitive closure.) 301 /// (not the transitive closure.)
301 /// 302 ///
302 /// Adds the results to [elements] and [constants]. 303 /// Adds the results to [elements] and [constants].
303 void _collectAllElementsAndConstantsResolvedFrom(Element element, 304 void _collectAllElementsAndConstantsResolvedFrom(Element element,
304 Set<Element> elements, 305 Set<Element> elements,
305 Set<Constant> constants) { 306 Set<Constant> constants) {
307 // TODO(sigurdm): How is metadata on a patch-class handled?
306 element = element.implementation; 308 element = element.implementation;
Johnni Winther 2014/04/01 13:20:00 Remove this line.
sigurdm 2014/04/01 13:57:44 Done.
307 for (MetadataAnnotation metadata in element.metadata) { 309 for (MetadataAnnotation metadata in element.metadata) {
308 if (metadata.value != null) { 310 if (metadata.value != null) {
309 constants.add(metadata.value); 311 constants.add(metadata.value);
310 elements.add(metadata.value.computeType(compiler).element); 312 elements.add(metadata.value.computeType(compiler).element);
311 } 313 }
312 } 314 }
313 if (element.isClass()) { 315 if (element.isClass()) {
314 // If we see a class, add everything its instance members refer 316 // If we see a class, add everything its instance members refer
315 // to. Static members are not relevant. 317 // to. Static members are not relevant.
316 ClassElement cls = element.declaration; 318 ClassElement cls = element.declaration;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 437
436 if (mirrorTask.librariesWithUsage.contains(library)) { 438 if (mirrorTask.librariesWithUsage.contains(library)) {
437 439
438 Map<LibraryElement, List<MirrorUsage>> mirrorsResult = 440 Map<LibraryElement, List<MirrorUsage>> mirrorsResult =
439 mirrorTask.analyzer.collectMirrorsUsedAnnotation(); 441 mirrorTask.analyzer.collectMirrorsUsedAnnotation();
440 442
441 // If there is a MirrorsUsed annotation we add only the needed 443 // If there is a MirrorsUsed annotation we add only the needed
442 // things to the output units for the library. 444 // things to the output units for the library.
443 List<MirrorUsage> mirrorUsages = mirrorsResult[library]; 445 List<MirrorUsage> mirrorUsages = mirrorsResult[library];
444 if (mirrorUsages == null) continue; 446 if (mirrorUsages == null) continue;
447
448 void mapDependenciesIfResolved(Element element) {
449 // If there is a target for this class, but no use of mirrors the
450 // class will not be resolved. We just skip it.
451 if (element.isClass() &&
karlklose 2014/04/01 13:48:18 Consider using an is-test here, as you expect a su
sigurdm 2014/04/01 13:57:44 Done.
452 (element as ClassElement).resolutionState != STATE_DONE) {
Johnni Winther 2014/04/01 13:20:00 Use `!isResolved` instead of `resolutionState != S
sigurdm 2014/04/01 13:57:44 Done.
453 return;
454 }
455 _mapDependencies(element, deferredImport);
456 }
457
445 for (MirrorUsage usage in mirrorUsages) { 458 for (MirrorUsage usage in mirrorUsages) {
446 if (usage.targets != null) { 459 if (usage.targets != null) {
447 for (Element dependency in usage.targets) { 460 for (Element dependency in usage.targets) {
448 _mapDependencies(dependency, deferredImport); 461 if (dependency.isLibrary()) {
462 LibraryElement library = dependency;
463 library.forEachLocalMember(mapDependenciesIfResolved);
464 } else {
465 mapDependenciesIfResolved(dependency);
466 }
449 } 467 }
450 } 468 }
451 if (usage.metaTargets != null) { 469 if (usage.metaTargets != null) {
452 for (Element dependency in usage.metaTargets) { 470 for (Element dependency in usage.metaTargets) {
453 _mapDependencies(dependency, deferredImport); 471 _mapDependencies(dependency, deferredImport);
454 } 472 }
455 } 473 }
456 } 474 }
457 } else { 475 } else {
458 // If there is no MirrorsUsed annotation we add _everything_ to 476 // If there is no MirrorsUsed annotation we add _everything_ to
(...skipping 18 matching lines...) Expand all
477 // deferred libraries at the same time. 495 // deferred libraries at the same time.
478 bool usesMirrors = false; 496 bool usesMirrors = false;
479 for (LibraryTag tag in library.tags) { 497 for (LibraryTag tag in library.tags) {
480 if (tag is! Import) continue; 498 if (tag is! Import) continue;
481 if (library.getLibraryFromTag(tag) == compiler.mirrorsLibrary) { 499 if (library.getLibraryFromTag(tag) == compiler.mirrorsLibrary) {
482 usesMirrors = true; 500 usesMirrors = true;
483 break; 501 break;
484 } 502 }
485 } 503 }
486 if (usesMirrors) { 504 if (usesMirrors) {
487 for (Link link in compiler.enqueuer.allElementsByName.values) { 505 // Add all resolved elements to the output unit.
488 for (Element dependency in link) { 506 for (Element element in
489 _mapDependencies(dependency, deferredImport); 507 compiler.enqueuer.resolution.resolvedElements.keys) {
490 } 508 _mapDependencies(element, deferredImport);
509 }
510 for (Element element in
511 compiler.mirrorDependencies.otherDependencies) {
512 _mapDependencies(element, deferredImport);
491 } 513 }
492 } 514 }
493 } 515 }
494 } 516 }
495 } 517 }
496 } 518 }
497 519
498 /// Goes through [allConstants] and adjusts their outputUnits. 520 /// Goes through [allConstants] and adjusts their outputUnits.
499 void _adjustConstantsOutputUnit(Set<Constant> allConstants) { 521 void _adjustConstantsOutputUnit(Set<Constant> allConstants) {
500 // A constant has three dependencies: 522 // A constant has three dependencies:
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 } 770 }
749 if (splitProgram && compiler.backend is DartBackend) { 771 if (splitProgram && compiler.backend is DartBackend) {
750 // TODO(sigurdm): Implement deferred loading for dart2dart. 772 // TODO(sigurdm): Implement deferred loading for dart2dart.
751 splitProgram = false; 773 splitProgram = false;
752 compiler.reportInfo( 774 compiler.reportInfo(
753 lastDeferred, 775 lastDeferred,
754 MessageKind.DEFERRED_LIBRARY_DART_2_DART); 776 MessageKind.DEFERRED_LIBRARY_DART_2_DART);
755 } 777 }
756 } 778 }
757 } 779 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698