Skip to content

Commit

Permalink
Parts. Rename to LibraryCycle.dispose()
Browse files Browse the repository at this point in the history
Change-Id: I872f6af61d4709ab693dcfd996ab6f1bc91e288a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/376801
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and Commit Queue committed Jul 19, 2024
1 parent 55ff601 commit 6c22a5a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/analysis/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2032,7 +2032,7 @@ class AnalysisDriver {
for (var file in affected) {
var kind = file.kind;
if (kind is LibraryFileKind) {
kind.invalidateLibraryCycle();
kind.disposeLibraryCycle();
}
accumulatedAffected.add(file.path);
}
Expand Down
44 changes: 22 additions & 22 deletions pkg/analyzer/lib/src/dart/analysis/file_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ abstract class FileKind {
FileKind({
required this.file,
}) {
invalidateLibraryCycle();
disposeLibraryCycle();
}

/// When [library] returns `null`, this getter is used to look at this
Expand Down Expand Up @@ -549,7 +549,7 @@ abstract class FileKind {

@mustCallSuper
void dispose() {
invalidateLibraryCycle();
disposeLibraryCycle();

_augmentationImports?.disposeAll();
_libraryExports?.disposeAll();
Expand All @@ -558,6 +558,19 @@ abstract class FileKind {
_docImports?.disposeAll();
}

/// Dispose the containing [LibraryFileKind] cycle.
void disposeLibraryCycle() {
// Macro generated files never add new dependencies.
// So, there is no reason to dispose.
if (file.isMacroAugmentation) {
return;
}

for (var reference in file.referencingFiles) {
reference.kind.disposeLibraryCycle();
}
}

bool hasAugmentation(AugmentationFileKind augmentation) {
for (var import in augmentationImports) {
if (import is AugmentationImportWithFile) {
Expand Down Expand Up @@ -590,19 +603,6 @@ abstract class FileKind {
.any((import) => import.importedFile == file);
}

/// Invalidates the containing [LibraryFileKind] cycle.
void invalidateLibraryCycle() {
// Macro generated files never add new dependencies.
// So, there is no reason to dispose.
if (file.isMacroAugmentation) {
return;
}

for (var reference in file.referencingFiles) {
reference.kind.invalidateLibraryCycle();
}
}

/// Creates a [LibraryImportState] with the given unlinked [directive].
LibraryImportState _buildLibraryImportState(
UnlinkedLibraryImportDirective directive,
Expand Down Expand Up @@ -2288,7 +2288,13 @@ class LibraryFileKind extends LibraryOrAugmentationFileKind {
super.dispose();
}

/// When the library cycle that contains this library is invalidated, the
@override
void disposeLibraryCycle() {
_libraryCycle?.dispose();
_libraryCycle = null;
}

/// When the library cycle that contains this library is disposed, the
/// macros might potentially generate different code, or no code at all. So,
/// we discard the existing macro augmentation library, it will be rebuilt
/// during linking.
Expand All @@ -2310,12 +2316,6 @@ class LibraryFileKind extends LibraryOrAugmentationFileKind {
disposeMacroAugmentations(disposeFiles: false);
}

@override
void invalidateLibraryCycle() {
_libraryCycle?.invalidate();
_libraryCycle = null;
}

void removeLastMacroAugmentation() {
_macroImports = _macroImports.withoutLast.toFixedList();
_augmentationImports = augmentationImports.withoutLast.toFixedList();
Expand Down
10 changes: 5 additions & 5 deletions pkg/analyzer/lib/src/dart/analysis/library_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class LibraryCycle {
/// The library cycles that this cycle references directly.
final Set<LibraryCycle> directDependencies;

/// The cycles that use this cycle, used to [invalidate] transitively.
/// The cycles that use this cycle, used to [dispose] transitively.
final List<LibraryCycle> directUsers = [];

/// The transitive API signature of this cycle.
Expand Down Expand Up @@ -135,16 +135,16 @@ class LibraryCycle {
/// The key of the macro kernel in the byte store.
String get macroKey => '$implSignature.macro_kernel';

/// Invalidate this cycle and any cycles that directly or indirectly use it.
/// Dispose this cycle and any cycles that directly or indirectly use it.
///
/// Practically invalidation means that we clear the library cycle in all the
/// Practically this means that we clear the library cycle in all the
/// [libraries] that share this [LibraryCycle] instance.
void invalidate() {
void dispose() {
for (var library in libraries) {
library.internal_setLibraryCycle(null);
}
for (var user in directUsers.toList()) {
user.invalidate();
user.dispose();
}
for (var directDependency in directDependencies) {
directDependency.directUsers.remove(this);
Expand Down

0 comments on commit 6c22a5a

Please sign in to comment.