Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5f32f4d

Browse files
committed
[cfe] Separate patch from regular libraries
+ handle them through the origin library. This prepares for supporting multiple patch libraries for the same library. Change-Id: Ib4934fd2f2c7f743fa342dae86002ac72d57f9a3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/222304 Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
1 parent a2d1136 commit 5f32f4d

File tree

15 files changed

+672
-461
lines changed

15 files changed

+672
-461
lines changed

pkg/front_end/lib/src/fasta/builder/builder.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,6 @@ abstract class Builder {
200200
/// Returns the number of patches that was finished.
201201
int finishPatch();
202202

203-
/// Resolve constructors (lookup names in scope) recorded in this builder and
204-
/// return the number of constructors resolved.
205-
int resolveConstructors(covariant Builder? parent);
206-
207203
/// Return `true` if this builder is a duplicate of another with the same
208204
/// name. This is `false` for the builder first declared amongst duplicates.
209205
bool get isDuplicate;
@@ -304,9 +300,6 @@ abstract class BuilderImpl implements Builder {
304300
unsupported("${runtimeType}.finishPatch", charOffset, fileUri);
305301
}
306302

307-
@override
308-
int resolveConstructors(covariant Builder parent) => 0;
309-
310303
@override
311304
bool get isDuplicate => next != null;
312305
}

pkg/front_end/lib/src/fasta/builder/library_builder.dart

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import '../scope.dart';
2929

3030
import 'builder.dart';
3131
import 'class_builder.dart';
32-
import 'field_builder.dart';
3332
import 'member_builder.dart';
3433
import 'modifier_builder.dart';
3534
import 'name_iterator.dart';
@@ -101,14 +100,6 @@ abstract class LibraryBuilder implements ModifierBuilder {
101100
String name, Builder declaration, Builder other, int charOffset,
102101
{bool isExport: false, bool isImport: false});
103102

104-
int finishDeferredLoadTearoffs();
105-
106-
int finishForwarders();
107-
108-
int finishNativeMethods();
109-
110-
int finishPatchMethods();
111-
112103
/// Looks up [constructorName] in the class named [className].
113104
///
114105
/// The class is looked up in this library's export scope unless
@@ -124,21 +115,6 @@ abstract class LibraryBuilder implements ModifierBuilder {
124115
MemberBuilder getConstructor(String className,
125116
{String constructorName, bool bypassLibraryPrivacy: false});
126117

127-
int finishTypeVariables(ClassBuilder object, TypeBuilder dynamicType);
128-
129-
/// Computes variances of type parameters on typedefs.
130-
///
131-
/// The variance property of type parameters on typedefs is computed from the
132-
/// use of the parameters in the right-hand side of the typedef definition.
133-
int computeVariances() => 0;
134-
135-
/// This method instantiates type parameters to their bounds in some cases
136-
/// where they were omitted by the programmer and not provided by the type
137-
/// inference. The method returns the number of distinct type variables
138-
/// that were instantiated in this library.
139-
int computeDefaultTypes(TypeBuilder dynamicType, TypeBuilder nullType,
140-
TypeBuilder bottomType, ClassBuilder objectClass);
141-
142118
void becomeCoreLibrary();
143119

144120
void addSyntheticDeclarationOfDynamic();
@@ -160,10 +136,6 @@ abstract class LibraryBuilder implements ModifierBuilder {
160136

161137
void recordAccess(int charOffset, int length, Uri fileUri);
162138

163-
void buildOutlineExpressions();
164-
165-
List<FieldBuilder>? takeImplicitlyTypedFields();
166-
167139
bool get isNonNullableByDefault;
168140

169141
Nullability get nullable;
@@ -285,18 +257,6 @@ abstract class LibraryBuilderImpl extends ModifierBuilderImpl
285257
}
286258
}
287259

288-
@override
289-
int finishDeferredLoadTearoffs() => 0;
290-
291-
@override
292-
int finishForwarders() => 0;
293-
294-
@override
295-
int finishNativeMethods() => 0;
296-
297-
@override
298-
int finishPatchMethods() => 0;
299-
300260
@override
301261
MemberBuilder getConstructor(String className,
302262
{String? constructorName, bool bypassLibraryPrivacy: false}) {
@@ -339,18 +299,6 @@ abstract class LibraryBuilderImpl extends ModifierBuilderImpl
339299
null);
340300
}
341301

