anchor.diff:    }
   
     /// Computes the set of [FileState]'s used/not used to analyze the given
  -  /// [files]. Removes the [FileState]'s of the files not used for analysis from
  +  /// [paths]. Removes the [FileState]'s of the files not used for analysis from
     /// the cache. Returns the set of unused [FileState]'s.
  -  Set<FileState> removeUnusedFiles(List<String> files) {
  -    var allReferenced = <String>{};
  -    for (var path in files) {
  -      allReferenced.add(path);
  -      _pathToFile[path]?.collectAllReferencedFiles(allReferenced);
  -    }
  -
  -    var unusedPaths = _pathToFile.keys.toSet();
  -    unusedPaths.removeAll(allReferenced);
  -
  -    var removedFiles = <FileState>{};
  -    for (var path in unusedPaths) {
  -      changeFile(path, removedFiles);
  -    }
  -
  -    return removedFiles;
  +  Set<FileState> removeUnusedFiles(List<String> paths) {
  +    final referenced = <FileState>{};
  +    for (final path in paths) {
  +      final library = _pathToFile[path]?.kind.library;
  +      library?.collectTransitive(referenced);
  +    }
  +
  +    final removed = <FileState>{};
  +    for (final file in _pathToFile.values.toList()) {
  +      if (!referenced.contains(file)) {
  +        changeFile(file.path, removed);
  +      }
  +    }
  +
  +    return removed;
     }
   
     /// Clear all [FileState] data - all maps from path or URI, etc.
  
positive.code:     }).toList();
    }
  
    /// Directives are usually pulled lazily (so that we can parse a file
    /// without pulling all its transitive references), but when we output
    /// textual dumps we want to check that we reference only objects that
  
negative.code:   @override
    bool operator ==(Object other) {
      return other is FileState && other.uri == uri;
    }
  
    /// Return a new parsed unresolved [CompilationUnit].
  