Skip to content

Commit

Permalink
Version 3.6.0-71.0.dev
Browse files Browse the repository at this point in the history
Merge 12ec42e into dev
  • Loading branch information
Dart CI committed Jul 23, 2024
2 parents b937619 + 12ec42e commit 7beae00
Show file tree
Hide file tree
Showing 14 changed files with 1,147 additions and 107 deletions.
14 changes: 14 additions & 0 deletions pkg/analyzer/lib/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,26 @@ abstract class CompilationUnitElement implements UriReferencedElement {
/// The top-level functions declared in this compilation unit.
List<FunctionElement> get functions;

/// The libraries exported by this unit.
List<LibraryExportElement> get libraryExports;

/// The prefixes used by [libraryImports].
///
/// Each prefix can be used in more than one `import` directive.
List<PrefixElement> get libraryImportPrefixes;

/// The libraries imported by this unit.
List<LibraryImportElement> get libraryImports;

/// The [LineInfo] for the [source].
LineInfo get lineInfo;

/// The mixins declared in this compilation unit.
List<MixinElement> get mixins;

/// The parts included by this unit.
List<PartElement> get parts;

@override
AnalysisSession get session;

Expand Down
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 @@ -96,7 +96,7 @@ import 'package:meta/meta.dart';
// TODO(scheglov): Clean up the list of implicitly analyzed files.
class AnalysisDriver {
/// The version of data format, should be incremented on every format change.
static const int DATA_VERSION = 372;
static const int DATA_VERSION = 373;

/// The number of exception contexts allowed to write. Once this field is
/// zero, we stop writing any new exception contexts in this process.
Expand Down
79 changes: 79 additions & 0 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,20 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl
@override
final Source librarySource;

/// The libraries exported by this unit.
List<LibraryExportElementImpl> _libraryExports =
_Sentinel.libraryExportElement;

/// The libraries imported by this unit.
List<LibraryImportElementImpl> _libraryImports =
_Sentinel.libraryImportElement;

/// The cached list of prefixes from [libraryImports].
List<PrefixElementImpl>? _libraryImportPrefixes;

/// The parts included by this unit.
List<PartElementImpl> _parts = const <PartElementImpl>[];

/// A list containing all of the top-level accessors (getters and setters)
/// contained in this compilation unit.
List<PropertyAccessorElementImpl> _accessors = const [];
Expand Down Expand Up @@ -883,6 +897,46 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl
@override
ElementKind get kind => ElementKind.COMPILATION_UNIT;

@override
List<LibraryExportElementImpl> get libraryExports {
linkedData?.read(this);
return _libraryExports;
}

set libraryExports(List<LibraryExportElementImpl> exports) {
for (var exportElement in exports) {
exportElement.enclosingElement = this;
}
_libraryExports = exports;
}

List<LibraryExportElementImpl> get libraryExports_unresolved {
return _libraryExports;
}

@override
List<PrefixElementImpl> get libraryImportPrefixes {
return _libraryImportPrefixes ??= _buildPrefixesFromImports();
}

@override
List<LibraryImportElementImpl> get libraryImports {
linkedData?.read(this);
return _libraryImports;
}

set libraryImports(List<LibraryImportElementImpl> imports) {
for (var importElement in imports) {
importElement.enclosingElement = this;
}
_libraryImports = imports;
_libraryImportPrefixes = null;
}

List<LibraryImportElementImpl> get libraryImports_unresolved {
return _libraryImports;
}

@override
List<ElementAnnotationImpl> get metadata {
linkedData?.read(this);
Expand All @@ -902,6 +956,20 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl
_mixins = mixins;
}

@override
List<PartElementImpl> get parts => _parts;

set parts(List<PartElementImpl> parts) {
for (var part in parts) {
part.enclosingElement = this;
var uri = part.uri;
if (uri is DirectiveUriWithUnitImpl) {
uri.unit.enclosingElement = this;
}
}
_parts = parts;
}

@override
AnalysisSession get session => enclosingElement.session;

Expand Down Expand Up @@ -983,6 +1051,17 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl

this.linkedData = linkedData;
}

List<PrefixElementImpl> _buildPrefixesFromImports() {
var prefixes = <PrefixElementImpl>{};
for (var import in libraryImports) {
var prefix = import.prefix?.element;
if (prefix != null) {
prefixes.add(prefix);
}
}
return prefixes.toFixedList();
}
}