342-
@override
343-
int finishTypeVariables(ClassBuilder object, TypeBuilder dynamicType) => 0;
344-
345-
@override
346-
int computeVariances() => 0;
347-
348-
@override
349-
int computeDefaultTypes(TypeBuilder dynamicType, TypeBuilder nullType,
350-
TypeBuilder bottomType, ClassBuilder objectClass) {
351-
return 0;
352-
}
353-
354302
@override
355303
void becomeCoreLibrary() {
356304
if (scope.lookupLocalMember("dynamic", setter: false) == null) {
@@ -391,12 +339,6 @@ abstract class LibraryBuilderImpl extends ModifierBuilderImpl
391339
@override
392340
void recordAccess(int charOffset, int length, Uri fileUri) {}
393341

394-
@override
395-
void buildOutlineExpressions() {}
396-
397-
@override
398-
List<FieldBuilder>? takeImplicitlyTypedFields() => null;
399-
400342
@override
401343
Nullability get nullable {
402344
return isNonNullableByDefault ? Nullability.nullable : Nullability.legacy;
@@ -438,7 +380,7 @@ abstract class LibraryBuilderImpl extends ModifierBuilderImpl
438380

439381
@override
440382
StringBuffer printOn(StringBuffer buffer) {
441-
return buffer..write(name ?? importUri);
383+
return buffer..write(name ?? (isPart ? fileUri : importUri));
442384
}
443385
}
444386

pkg/front_end/lib/src/fasta/incremental_compiler.dart

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -465,24 +465,17 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
465465
Set<Library> newDillLibraryBuilders = new Set<Library>();
466466
_userBuilders ??= <Uri, LibraryBuilder>{};
467467
Map<LibraryBuilder, List<LibraryBuilder>>? convertedLibraries;
468-
for (LibraryBuilder builder
469-
in nextGoodKernelTarget.loader.libraryBuilders) {
470-
if (builder is SourceLibraryBuilder) {
471-
DillLibraryBuilder dillBuilder =
472-
_dillLoadedData!.loader.appendLibrary(builder.library);
473-
nextGoodKernelTarget.loader.registerLibraryBuilder(
474-
// TODO(johnniwinther): Why do we need to create
475-
// [DillLibraryBuilder]s for the patch library file uris?
476-
dillBuilder,
477-
builder.isPatch ? builder.fileUri : null);
478-
_userBuilders![builder.importUri] = dillBuilder;
479-
newDillLibraryBuilders.add(builder.library);
480-
changed = true;
481-
if (experimentalInvalidation != null) {
482-
convertedLibraries ??=
483-
new Map<LibraryBuilder, List<LibraryBuilder>>();
484-
convertedLibraries[builder] = [dillBuilder];
485-
}
468+
for (SourceLibraryBuilder builder
469+
in nextGoodKernelTarget.loader.sourceLibraryBuilders) {
470+
DillLibraryBuilder dillBuilder =
471+
_dillLoadedData!.loader.appendLibrary(builder.library);
472+
nextGoodKernelTarget.loader.registerLibraryBuilder(dillBuilder);
473+
_userBuilders![builder.importUri] = dillBuilder;
474+
newDillLibraryBuilders.add(builder.library);
475+
changed = true;
476+
if (experimentalInvalidation != null) {
477+
convertedLibraries ??= new Map<LibraryBuilder, List<LibraryBuilder>>();
478+
convertedLibraries[builder] = [dillBuilder];
486479
}
487480
}
488481
if (changed) {
@@ -537,6 +530,8 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
537530

538531
bool _checkEquivalentScopes(
539532
SourceLoader sourceLoader, DillLoader dillLoader) {
533+
// TODO(johnniwinther): Use [SourceLoader.sourceLibraryBuilders] here.
534+
// Currently this causes a failure in incremental_dartino_suite.dart.
540535
for (LibraryBuilder sourceLibraryBuilder in sourceLoader.libraryBuilders) {
541536
if (sourceLibraryBuilder is SourceLibraryBuilder) {
542537
Uri uri = sourceLibraryBuilder.importUri;
@@ -1733,12 +1728,11 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
17331728
}
17341729

17351730
SourceLibraryBuilder debugLibrary = new SourceLibraryBuilder(
1736-
libraryUri,
1737-
debugExprUri,
1738-
/*packageUri*/ null,
1739-
new ImplicitLanguageVersion(libraryBuilder.library.languageVersion),
1740-
lastGoodKernelTarget.loader,
1741-
null,
1731+
importUri: libraryUri,
1732+
fileUri: debugExprUri,
1733+
packageLanguageVersion:
1734+
new ImplicitLanguageVersion(libraryBuilder.library.languageVersion),
1735+
loader: lastGoodKernelTarget.loader,
17421736
scope: libraryBuilder.scope.createNestedScope("expression"),
17431737
nameOrigin: libraryBuilder,
17441738
);

pkg/front_end/lib/src/fasta/kernel/kernel_target.dart

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -361,23 +361,6 @@ class KernelTarget extends TargetImplementation {
361361
return entryPoint;
362362
}
363363

364-
/// Returns classes defined in libraries in [loader].
365-
List<SourceClassBuilder> collectMyClasses() {
366-
List<SourceClassBuilder> result = <SourceClassBuilder>[];
367-
for (LibraryBuilder library in loader.libraryBuilders) {
368-
if (library.loader == loader) {
369-
Iterator<Builder> iterator = library.iterator;
370-
while (iterator.moveNext()) {
371-
Builder member = iterator.current;
372-
if (member is SourceClassBuilder && !member.isPatch) {
373-
result.add(member);
374-
}
375-
}
376-
}
377-
}
378-
return result;
379-
}
380-
381364
/// The class [cls] is involved in a cyclic definition. This method should
382365
/// ensure that the cycle is broken, for example, by removing superclass and
383366
/// implemented interfaces.
@@ -460,10 +443,10 @@ class KernelTarget extends TargetImplementation {
460443
finishSynthesizedParameters();
461444
loader.finishDeferredLoadTearoffs();
462445
loader.finishNoSuchMethodForwarders();
463-
List<SourceClassBuilder> myClasses = collectMyClasses();
446+
List<SourceClassBuilder> sourceClasses = loader.collectSourceClasses();
464447
loader.finishNativeMethods();
465448
loader.finishPatchMethods();
466-
finishAllConstructors(myClasses);
449+
finishAllConstructors(sourceClasses);
467450
runBuildTransformations();
468451

469452
if (verify) this.verify();
@@ -625,33 +608,8 @@ class KernelTarget extends TargetImplementation {
625608

626609
void installDefaultSupertypes() {
627610
Class objectClass = this.objectClass;
628-
for (LibraryBuilder library in loader.libraryBuilders) {
629-
if (library.loader == loader) {
630-
Iterator<Builder> iterator = library.iterator;
631-
while (iterator.moveNext()) {
632-
Builder declaration = iterator.current;
633-
if (declaration is SourceClassBuilder) {
634-
Class cls = declaration.cls;
635-
if (cls != objectClass) {
636-
cls.supertype ??= objectClass.asRawSupertype;
637-
declaration.supertypeBuilder ??= new NamedTypeBuilder(
638-
"Object",
639-
const NullabilityBuilder.omitted(),
640-
/* arguments = */ null,
641-
/* fileUri = */ null,
642-
/* charOffset = */ null,
643-
instanceTypeVariableAccess:
644-
InstanceTypeVariableAccessState.Unexpected)
645-
..bind(objectClassBuilder);
646-
}
647-
if (declaration.isMixinApplication) {
648-
cls.mixedInType = declaration.mixedInTypeBuilder!
649-
.buildMixedInType(
650-
library, declaration.charOffset, declaration.fileUri);
651-
}
652-
}
653-
}
654-
}
611+
for (SourceLibraryBuilder library in loader.sourceLibraryBuilders) {
612+
library.installDefaultSupertypes(objectClassBuilder, objectClass);
655613
}
656614
ticker.logMs("Installed Object as implicit superclass");
657615
}

pkg/front_end/lib/src/fasta/source/source_class_builder.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,6 @@ class SourceClassBuilder extends ClassBuilderImpl
913913
new ConstructorTearOff(constructorBuilder.member)..parent = literal);
914914
}
915915

916-
@override
917916
int resolveConstructors(SourceLibraryBuilder library) {
918917
if (constructorReferences == null) return 0;
919918
for (ConstructorReferenceBuilder ref in constructorReferences!) {

0 commit comments

Comments
 (0)