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

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

Issue 2937103002: Cache transitive files in FileState. (Closed)
Patch Set: Created 3 years, 6 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:typed_data'; 6 import 'dart:typed_data';
7 7
8 import 'package:convert/convert.dart'; 8 import 'package:convert/convert.dart';
9 import 'package:crypto/crypto.dart'; 9 import 'package:crypto/crypto.dart';
10 import 'package:front_end/file_system.dart'; 10 import 'package:front_end/file_system.dart';
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 bool _hasMixinApplication; 42 bool _hasMixinApplication;
43 List<int> _apiSignature; 43 List<int> _apiSignature;
44 44
45 List<NamespaceExport> _exports; 45 List<NamespaceExport> _exports;
46 List<FileState> _importedLibraries; 46 List<FileState> _importedLibraries;
47 List<FileState> _exportedLibraries; 47 List<FileState> _exportedLibraries;
48 List<FileState> _partFiles; 48 List<FileState> _partFiles;
49 49
50 Set<FileState> _directReferencedFiles = new Set<FileState>(); 50 Set<FileState> _directReferencedFiles = new Set<FileState>();
51 List<FileState> _directReferencedLibraries = <FileState>[]; 51 List<FileState> _directReferencedLibraries = <FileState>[];
52 Set<FileState> _transitiveFiles;
52 53
53 /// This flag is set to `true` during the mark phase of garbage collection 54 /// This flag is set to `true` during the mark phase of garbage collection
54 /// and set back to `false` for survived instances. 55 /// and set back to `false` for survived instances.
55 bool _gcMarked = false; 56 bool _gcMarked = false;
56 57
57 FileState._(this._fsState, this.uri, this.fileUri); 58 FileState._(this._fsState, this.uri, this.fileUri);
58 59
59 /// The MD5 signature of the file API as a byte array. 60 /// The MD5 signature of the file API as a byte array.
60 /// It depends on all non-comment tokens outside the block bodies. 61 /// It depends on all non-comment tokens outside the block bodies.
61 List<int> get apiSignature => _apiSignature; 62 List<int> get apiSignature => _apiSignature;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 /// Return topologically sorted cycles of dependencies for this library. 100 /// Return topologically sorted cycles of dependencies for this library.
100 List<LibraryCycle> get topologicalOrder { 101 List<LibraryCycle> get topologicalOrder {
101 var libraryWalker = new _LibraryWalker(); 102 var libraryWalker = new _LibraryWalker();
102 libraryWalker.walk(libraryWalker.getNode(this)); 103 libraryWalker.walk(libraryWalker.getNode(this));
103 return libraryWalker.topologicallySortedCycles; 104 return libraryWalker.topologicallySortedCycles;
104 } 105 }
105 106
106 /// Return the set of transitive files - the file itself and all of the 107 /// Return the set of transitive files - the file itself and all of the
107 /// directly or indirectly referenced files. 108 /// directly or indirectly referenced files.
108 Set<FileState> get transitiveFiles { 109 Set<FileState> get transitiveFiles {
109 // TODO(scheglov) add caching. 110 if (_transitiveFiles == null) {
110 var transitiveFiles = new Set<FileState>(); 111 _transitiveFiles = new Set<FileState>();
111 112
112 void appendReferenced(FileState file) { 113 void appendReferenced(FileState file) {
113 if (transitiveFiles.add(file)) { 114 if (_transitiveFiles.add(file)) {
114 file._directReferencedFiles.forEach(appendReferenced); 115 file._directReferencedFiles.forEach(appendReferenced);
116 }
115 } 117 }
118
119 appendReferenced(this);
116 } 120 }
117 121 return _transitiveFiles;
118 appendReferenced(this);
119 return transitiveFiles;
120 } 122 }
121 123
122 @override 124 @override
123 bool operator ==(Object other) { 125 bool operator ==(Object other) {
124 return other is FileState && other.uri == uri; 126 return other is FileState && other.uri == uri;
125 } 127 }
126 128
127 /// Read the file content and ensure that all of the file properties are 129 /// Read the file content and ensure that all of the file properties are
128 /// consistent with the read content, including all its dependencies. 130 /// consistent with the read content, including all its dependencies.
129 Future<Null> refresh() async { 131 Future<Null> refresh() async {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } 186 }
185 } 187 }
186 for (var part_ in unlinkedUnit.parts) { 188 for (var part_ in unlinkedUnit.parts) {
187 FileState file = await _getFileForRelativeUri(part_); 189 FileState file = await _getFileForRelativeUri(part_);
188 if (file != null) { 190 if (file != null) {
189 _partFiles.add(file); 191 _partFiles.add(file);
190 } 192 }
191 } 193 }
192 194
193 // Compute referenced files. 195 // Compute referenced files.
196 var oldDirectReferencedFiles = _directReferencedFiles;
194 _directReferencedFiles = new Set<FileState>() 197 _directReferencedFiles = new Set<FileState>()
195 ..addAll(_importedLibraries) 198 ..addAll(_importedLibraries)
196 ..addAll(_exportedLibraries) 199 ..addAll(_exportedLibraries)
197 ..addAll(_partFiles); 200 ..addAll(_partFiles);
198 _directReferencedLibraries = (new Set<FileState>() 201 _directReferencedLibraries = (new Set<FileState>()
199 ..addAll(_importedLibraries) 202 ..addAll(_importedLibraries)
200 ..addAll(_exportedLibraries)) 203 ..addAll(_exportedLibraries))
201 .toList(); 204 .toList();
205
206 // If the set of directly referenced files of this file is changed,
207 // then the transitive sets of files that include this file are also
208 // changed. Reset these transitive sets.
209 if (_directReferencedFiles.length != oldDirectReferencedFiles.length ||
210 !_directReferencedFiles.containsAll(oldDirectReferencedFiles)) {
211 for (var file in _fsState._uriToFile.values) {
212 if (file._transitiveFiles != null &&
213 file._transitiveFiles.contains(this)) {
214 file._transitiveFiles = null;
215 }
216 }
217 }
202 } 218 }
203 219
204 @override 220 @override
205 String toString() { 221 String toString() {
206 if (uri.scheme == 'file') return uri.path; 222 if (uri.scheme == 'file') return uri.path;
207 return uri.toString(); 223 return uri.toString();
208 } 224 }
209 225
210 /// Fasta unconditionally loads all VM libraries. In order to be able to 226 /// Fasta unconditionally loads all VM libraries. In order to be able to
211 /// serve them using the file system view, pretend that all of them were 227 /// serve them using the file system view, pretend that all of them were
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 cycle.libraries.add(node.file); 509 cycle.libraries.add(node.file);
494 fileToCycleMap[node.file] = cycle; 510 fileToCycleMap[node.file] = cycle;
495 } 511 }
496 topologicallySortedCycles.add(cycle); 512 topologicallySortedCycles.add(cycle);
497 } 513 }
498 514
499 _LibraryNode getNode(FileState file) { 515 _LibraryNode getNode(FileState file) {
500 return nodesOfFiles.putIfAbsent(file, () => new _LibraryNode(this, file)); 516 return nodesOfFiles.putIfAbsent(file, () => new _LibraryNode(this, file));
501 } 517 }
502 } 518 }
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