/// A [FieldElement] for a 'const' or 'final' field that has an initializer.
Expand Down
50 changes: 43 additions & 7 deletions pkg/analyzer/lib/src/summary2/bundle_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ class ClassElementLinkedData extends ElementLinkedData<ClassElementImpl> {

class CompilationUnitElementLinkedData
extends ElementLinkedData<CompilationUnitElementImpl> {
ApplyConstantOffsets? applyConstantOffsets;

CompilationUnitElementLinkedData({
required Reference reference,
required LibraryReader libraryReader,
Expand All @@ -185,7 +187,29 @@ class CompilationUnitElementLinkedData
}

@override
void _read(element, reader) {}
void _read(element, reader) {
for (var import in element.libraryImports) {
import.metadata = reader._readAnnotationList(
unitElement: unitElement,
);
var uri = import.uri;
if (uri is DirectiveUriWithLibraryImpl) {
uri.library = reader.libraryOfUri(uri.source.uri);
}
}

for (var export in element.libraryExports) {
export.metadata = reader._readAnnotationList(
unitElement: unitElement,
);
var uri = export.uri;
if (uri is DirectiveUriWithLibraryImpl) {
uri.library = reader.libraryOfUri(uri.source.uri);
}
}

applyConstantOffsets?.perform();
}
}

class ConstructorElementLinkedData
Expand Down Expand Up @@ -912,7 +936,7 @@ class LibraryReader {
}

DirectiveUri _readDirectiveUri({
required LibraryOrAugmentationElementImpl container,
required ElementImpl container,
}) {
DirectiveUriWithRelativeUriStringImpl readWithRelativeUriString() {
var relativeUriString = _reader.readStringReference();
Expand Down Expand Up @@ -956,7 +980,7 @@ class LibraryReader {
case DirectiveUriKind.withAugmentation:
var parent = readWithSource();
var augmentation = _readAugmentationElement(
augmentationTarget: container,
augmentationTarget: container as LibraryOrAugmentationElementImpl,
unitSource: parent.source,
);
return DirectiveUriWithAugmentationImpl(
Expand All @@ -975,7 +999,7 @@ class LibraryReader {
case DirectiveUriKind.withUnit:
var parent = readWithSource();
var unitElement = _readUnitElement(
containerSource: container.source,
containerSource: container.source!,
unitSource: parent.source,
unitContainerRef: _reference.getChild('@unit'),
);
Expand Down Expand Up @@ -1061,7 +1085,7 @@ class LibraryReader {
}

LibraryExportElementImpl _readExportElement({
required LibraryOrAugmentationElementImpl container,
required ElementImpl container,
}) {
return LibraryExportElementImpl(
combinators: _reader.readTypedList(_readNamespaceCombinator),
Expand Down Expand Up @@ -1273,7 +1297,7 @@ class LibraryReader {
}

LibraryImportElementImpl _readImportElement({
required LibraryOrAugmentationElementImpl container,
required ElementImpl container,
}) {
var element = LibraryImportElementImpl(
combinators: _reader.readTypedList(_readNamespaceCombinator),
Expand All @@ -1290,7 +1314,7 @@ class LibraryReader {
}

ImportElementPrefixImpl? _readImportElementPrefix({
required LibraryOrAugmentationElementImpl container,
required ElementImpl container,
}) {
PrefixElementImpl buildElement(String name) {
// TODO(scheglov): Make reference required.
Expand Down Expand Up @@ -1819,6 +1843,18 @@ class LibraryReader {
unitElement.uri = _reader.readOptionalStringReference();
unitElement.isSynthetic = _reader.readBool();

unitElement.libraryImports = _reader.readTypedList(() {
return _readImportElement(
container: unitElement,
);
});

unitElement.libraryExports = _reader.readTypedList(() {
return _readExportElement(
container: unitElement,
);
});

_readClasses(unitElement, unitReference);
_readEnums(unitElement, unitReference);
_readExtensions(unitElement, unitReference);
Expand Down
4 changes: 4 additions & 0 deletions pkg/analyzer/lib/src/summary2/bundle_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,10 @@ class BundleWriter {

_sink._writeOptionalStringReference(unitElement.uri);
_sink.writeBool(unitElement.isSynthetic);

_writeList(unitElement.libraryImports, _writeImportElement);
_writeList(unitElement.libraryExports, _writeExportElement);

_writeList(unitElement.classes, _writeClassElement);
_writeList(unitElement.enums, _writeEnumElement);
_writeList(unitElement.extensions, _writeExtensionElement);
Expand Down
35 changes: 27 additions & 8 deletions pkg/analyzer/lib/src/summary2/informative_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ class InformativeDataApplier {
unitElement.setCodeRange(unitInfo.codeOffset, unitInfo.codeLength);
unitElement.lineInfo = LineInfo(unitInfo.lineStarts);

_applyToImports(unitElement.libraryImports_unresolved, unitInfo);
_applyToExports(unitElement.libraryExports_unresolved, unitInfo);

var applyOffsets = ApplyConstantOffsets(
unitInfo.libraryConstantOffsets,
(applier) {
applier.applyToMetadata(unitElement);
applier.applyToImports(unitElement.libraryImports);
applier.applyToExports(unitElement.libraryExports);
},
);

_applyToAccessors(unitElement.accessors, unitInfo.accessors);

forCorrespondingPairs(
Expand Down Expand Up @@ -157,6 +169,13 @@ class InformativeDataApplier {
unitInfo.genericTypeAliases,
_applyToGenericTypeAlias,
);

var linkedData = unitElement.linkedData;
if (linkedData is CompilationUnitElementLinkedData) {
linkedData.applyConstantOffsets = applyOffsets;
} else {
applyOffsets.perform();
}
}

void _applyToAccessors(
Expand Down Expand Up @@ -203,8 +222,8 @@ class InformativeDataApplier {
element.documentationComment = info.docComment;
}

_applyToImports(element, info);
_applyToExports(element, info);
_applyToImports(element.imports_unresolved, info);
_applyToExports(element.exports_unresolved, info);

var applyOffsets = ApplyConstantOffsets(
info.libraryConstantOffsets,
Expand Down Expand Up @@ -385,11 +404,11 @@ class InformativeDataApplier {
}

void _applyToExports(
LibraryOrAugmentationElementImpl element,
List<LibraryExportElementImpl> exports,
_InfoUnit info,
) {
forCorrespondingPairs<LibraryExportElement, _InfoExport>(
element.exports_unresolved,
exports,
info.exports,
(element, info) {
element as LibraryExportElementImpl;
Expand Down Expand Up @@ -637,11 +656,11 @@ class InformativeDataApplier {
}

void _applyToImports(
LibraryOrAugmentationElementImpl element,
List<LibraryImportElementImpl> imports,
_InfoUnit info,
) {
forCorrespondingPairs<LibraryImportElement, _InfoImport>(
element.imports_unresolved,
imports,
info.imports,
(element, info) {
element as LibraryImportElementImpl;
Expand All @@ -665,8 +684,8 @@ class InformativeDataApplier {
element.documentationComment = info.docComment;
}

_applyToImports(element, info);
_applyToExports(element, info);
_applyToImports(element.imports_unresolved, info);
_applyToExports(element.exports_unresolved, info);

forCorrespondingPairs<PartElement, _InfoPart>(
element.parts,
Expand Down
8 changes: 6 additions & 2 deletions pkg/analyzer/lib/src/summary2/library_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1065,16 +1065,20 @@ class LibraryBuilder with MacroApplicationsContainer {
required LibraryOrAugmentationFileKind kind,
required LibraryOrAugmentationElementImpl container,
}) {
container.libraryExports = kind.libraryExports.map((state) {
var definingUnit = container.definingCompilationUnit;

definingUnit.libraryExports = kind.libraryExports.map((state) {
return _buildExport(state);
}).toFixedList();
container.libraryExports = definingUnit.libraryExports;

container.libraryImports = kind.libraryImports.map((state) {
definingUnit.libraryImports = kind.libraryImports.map((state) {
return _buildImport(
container: container,
state: state,
);
}).toFixedList();
container.libraryImports = definingUnit.libraryImports;

container.augmentationImports = kind.augmentationImports.map((state) {
return _buildAugmentationImport(
Expand Down
10 changes: 10 additions & 0 deletions pkg/analyzer/test/src/summary/element_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,16 @@ class _ElementWriter {

void _writeUnitElement(CompilationUnitElementImpl e) {
_writeReference(e);

if (configuration.withImports) {
var imports = e.libraryImports.where((import) {
return configuration.withSyntheticDartCoreImport || !import.isSynthetic;
}).toList();
_writeElements('libraryImports', imports, _writeImportElement);
}
_writeElements('libraryExports', e.libraryExports, _writeExportElement);
_writeElements('partIncludes', e.parts, _writePartElement);

_writeElements('classes', e.classes, _writeInterfaceElement);
_writeElements('enums', e.enums, _writeInterfaceElement);
_writeElements('extensions', e.extensions, _writeExtensionElement);
Expand Down
Loading

0 comments on commit 7beae00

Please sign in to comment.