[cfe] Add library dependencies from macros

This updates the processing of macro generated augmentation libraries
to add library dependencies of the augmentation libraries to the
emitted library.

Change-Id: Ibc06a3c309fb3cfc8eb1f02beda637dfd9a3ea62
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/347601
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
Johnni Winther 2024-01-23 13:46:27 +00:00 committed by Commit Queue
parent 694c2911e2
commit 1bd8755035
28 changed files with 149 additions and 39 deletions

View file

@ -2040,8 +2040,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
}
}
debugLibrary.buildOutlineNodes(lastGoodKernelTarget.loader.coreLibrary,
modifyTarget: false);
debugLibrary.buildOutlineNodes(lastGoodKernelTarget.loader.coreLibrary);
Expression compiledExpression = await lastGoodKernelTarget.loader
.buildExpression(
debugLibrary,

View file

@ -371,8 +371,7 @@ class KernelTarget extends TargetImplementation {
loader.finishTypeVariables(
augmentationLibraries, objectClassBuilder, dynamicType);
for (SourceLibraryBuilder augmentationLibrary in augmentationLibraries) {
augmentationLibrary.buildOutlineNodes(loader.coreLibrary,
modifyTarget: false);
augmentationLibrary.buildOutlineNodes(loader.coreLibrary);
}
loader.resolveConstructors(augmentationLibraries);
}

View file

@ -547,12 +547,8 @@ class DietListener extends StackListenerImpl {
if (importUri.startsWith("dart-ext:")) return;
Library libraryNode = libraryBuilder.library;
LibraryDependency? dependency;
if (importExportDirectiveIndex < libraryNode.dependencies.length) {
// TODO(johnniwinther): Include dependencies from macro libraries in
// library dependencies.
dependency = libraryNode.dependencies[importExportDirectiveIndex++];
}
LibraryDependency? dependency =
libraryNode.dependencies[importExportDirectiveIndex++];
parseMetadata(libraryBuilder.bodyBuilderContext, libraryBuilder, metadata,
dependency);
}

View file

@ -1137,8 +1137,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
}
/// Builds the core AST structure of this library as needed for the outline.
Library buildOutlineNodes(LibraryBuilder coreLibrary,
{bool modifyTarget = true}) {
Library buildOutlineNodes(LibraryBuilder coreLibrary) {
// TODO(johnniwinther): Avoid the need to process patch libraries before
// the origin. Currently, settings performed by the patch are overridden
// by the origin. For instance, the `Map` class is abstract in the origin
@ -1148,7 +1147,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
Iterable<SourceLibraryBuilder>? patches = this.patchLibraries;
if (patches != null) {
for (SourceLibraryBuilder patchLibrary in patches) {
patchLibrary.buildOutlineNodes(coreLibrary, modifyTarget: modifyTarget);
patchLibrary.buildOutlineNodes(coreLibrary);
}
}
@ -1161,8 +1160,6 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
_buildOutlineNodes(iterator.current, coreLibrary);
}
if (!modifyTarget) return library;
library.isSynthetic = isSynthetic;
library.isUnsupported = isUnsupported;
addDependencies(library, new Set<SourceLibraryBuilder>());

View file

@ -4,6 +4,9 @@ import "package:macro/cascade.dart" as cas;
import "dart:core" as core;
import "package:macro/cascade.dart";
import "package:macro/cascade.dart" as prefix0;
import "org-dartlang-test:///a/b/c/main.dart" as prefix1;
import "org-dartlang-test:///a/b/c/main.dart" as prefix0;
@#C1
class Class extends core::Object {

View file

@ -4,6 +4,8 @@ import "package:macro/data_class.dart" as dat;
import "dart:core" as core;
import "package:macro/data_class.dart";
import "dart:core" as prefix0;
import "dart:core" as prefix0;
@#C1
class Foo extends core::Object {

View file

@ -57,26 +57,8 @@ static field core::int? topLevelField1;
static final field core::int? topLevelField3 = null;
@#C6
late static field core::int? topLevelField4;
@#C7
static method topLevelFunction1() → void {}
@#C7
external static method topLevelFunction2() → void;
@#C6
external static get topLevelField2() → core::int?;
@#C6
external static set topLevelField2(synthesized core::int? #externalFieldValue) → void;
@#C7
static get topLevelGetter1() → core::int?
return null;
@#C7
static set topLevelSetter1(core::int? value) → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-0 */ Class1_instanceMethod1GeneratedMethod_() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-1 */ Class1_instanceGetter1GeneratedMethod_g() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-2 */ Class1_operatorGeneratedMethod_o() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-3 */ Class1_instanceField1GeneratedMethod_() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-4 */ Class1_instanceField2GeneratedMethod_f() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-5 */ Class1_instanceField3GeneratedMethod_fl() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-6 */ Class1_instanceSetter1GeneratedMethod_s() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-10 */ Class1Introspection() → void {
core::print("constructors='','redirect','fact'");
core::print("fields='instanceField1','instanceField2','instanceField3'");
@ -95,10 +77,28 @@ static method /* from org-dartlang-augmentation:/a/b/c/main.dart-16 */ topLevelF
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-17 */ topLevelFunction2GeneratedMethod_e() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-18 */ topLevelField1GeneratedMethod_() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-19 */ topLevelField2GeneratedMethod_e() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-2 */ Class1_operatorGeneratedMethod_o() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-20 */ topLevelField3GeneratedMethod_f() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-21 */ topLevelField4GeneratedMethod_l() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-22 */ topLevelGetter1GeneratedMethod_g() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-23 */ topLevelSetter1GeneratedMethod_s() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-3 */ Class1_instanceField1GeneratedMethod_() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-4 */ Class1_instanceField2GeneratedMethod_f() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-5 */ Class1_instanceField3GeneratedMethod_fl() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-6 */ Class1_instanceSetter1GeneratedMethod_s() → void {}
@#C7
static method topLevelFunction1() → void {}
@#C7
external static method topLevelFunction2() → void;
@#C6
external static get topLevelField2() → core::int?;
@#C6
external static set topLevelField2(synthesized core::int? #externalFieldValue) → void;
@#C7
static get topLevelGetter1() → core::int?
return null;
@#C7
static set topLevelSetter1(core::int? value) → void {}
constants {
#C1 = mac::ClassDeclarationsMacro1 {}

View file

@ -9,6 +9,10 @@ import "package:macro/macro.dart";
import "dart:async";
import "dart:math";
import "dart:convert";
import "dart:core" as prefix2_0;
import "dart:async" as prefix2_1;
import "dart:math" as prefix2_2;
import "dart:convert" as prefix2_3;
@#C1
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-0 */ function(core::int i, FutureOr<math::Random>f, con::JsonCodec c) → void {

View file

@ -4,6 +4,11 @@ import "dart:core" as core;
import "package:macro/macro.dart" as mac;
import "package:macro/macro.dart";
import "dart:core" as prefix0;
import "dart:core" as prefix0;
import "dart:core" as prefix0;
import "dart:core" as prefix0;
import "dart:core" as prefix0;
abstract class Interface extends core::Object {
synthetic constructor •() → self::Interface

View file

@ -4,6 +4,7 @@ import "package:macro/macro.dart" as mac;
import "dart:core" as core;
import "package:macro/macro.dart";
import "dart:core" as prefix0;
@#C1
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-0 */ topLevelFunction1(core::int a) → void {

View file

@ -4,6 +4,7 @@ import "dart:core" as core;
import "package:macro/macro.dart" as mac;
import "package:macro/macro.dart";
import "org-dartlang-test:///a/b/c/main.dart" as prefix0;
class A extends core::Object {
synthetic constructor •() → self::A
@ -40,6 +41,10 @@ class D2 extends core::Object {
: super core::Object::•()
;
}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-0 */ topLevelFunction1GeneratedMethod_es() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-1 */ topLevelFunction2GeneratedMethod_s() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-2 */ topLevelFunction3GeneratedMethod_() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-3 */ topLevelFunction4GeneratedMethod_() → void {}
@#C1
@#C2
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-4 */ topLevelFunction1(self::A a) → self::A {
@ -68,10 +73,6 @@ static method /* from org-dartlang-augmentation:/a/b/c/main.dart-4 */ topLevelFu
core::print("isSubtype=false");
throw 42;
}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-0 */ topLevelFunction1GeneratedMethod_es() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-1 */ topLevelFunction2GeneratedMethod_s() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-2 */ topLevelFunction3GeneratedMethod_() → void {}
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-3 */ topLevelFunction4GeneratedMethod_() → void {}
constants {
#C1 = mac::FunctionDeclarationsMacro2 {}

View file

@ -4,6 +4,7 @@ import "package:macro/macro.dart" as mac;
import "dart:core" as core;
import "package:macro/macro.dart";
import "dart:core" as prefix0;
@#C1
class A extends core::Object {

View file

@ -6,6 +6,8 @@ import "dart:math" as math;
import "dart:math" as math;
import "package:macro/macro.dart";
import "dart:core" as prefix0;
import "dart:math" as prefix1;
@#C1
static method /* from org-dartlang-augmentation:/a/b/c/main.dart-0 */ topLevelFunction1() → void {

View file

@ -11,7 +11,7 @@ class ToStringMacro implements ClassDeclarationsMacro {
const ToStringMacro();
@override
FutureOr<void> buildDeclarationsForClass(IntrospectableClassDeclaration clazz,
FutureOr<void> buildDeclarationsForClass(ClassDeclaration clazz,
MemberDeclarationBuilder builder) async {
Iterable<MethodDeclaration> methods = await builder.methodsOf(clazz);
if (!methods.any((m) => m.identifier.name == 'toString')) {
@ -44,7 +44,7 @@ class InjectMacro implements ClassDeclarationsMacro {
const InjectMacro();
@override
FutureOr<void> buildDeclarationsForClass(IntrospectableClassDeclaration clazz,
FutureOr<void> buildDeclarationsForClass(ClassDeclaration clazz,
MemberDeclarationBuilder builder) async {
Iterable<MethodDeclaration> methods = await builder.methodsOf(clazz);
if (!methods.any((m) => m.identifier.name == 'injectedMethod')) {

View file

@ -4,6 +4,7 @@ import "package:macro/macro.dart" as mac;
import "dart:core" as core;
import "package:macro/macro.dart";
import "dart:core" as prefix0;
@#C1
class DataClass extends core::Object {

View file

@ -4,6 +4,7 @@ import "package:macro/macro.dart" as mac;
import "dart:core" as core;
import "package:macro/macro.dart";
import "dart:core" as prefix0;
@#C1
class DataClass extends core::Object {

View file

@ -4,6 +4,7 @@ import "package:macro/macro.dart" as mac;
import "dart:core" as core;
import "package:macro/macro.dart";
import "dart:core" as prefix0;
@#C1
class Class extends core::Object {

View file

@ -4,6 +4,7 @@ import "package:macro/macro.dart" as mac;
import "dart:core" as core;
import "package:macro/macro.dart";
import "dart:core" as prefix0;
@#C1
class Class extends core::Object {

View file

@ -116,6 +116,9 @@ Future<void> main(List<String> args) async {
IncrementalCompilerResult incrementalCompilerResult =
await compiler.computeDelta(entryPoints: [entryPoint]);
Component component = incrementalCompilerResult.component;
if (component.problemsAsJson?.isNotEmpty ?? false) {
throw 'Unexpected errors.';
}
StringBuffer buffer = new StringBuffer();
Printer printer = new Printer(buffer)
..writeProblemsAsJson(

View file

@ -0,0 +1,12 @@
// Copyright (c) 2024, 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:core' as prefix;
import 'dart:core' as prefix;
import 'dart:core' as prefix0;
main() {
prefix.String s1 = '';
prefix0.String s2 = s1;
}

View file

@ -0,0 +1,12 @@
library;
import self as self;
import "dart:core" as core;
import "dart:core" as prefix;
import "dart:core" as prefix;
import "dart:core" as prefix0;
static method main() → dynamic {
core::String s1 = "";
core::String s2 = s1;
}

View file

@ -0,0 +1,12 @@
library;
import self as self;
import "dart:core" as core;
import "dart:core" as prefix;
import "dart:core" as prefix;
import "dart:core" as prefix0;
static method main() → dynamic {
core::String s1 = "";
core::String s2 = s1;
}

View file

@ -0,0 +1,7 @@
import 'dart:core' as prefix;
import 'dart:core' as prefix;
import 'dart:core' as prefix0;
main() {}

View file

@ -0,0 +1,5 @@
import 'dart:core' as prefix;
import 'dart:core' as prefix;
import 'dart:core' as prefix0;
main() {}

View file

@ -0,0 +1,12 @@
library;
import self as self;
import "dart:core" as core;
import "dart:core" as prefix;
import "dart:core" as prefix;
import "dart:core" as prefix0;
static method main() → dynamic {
core::String s1 = "";
core::String s2 = s1;
}

View file

@ -0,0 +1,12 @@
library;
import self as self;
import "dart:core" as core;
import "dart:core" as prefix;
import "dart:core" as prefix;
import "dart:core" as prefix0;
static method main() → dynamic {
core::String s1 = "";
core::String s2 = s1;
}

View file

@ -0,0 +1,9 @@
library;
import self as self;
import "dart:core" as prefix;
import "dart:core" as prefix;
import "dart:core" as prefix0;
static method main() → dynamic
;

View file

@ -0,0 +1,12 @@
library;
import self as self;
import "dart:core" as core;
import "dart:core" as prefix;
import "dart:core" as prefix;
import "dart:core" as prefix0;
static method main() → dynamic {
core::String s1 = "";
core::String s2 = s1;
}