Skip to content

Commit

Permalink
Version 3.6.0-35.0.dev
Browse files Browse the repository at this point in the history
Merge c437107 into dev
  • Loading branch information
Dart CI committed Jul 12, 2024
2 parents 797d3df + c437107 commit e986ed9
Show file tree
Hide file tree
Showing 20 changed files with 389 additions and 252 deletions.
8 changes: 5 additions & 3 deletions pkg/front_end/lib/src/base/export.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import 'package:kernel/ast.dart';
import '../builder/builder.dart';
import '../builder/library_builder.dart';
import 'combinator.dart' show CombinatorBuilder;
import 'uri_offset.dart';

class Export {
/// The library that is exporting [exported];
final LibraryBuilder exporter;
/// The compilation unit that is exporting [exported];
final CompilationUnit exporter;

/// The library being exported.
CompilationUnit exportedCompilationUnit;
Expand Down Expand Up @@ -41,6 +42,7 @@ class Export {
combinator.names.contains(name)) return false;
}
}
return exporter.addToExportScope(name, member, charOffset);
return exporter.libraryBuilder.addToExportScope(name, member,
uriOffset: new UriOffset(exporter.fileUri, charOffset));
}
}
7 changes: 2 additions & 5 deletions pkg/front_end/lib/src/base/import.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ import 'combinator.dart' show CombinatorBuilder;
import 'configuration.dart' show Configuration;

