Skip to content

Commit

Permalink
Macro. More ordering for declarations phase.
Browse files Browse the repository at this point in the history
Change-Id: I01e528a0f077367929e9e631992644b198165d6b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333581
Commit-Queue: Konstantin Shcheglov <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
  • Loading branch information
scheglov authored and Commit Queue committed Nov 2, 2023
1 parent 7a343d0 commit f3cd5c1
Show file tree
Hide file tree
Showing 7 changed files with 1,269 additions and 249 deletions.
97 changes: 52 additions & 45 deletions pkg/analyzer/lib/src/summary2/library_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -350,66 +350,71 @@ class LibraryBuilder {
_declaredReferences[name] = reference;
}

Future<void> executeMacroDeclarationsPhase({
/// Completes with `true` if a macro application was run in this library.
///
/// Completes with `false` if there are no macro applications to run, either
/// because we ran all, or those that we have not run yet have dependencies
/// of interfaces declared in other libraries that, and we have not run yet
/// declarations phase macro applications for them.
Future<bool> executeMacroDeclarationsPhase({
required OperationPerformanceImpl performance,
}) async {
final macroApplier = linker.macroApplier;
if (macroApplier == null) {
return;
return false;
}

while (true) {
final results = await macroApplier.executeDeclarationsPhase(
typeSystem: element.typeSystem,
);
final results = await macroApplier.executeDeclarationsPhase(
library: element,
);

// No more applications to execute.
if (results == null) {
break;
}
// No more applications to execute.
if (results == null) {
return false;
}

// No results from the application.
if (results.isEmpty) {
continue;
}
// No results from the application.
if (results.isEmpty) {
return true;
}

_macroResults.add(results);
_macroResults.add(results);

final augmentationCode = macroApplier.buildAugmentationLibraryCode(
results,
);
if (augmentationCode == null) {
continue;
}
final augmentationCode = macroApplier.buildAugmentationLibraryCode(
results,
);
if (augmentationCode == null) {
return true;
}

final importState = kind.addMacroAugmentation(
augmentationCode,
addLibraryAugmentDirective: true,
partialIndex: _macroResults.length,
);
final importState = kind.addMacroAugmentation(
augmentationCode,
addLibraryAugmentDirective: true,
partialIndex: _macroResults.length,
);

final augmentation = _addMacroAugmentation(importState);
final augmentation = _addMacroAugmentation(importState);

final macroLinkingUnit = units.last;
ElementBuilder(
libraryBuilder: this,
container: macroLinkingUnit.container,
unitReference: macroLinkingUnit.reference,
unitElement: macroLinkingUnit.element,
).buildDeclarationElements(macroLinkingUnit.node);
final macroLinkingUnit = units.last;
ElementBuilder(
libraryBuilder: this,
container: macroLinkingUnit.container,
unitReference: macroLinkingUnit.reference,
unitElement: macroLinkingUnit.element,
).buildDeclarationElements(macroLinkingUnit.node);

final nodesToBuildType = NodesToBuildType();
final resolver =
ReferenceResolver(linker, nodesToBuildType, augmentation);
macroLinkingUnit.node.accept(resolver);
TypesBuilder(linker).build(nodesToBuildType);
final nodesToBuildType = NodesToBuildType();
final resolver = ReferenceResolver(linker, nodesToBuildType, augmentation);
macroLinkingUnit.node.accept(resolver);
TypesBuilder(linker).build(nodesToBuildType);

// Append applications from the partial augmentation.
await macroApplier.add(
container: augmentation,
unit: macroLinkingUnit.node,
);
}
// Append applications from the partial augmentation.
await macroApplier.add(
libraryElement: element,
container: augmentation,
unit: macroLinkingUnit.node,
);
return true;
}

Future<void> executeMacroTypesPhase({
Expand Down Expand Up @@ -460,6 +465,7 @@ class LibraryBuilder {

// Append applications from the partial augmentation.
await macroApplier.add(
libraryElement: element,
container: augmentation,
unit: macroLinkingUnit.node,
);
Expand All @@ -470,6 +476,7 @@ class LibraryBuilder {
Future<void> fillMacroApplier(LibraryMacroApplier macroApplier) async {
for (final linkingUnit in units) {
await macroApplier.add(
libraryElement: element,
container: element,
unit: linkingUnit.node,
);
Expand Down
14 changes: 10 additions & 4 deletions pkg/analyzer/lib/src/summary2/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,16 @@ class Linker {
Future<void> _executeMacroDeclarationsPhase({
required OperationPerformanceImpl performance,
}) async {
for (final library in builders.values) {
await library.executeMacroDeclarationsPhase(
performance: performance,
);
while (true) {
var hasProgress = false;
for (final library in builders.values) {
hasProgress |= await library.executeMacroDeclarationsPhase(
performance: performance,
);
}
if (!hasProgress) {
break;
}
}
}

Expand Down
Loading

0 comments on commit f3cd5c1

Please sign in to comment.