Version 2.18.0-238.0.dev
Merge commit 'fd185c0dec8386aa52481de388b989bb944fd8b3' into 'dev'
diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart
index d0d0c33..ba502a6 100644
--- a/pkg/analyzer/lib/src/dart/analysis/driver.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart
@@ -777,7 +777,7 @@
}
var units = <ParsedUnitResult>[];
- for (var unitFile in file.libraryFiles) {
+ for (var unitFile in kind.files) {
var unitPath = unitFile.path;
var unitResult = parseFileSync(unitPath);
if (unitResult is! ParsedUnitResult) {
@@ -1707,11 +1707,20 @@
CaughtException caught = CaughtException(exception, stackTrace);
var fileContentMap = <String, String>{};
- var libraryFile = _fsState.getFileForPath(path);
+
+ var fileContent = '';
try {
- for (var file in libraryFile.libraryFiles) {
- var path = file.path;
- fileContentMap[path] = file.content;
+ final file = _fsState.getFileForPath(path);
+ fileContent = file.content;
+ final fileKind = file.kind;
+ final libraryKind = fileKind.library;
+ if (libraryKind != null) {
+ for (final file in libraryKind.files) {
+ fileContentMap[file.path] = file.content;
+ }
+ } else {
+ final file = fileKind.file;
+ fileContentMap[file.path] = file.content;
}
} catch (_) {
// We might get an exception while parsing to access parts.
@@ -1728,7 +1737,7 @@
ExceptionResult(
filePath: path,
fileContentMap: fileContentMap,
- fileContent: libraryFile.content,
+ fileContent: fileContent,
exception: caught,
contextKey: contextKey,
),
diff --git a/pkg/analyzer/lib/src/dart/analysis/file_state.dart b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
index c436ab7..1164841 100644
--- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
@@ -38,6 +38,7 @@
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
import 'package:analyzer/src/util/performance/operation_performance.dart';
import 'package:analyzer/src/util/uri.dart';
+import 'package:analyzer/src/utilities/extensions/collection.dart';
import 'package:analyzer/src/workspace/workspace.dart';
import 'package:collection/collection.dart';
import 'package:convert/convert.dart';
@@ -59,6 +60,9 @@
// TODO(scheglov): implement asLibrary
throw UnimplementedError();
}
+
+ /// Returns `true` if the `library augment` directive confirms [container].
+ bool isAugmentationOf(LibraryOrAugmentationFileKind container);
}
/// The URI of the [directive] can be resolved.
@@ -99,6 +103,11 @@
}
return null;
}
+
+ @override
+ bool isAugmentationOf(LibraryOrAugmentationFileKind container) {
+ return uriFile == container.file;
+ }
}
/// The URI of the [directive] can not be resolved.
@@ -110,6 +119,9 @@
@override
LibraryFileStateKind? get library => null;
+
+ @override
+ bool isAugmentationOf(LibraryOrAugmentationFileKind container) => false;
}
/// Information about a single `import` directive.
@@ -277,10 +289,8 @@
/// Files that reference this file.
final Set<FileState> referencingFiles = {};
- List<FileState?> _augmentationFiles = [];
List<FileState?>? _importedFiles;
List<FileState?>? _exportedFiles;
- List<FileState> _libraryFiles = [];
Set<FileState>? _directReferencedFiles;
@@ -306,11 +316,6 @@
/// The unlinked API signature of the file.
Uint8List get apiSignature => _apiSignature!;
- /// The list of imported augmentations.
- List<FileState?> get augmentationFiles {
- return _augmentationFiles;
- }
-
/// The content of the file.
String get content => _fileContent!.content;
@@ -384,12 +389,6 @@
FileStateKind get kind => _kind!;
- /// The list of files files that this library consists of, i.e. this library
- /// file itself and its [partedFiles].
- List<FileState> get libraryFiles {
- return _libraryFiles;
- }
-
/// Return information about line in the file.
LineInfo get lineInfo => _lineInfo!;
@@ -574,8 +573,6 @@
// Read parts eagerly to link parts to libraries.
_updateKind();
- _updatePartedFiles();
- _updateAugmentationFiles();
// Update mapping from subtyped names to files.
for (var name in _driverUnlinkedUnit!.subtypedNames) {
@@ -750,23 +747,10 @@
}
}
- removeForOne(_augmentationFiles);
removeForOne(_exportedFiles);
removeForOne(_importedFiles);
}
- void _updateAugmentationFiles() {
- _augmentationFiles = unlinked2.augmentations.map((directive) {
- return _fileForRelativeUri(directive.uri).map(
- (augmentation) {
- augmentation?.referencingFiles.add(this);
- return augmentation;
- },
- (_) => null,
- );
- }).toList();
- }
-
void _updateKind() {
_kind?.dispose();
@@ -794,10 +778,11 @@
);
}
} else if (libraryDirective != null) {
- _kind = LibraryFileStateKind(
+ final kind = _kind = LibraryFileStateKind(
file: this,
name: libraryDirective.name,
);
+ _fsState._libraryNameToFiles.add(kind);
} else if (partOfNameDirective != null) {
_kind = PartOfNameFileStateKind(
file: this,
@@ -828,18 +813,9 @@
);
}
- _fsState._libraryNameToFiles.add(_kind);
_invalidatesLibrariesOfThisPart();
}
- /// TODO(scheglov) Stop using [partedFiles].
- void _updatePartedFiles() {
- _libraryFiles = [
- this,
- ...partedFiles.whereNotNull(),
- ];
- }
-
static UnlinkedUnit serializeAstUnlinked2(
CompilationUnit unit, {
required bool isDartCore,
@@ -1041,6 +1017,7 @@
/// Returns the library in which this file should be analyzed.
LibraryFileStateKind? get library;
+ @mustCallSuper
void dispose() {}
}
@@ -1234,7 +1211,6 @@
return result;
}
- @visibleForTesting
FileState? getExisting(File file) {
return _pathToFile[file.path];
}
@@ -1518,6 +1494,47 @@
bool get isSrc => (_flags & _isSrc) != 0;
}
+/// Information about a single `import augment` directive.
+class ImportAugmentationDirectiveState {
+ final LibraryOrAugmentationFileKind container;
+ final UnlinkedImportAugmentationDirective directive;
+
+ ImportAugmentationDirectiveState({
+ required this.container,
+ required this.directive,
+ });
+
+ /// Returns a [Source] that is referenced by this directive.
+ ///
+ /// Returns `null` if the URI cannot be resolved into a [Source].
+ Source? get importedSource => null;
+}
+
+/// [PartDirectiveState] that has a valid URI that references a file.
+class ImportAugmentationDirectiveWithFile
+ extends ImportAugmentationDirectiveState {
+ final FileState importedFile;
+
+ ImportAugmentationDirectiveWithFile({
+ required super.container,
+ required super.directive,
+ required this.importedFile,
+ });
+
+ /// If [importedFile] is a [AugmentationFileStateKind], and it confirms that
+ /// it is an augmentation of the [container], returns the [importedFile].
+ AugmentationFileStateKind? get importedAugmentation {
+ final kind = importedFile.kind;
+ if (kind is AugmentationFileStateKind && kind.isAugmentationOf(container)) {
+ return kind;
+ }
+ return null;
+ }
+
+ @override
+ Source? get importedSource => importedFile.source;
+}
+
/// Information about a single `import` directive.
class ImportDirectiveState {
final UnlinkedNamespaceDirective directive;
@@ -1603,6 +1620,29 @@
required this.name,
});
+ /// The list of files files that this library consists of, i.e. this library
+ /// file itself, its [parts], and augmentations.
+ List<FileState> get files {
+ final files = [
+ file,
+ ];
+
+ // TODO(scheglov) When we include only valid parts, use this instead.
+ final includeOnlyValidParts = 0 > 1;
+ for (final part in parts) {
+ if (part is PartDirectiveWithFile) {
+ if (includeOnlyValidParts) {
+ files.addIfNotNull(part.includedPart?.file);
+ } else {
+ files.add(part.includedFile);
+ }
+ }
+ }
+
+ // TODO(scheglov) Include augmentations.
+ return files;
+ }
+
LibraryCycle? get internal_libraryCycle => _libraryCycle;
@override
@@ -1647,6 +1687,12 @@
}
@override
+ void discoverReferencedFiles() {
+ super.discoverReferencedFiles();
+ parts;
+ }
+
+ @override
void dispose() {
invalidateLibraryCycle();
file._fsState._libraryNameToFiles.remove(this);
@@ -1660,23 +1706,7 @@
}
}
- final imports = _imports;
- if (imports != null) {
- for (final import in imports) {
- if (import is ImportDirectiveWithFile) {
- import.importedFile.referencingFiles.remove(file);
- }
- }
- }
-
- final exports = _exports;
- if (exports != null) {
- for (final export in exports) {
- if (export is ExportDirectiveWithFile) {
- export.exportedFile.referencingFiles.remove(file);
- }
- }
- }
+ super.dispose();
}
bool hasPart(PartFileStateKind partKind) {
@@ -1701,6 +1731,7 @@
}
abstract class LibraryOrAugmentationFileKind extends FileStateKind {
+ List<ImportAugmentationDirectiveState>? _augmentations;
List<ExportDirectiveState>? _exports;
List<ImportDirectiveState>? _imports;
@@ -1708,6 +1739,34 @@
required super.file,
});
+ List<ImportAugmentationDirectiveState> get augmentations {
+ return _augmentations ??= file.unlinked2.augmentations.map((directive) {
+ return file._fileForRelativeUri(directive.uri).map(
+ (refFile) {
+ if (refFile != null) {
+ refFile.referencingFiles.add(file);
+ return ImportAugmentationDirectiveWithFile(
+ container: this,
+ directive: directive,
+ importedFile: refFile,
+ );
+ } else {
+ return ImportAugmentationDirectiveState(
+ container: this,
+ directive: directive,
+ );
+ }
+ },
+ (externalLibrary) {
+ return ImportAugmentationDirectiveState(
+ container: this,
+ directive: directive,
+ );
+ },
+ );
+ }).toList();
+ }
+
List<ExportDirectiveState> get exports {
return _exports ??= file.unlinked2.exports.map((directive) {
final uriStr = file._selectRelativeUri(directive);
@@ -1762,8 +1821,63 @@
}).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
+ /// are available. So, we need to discover all referenced files before
+ /// we register available objects.
+ @visibleForTesting
+ void discoverReferencedFiles() {
+ exports;
+ imports;
+ for (final import in augmentations) {
+ if (import is ImportAugmentationDirectiveWithFile) {
+ import.importedAugmentation?.discoverReferencedFiles();
+ }
+ }
+ }
+
+ @override
+ void dispose() {
+ final augmentations = _augmentations;
+ if (augmentations != null) {
+ for (final import in augmentations) {
+ if (import is ImportAugmentationDirectiveWithFile) {
+ import.importedFile.referencingFiles.remove(file);
+ }
+ }
+ }
+
+ final exports = _exports;
+ if (exports != null) {
+ for (final export in exports) {
+ if (export is ExportDirectiveWithFile) {
+ export.exportedFile.referencingFiles.remove(file);
+ }
+ }
+ }
+
+ final imports = _imports;
+ if (imports != null) {
+ for (final import in imports) {
+ if (import is ImportDirectiveWithFile) {
+ import.importedFile.referencingFiles.remove(file);
+ }
+ }
+ }
+
+ super.dispose();
+ }
+
bool hasAugmentation(AugmentationFileStateKind augmentation) {
- return file.augmentationFiles.contains(augmentation.file);
+ for (final import in augmentations) {
+ if (import is ImportAugmentationDirectiveWithFile) {
+ if (import.importedFile == augmentation.file) {
+ return true;
+ }
+ }
+ }
+ return false;
}
}
@@ -1977,14 +2091,11 @@
}
/// If [kind] is a named library, register it.
- /// TODO(scheglov) Use [LibraryFileStateKind]
- void add(FileStateKind? kind) {
- if (kind is LibraryFileStateKind) {
- final name = kind.name;
- if (name != null) {
- final libraries = _map[name] ??= [];
- libraries.add(kind);
- }
+ void add(LibraryFileStateKind kind) {
+ final name = kind.name;
+ if (name != null) {
+ final libraries = _map[name] ??= [];
+ libraries.add(kind);
}
}
@@ -1993,17 +2104,14 @@
}
/// If [kind] is a named library, unregister it.
- /// TODO(scheglov) Use [LibraryFileStateKind]
- void remove(FileStateKind? kind) {
- if (kind is LibraryFileStateKind) {
- final name = kind.name;
- if (name != null) {
- final libraries = _map[name];
- if (libraries != null) {
- libraries.remove(kind);
- if (libraries.isEmpty) {
- _map.remove(name);
- }
+ void remove(LibraryFileStateKind kind) {
+ final name = kind.name;
+ if (name != null) {
+ final libraries = _map[name];
+ if (libraries != null) {
+ libraries.remove(kind);
+ if (libraries.isEmpty) {
+ _map.remove(name);
}
}
}
diff --git a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
index bbadd99..a81f6e1 100644
--- a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
@@ -280,11 +280,11 @@
}
if (_analysisOptions.lint) {
- var allUnits = _library.file.libraryFiles
+ var allUnits = _library.files
.map((file) => LinterContextUnit(file.content, units[file]!))
.toList();
for (int i = 0; i < allUnits.length; i++) {
- _computeLints(_library.file.libraryFiles[i], allUnits[i], allUnits,
+ _computeLints(_library.files[i], allUnits[i], allUnits,
analysisOptions: _analysisOptions);
}
}
@@ -295,7 +295,7 @@
// This must happen after all other diagnostics have been computed but
// before the list of diagnostics has been filtered.
- for (var file in _library.file.libraryFiles) {
+ for (var file in _library.files) {
IgnoreValidator(
_getErrorReporter(file),
_getErrorListener(file).errors,
@@ -568,7 +568,7 @@
var units = <FileState, CompilationUnitImpl>{};
// Parse all files.
- for (FileState file in _library.file.libraryFiles) {
+ for (FileState file in _library.files) {
units[file] = _parse(file);
}
diff --git a/pkg/analyzer/lib/src/dart/analysis/library_context.dart b/pkg/analyzer/lib/src/dart/analysis/library_context.dart
index ed95565..fdf5ba2 100644
--- a/pkg/analyzer/lib/src/dart/analysis/library_context.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/library_context.dart
@@ -144,7 +144,7 @@
var macroLibraries = <MacroLibrary>[];
for (var library in cycle.libraries) {
var macroClasses = <MacroClass>[];
- for (var file in library.file.libraryFiles) {
+ for (var file in library.files) {
unitsInformativeBytes[file.uri] = file.unlinked2.informativeBytes;
for (var macroClass in file.unlinked2.macroClasses) {
macroClasses.add(
@@ -182,7 +182,7 @@
var inputUnits = <LinkInputUnit>[];
var partIndex = -1;
- for (var file in library.file.libraryFiles) {
+ for (var file in library.files) {
var isSynthetic = !file.exists;
var unit = file.parse();
@@ -357,7 +357,7 @@
) {
var fileContentMap = <String, String>{};
for (var library in cycle.libraries) {
- for (var file in library.file.libraryFiles) {
+ for (var file in library.files) {
fileContentMap[file.path] = file.content;
}
}
diff --git a/pkg/analyzer/lib/src/dart/analysis/library_graph.dart b/pkg/analyzer/lib/src/dart/analysis/library_graph.dart
index 405c981..1cfb843 100644
--- a/pkg/analyzer/lib/src/dart/analysis/library_graph.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/library_graph.dart
@@ -57,7 +57,7 @@
late final bool hasMacroClass = () {
for (final library in libraries) {
- for (final file in library.file.libraryFiles) {
+ for (final file in library.files) {
if (file.unlinked2.macroClasses.isNotEmpty) {
return true;
}
@@ -110,7 +110,7 @@
mightBeExecutedByMacroClass = true;
// Mark each file of the cycle.
for (final library in libraries) {
- for (final file in library.file.libraryFiles) {
+ for (final file in library.files) {
file.mightBeExecutedByMacroClass = true;
}
}
@@ -203,14 +203,16 @@
implSignature.addLanguageVersion(file.packageLanguageVersion);
implSignature.addString(file.uriStr);
- apiSignature.addInt(file.libraryFiles.length);
- for (var file in file.libraryFiles) {
+ final libraryFiles = node.kind.files;
+
+ apiSignature.addInt(libraryFiles.length);
+ for (var file in libraryFiles) {
apiSignature.addBool(file.exists);
apiSignature.addBytes(file.apiSignature);
}
- implSignature.addInt(file.libraryFiles.length);
- for (var file in file.libraryFiles) {
+ implSignature.addInt(libraryFiles.length);
+ for (var file in libraryFiles) {
implSignature.addBool(file.exists);
implSignature.addString(file.contentHash);
}
diff --git a/pkg/analyzer/lib/src/dart/analysis/search.dart b/pkg/analyzer/lib/src/dart/analysis/search.dart
index 5a41567..657f117 100644
--- a/pkg/analyzer/lib/src/dart/analysis/search.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/search.dart
@@ -414,10 +414,13 @@
if (name.startsWith('_')) {
String libraryPath = element.library!.source.fullName;
if (searchedFiles.add(libraryPath, this)) {
- FileState library = _driver.fsState.getFileForPath(libraryPath);
- for (FileState file in library.libraryFiles) {
- if (file.path == path || file.referencedNames.contains(name)) {
- files.add(file.path);
+ final libraryFile = _driver.fsState.getFileForPath(libraryPath);
+ final libraryKind = libraryFile.kind;
+ if (libraryKind is LibraryFileStateKind) {
+ for (final file in libraryKind.files) {
+ if (file.path == path || file.referencedNames.contains(name)) {
+ files.add(file.path);
+ }
}
}
}
@@ -471,26 +474,25 @@
CompilationUnitElement element) async {
String path = element.source.fullName;
- // If the path is not known, then the file is not referenced.
- if (!_driver.fsState.knownFilePaths.contains(path)) {
+ final file = _driver.resourceProvider.getFile(path);
+ final fileState = _driver.fsState.getExisting(file);
+
+ // If the file is not known, then it is not referenced.
+ if (fileState == null) {
return const <SearchResult>[];
}
- // Check every file that references the given path.
+ // Check files that reference the given file.
List<SearchResult> results = <SearchResult>[];
- List<FileState> knownFiles = _driver.fsState.knownFiles.toList();
- for (FileState file in knownFiles) {
- for (FileState referencedFile in file.directReferencedFiles) {
- if (referencedFile.path == path) {
- await _addResultsInFile(
- results,
- element,
- const {
- IndexRelationKind.IS_REFERENCED_BY: SearchResultKind.REFERENCE
- },
- file.path);
- }
- }
+ for (final reference in fileState.referencingFiles) {
+ await _addResultsInFile(
+ results,
+ element,
+ const {
+ IndexRelationKind.IS_REFERENCED_BY: SearchResultKind.REFERENCE,
+ },
+ reference.path,
+ );
}
return results;
}
diff --git a/pkg/analyzer/test/src/dart/analysis/analyzer_state_printer.dart b/pkg/analyzer/test/src/dart/analysis/analyzer_state_printer.dart
index c7eab9b..242801d 100644
--- a/pkg/analyzer/test/src/dart/analysis/analyzer_state_printer.dart
+++ b/pkg/analyzer/test/src/dart/analysis/analyzer_state_printer.dart
@@ -92,13 +92,31 @@
_indent = indent;
}
- /// TODO(scheglov) Support unresolved URIs, not augmentations, etc.
- void _writeAugmentations(LibraryOrAugmentationFileKind kind) {
- final files = kind.file.augmentationFiles.whereNotNull();
- if (files.isNotEmpty) {
- final keys = files.map(idProvider.fileState).join(' ');
- _writelnWithIndent('augmentations: $keys');
- }
+ void _writeAugmentations(LibraryOrAugmentationFileKind container) {
+ _writeElements<ImportAugmentationDirectiveState>(
+ 'augmentations',
+ container.augmentations,
+ (augmentation) {
+ expect(augmentation.container, same(container));
+ if (augmentation is ImportAugmentationDirectiveWithFile) {
+ final file = augmentation.importedFile;
+ sink.write(_indent);
+
+ final importedAugmentation = augmentation.importedAugmentation;
+ if (importedAugmentation != null) {
+ expect(importedAugmentation.file, file);
+ sink.write(idProvider.fileStateKind(importedAugmentation));
+ } else {
+ sink.write('notAugmentation ${idProvider.fileState(file)}');
+ }
+ sink.writeln();
+ } else {
+ sink.write(_indent);
+ sink.write('uri: ${_stringOfUriStr(augmentation.directive.uri)}');
+ sink.writeln();
+ }
+ },
+ );
}
void _writeByteStore() {
@@ -336,16 +354,14 @@
}
}
- // Ask referenced libraries.
+ // Discover referenced files.
// This is required for consistency checking.
- // TODO(scheglov) Remove when we use these for cycles.
for (final fileData in testData.files.values.toList()) {
final current = fileSystemState.getExisting(fileData.file);
if (current != null) {
final kind = current.kind;
if (kind is LibraryOrAugmentationFileKind) {
- kind.imports;
- kind.exports;
+ kind.discoverReferencedFiles();
}
}
}
diff --git a/pkg/analyzer/test/src/dart/analysis/file_state_test.dart b/pkg/analyzer/test/src/dart/analysis/file_state_test.dart
index b121f74..5ac5829 100644
--- a/pkg/analyzer/test/src/dart/analysis/file_state_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/file_state_test.dart
@@ -686,7 +686,8 @@
kind: library_0
imports
library_3 dart:core synthetic
- augmentations: file_1
+ augmentations
+ augmentation_1
cycle_0
dependencies: dart:core
libraries: library_0
@@ -701,7 +702,8 @@
library: library_0
imports
library_3 dart:core synthetic
- augmentations: file_2
+ augmentations
+ augmentation_2
referencingFiles: file_0
unlinkedKey: k01
/home/test/lib/c.dart
@@ -756,7 +758,8 @@
uriFile: file_0
imports
library_3 dart:core synthetic
- augmentations: file_2
+ augmentations
+ augmentation_2
unlinkedKey: k01
/home/test/lib/c.dart
uri: package:test/c.dart
@@ -799,7 +802,8 @@
kind: library_0
imports
library_3 dart:core synthetic
- augmentations: file_1
+ augmentations
+ augmentation_1
cycle_0
dependencies: dart:core
libraries: library_0
@@ -853,7 +857,8 @@
kind: library_0
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ notAugmentation file_1
cycle_0
dependencies: dart:core
libraries: library_0
@@ -867,7 +872,8 @@
augmented: augmentation_1
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ augmentation_1
referencingFiles: file_0 file_1
unlinkedKey: k01
libraryCycles
@@ -901,7 +907,8 @@
kind: library_0
imports
library_3 dart:core synthetic
- augmentations: file_1
+ augmentations
+ augmentation_1
cycle_0
dependencies: dart:core
libraries: library_0
@@ -916,7 +923,8 @@
library: library_0
imports
library_3 dart:core synthetic
- augmentations: file_2
+ augmentations
+ augmentation_2
referencingFiles: file_0 file_2
unlinkedKey: k01
/home/test/lib/c.dart
@@ -928,7 +936,8 @@
library: library_0
imports
library_3 dart:core synthetic
- augmentations: file_1
+ augmentations
+ notAugmentation file_1
referencingFiles: file_1
unlinkedKey: k02
libraryCycles
@@ -936,7 +945,7 @@
''');
}
- test_newFile_augmentation_invalid() async {
+ test_newFile_augmentation_invalidRelativeUri() async {
final a = newFile('$testPackageLibPath/a.dart', r'''
library augment 'da:';
''');
@@ -978,7 +987,8 @@
kind: library_0
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ augmentation_1
cycle_0
dependencies: dart:core
libraries: library_0
@@ -1130,7 +1140,8 @@
kind: library_0
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ augmentation_1
cycle_0
dependencies: dart:core
libraries: library_0
@@ -1162,7 +1173,8 @@
kind: library_0
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ augmentation_1
cycle_0
dependencies: dart:core
libraries: library_0
@@ -1175,7 +1187,8 @@
kind: library_7
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ notAugmentation file_1
cycle_2
dependencies: dart:core
libraries: library_7
@@ -1207,7 +1220,8 @@
kind: library_0
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ augmentation_1
cycle_0
dependencies: dart:core
libraries: library_0
@@ -1220,7 +1234,8 @@
kind: library_8
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ notAugmentation file_1
cycle_3
dependencies: dart:core
libraries: library_8
@@ -1266,7 +1281,8 @@
kind: library_8
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ notAugmentation file_1
cycle_3
dependencies: dart:core
libraries: library_8
@@ -1354,7 +1370,8 @@
kind: library_11
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ notAugmentation file_1
cycle_6
dependencies: dart:core
libraries: library_11
@@ -1388,7 +1405,8 @@
kind: library_12
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ augmentation_1
cycle_7
dependencies: dart:core
libraries: library_12
@@ -1401,7 +1419,8 @@
kind: library_11
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ notAugmentation file_1
cycle_6
dependencies: dart:core
libraries: library_11
@@ -1451,6 +1470,62 @@
''');
}
+ test_newFile_library_augmentations_invalidRelativeUri() async {
+ final a = newFile('$testPackageLibPath/a.dart', r'''
+import augment 'da:';
+''');
+
+ fileStateFor(a);
+
+ assertDriverStateString(testFile, r'''
+files
+ /home/test/lib/a.dart
+ uri: package:test/a.dart
+ current
+ id: file_0
+ kind: library_0
+ imports
+ library_1 dart:core synthetic
+ augmentations
+ uri: da:
+ cycle_0
+ dependencies: dart:core
+ libraries: library_0
+ apiSignature_0
+ unlinkedKey: k00
+libraryCycles
+elementFactory
+''');
+ }
+
+ test_newFile_library_augmentations_invalidRelativeUri_empty() {
+ final a = newFile('$testPackageLibPath/a.dart', r'''
+import augment '';
+''');
+
+ fileStateFor(a);
+
+ assertDriverStateString(testFile, r'''
+files
+ /home/test/lib/a.dart
+ uri: package:test/a.dart
+ current
+ id: file_0
+ kind: library_0
+ imports
+ library_1 dart:core synthetic
+ augmentations
+ uri: ''
+ cycle_0
+ dependencies: dart:core
+ libraries: library_0
+ apiSignature_0
+ unlinkedKey: k00
+libraryCycles
+elementFactory
+''');
+ }
+
test_newFile_library_dartCore() async {
final core = fsStateFor(testFile).getFileForUri(
Uri.parse('dart:core'),
@@ -3900,7 +3975,8 @@
kind: library_0
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ augmentation_1
cycle_0
dependencies: dart:core
libraries: library_0
@@ -3927,6 +4003,7 @@
// Not an augmentation anymore, but a library.
// But `a.dart` still uses `b.dart` as an augmentation.
+ // TODO(scheglov) Any `augmentation_to_X` should change the signature.
assertDriverStateString(testFile, r'''
files
/home/test/lib/a.dart
@@ -3936,7 +4013,8 @@
kind: library_0
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ notAugmentation file_1
cycle_0
dependencies: dart:core
libraries: library_0
@@ -3970,7 +4048,8 @@
kind: library_8
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ notAugmentation file_1
cycle_3
dependencies: dart:core
libraries: library_8
@@ -4016,7 +4095,8 @@
name: my.lib
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ augmentation_1
cycle_0
dependencies: dart:core
libraries: library_0
@@ -4059,7 +4139,8 @@
name: my.lib
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ notAugmentation file_1
cycle_0
dependencies: dart:core
libraries: library_0
@@ -4090,7 +4171,8 @@
name: my.lib
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ notAugmentation file_1
cycle_2
dependencies: dart:core
libraries: library_8
@@ -4167,7 +4249,8 @@
kind: library_0
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ augmentation_1
cycle_0
dependencies: dart:core
libraries: library_0
@@ -4206,7 +4289,8 @@
kind: library_0
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ notAugmentation file_1
cycle_0
dependencies: dart:core
libraries: library_0
@@ -4235,7 +4319,8 @@
kind: library_8
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ notAugmentation file_1
cycle_2
dependencies: dart:core
libraries: library_8
@@ -4511,7 +4596,8 @@
kind: library_0
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ notAugmentation file_1
cycle_0
dependencies: dart:core
libraries: library_0
@@ -4551,7 +4637,8 @@
kind: library_0
imports
library_2 dart:core synthetic
- augmentations: file_1
+ augmentations
+ augmentation_7
cycle_0
dependencies: dart:core
libraries: library_0
diff --git a/pkg/analyzer_cli/lib/src/driver.dart b/pkg/analyzer_cli/lib/src/driver.dart
index be1bca1..56b1585 100644
--- a/pkg/analyzer_cli/lib/src/driver.dart
+++ b/pkg/analyzer_cli/lib/src/driver.dart
@@ -342,7 +342,7 @@
if (kind is LibraryFileStateKind) {
var status = await _runAnalyzer(file, options, formatter);
allResult = allResult.max(status);
- analyzedFiles.addAll(file.libraryFiles);
+ analyzedFiles.addAll(kind.files);
} else if (kind is PartFileStateKind) {
partFiles.add(file);
}
diff --git a/pkg/compiler/lib/src/deferred_load/algorithm_state.dart b/pkg/compiler/lib/src/deferred_load/algorithm_state.dart
index 34c13c4..b5d7726 100644
--- a/pkg/compiler/lib/src/deferred_load/algorithm_state.dart
+++ b/pkg/compiler/lib/src/deferred_load/algorithm_state.dart
@@ -50,7 +50,7 @@
/// update later if we cannot. For more detail on [oldSet] and [newSet],
/// please see the comment in deferred_load.dart.
void update(EntityData entityData, ImportSet oldSet, ImportSet newSet) {
- ImportSet currentSet = entityToSet[entityData];
+ ImportSet currentSet = entityToSet[entityData] ?? importSets.emptySet;
// If [currentSet] == [newSet], then currentSet must include all of newSet.
if (currentSet == newSet) return;
@@ -67,11 +67,11 @@
if (currentSet == oldSet) {
// Continue recursively updating from [oldSet] to [newSet].
entityToSet[entityData] = newSet;
- updateDependencies(entityData, oldSet, newSet);
+ _updateDependencies(entityData, oldSet, newSet);
} else if (entityData.needsRecursiveUpdate) {
assert(
// Invariant: we must mark main before we mark any deferred import.
- newSet != importSets.mainSet || oldSet != null,
+ newSet != importSets.mainSet || oldSet != importSets.emptySet,
failedAt(
NO_LOCATION_SPANNABLE,
"Tried to assign to the main output unit, but it was assigned "
@@ -106,7 +106,7 @@
/// Updates the dependencies of a given [EntityData] from [oldSet] to
/// [newSet].
- void updateDependencies(
+ void _updateDependencies(
EntityData entityData, ImportSet oldSet, ImportSet newSet) {
assert(directDependencies.containsKey(entityData));
var directDependenciesList = directDependencies[entityData];
diff --git a/pkg/compiler/lib/src/deferred_load/import_set.dart b/pkg/compiler/lib/src/deferred_load/import_set.dart
index eaf268e..fc5f0ee 100644
--- a/pkg/compiler/lib/src/deferred_load/import_set.dart
+++ b/pkg/compiler/lib/src/deferred_load/import_set.dart
@@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-// @dart = 2.10
-
import 'output_unit.dart';
import 'program_split_constraints/builder.dart' as psc show SetTransition;
@@ -61,12 +59,12 @@
final Map<ImportEntity, _DeferredImport> _importIndex = {};
/// The canonical instance representing the empty import set.
- final ImportSet _emptySet = ImportSet.empty();
+ final ImportSet emptySet = _EmptyImportSet();
/// The [ImportSet] representing the main output unit.
- ImportSet _mainSet;
+ late ImportSet _mainSet;
ImportSet get mainSet {
- assert(_mainSet != null && _mainSet.unit != null);
+ assert(_mainSet.unit != null);
return _mainSet;
}
@@ -81,14 +79,14 @@
/// [ImportEntity].
ImportSet _singleton(ImportEntity import) {
// Ensure we have import in the index.
- return _emptySet._add(_wrap(import));
+ return emptySet._add(_wrap(import));
}
/// A helper method to convert a [Set<ImportEntity>] to an [ImportSet].
ImportSet setOfImportsToImportSet(Set<ImportEntity> setOfImports) {
List<_DeferredImport> imports = setOfImports.map(_wrap).toList();
imports.sort((a, b) => a.index - b.index);
- var result = _emptySet;
+ var result = emptySet;
for (var import in imports) {
result = result._add(import);
}
@@ -124,8 +122,8 @@
/// Get the import set that includes the union of [a] and [b].
ImportSet union(ImportSet a, ImportSet b) {
- if (a == null || a.isEmpty) return b;
- if (b == null || b.isEmpty) return a;
+ if (a is _EmptyImportSet) return b;
+ if (b is _EmptyImportSet) return a;
// Create the union by merging the imports in canonical order. The sets are
// basically lists linked by the `_previous` field in reverse order. We do a
@@ -137,11 +135,11 @@
List<_DeferredImport> imports = [];
while (true) {
- if (a.isEmpty) {
+ if (a is! _NonEmptyImportSet) {
result = b;
break;
}
- if (b.isEmpty || identical(a, b)) {
+ if (b is! _NonEmptyImportSet || identical(a, b)) {
result = a;
break;
}
@@ -181,7 +179,7 @@
// Try and apply any [ImportSetTransition]s that have not yet been
// applied to this [ImportSet].
- var candidateTransitions = allCandidateTransitions[originalImportSet];
+ var candidateTransitions = allCandidateTransitions[originalImportSet]!;
for (var transition in candidateTransitions) {
if (originalImportSet.containsAll(transition.source)) {
importSet = union(importSet, transition.transitions);
@@ -221,25 +219,20 @@
}
/// A canonical set of deferred imports.
-class ImportSet {
- /// Last element added to set.
- ///
- /// This set comprises [_import] appended onto [_previous]. *Note*: [_import]
- /// is the last element in the set in the canonical order imposed by
- /// [ImportSetLattice].
- final _DeferredImport _import; // `null` for empty ImportSet
- /// The set containing all previous elements.
- final ImportSet _previous;
- final int length;
+abstract class ImportSet {
+ /// Links to other import sets in the lattice by adding one import.
+ final Map<_DeferredImport, _NonEmptyImportSet> _transitions = Maplet();
- bool get isEmpty => _import == null;
- bool get isNotEmpty => _import != null;
+ /// The output unit corresponding to this set of imports, if any.
+ OutputUnit? unit;
+
+ int get length;
/// Returns an iterable over the imports in this set in canonical order.
Iterable<_DeferredImport> collectImports() {
List<_DeferredImport> result = [];
ImportSet current = this;
- while (current.isNotEmpty) {
+ while (current is _NonEmptyImportSet) {
result.add(current._import);
current = current._previous;
}
@@ -247,25 +240,12 @@
return result.reversed;
}
- /// Links to other import sets in the lattice by adding one import.
- final Map<_DeferredImport, ImportSet> _transitions = Maplet();
-
- ImportSet.empty()
- : _import = null,
- _previous = null,
- length = 0;
-
- ImportSet(this._import, this._previous, this.length);
-
- /// The output unit corresponding to this set of imports, if any.
- OutputUnit unit;
-
/// Returns true if this [ImportSet] contains all of [other].
bool containsAll(ImportSet other) {
var current = this;
while (true) {
- if (other.isEmpty) return true;
- if (current.isEmpty) return false;
+ if (other is! _NonEmptyImportSet) return true;
+ if (current is! _NonEmptyImportSet) return false;
if (current._import.index > other._import.index) {
current = current._previous;
@@ -284,8 +264,10 @@
/// this current set. This should only be called from [ImportSetLattice],
/// since it is where we preserve this invariant.
ImportSet _add(_DeferredImport import) {
- assert(_import == null || import.index > _import.index);
- return _transitions[import] ??= ImportSet(import, this, length + 1);
+ var self = this;
+ assert(self is! _NonEmptyImportSet || import.index > self._import.index);
+ return _transitions[import] ??=
+ _NonEmptyImportSet(import, this, length + 1);
}
@override
@@ -304,3 +286,25 @@
Set<ImportEntity> toSet() =>
collectImports().map((i) => i.declaration).toSet();
}
+
+class _NonEmptyImportSet extends ImportSet {
+ /// Last element added to set.
+ ///
+ /// This set comprises [_import] appended onto [_previous]. *Note*: [_import]
+ /// is the last element in the set in the canonical order imposed by
+ /// [ImportSetLattice].
+ final _DeferredImport _import; // `null` for empty ImportSet
+
+ /// The set containing all previous elements.
+ final ImportSet _previous;
+
+ @override
+ final int length;
+
+ _NonEmptyImportSet(this._import, this._previous, this.length);
+}
+
+class _EmptyImportSet extends ImportSet {
+ @override
+ int get length => 0;
+}
diff --git a/pkg/compiler/lib/src/deferred_load/work_queue.dart b/pkg/compiler/lib/src/deferred_load/work_queue.dart
index 072ff66..f75174b 100644
--- a/pkg/compiler/lib/src/deferred_load/work_queue.dart
+++ b/pkg/compiler/lib/src/deferred_load/work_queue.dart
@@ -67,7 +67,7 @@
var entityData = item.entityData;
pendingWorkItems.remove(entityData);
state.processEntity(entityData);
- ImportSet oldSet = state.entityToSet[entityData];
+ ImportSet oldSet = state.entityToSet[entityData] ?? _importSets.emptySet;
ImportSet newSet = _importSets.union(oldSet, item.importsToAdd);
state.update(entityData, oldSet, newSet);
}
diff --git a/runtime/tests/concurrency/stress_test_list.json b/runtime/tests/concurrency/stress_test_list.json
index c40bb0d..f0310dc 100644
--- a/runtime/tests/concurrency/stress_test_list.json
+++ b/runtime/tests/concurrency/stress_test_list.json
@@ -3315,7 +3315,6 @@
"../../../tests/standalone/io/many_file_operations_test.dart",
"../../../tests/standalone/io/named_pipe_script_test.dart",
"../../../tests/standalone/io/network_interface_test.dart",
- "../../../tests/standalone/io/network_policy_test.dart",
"../../../tests/standalone/io/parent_test.dart",
"../../../tests/standalone/io/platform_os_version_test.dart",
"../../../tests/standalone/io/process_exit_test.dart",
@@ -6637,7 +6636,6 @@
"../../../tests/standalone_2/io/many_directory_operations_test.dart",
"../../../tests/standalone_2/io/many_file_operations_test.dart",
"../../../tests/standalone_2/io/network_interface_test.dart",
- "../../../tests/standalone_2/io/network_policy_test.dart",
"../../../tests/standalone_2/io/parent_test.dart",
"../../../tests/standalone_2/io/platform_os_version_test.dart",
"../../../tests/standalone_2/io/process_exit_test.dart",
diff --git a/sdk/lib/io/embedder_config.dart b/sdk/lib/io/embedder_config.dart
index 9b934a6..bcb4a01 100644
--- a/sdk/lib/io/embedder_config.dart
+++ b/sdk/lib/io/embedder_config.dart
@@ -36,24 +36,6 @@
@pragma('vm:entry-point')
static bool _maySleep = true;
- /// Whether the isolate may establish insecure socket connections
- /// to all domains.
- ///
- /// This setting can be overridden by per-domain policies.
- @Deprecated(
- "To be re-implemented in https://github.com/flutter/flutter/issues/54448")
- @pragma('vm:entry-point')
- static bool _mayInsecurelyConnectToAllDomains = true;
-
- /// Domain network policies set by embedder.
- @Deprecated(
- "To be re-implemented in https://github.com/flutter/flutter/issues/54448")
- @pragma('vm:entry-point')
- static void _setDomainPolicies(String domainNetworkPolicyJson) {
- // Doesn't do anything because the implementation has been reverted in
- // https://github.com/flutter/flutter/issues/72723.
- }
-
// TODO(zra): Consider adding:
// - an option to disallow modifying SecurityContext.defaultContext
// - an option to disallow closing stdout and stderr.
diff --git a/sdk/lib/io/io.dart b/sdk/lib/io/io.dart
index dbecc26..014acd4 100644
--- a/sdk/lib/io/io.dart
+++ b/sdk/lib/io/io.dart
@@ -220,7 +220,6 @@
part 'io_service.dart';
part 'link.dart';
part 'namespace_impl.dart';
-part 'network_policy.dart';
part 'network_profiling.dart';
part 'overrides.dart';
part 'platform.dart';
diff --git a/sdk/lib/io/io_sources.gni b/sdk/lib/io/io_sources.gni
index fb148df..7410a13 100644
--- a/sdk/lib/io/io_sources.gni
+++ b/sdk/lib/io/io_sources.gni
@@ -20,7 +20,6 @@
"io_sink.dart",
"link.dart",
"namespace_impl.dart",
- "network_policy.dart",
"network_profiling.dart",
"overrides.dart",
"platform.dart",
diff --git a/sdk/lib/io/network_policy.dart b/sdk/lib/io/network_policy.dart
deleted file mode 100644
index ef00ffc..0000000
--- a/sdk/lib/io/network_policy.dart
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-part of dart.io;
-
-/// Whether insecure connections to [host] are allowed.
-///
-/// This API is deprecated and always returns true. See
-/// https://github.com/flutter/flutter/issues/72723 for more details.
-///
-/// [host] must be a [String] or [InternetAddress].
-///
-/// If any of the domain policies match [host], the matching policy will make
-/// the decision. If multiple policies apply, the top matching policy makes the
-/// decision. If none of the domain policies match, the embedder default is
-/// used.
-///
-/// Loopback addresses are always allowed.
-@Deprecated("See https://github.com/flutter/flutter/issues/54448 for followup")
-bool isInsecureConnectionAllowed(dynamic host) {
- return true;
-}
diff --git a/tests/standalone/io/network_policy_test.dart b/tests/standalone/io/network_policy_test.dart
deleted file mode 100644
index 2f9878d..0000000
--- a/tests/standalone/io/network_policy_test.dart
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-import 'dart:io';
-
-import "package:expect/expect.dart";
-
-void _checkAllows(List<String> domains) {
- for (final domain in domains) {
- Expect.isTrue(
- isInsecureConnectionAllowed(domain), "$domain should be allowed.");
- }
-}
-
-void main() {
- // All domains and addresses are allowed.
- _checkAllows([
- "mailfoobar.com",
- "abc.com",
- "oobar.com",
- "foobar.co",
- "128.221.55.31",
- "fe80::4607:0bff:fea0:7747%invalid",
- "baz.foobar.com",
- "foobar.com",
- "test.baz.foobar.com",
- "test2.test.baz.foobar.com",
- "::1",
- "localhost",
- ]);
-}
diff --git a/tests/standalone_2/io/network_policy_test.dart b/tests/standalone_2/io/network_policy_test.dart
deleted file mode 100644
index 108f1d4..0000000
--- a/tests/standalone_2/io/network_policy_test.dart
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-// @dart = 2.9
-
-import 'dart:io';
-
-import "package:expect/expect.dart";
-
-void _checkAllows(List<String> domains) {
- for (final domain in domains) {
- Expect.isTrue(
- isInsecureConnectionAllowed(domain), "$domain should be allowed.");
- }
-}
-
-void main() {
- // All domains and addresses are allowed.
- _checkAllows([
- "mailfoobar.com",
- "abc.com",
- "oobar.com",
- "foobar.co",
- "128.221.55.31",
- "fe80::4607:0bff:fea0:7747%invalid",
- "baz.foobar.com",
- "foobar.com",
- "test.baz.foobar.com",
- "test2.test.baz.foobar.com",
- "::1",
- "localhost",
- ]);
-}
diff --git a/tools/VERSION b/tools/VERSION
index f2683d3..4195349 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
MAJOR 2
MINOR 18
PATCH 0
-PRERELEASE 237
+PRERELEASE 238
PRERELEASE_PATCH 0
\ No newline at end of file