class Import {
/// The library that is importing [imported];
final SourceLibraryBuilder importer;

/// The library being imported.
CompilationUnit? importedCompilationUnit;

Expand Down Expand Up @@ -49,7 +46,7 @@ class Import {
LibraryDependency? libraryDependency;

Import(
this.importer,
SourceLibraryBuilder importer,
this.importedCompilationUnit,
this.isAugmentationImport,
this.deferred,
Expand All @@ -73,7 +70,7 @@ class Import {
LibraryBuilder? get importedLibraryBuilder =>
importedCompilationUnit?.libraryBuilder;

void finalizeImports(SourceLibraryBuilder importer) {
void finalizeImports(SourceCompilationUnit importer) {
if (nativeImportPath != null) return;
void Function(String, Builder) add;
if (prefixBuilder == null) {
Expand Down
95 changes: 94 additions & 1 deletion pkg/front_end/lib/src/base/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@ import '../builder/library_builder.dart';
import '../builder/member_builder.dart';
import '../builder/metadata_builder.dart';
import '../builder/name_iterator.dart';
import '../codes/cfe_codes.dart';
import '../builder/prefix_builder.dart';
import '../kernel/body_builder.dart' show JumpTarget;
import '../kernel/body_builder_context.dart';
import '../kernel/hierarchy/class_member.dart' show ClassMember;
import '../kernel/kernel_helper.dart';
import '../kernel/load_library_builder.dart';
import '../source/source_class_builder.dart';
import '../source/source_extension_builder.dart';
import '../source/source_extension_type_declaration_builder.dart';
import '../source/source_function_builder.dart';
import '../source/source_library_builder.dart';
import '../source/source_member_builder.dart';
import '../util/helpers.dart' show DelayedActionPerformer;
import 'messages.dart';
import 'problems.dart' show internalProblem, unsupported;
import 'uri_offset.dart';

enum ScopeKind {
/// Scope of pattern switch-case statements
Expand Down Expand Up @@ -856,6 +859,96 @@ abstract class LazyScope extends Scope {
}
}

/// Computes a builder for the import/export collision between [declaration] and
/// [other] and adds it to [scope].
Builder computeAmbiguousDeclarationForScope(ProblemReporting problemReporting,
Scope scope, String name, Builder declaration, Builder other,
{required UriOffset uriOffset,
bool isExport = false,
bool isImport = false}) {
// TODO(ahe): Can I move this to Scope or Prefix?
if (declaration == other) return declaration;
if (declaration is InvalidTypeDeclarationBuilder) return declaration;
if (other is InvalidTypeDeclarationBuilder) return other;
if (declaration is AccessErrorBuilder) {
// Coverage-ignore-block(suite): Not run.
AccessErrorBuilder error = declaration;
declaration = error.builder;
}
if (other is AccessErrorBuilder) {
// Coverage-ignore-block(suite): Not run.
AccessErrorBuilder error = other;
other = error.builder;
}
Builder? preferred;
Uri? uri;
Uri? otherUri;
if (scope.lookupLocalMember(name, setter: false) == declaration) {
preferred = declaration;
} else {
uri = computeLibraryUri(declaration);
otherUri = computeLibraryUri(other);
if (declaration is LoadLibraryBuilder) {
preferred = declaration;
} else if (other is LoadLibraryBuilder) {
preferred = other;
} else if (otherUri.isScheme("dart") && !uri.isScheme("dart")) {
preferred = declaration;
} else if (uri.isScheme("dart") && !otherUri.isScheme("dart")) {
preferred = other;
}
}
if (preferred != null) {
return preferred;
}
if (declaration.next == null && other.next == null) {
if (isImport &&
declaration is PrefixBuilder &&
// Coverage-ignore(suite): Not run.
other is PrefixBuilder) {
// Coverage-ignore-block(suite): Not run.
// Handles the case where the same prefix is used for different
// imports.
return declaration
..exportScope.merge(other.exportScope,
(String name, Builder existing, Builder member) {
return computeAmbiguousDeclarationForScope(
problemReporting, scope, name, existing, member,
uriOffset: uriOffset, isExport: isExport, isImport: isImport);
});
}
}
Uri firstUri = uri!;
Uri secondUri = otherUri!;
if (firstUri.toString().compareTo(secondUri.toString()) > 0) {
firstUri = secondUri;
secondUri = uri;
}
if (isExport) {
Template<Message Function(String name, Uri uri, Uri uri2)> template =
templateDuplicatedExport;
Message message = template.withArguments(name, firstUri, secondUri);
problemReporting.addProblem(
message, uriOffset.fileOffset, noLength, uriOffset.uri);
}
Template<Message Function(String name, Uri uri, Uri uri2)> builderTemplate =
isExport
? templateDuplicatedExportInType
: templateDuplicatedImportInType;
Message message = builderTemplate.withArguments(
name,
// TODO(ahe): We should probably use a context object here
// instead of including URIs in this message.
firstUri,
secondUri);
// We report the error lazily (setting suppressMessage to false) because the
// spec 18.1 states that 'It is not an error if N is introduced by two or
// more imports but never referred to.'
return new InvalidTypeDeclarationBuilder(name,
message.withLocation(uriOffset.uri, uriOffset.fileOffset, name.length),
suppressMessage: false);
}

abstract class ProblemBuilder extends BuilderImpl {
final String name;

Expand Down
2 changes: 1 addition & 1 deletion pkg/front_end/lib/src/builder/function_type_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class _InferredFunctionTypeBuilder extends FunctionTypeBuilderImpl
} else {
InferableTypeUse inferableTypeUse =
new InferableTypeUse(library as SourceLibraryBuilder, this, typeUse);
library.registerInferableType(inferableTypeUse);
library.loader.inferableTypes.registerInferableType(inferableTypeUse);
return new InferredType.fromInferableTypeUse(inferableTypeUse);
}
}
Expand Down
24 changes: 11 additions & 13 deletions pkg/front_end/lib/src/builder/library_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import '../base/messages.dart'
templateInternalProblemPrivateConstructorAccess;
import '../base/problems.dart' show internalProblem;
import '../base/scope.dart';
import '../base/uri_offset.dart';
import '../kernel/hierarchy/members_builder.dart';
import '../source/name_scheme.dart';
import '../source/offset_map.dart';
Expand All @@ -35,7 +36,6 @@ import '../source/source_loader.dart';
import 'builder.dart';
import 'constructor_reference_builder.dart';
import 'declaration_builders.dart';
import 'inferable_type_builder.dart';
import 'member_builder.dart';
import 'metadata_builder.dart';
import 'modifier_builder.dart';
Expand Down Expand Up @@ -81,7 +81,7 @@ sealed class CompilationUnit {

List<Export> get exporters;

void addExporter(LibraryBuilder exporter,
void addExporter(CompilationUnit exporter,
List<CombinatorBuilder>? combinators, int charOffset);

/// Returns an iterator of all members (typedefs, classes and members)
Expand Down Expand Up @@ -180,8 +180,6 @@ abstract class SourceCompilationUnit implements CompilationUnit {

List<MetadataBuilder>? get metadata;

void collectInferableTypes(List<InferableType> inferableTypes);

void takeMixinApplications(
Map<SourceClassBuilder, TypeBuilder> mixinApplications);

Expand Down Expand Up @@ -230,6 +228,8 @@ abstract class SourceCompilationUnit implements CompilationUnit {
required List<CombinatorBuilder>? combinators,
required bool deferred});

void addToScope(String name, Builder member, int charOffset, bool isImport);

void addImportsToScope();

int finishDeferredLoadTearoffs();
Expand Down Expand Up @@ -337,11 +337,8 @@ abstract class LibraryBuilder implements Builder, ProblemReporting {
NameIterator<T> fullMemberNameIterator<T extends Builder>();

/// Returns true if the export scope was modified.
bool addToExportScope(String name, Builder member, [int charOffset = -1]);

Builder computeAmbiguousDeclaration(
String name, Builder declaration, Builder other, int charOffset,
{bool isExport = false, bool isImport = false});
bool addToExportScope(String name, Builder member,
{required UriOffset uriOffset});

/// Looks up [constructorName] in the class named [className].
///
Expand Down Expand Up @@ -471,7 +468,8 @@ abstract class LibraryBuilderImpl extends ModifierBuilderImpl
}

@override
bool addToExportScope(String name, Builder member, [int charOffset = -1]) {
bool addToExportScope(String name, Builder member,
{required UriOffset uriOffset}) {
if (name.startsWith("_")) return false;
if (member is PrefixBuilder) return false;
Builder? existing =
Expand All @@ -480,9 +478,9 @@ abstract class LibraryBuilderImpl extends ModifierBuilderImpl
return false;
} else {
if (existing != null) {
Builder result = computeAmbiguousDeclaration(
name, existing, member, charOffset,
isExport: true);
Builder result = computeAmbiguousDeclarationForScope(
this, scope, name, existing, member,
uriOffset: uriOffset, isExport: true);
exportScope.addLocalMember(name, result, setter: member.isSetter);
return result != existing;
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/front_end/lib/src/builder/named_type_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ class _InferredNamedTypeBuilder extends NamedTypeBuilderImpl
} else {
InferableTypeUse inferableTypeUse =
new InferableTypeUse(library as SourceLibraryBuilder, this, typeUse);
library.registerInferableType(inferableTypeUse);
library.loader.inferableTypes.registerInferableType(inferableTypeUse);
return new InferredType.fromInferableTypeUse(inferableTypeUse);
}
}
Expand Down
26 changes: 24 additions & 2 deletions pkg/front_end/lib/src/builder/omitted_type_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'package:kernel/ast.dart';
import 'package:kernel/class_hierarchy.dart';

import '../kernel/hierarchy/hierarchy_builder.dart';
import '../kernel/implicit_field_type.dart';
import '../source/builder_factory.dart';
import '../source/source_library_builder.dart';
Expand Down Expand Up @@ -125,7 +126,7 @@ class InferableTypeBuilder extends OmittedTypeBuilderImpl
} else {
InferableTypeUse inferableTypeUse =
new InferableTypeUse(library as SourceLibraryBuilder, this, typeUse);
library.registerInferableType(inferableTypeUse);
library.loader.inferableTypes.registerInferableType(inferableTypeUse);
return new InferredType.fromInferableTypeUse(inferableTypeUse);
}
}
Expand Down Expand Up @@ -227,7 +228,7 @@ class DependentTypeBuilder extends OmittedTypeBuilderImpl
} else {
InferableTypeUse inferableTypeUse =
new InferableTypeUse(library as SourceLibraryBuilder, this, typeUse);
library.registerInferableType(inferableTypeUse);
library.loader.inferableTypes.registerInferableType(inferableTypeUse);
return new InferredType.fromInferableTypeUse(inferableTypeUse);
}
}
Expand Down Expand Up @@ -265,3 +266,24 @@ abstract class Inferable {
/// [InferableTypeBuilder]s.
void inferTypes(ClassHierarchyBase hierarchy);
}

class InferableTypes {
final List<InferableType> _inferableTypes = [];

InferableTypeBuilder addInferableType() {
InferableTypeBuilder typeBuilder = new InferableTypeBuilder();
registerInferableType(typeBuilder);
return typeBuilder;
}

void registerInferableType(InferableType inferableType) {
_inferableTypes.add(inferableType);
}

void inferTypes(ClassHierarchyBuilder classHierarchyBuilder) {
for (InferableType typeBuilder in _inferableTypes) {
typeBuilder.inferType(classHierarchyBuilder);
}
_inferableTypes.clear();
}
}
7 changes: 4 additions & 3 deletions pkg/front_end/lib/src/builder/prefix_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ library fasta.prefix_builder;
import 'package:kernel/ast.dart' show LibraryDependency;

import '../base/scope.dart';
import '../base/uri_offset.dart';
import '../codes/cfe_codes.dart';
import '../kernel/load_library_builder.dart' show LoadLibraryBuilder;
import '../source/source_library_builder.dart';
Expand Down Expand Up @@ -63,9 +64,9 @@ class PrefixBuilder extends BuilderImpl {
Builder result;
if (existing != null) {
// Coverage-ignore-block(suite): Not run.
result = parent.computeAmbiguousDeclaration(
name, existing, member, charOffset,
isExport: true);
result = computeAmbiguousDeclarationForScope(
parent, parent.scope, name, existing, member,
uriOffset: new UriOffset(fileUri, charOffset), isExport: true);
} else {
result = member;
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/front_end/lib/src/builder/record_type_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ class _InferredRecordTypeBuilder extends RecordTypeBuilderImpl
} else {
InferableTypeUse inferableTypeUse =
new InferableTypeUse(library as SourceLibraryBuilder, this, typeUse);
library.registerInferableType(inferableTypeUse);
library.loader.inferableTypes.registerInferableType(inferableTypeUse);
return new InferredType.fromInferableTypeUse(inferableTypeUse);
}
}
Expand Down
28 changes: 2 additions & 26 deletions pkg/front_end/lib/src/dill/dill_library_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ import '../builder/member_builder.dart';
import '../builder/name_iterator.dart';
import '../builder/never_type_declaration_builder.dart';
import '../codes/cfe_codes.dart'
show
LocatedMessage,
Message,
Severity,
noLength,
templateDuplicatedDeclaration,
templateUnspecified;
show LocatedMessage, Message, Severity, noLength, templateUnspecified;
import '../kernel/constructor_tearoff_lowering.dart';
import '../kernel/utils.dart';
import 'dill_class_builder.dart' show DillClassBuilder;
Expand Down Expand Up @@ -63,7 +57,7 @@ class DillCompilationUnitImpl extends DillCompilationUnit {
DillCompilationUnitImpl(this._dillLibraryBuilder);

@override
void addExporter(LibraryBuilder exporter,
void addExporter(CompilationUnit exporter,
List<CombinatorBuilder>? combinators, int charOffset) {
exporters.add(new Export(exporter, this, combinators, charOffset));
}
Expand Down Expand Up @@ -372,24 +366,6 @@ class DillLibraryBuilder extends LibraryBuilderImpl {
typedef.name, new DillTypeAliasBuilder(typedef, tearOffs, this));
}

@override
// Coverage-ignore(suite): Not run.
Builder computeAmbiguousDeclaration(
String name, Builder builder, Builder other, int charOffset,
{bool isExport = false, bool isImport = false}) {
if (builder == other) return builder;
if (builder is InvalidTypeDeclarationBuilder) return builder;
if (other is InvalidTypeDeclarationBuilder) return other;
// For each entry mapping key `k` to declaration `d` in `NS` an entry
// mapping `k` to `d` is added to the exported namespace of `L` unless a
// top-level declaration with the name `k` exists in `L`.
if (builder.parent == this) return builder;
Message message = templateDuplicatedDeclaration.withArguments(name);
addProblem(message, charOffset, name.length, fileUri);
return new InvalidTypeDeclarationBuilder(
name, message.withLocation(fileUri, charOffset, name.length));
}

@override
// Coverage-ignore(suite): Not run.
String get fullNameForErrors {
Expand Down
Loading

0 comments on commit e986ed9

Please sign in to comment.