Skip to content

Commit

Permalink
Version 3.6.0-51.0.dev
Browse files Browse the repository at this point in the history
Merge c51d5bd into dev
  • Loading branch information
Dart CI committed Jul 17, 2024
2 parents df3dd0b + c51d5bd commit d679a4c
Show file tree
Hide file tree
Showing 18 changed files with 234 additions and 114 deletions.
116 changes: 101 additions & 15 deletions pkg/front_end/lib/src/base/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ 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 'problems.dart' show internalProblem;
import 'uri_offset.dart';

enum ScopeKind {
Expand Down Expand Up @@ -106,6 +106,66 @@ enum ScopeKind {
typeParameters,
}

abstract class NestedScope {
NestedScope? get parent;
}

abstract class ParentScope implements NestedScope {
@override
ParentScope? get parent;
void forEachExtension(void Function(ExtensionBuilder) f);
Builder? lookup(String name, int charOffset, Uri fileUri);
JumpTarget? lookupLabel(String name);
Builder? lookupSetter(String name, int charOffset, Uri fileUri);
int writeOn(StringSink sink);
}

abstract class LocalScope extends NestedScope {
ScopeKind get kind;

@override
LocalScope? get parent;

LocalScope createNestedScope(
{required String debugName,
bool isModifiable = true,
required ScopeKind kind,
Map<String, Builder>? local});

LocalScope createNestedLabelScope();

Iterable<Builder> get localMembers;

Builder? lookupLocalMember(String name, {required bool setter});

List<int>? declare(String name, Builder builder, Uri uri);

void addLocalMember(String name, Builder member, {required bool setter});

void declareLabel(String name, JumpTarget target);
bool hasLocalLabel(String name);
bool claimLabel(String name);
JumpTarget? lookupLabel(String name);

Builder? lookup(String name, int charOffset, Uri fileUri);
Builder? lookupSetter(String name, int charOffset, Uri uri);

Map<String, List<int>>? get usedNames;

Iterator<T> filteredIterator<T extends Builder>(
{Builder? parent,
required bool includeDuplicates,
required bool includeAugmentations});

SwitchScope get switchScope;
}

abstract class SwitchScope {
Map<String, JumpTarget>? get unclaimedForwardDeclarations;
JumpTarget? lookupLabel(String name);
void forwardDeclareLabel(String name, JumpTarget target);
}

class MutableScope {
/// Names declared in this scope.
Map<String, Builder>? _local;
Expand Down Expand Up @@ -146,7 +206,7 @@ class MutableScope {

/// The scope that this scope is nested within, or `null` if this is the top
/// level scope.
Scope? _parent;
ParentScope? _parent;

final String classNameOrDebugName;

Expand All @@ -155,13 +215,14 @@ class MutableScope {
MutableScope(this.kind, this._local, this._setters, this._extensions,
this._parent, this.classNameOrDebugName);

Scope? get parent => _parent;
ParentScope? get parent => _parent;

@override
String toString() => "Scope(${kind}, $classNameOrDebugName, ${_local?.keys})";
}

class Scope extends MutableScope {
class Scope extends MutableScope
implements ParentScope, LocalScope, SwitchScope {
/// Indicates whether an attempt to declare new names in this scope should
/// succeed.
final bool isModifiable;
Expand All @@ -170,6 +231,7 @@ class Scope extends MutableScope {

Map<String, JumpTarget>? forwardDeclaredLabels;

@override
Map<String, List<int>>? usedNames;

Map<String, List<Builder>>? augmentations;
Expand All @@ -181,7 +243,7 @@ class Scope extends MutableScope {
Map<String, Builder>? local,
Map<String, MemberBuilder>? setters,
Set<ExtensionBuilder>? extensions,
Scope? parent,
ParentScope? parent,
this.augmentations,
this.setterAugmentations,
required String debugName,
Expand All @@ -205,12 +267,22 @@ class Scope extends MutableScope {
isModifiable: false);

Scope.nested(Scope parent, String debugName,
{bool isModifiable = true, required ScopeKind kind})
{bool isModifiable = true,
required ScopeKind kind,
Map<String, Builder>? local})
: this(
kind: kind,
parent: parent,
debugName: debugName,
isModifiable: isModifiable);
isModifiable: isModifiable,
local: local);

@override
SwitchScope get switchScope => this;

// TODO(johnniwinther): Remove this.
@override
Scope? get parent => _parent as Scope?;

/// Returns an iterator of all members and setters mapped in this scope,
/// including duplicate members mapped to the same name.
Expand Down Expand Up @@ -241,6 +313,7 @@ class Scope extends MutableScope {
/// declared member is included. If [includeAugmentations] is `true`, both
/// original and augmenting/patching members are included, otherwise, only
/// original members are included.
@override
Iterator<T> filteredIterator<T extends Builder>(
{Builder? parent,
required bool includeDuplicates,
Expand Down Expand Up @@ -443,27 +516,25 @@ class Scope extends MutableScope {
isModifiable: isModifiable);
}

// Coverage-ignore(suite): Not run.
/// Don't use this. Use [becomePartOf] instead.
void set parent(_) => unsupported("parent=", -1, null);

/// This scope becomes equivalent to [scope]. This is used for parts to
/// become part of their library's scope.
void becomePartOf(Scope scope) {
assert(_parent!._parent == null);
assert(scope._parent!._parent == null);
assert(_parent!.parent == null);
assert(scope._parent!.parent == null);
super._local = scope._local;
super._setters = scope._setters;
super._parent = scope._parent;
super._extensions = scope._extensions;
}

@override
Scope createNestedScope(
{required String debugName,
bool isModifiable = true,
required ScopeKind kind}) {
required ScopeKind kind,
Map<String, Builder>? local}) {
return new Scope.nested(this, debugName,
isModifiable: isModifiable, kind: kind);
isModifiable: isModifiable, kind: kind, local: local);
}

Scope withTypeVariables(List<NominalVariableBuilder>? typeVariables) {
Expand Down Expand Up @@ -495,6 +566,7 @@ class Scope extends MutableScope {
/// L: var x;
/// x = 42;
/// print("The answer is $x.");
@override
Scope createNestedLabelScope() {
// The scopes needs to reference the same locals and setters so we have to
// eagerly initialize them.
Expand Down Expand Up @@ -544,6 +616,7 @@ class Scope extends MutableScope {
}

/// Lookup a member with [name] in the scope.
@override
Builder? lookup(String name, int charOffset, Uri fileUri,
{bool isInstanceScope = true}) {
recordUse(name, charOffset);
Expand All @@ -565,6 +638,7 @@ class Scope extends MutableScope {
return builder ?? _parent?.lookup(name, charOffset, fileUri);
}

@override
Builder? lookupSetter(String name, int charOffset, Uri fileUri,
{bool isInstanceScope = true}) {
recordUse(name, charOffset);
Expand All @@ -586,10 +660,12 @@ class Scope extends MutableScope {
return builder ?? _parent?.lookupSetter(name, charOffset, fileUri);
}

@override
Builder? lookupLocalMember(String name, {required bool setter}) {
return setter ? (_setters?[name]) : (_local?[name]);
}

@override
void addLocalMember(String name, Builder member, {required bool setter}) {
if (setter) {
(_setters ??= // Coverage-ignore(suite): Not run.
Expand All @@ -611,11 +687,14 @@ class Scope extends MutableScope {
_extensions?.forEach(f);
}

@override
Iterable<Builder> get localMembers => _local?.values ?? const {};

@override
bool hasLocalLabel(String name) =>
labels != null && labels!.containsKey(name);

@override
void declareLabel(String name, JumpTarget target) {
if (isModifiable) {
labels ??= <String, JumpTarget>{};
Expand All @@ -626,12 +705,14 @@ class Scope extends MutableScope {
}
}

@override
void forwardDeclareLabel(String name, JumpTarget target) {
declareLabel(name, target);
forwardDeclaredLabels ??= <String, JumpTarget>{};
forwardDeclaredLabels![name] = target;
}

@override
bool claimLabel(String name) {
if (forwardDeclaredLabels == null ||
forwardDeclaredLabels!.remove(name) == null) {
Expand All @@ -643,10 +724,12 @@ class Scope extends MutableScope {
return true;
}

@override
Map<String, JumpTarget>? get unclaimedForwardDeclarations {
return forwardDeclaredLabels;
}

@override
JumpTarget? lookupLabel(String name) {
return labels?[name] ?? _parent?.lookupLabel(name);
}
Expand All @@ -657,6 +740,7 @@ class Scope extends MutableScope {
/// that can be used as context for reporting a compile-time error about
/// [name] being used before its declared. [fileUri] is used to bind the
/// location of this message.
@override
List<int>? declare(String name, Builder builder, Uri fileUri) {
if (isModifiable) {
List<int>? previousOffsets = usedNames?[name];
Expand All @@ -678,6 +762,7 @@ class Scope extends MutableScope {
}

/// Calls [f] for each extension in this scope and parent scopes.
@override
void forEachExtension(void Function(ExtensionBuilder) f) {
_extensions?.forEach(f);
_parent?.forEachExtension(f);
Expand Down Expand Up @@ -724,6 +809,7 @@ class Scope extends MutableScope {
}

// Coverage-ignore(suite): Not run.
@override
int writeOn(StringSink sink) {
int nestingLevel = (_parent?.writeOn(sink) ?? -1) + 1;
String indent = " " * nestingLevel;
Expand Down
9 changes: 1 addition & 8 deletions pkg/front_end/lib/src/builder/library_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -386,20 +386,13 @@ abstract class LibraryBuilder implements Builder, ProblemReporting {

abstract class LibraryBuilderImpl extends ModifierBuilderImpl
implements LibraryBuilder {
@override
final Scope scope;

@override
final Scope exportScope;

@override
final Uri fileUri;

@override
bool mayImplementRestrictedTypes = false;

LibraryBuilderImpl(this.fileUri, this.scope, this.exportScope)
: super(null, -1);
LibraryBuilderImpl(this.fileUri) : super(null, -1);

@override
// Coverage-ignore(suite): Not run.
Expand Down
31 changes: 17 additions & 14 deletions pkg/front_end/lib/src/dill/dill_library_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,15 @@ import 'dill_member_builder.dart';
import 'dill_type_alias_builder.dart' show DillTypeAliasBuilder;

class LazyLibraryScope extends LazyScope {
DillLibraryBuilder? libraryBuilder;
final DillLibraryBuilder libraryBuilder;

LazyLibraryScope.top({bool isModifiable = false})
LazyLibraryScope.top(this.libraryBuilder)
: super(<String, Builder>{}, <String, MemberBuilder>{}, null, "top",
isModifiable: isModifiable, kind: ScopeKind.library);
isModifiable: false, kind: ScopeKind.library);

@override
void ensureScope() {
if (libraryBuilder == null) {
throw new StateError("No library builder.");
}
libraryBuilder!.ensureLoaded();
libraryBuilder.ensureLoaded();
}
}

Expand Down Expand Up @@ -118,6 +115,10 @@ class DillCompilationUnitImpl extends DillCompilationUnit {
}

class DillLibraryBuilder extends LibraryBuilderImpl {
late final LazyLibraryScope _scope;

late final LazyLibraryScope _exportScope;

@override
final Library library;

Expand All @@ -141,15 +142,17 @@ class DillLibraryBuilder extends LibraryBuilderImpl {
bool isBuilt = false;
bool isBuiltAndMarked = false;

DillLibraryBuilder(this.library, this.loader)
: super(library.fileUri, new LazyLibraryScope.top(),
new LazyLibraryScope.top()) {
LazyLibraryScope lazyScope = scope as LazyLibraryScope;
lazyScope.libraryBuilder = this;
LazyLibraryScope lazyExportScope = exportScope as LazyLibraryScope;
lazyExportScope.libraryBuilder = this;
DillLibraryBuilder(this.library, this.loader) : super(library.fileUri) {
_scope = new LazyLibraryScope.top(this);
_exportScope = new LazyLibraryScope.top(this);
}

@override
Scope get scope => _scope;

@override
Scope get exportScope => _exportScope;

@override
List<Export> get exporters => mainCompilationUnit.exporters;

Expand Down
Loading

0 comments on commit d679a4c

Please sign in to comment.