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

Side by Side Diff: pkg/compiler/lib/src/library_loader.dart

Issue 1809533004: Support serialization of WorldImpact (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 dart2js.library_loader; 5 library dart2js.library_loader;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'common.dart'; 9 import 'common.dart';
10 import 'common/names.dart' show 10 import 'common/names.dart' show
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 return createLibrary(currentHandler, null, resolvedUri, 362 return createLibrary(currentHandler, null, resolvedUri,
363 skipFileWithPartOfTag: skipFileWithPartOfTag) 363 skipFileWithPartOfTag: skipFileWithPartOfTag)
364 .then((LibraryElement library) { 364 .then((LibraryElement library) {
365 if (library == null) { 365 if (library == null) {
366 currentHandler = null; 366 currentHandler = null;
367 return null; 367 return null;
368 } 368 }
369 return reporter.withCurrentElement(library, () { 369 return reporter.withCurrentElement(library, () {
370 return measure(() { 370 return measure(() {
371 currentHandler.computeExports(); 371 currentHandler.computeExports();
372 LoadedLibraries loadedLibraries = 372 LoadedLibraries loadedLibraries = new _LoadedLibraries(
373 new _LoadedLibraries(library, currentHandler.nodeMap, this); 373 library,
374 currentHandler.newLibraries,
375 currentHandler.nodeMap,
376 this);
374 currentHandler = null; 377 currentHandler = null;
375 return compiler.onLibrariesLoaded(loadedLibraries) 378 return compiler.onLibrariesLoaded(loadedLibraries)
376 .then((_) => library); 379 .then((_) => library);
377 }); 380 });
378 }); 381 });
379 }); 382 });
380 }); 383 });
381 } 384 }
382 385
383 /** 386 /**
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 }); 592 });
590 } 593 }
591 594
592 /// Loads the deserialized [library] with the [handler]. 595 /// Loads the deserialized [library] with the [handler].
593 /// 596 ///
594 /// All libraries imported or exported transitively from [library] will be 597 /// All libraries imported or exported transitively from [library] will be
595 /// loaded as well. 598 /// loaded as well.
596 Future<LibraryElement> loadDeserializedLibrary( 599 Future<LibraryElement> loadDeserializedLibrary(
597 LibraryDependencyHandler handler, 600 LibraryDependencyHandler handler,
598 LibraryElement library) { 601 LibraryElement library) {
599 compiler.onLibraryCreated(library);
600 libraryCanonicalUriMap[library.canonicalUri] = library; 602 libraryCanonicalUriMap[library.canonicalUri] = library;
603 handler.registerNewLibrary(library);
601 return compiler.onLibraryScanned(library, handler).then((_) { 604 return compiler.onLibraryScanned(library, handler).then((_) {
602 return Future.forEach(library.imports, (ImportElement import) { 605 return Future.forEach(library.imports, (ImportElement import) {
603 return createLibrary(handler, library, import.uri); 606 return createLibrary(handler, library, import.uri);
604 }).then((_) { 607 }).then((_) {
605 return Future.forEach(library.exports, (ExportElement export) { 608 return Future.forEach(library.exports, (ExportElement export) {
606 return createLibrary(handler, library, export.uri); 609 return createLibrary(handler, library, export.uri);
607 }).then((_) => library); 610 }).then((_) => library);
608 }); 611 });
609 }); 612 });
610 } 613 }
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 /** 1154 /**
1152 * Helper class used for computing the possibly cyclic import/export scopes of 1155 * Helper class used for computing the possibly cyclic import/export scopes of
1153 * a set of libraries. 1156 * a set of libraries.
1154 * 1157 *
1155 * This class is used by [ScannerTask.scanLibrary] to collect all newly loaded 1158 * This class is used by [ScannerTask.scanLibrary] to collect all newly loaded
1156 * libraries and to compute their import/export scopes through a fixed-point 1159 * libraries and to compute their import/export scopes through a fixed-point
1157 * algorithm. 1160 * algorithm.
1158 */ 1161 */
1159 class LibraryDependencyHandler implements LibraryLoader { 1162 class LibraryDependencyHandler implements LibraryLoader {
1160 final _LibraryLoaderTask task; 1163 final _LibraryLoaderTask task;
1164 final List<LibraryElement> _newLibraries = <LibraryElement>[];
1161 1165
1162 /** 1166 /**
1163 * Newly loaded libraries and their corresponding node in the library 1167 * Newly loaded libraries and their corresponding node in the library
1164 * dependency graph. Libraries that have already been fully loaded are not 1168 * dependency graph. Libraries that have already been fully loaded are not
1165 * part of the dependency graph of this handler since their export scopes have 1169 * part of the dependency graph of this handler since their export scopes have
1166 * already been computed. 1170 * already been computed.
1167 */ 1171 */
1168 Map<LibraryElement, LibraryDependencyNode> nodeMap = 1172 Map<LibraryElement, LibraryDependencyNode> nodeMap =
1169 new Map<LibraryElement, LibraryDependencyNode>(); 1173 new Map<LibraryElement, LibraryDependencyNode>();
1170 1174
1171 LibraryDependencyHandler(this.task); 1175 LibraryDependencyHandler(this.task);
1172 1176
1173 Compiler get compiler => task.compiler; 1177 Compiler get compiler => task.compiler;
1174 1178
1175 DiagnosticReporter get reporter => task.reporter; 1179 DiagnosticReporter get reporter => task.reporter;
1176 1180
1177 /// The libraries loaded with this handler. 1181 /// The libraries created with this handler.
1178 Iterable<LibraryElement> get loadedLibraries => nodeMap.keys; 1182 Iterable<LibraryElement> get newLibraries => _newLibraries;
1179 1183
1180 /** 1184 /**
1181 * Performs a fixed-point computation on the export scopes of all registered 1185 * Performs a fixed-point computation on the export scopes of all registered
1182 * libraries and creates the import/export of the libraries based on the 1186 * libraries and creates the import/export of the libraries based on the
1183 * fixed-point. 1187 * fixed-point.
1184 */ 1188 */
1185 void computeExports() { 1189 void computeExports() {
1186 bool changed = true; 1190 bool changed = true;
1187 while (changed) { 1191 while (changed) {
1188 changed = false; 1192 changed = false;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 assert(invariant(library, importingNode != null, 1261 assert(invariant(library, importingNode != null,
1258 message: "$library has not been registered")); 1262 message: "$library has not been registered"));
1259 importingNode.registerImportDependency(libraryDependency, loadedLibrary); 1263 importingNode.registerImportDependency(libraryDependency, loadedLibrary);
1260 } 1264 }
1261 } 1265 }
1262 1266
1263 /** 1267 /**
1264 * Registers [library] for the processing of its import/export scope. 1268 * Registers [library] for the processing of its import/export scope.
1265 */ 1269 */
1266 void registerNewLibrary(LibraryElement library) { 1270 void registerNewLibrary(LibraryElement library) {
1267 nodeMap[library] = new LibraryDependencyNode(library);
1268 compiler.onLibraryCreated(library); 1271 compiler.onLibraryCreated(library);
1272 _newLibraries.add(library);
1273 if (!library.exportsHandled) {
1274 nodeMap[library] = new LibraryDependencyNode(library);
1275 }
1269 } 1276 }
1270 1277
1271 /** 1278 /**
1272 * Registers all top-level entities of [library] as starting point for the 1279 * Registers all top-level entities of [library] as starting point for the
1273 * fixed-point computation of the import/export scopes. 1280 * fixed-point computation of the import/export scopes.
1274 */ 1281 */
1275 void registerLibraryExports(LibraryElement library) { 1282 void registerLibraryExports(LibraryElement library) {
1276 nodeMap[library].registerInitialExports(); 1283 nodeMap[library].registerInitialExports();
1277 } 1284 }
1278 1285
(...skipping 28 matching lines...) Expand all
1307 void forEachImportChain(Uri uri, 1314 void forEachImportChain(Uri uri,
1308 {bool callback(Link<Uri> importChainReversed)}); 1315 {bool callback(Link<Uri> importChainReversed)});
1309 } 1316 }
1310 1317
1311 class _LoadedLibraries implements LoadedLibraries { 1318 class _LoadedLibraries implements LoadedLibraries {
1312 final _LibraryLoaderTask task; 1319 final _LibraryLoaderTask task;
1313 final LibraryElement rootLibrary; 1320 final LibraryElement rootLibrary;
1314 final Map<Uri, LibraryElement> loadedLibraries = <Uri, LibraryElement>{}; 1321 final Map<Uri, LibraryElement> loadedLibraries = <Uri, LibraryElement>{};
1315 final Map<LibraryElement, LibraryDependencyNode> nodeMap; 1322 final Map<LibraryElement, LibraryDependencyNode> nodeMap;
1316 1323
1317 _LoadedLibraries(this.rootLibrary, this.nodeMap, this.task) { 1324 _LoadedLibraries(
1318 nodeMap.keys.forEach((LibraryElement loadedLibrary) { 1325 this.rootLibrary,
1326 Iterable<LibraryElement> libraries,
1327 this.nodeMap,
1328 this.task) {
1329 libraries.forEach((LibraryElement loadedLibrary) {
1319 loadedLibraries[loadedLibrary.canonicalUri] = loadedLibrary; 1330 loadedLibraries[loadedLibrary.canonicalUri] = loadedLibrary;
1320 }); 1331 });
1321 } 1332 }
1322 1333
1323 Uri get rootUri => rootLibrary.canonicalUri; 1334 Uri get rootUri => rootLibrary.canonicalUri;
1324 1335
1325 bool containsLibrary(Uri uri) => loadedLibraries.containsKey(uri); 1336 bool containsLibrary(Uri uri) => loadedLibraries.containsKey(uri);
1326 1337
1327 LibraryElement getLibrary(Uri uri) => loadedLibraries[uri]; 1338 LibraryElement getLibrary(Uri uri) => loadedLibraries[uri];
1328 1339
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 return; 1410 return;
1400 } 1411 }
1401 suffixes.add(const Link<Uri>().prepend(canonicalUri)); 1412 suffixes.add(const Link<Uri>().prepend(canonicalUri));
1402 } 1413 }
1403 suffixChainMap[library] = suffixes; 1414 suffixChainMap[library] = suffixes;
1404 return; 1415 return;
1405 } 1416 }
1406 1417
1407 computeSuffixes(rootLibrary, const Link<Uri>()); 1418 computeSuffixes(rootLibrary, const Link<Uri>());
1408 } 1419 }
1420
1421 String toString() => 'root=$rootLibrary,libraries=${loadedLibraries.keys}';
1409 } 1422 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698