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

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

Issue 12033003: Deferred (aka lazy) loading of static functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased Created 7 years, 10 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
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
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.
4
5 class DeferredLoadTask extends CompilerTask {
6 DeferredLoadTask(Compiler compiler) : super(compiler);
7 String get name => 'Lazy';
8 final Set<LibraryElement> deferredLibraries = new Set<LibraryElement>();
9
10 bool isDeferred(Element element) {
11 // TODO(ahe): This is really a graph coloring problem. We should
12 // make sure that libraries and elements only used by a deferred
13 // library are also deferred.
14 // Also, if something is deferred depends on your
15 // perspective. Inside a deferred library, other elements of the
16 // same library are not deferred. We should add an extra parameter
17 // to this method to indicate "from where".
18 return deferredLibraries.contains(element.getLibrary());
19 }
20
21 void registerMainApp(LibraryElement mainApp) {
22 if (mainApp == null) return;
23 compiler.withCurrentElement(mainApp, () {
24 deferredLibraries.addAll(new List.from(findDeferredLibraries(mainApp)));
25 });
26 }
27
28 Link<Element> findDeferredLibraries(LibraryElement library) {
29 Link<Element> link = const Link<Element>();
30 for (LibraryTag tag in library.tags) {
31 for (MetadataAnnotation metadata in tag.metadata) {
32 metadata.ensureResolved(compiler);
33 if (metadata.value.type.element == compiler.deferLoadClass) {
34 ConstructedConstant value = metadata.value;
35 SourceString expectedName = value.fields[0].toDartString().source;
36 LibraryElement deferredLibrary = library.getDependency(tag);
37 link = link.prepend(deferredLibrary);
38 note(tag, 'Defer loading of $deferredLibrary');
39 SourceString actualName =
40 new SourceString(deferredLibrary.getLibraryOrScriptName());
41 if (expectedName != actualName) {
42 compiler.reportErrorCode(
43 metadata,
44 MessageKind.GENERIC, // DO NOT SUBMIT (add proper error code).
45 {'text':
46 'Library name mismatch "${expectedName.slowToString()}" != '
47 '"${actualName.slowToString()}"'});
48 } else {
49 // DO NOT SUBMIT (this is for debugging).
50 note(metadata,
51 '${actualName.slowToString()} matches $deferredLibrary');
52 }
53 }
54 }
55 }
56 return link;
57 }
58
59 void note(Spannable node, message) {
60 compiler.reportMessage(compiler.spanFromSpannable(node),
61 MessageKind.GENERIC.error({'text': message}),
62 api.Diagnostic.INFO);
63 }
64 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698