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

Side by Side Diff: pkg/analyzer/lib/src/generated/element.dart

Issue 1413273002: Library Cycle invalidation (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix some comments Created 5 years, 2 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) 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 engine.element; 5 library engine.element;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' show min; 8 import 'dart:math' show min;
9 9
10 import 'package:analyzer/src/generated/utilities_general.dart'; 10 import 'package:analyzer/src/generated/utilities_general.dart';
(...skipping 7500 matching lines...) Expand 10 before | Expand all | Expand 10 after
7511 for (ImportElement importElement in imports) { 7511 for (ImportElement importElement in imports) {
7512 (importElement as ImportElementImpl).enclosingElement = this; 7512 (importElement as ImportElementImpl).enclosingElement = this;
7513 PrefixElementImpl prefix = importElement.prefix as PrefixElementImpl; 7513 PrefixElementImpl prefix = importElement.prefix as PrefixElementImpl;
7514 if (prefix != null) { 7514 if (prefix != null) {
7515 prefix.enclosingElement = this; 7515 prefix.enclosingElement = this;
7516 } 7516 }
7517 } 7517 }
7518 this._imports = imports; 7518 this._imports = imports;
7519 } 7519 }
7520 7520
7521 /** Given an update to this library which may have added or deleted edges
7522 * in the import/export graph originating from this node only, remove any
7523 * cached library cycles in the element model which may have been invalidated.
7524 */
7525 void invalidateLibraryCycles() {
7526 if (_libraryCycle == null) {
7527 // We have already invalidated this node, or we have never computed
7528 // library cycle information for it. In the former case, we're done. In
7529 // the latter case, this node cannot be reachable from any node for which
7530 // we have computed library cycle information. Therefore, any edges added
7531 // or deleted in the update causing this invalidation can only be edges to
7532 // nodes which either have no library cycle information (and hence do not
7533 // need invalidation), or which do not reach this node by any path.
7534 // In either case, no further invalidation is needed.
7535 return;
7536 }
7537 // If we have pre-computed library cycle information, then we must
7538 // invalidate the information both on this element, and on certain
7539 // other elements. Edges originating at this node may have been
7540 // added or deleted. A deleted edge that points outside of this cycle
7541 // cannot change the cycle information for anything outside of this cycle,
7542 // and so it is sufficient to delete the cached library information on this
7543 // cycle. An added edge which points to another node within the cycle
7544 // induces no invalidation. An added edge which points to a node earlier
7545 // in the topological sort of cycles induces no invalidation (since there
7546 // are by definition no back edges from earlier cycles in the topological
7547 // order, and hence no possible cycle can have been introduced. The only
7548 // remaining case is that we have added an edge to a node which is later
7549 // in the topological sort of cycles. This can induce cycles, since it
7550 // represents a new back edge. It would be sufficient to invalidate the
7551 // cycle information for all nodes that are between the target and the
7552 // node in the topological order. For simplicity, we simply invalidate
7553 // all nodes which are reachable from the the source node.
7554 // Note that in the invalidation phase, we do not cut off when we encounter
7555 // a node with no library cycle information, since we do not know whether
7556 // we are in the case where invalidation has already been performed, or we
7557 // are in the case where library cycles have simply never been computed from
7558 // a newly reachable node.
7559 Set<LibraryElementImpl> active = new HashSet();
7560 void invalidate(LibraryElementImpl library) {
7561 if (!active.add(library)) return;
7562 if (library._libraryCycle != null) {
7563 library._libraryCycle.forEach(invalidate);
7564 library._libraryCycle = null;
7565 }
7566 library.exportedLibraries.forEach(invalidate);
7567 library.importedLibraries.forEach(invalidate);
7568 }
7569 invalidate(this);
7570 }
7571
7521 @override 7572 @override
7522 bool get isBrowserApplication => 7573 bool get isBrowserApplication =>
7523 entryPoint != null && isOrImportsBrowserLibrary; 7574 entryPoint != null && isOrImportsBrowserLibrary;
7524 7575
7525 @override 7576 @override
7526 bool get isDartCore => name == "dart.core"; 7577 bool get isDartCore => name == "dart.core";
7527 7578
7528 @override 7579 @override
7529 bool get isInSdk => 7580 bool get isInSdk =>
7530 StringUtilities.startsWith5(name, 0, 0x64, 0x61, 0x72, 0x74, 0x2E); 7581 StringUtilities.startsWith5(name, 0, 0x64, 0x61, 0x72, 0x74, 0x2E);
(...skipping 3399 matching lines...) Expand 10 before | Expand all | Expand 10 after
10930 10981
10931 @override 10982 @override
10932 void visitElement(Element element) { 10983 void visitElement(Element element) {
10933 int offset = element.nameOffset; 10984 int offset = element.nameOffset;
10934 if (offset != -1) { 10985 if (offset != -1) {
10935 map[offset] = element; 10986 map[offset] = element;
10936 } 10987 }
10937 super.visitElement(element); 10988 super.visitElement(element);
10938 } 10989 }
10939 } 10990 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/task/dart.dart » ('j') | pkg/analyzer/lib/src/task/driver.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698