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

Side by Side Diff: pkg/front_end/lib/src/incremental/file_state.dart

Issue 3009683002: Remember direct dependencies in LibraryCycle. (Closed)
Patch Set: Created 3 years, 3 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
« no previous file with comments | « no previous file | pkg/front_end/test/src/incremental/file_state_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:convert'; 6 import 'dart:convert';
7 import 'dart:typed_data'; 7 import 'dart:typed_data';
8 8
9 import 'package:convert/convert.dart'; 9 import 'package:convert/convert.dart';
10 import 'package:crypto/crypto.dart'; 10 import 'package:crypto/crypto.dart';
11 import 'package:front_end/file_system.dart'; 11 import 'package:front_end/file_system.dart';
12 import 'package:front_end/src/base/resolve_relative_uri.dart'; 12 import 'package:front_end/src/base/resolve_relative_uri.dart';
13 import 'package:front_end/src/byte_store/byte_store.dart';
13 import 'package:front_end/src/dependency_walker.dart' as graph; 14 import 'package:front_end/src/dependency_walker.dart' as graph;
14 import 'package:front_end/src/fasta/uri_translator.dart'; 15 import 'package:front_end/src/fasta/uri_translator.dart';
15 import 'package:front_end/src/byte_store/byte_store.dart';
16 import 'package:front_end/src/incremental/format.dart'; 16 import 'package:front_end/src/incremental/format.dart';
17 import 'package:front_end/src/incremental/unlinked_unit.dart'; 17 import 'package:front_end/src/incremental/unlinked_unit.dart';
18 import 'package:kernel/target/targets.dart'; 18 import 'package:kernel/target/targets.dart';
19 19
20 /// This function is called for each newly discovered file, and the returned 20 /// This function is called for each newly discovered file, and the returned
21 /// [Future] is awaited before reading the file content. 21 /// [Future] is awaited before reading the file content.
22 typedef Future<Null> NewFileFn(Uri uri); 22 typedef Future<Null> NewFileFn(Uri uri);
23 23
24 /// Information about a file being compiled, explicitly or implicitly. 24 /// Information about a file being compiled, explicitly or implicitly.
25 /// 25 ///
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 372
373 /// Return the [FileState] for the given [fileUri], or `null` if the 373 /// Return the [FileState] for the given [fileUri], or `null` if the
374 /// [fileUri] does not yet correspond to any referenced [FileState]. 374 /// [fileUri] does not yet correspond to any referenced [FileState].
375 FileState getFileByFileUri(Uri fileUri) => _fileUriToFile[fileUri]; 375 FileState getFileByFileUri(Uri fileUri) => _fileUriToFile[fileUri];
376 } 376 }
377 377
378 /// List of libraries that reference each other, so form a cycle. 378 /// List of libraries that reference each other, so form a cycle.
379 class LibraryCycle { 379 class LibraryCycle {
380 final List<FileState> libraries = <FileState>[]; 380 final List<FileState> libraries = <FileState>[];
381 381
382 /// [LibraryCycle]s that contain libraries directly import or export 382 /// The cycles this cycle directly depends on.
383 /// this [LibraryCycle]. 383 final Set<LibraryCycle> directDependencies = new Set<LibraryCycle>();
384
385 /// The cycles that directly import or export this cycle.
384 final List<LibraryCycle> directUsers = <LibraryCycle>[]; 386 final List<LibraryCycle> directUsers = <LibraryCycle>[];
385 387
386 bool get _isForVm { 388 bool get _isForVm {
387 return libraries.any((l) => l.uri.toString().endsWith('dart:_vmservice')); 389 return libraries.any((l) => l.uri.toString().endsWith('dart:_vmservice'));
388 } 390 }
389 391
390 @override 392 @override
391 String toString() { 393 String toString() {
392 if (_isForVm) { 394 if (_isForVm) {
393 return '[core + vm]'; 395 return '[core + vm]';
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 @override 481 @override
480 List<_LibraryNode> computeDependencies() { 482 List<_LibraryNode> computeDependencies() {
481 return file.directReferencedLibraries.map(walker.getNode).toList(); 483 return file.directReferencedLibraries.map(walker.getNode).toList();
482 } 484 }
483 } 485 }
484 486
485 /// Helper that organizes dependencies of a library into topologically 487 /// Helper that organizes dependencies of a library into topologically
486 /// sorted [LibraryCycle]s. 488 /// sorted [LibraryCycle]s.
487 class _LibraryWalker extends graph.DependencyWalker<_LibraryNode> { 489 class _LibraryWalker extends graph.DependencyWalker<_LibraryNode> {
488 final nodesOfFiles = <FileState, _LibraryNode>{}; 490 final nodesOfFiles = <FileState, _LibraryNode>{};
491 final fileToCycleMap = <FileState, LibraryCycle>{};
489 final topologicallySortedCycles = <LibraryCycle>[]; 492 final topologicallySortedCycles = <LibraryCycle>[];
490 final fileToCycleMap = <FileState, LibraryCycle>{};
491 493
492 @override 494 @override
493 void evaluate(_LibraryNode v) { 495 void evaluate(_LibraryNode v) {
494 evaluateScc([v]); 496 evaluateScc([v]);
495 } 497 }
496 498
497 @override 499 @override
498 void evaluateScc(List<_LibraryNode> scc) { 500 void evaluateScc(List<_LibraryNode> scc) {
499 var cycle = new LibraryCycle(); 501 var cycle = new LibraryCycle();
500 502
501 // Build the set of cycles this cycle directly depends on. 503 // Compute direct dependencies.
502 var directDependencies = new Set<LibraryCycle>();
503 for (var node in scc) { 504 for (var node in scc) {
504 var file = node.file; 505 var file = node.file;
505 for (var importedLibrary in file.importedLibraries) { 506 for (var importedLibrary in file.importedLibraries) {
506 var importedCycle = fileToCycleMap[importedLibrary]; 507 var importedCycle = fileToCycleMap[importedLibrary];
507 if (importedCycle != null) directDependencies.add(importedCycle); 508 if (importedCycle != null) {
509 cycle.directDependencies.add(importedCycle);
510 }
508 } 511 }
509 for (var exportedLibrary in file.exportedLibraries) { 512 for (var exportedLibrary in file.exportedLibraries) {
510 var exportedCycle = fileToCycleMap[exportedLibrary]; 513 var exportedCycle = fileToCycleMap[exportedLibrary];
511 if (exportedCycle != null) directDependencies.add(exportedCycle); 514 if (exportedCycle != null) {
515 cycle.directDependencies.add(exportedCycle);
516 }
512 } 517 }
513 } 518 }
514 519
515 // Register this cycle as a direct user of the direct dependencies. 520 // Register this cycle as a direct user of the direct dependencies.
516 for (var directDependency in directDependencies) { 521 for (var directDependency in cycle.directDependencies) {
517 directDependency.directUsers.add(cycle); 522 directDependency.directUsers.add(cycle);
518 } 523 }
519 524
525 // Fill the cycle with libraries.
520 for (var node in scc) { 526 for (var node in scc) {
521 node.isEvaluated = true; 527 node.isEvaluated = true;
522 cycle.libraries.add(node.file); 528 cycle.libraries.add(node.file);
523 fileToCycleMap[node.file] = cycle; 529 fileToCycleMap[node.file] = cycle;
524 } 530 }
531
525 topologicallySortedCycles.add(cycle); 532 topologicallySortedCycles.add(cycle);
526 } 533 }
527 534
528 _LibraryNode getNode(FileState file) { 535 _LibraryNode getNode(FileState file) {
529 return nodesOfFiles.putIfAbsent(file, () => new _LibraryNode(this, file)); 536 return nodesOfFiles.putIfAbsent(file, () => new _LibraryNode(this, file));
530 } 537 }
531 } 538 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/test/src/incremental/file_state_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698