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

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

Issue 221873002: Compute frontend/backend specific constants. (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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 Set<Constant> constantDependencies) { 285 Set<Constant> constantDependencies) {
286 TreeElements elements = 286 TreeElements elements =
287 compiler.enqueuer.resolution.getCachedElements(element); 287 compiler.enqueuer.resolution.getCachedElements(element);
288 if (elements == null) return; 288 if (elements == null) return;
289 for (Element dependency in elements.allElements) { 289 for (Element dependency in elements.allElements) {
290 if (Elements.isLocal(dependency) && !dependency.isFunction()) continue; 290 if (Elements.isLocal(dependency) && !dependency.isFunction()) continue;
291 if (Elements.isUnresolved(dependency)) continue; 291 if (Elements.isUnresolved(dependency)) continue;
292 if (dependency.isStatement()) continue; 292 if (dependency.isStatement()) continue;
293 elementDependencies.add(dependency); 293 elementDependencies.add(dependency);
294 } 294 }
295 constantDependencies.addAll(elements.allConstants); 295 elements.forEachConstantNode((Node n, _) {
296 // Explicitly depend on the backend constants.
297 constantDependencies.add(
298 compiler.backend.constantHandler.getConstantForNode(n, elements));
floitsch 2014/04/02 16:50:02 Introduce backend getter in this class?
Johnni Winther 2014/04/07 11:42:27 Done.
299 });
296 elementDependencies.addAll(elements.otherDependencies); 300 elementDependencies.addAll(elements.otherDependencies);
297 } 301 }
298 302
299 /// Finds all elements and constants that [element] depends directly on. 303 /// Finds all elements and constants that [element] depends directly on.
300 /// (not the transitive closure.) 304 /// (not the transitive closure.)
301 /// 305 ///
302 /// Adds the results to [elements] and [constants]. 306 /// Adds the results to [elements] and [constants].
303 void _collectAllElementsAndConstantsResolvedFrom(Element element, 307 void _collectAllElementsAndConstantsResolvedFrom(Element element,
304 Set<Element> elements, 308 Set<Element> elements,
305 Set<Constant> constants) { 309 Set<Constant> constants) {
306 element = element.implementation; 310 element = element.implementation;
307 for (MetadataAnnotation metadata in element.metadata) { 311 for (MetadataAnnotation metadata in element.metadata) {
308 if (metadata.value != null) { 312 Constant constant =
309 constants.add(metadata.value); 313 compiler.backend.constantHandler.getConstantForMetadata(metadata);
310 elements.add(metadata.value.computeType(compiler).element); 314 if (constant != null) {
315 constants.add(constant);
316 elements.add(constant.computeType(compiler).element);
311 } 317 }
312 } 318 }
313 if (element.isClass()) { 319 if (element.isClass()) {
314 // If we see a class, add everything its instance members refer 320 // If we see a class, add everything its instance members refer
315 // to. Static members are not relevant. 321 // to. Static members are not relevant.
316 ClassElement cls = element.declaration; 322 ClassElement cls = element.declaration;
317 cls.forEachLocalMember((Element e) { 323 cls.forEachLocalMember((Element e) {
318 if (!e.isInstanceMember()) return; 324 if (!e.isInstanceMember()) return;
319 _collectDependencies(e.implementation, elements, constants); 325 _collectDependencies(e.implementation, elements, constants);
320 }); 326 });
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 MirrorUsageAnalyzerTask mirrorTask = compiler.mirrorUsageAnalyzerTask; 418 MirrorUsageAnalyzerTask mirrorTask = compiler.mirrorUsageAnalyzerTask;
413 // For each import we record all mirrors-used elements from all the 419 // For each import we record all mirrors-used elements from all the
414 // libraries reached directly from that import. 420 // libraries reached directly from that import.
415 for (Import deferredImport in _allDeferredImports.keys) { 421 for (Import deferredImport in _allDeferredImports.keys) {
416 LibraryElement deferredLibrary = _allDeferredImports[deferredImport]; 422 LibraryElement deferredLibrary = _allDeferredImports[deferredImport];
417 for (LibraryElement library in 423 for (LibraryElement library in
418 _nonDeferredReachableLibraries(deferredLibrary)) { 424 _nonDeferredReachableLibraries(deferredLibrary)) {
419 // TODO(sigurdm): The metadata should go to the right output unit. 425 // TODO(sigurdm): The metadata should go to the right output unit.
420 // For now they all go to the main output unit. 426 // For now they all go to the main output unit.
421 for (MetadataAnnotation metadata in library.metadata) { 427 for (MetadataAnnotation metadata in library.metadata) {
422 if (metadata.value != null) { 428 Constant constant =
423 _mapDependencies(metadata.value.computeType(compiler).element, 429 compiler.backend.constantHandler.getConstantForMetadata(metadata);
430 if (constant != null) {
431 _mapDependencies(constant.computeType(compiler).element,
424 _fakeMainImport); 432 _fakeMainImport);
425 } 433 }
426 } 434 }
427 for (LibraryTag tag in library.tags) { 435 for (LibraryTag tag in library.tags) {
428 for (MetadataAnnotation metadata in tag.metadata) { 436 for (MetadataAnnotation metadata in tag.metadata) {
429 if (metadata.value != null) { 437 Constant constant = compiler.backend.constantHandler
430 _mapDependencies(metadata.value.computeType(compiler).element, 438 .getConstantForMetadata(metadata);
439 if (constant != null) {
440 _mapDependencies(constant.computeType(compiler).element,
431 _fakeMainImport); 441 _fakeMainImport);
432 } 442 }
433 } 443 }
434 } 444 }
435 445
436 if (mirrorTask.librariesWithUsage.contains(library)) { 446 if (mirrorTask.librariesWithUsage.contains(library)) {
437 447
438 Map<LibraryElement, List<MirrorUsage>> mirrorsResult = 448 Map<LibraryElement, List<MirrorUsage>> mirrorsResult =
439 mirrorTask.analyzer.collectMirrorsUsedAnnotation(); 449 mirrorTask.analyzer.collectMirrorsUsedAnnotation();
440 450
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 if (import == _fakeMainImport) { 579 if (import == _fakeMainImport) {
570 result = "main"; 580 result = "main";
571 } else if (import.isDeferred) { 581 } else if (import.isDeferred) {
572 result = import.prefix.toString(); 582 result = import.prefix.toString();
573 } else { 583 } else {
574 Link<MetadataAnnotation> metadatas = import.metadata; 584 Link<MetadataAnnotation> metadatas = import.metadata;
575 assert(metadatas != null); 585 assert(metadatas != null);
576 for (MetadataAnnotation metadata in metadatas) { 586 for (MetadataAnnotation metadata in metadatas) {
577 metadata.ensureResolved(compiler); 587 metadata.ensureResolved(compiler);
578 Element element = metadata.value.computeType(compiler).element; 588 Element element = metadata.value.computeType(compiler).element;
579 if (metadata.value.computeType(compiler).element == 589 if (element == deferredLibraryClass) {
580 deferredLibraryClass) {
581 ConstructedConstant constant = metadata.value; 590 ConstructedConstant constant = metadata.value;
582 StringConstant s = constant.fields[0]; 591 StringConstant s = constant.fields[0];
583 result = s.value.slowToString(); 592 result = s.value.slowToString();
584 break; 593 break;
585 } 594 }
586 } 595 }
587 } 596 }
588 assert(result != null); 597 assert(result != null);
589 importDeferName[import] = makeUnique(result, usedImportNames);; 598 importDeferName[import] = makeUnique(result, usedImportNames);;
590 } 599 }
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 } 757 }
749 if (splitProgram && compiler.backend is DartBackend) { 758 if (splitProgram && compiler.backend is DartBackend) {
750 // TODO(sigurdm): Implement deferred loading for dart2dart. 759 // TODO(sigurdm): Implement deferred loading for dart2dart.
751 splitProgram = false; 760 splitProgram = false;
752 compiler.reportInfo( 761 compiler.reportInfo(
753 lastDeferred, 762 lastDeferred,
754 MessageKind.DEFERRED_LIBRARY_DART_2_DART); 763 MessageKind.DEFERRED_LIBRARY_DART_2_DART);
755 } 764 }
756 } 765 }
757 } 766 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698