Skip to content

Commit 67a7d12

Browse files
johnniwintherCommit Queue
authored and
Commit Queue
committed
[cfe] Move indexedLibrary and exporter fields to CompilationUnits
Change-Id: I7c3d9ea07a908413f2300599c021f589bd668f7c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/374983 Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com> Reviewed-by: Jens Johansen <jensj@google.com>
1 parent e78b22b commit 67a7d12

File tree

4 files changed

+35
-26
lines changed

4 files changed

+35
-26
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ library fasta.library_builder;
66

77
import 'package:_fe_analyzer_shared/src/messages/severity.dart' show Severity;
88
import 'package:kernel/ast.dart' show Class, Library, Version;
9+
import 'package:kernel/reference_from_index.dart';
910

1011
import '../api_prototype/experimental_flags.dart';
1112
import '../base/combinator.dart' show CombinatorBuilder;
@@ -79,6 +80,8 @@ sealed class CompilationUnit {
7980
void recordAccess(
8081
CompilationUnit accessor, int charOffset, int length, Uri fileUri);
8182

83+
List<Export> get exporters;
84+
8285
void addExporter(LibraryBuilder exporter,
8386
List<CombinatorBuilder>? combinators, int charOffset);
8487

@@ -159,8 +162,6 @@ abstract class SourceCompilationUnit implements CompilationUnit {
159162

160163
List<ConstructorReferenceBuilder> get constructorReferences;
161164

162-
List<Export> get exporters;
163-
164165
LanguageVersion get languageVersion;
165166

166167
// TODO(johnniwinther): Remove this.
@@ -228,6 +229,9 @@ abstract class SourceCompilationUnit implements CompilationUnit {
228229

229230
void markLanguageVersionFinal();
230231

232+
/// Index of the library we use references for.
233+
IndexedLibrary? get indexedLibrary;
234+
231235
void addSyntheticImport(
232236
{required String uri,
233237
required String? prefix,
@@ -396,9 +400,6 @@ abstract class LibraryBuilderImpl extends ModifierBuilderImpl
396400
@override
397401
final Scope exportScope;
398402

399-
@override
400-
final List<Export> exporters = <Export>[];
401-
402403
@override
403404
final Uri fileUri;
404405

pkg/front_end/lib/src/dill/dill_library_builder.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ class LazyLibraryScope extends LazyScope {
5757
class DillCompilationUnitImpl extends DillCompilationUnit {
5858
final DillLibraryBuilder _dillLibraryBuilder;
5959

60+
@override
61+
final List<Export> exporters = <Export>[];
62+
6063
DillCompilationUnitImpl(this._dillLibraryBuilder);
6164

6265
@override
6366
void addExporter(LibraryBuilder exporter,
6467
List<CombinatorBuilder>? combinators, int charOffset) {
65-
_dillLibraryBuilder.exporters
66-
.add(new Export(exporter, this, combinators, charOffset));
68+
exporters.add(new Export(exporter, this, combinators, charOffset));
6769
}
6870

6971
@override
@@ -154,6 +156,9 @@ class DillLibraryBuilder extends LibraryBuilderImpl {
154156
lazyExportScope.libraryBuilder = this;
155157
}
156158

159+
@override
160+
List<Export> get exporters => mainCompilationUnit.exporters;
161+
157162
@override
158163
LibraryBuilder get origin => this;
159164

pkg/front_end/lib/src/source/source_compilation_unit.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class SourceCompilationUnitImpl
4444

4545
final List<Export> exports = <Export>[];
4646

47+
@override
48+
final List<Export> exporters = <Export>[];
49+
4750
/// List of [PrefixBuilder]s for imports with prefixes.
4851
List<PrefixBuilder>? _prefixBuilders;
4952

@@ -68,11 +71,16 @@ class SourceCompilationUnitImpl
6871
bool postponedProblemsIssued = false;
6972
List<PostponedProblem>? postponedProblems;
7073

74+
/// Index of the library we use references for.
75+
@override
76+
final IndexedLibrary? indexedLibrary;
77+
7178
SourceCompilationUnitImpl(
7279
this._sourceLibraryBuilder, this._libraryTypeParameterScopeBuilder,
7380
{required this.importUri,
7481
required this.fileUri,
75-
required this.packageLanguageVersion})
82+
required this.packageLanguageVersion,
83+
required this.indexedLibrary})
7684
: currentTypeParameterScopeBuilder = _libraryTypeParameterScopeBuilder,
7785
_languageVersion = packageLanguageVersion;
7886

@@ -134,16 +142,14 @@ class SourceCompilationUnitImpl
134142
return previous;
135143
}
136144

137-
IndexedLibrary? get indexedLibrary => _sourceLibraryBuilder.indexedLibrary;
138-
139145
// TODO(johnniwinther): Use [_indexedContainer] for library members and make
140146
// it [null] when there is null corresponding [IndexedContainer].
141147
IndexedContainer? _indexedContainer;
142148

143149
@override
144150
void beginIndexedContainer(String name,
145151
{required bool isExtensionTypeDeclaration}) {
146-
if (_sourceLibraryBuilder.indexedLibrary != null) {
152+
if (indexedLibrary != null) {
147153
if (isExtensionTypeDeclaration) {
148154
_indexedContainer =
149155
indexedLibrary!.lookupIndexedExtensionTypeDeclaration(name);
@@ -170,8 +176,7 @@ class SourceCompilationUnitImpl
170176
@override
171177
void addExporter(LibraryBuilder exporter,
172178
List<CombinatorBuilder>? combinators, int charOffset) {
173-
_sourceLibraryBuilder.exporters
174-
.add(new Export(exporter, this, combinators, charOffset));
179+
exporters.add(new Export(exporter, this, combinators, charOffset));
175180
}
176181

177182
@override
@@ -436,9 +441,6 @@ class SourceCompilationUnitImpl
436441
List<ConstructorReferenceBuilder> get constructorReferences =>
437442
_sourceLibraryBuilder.constructorReferences;
438443

439-
@override
440-
List<Export> get exporters => _sourceLibraryBuilder.exporters;
441-
442444
@override
443445
Library get library => _sourceLibraryBuilder.library;
444446

@@ -2345,8 +2347,7 @@ class SourceCompilationUnitImpl
23452347
}
23462348
Reference? procedureReference;
23472349
Reference? tearOffReference;
2348-
IndexedContainer? indexedContainer =
2349-
_indexedContainer ?? _sourceLibraryBuilder.indexedLibrary;
2350+
IndexedContainer? indexedContainer = _indexedContainer ?? indexedLibrary;
23502351

23512352
bool isAugmentation = isAugmenting && (modifiers & augmentMask) != 0;
23522353
if (indexedContainer != null && !isAugmentation) {
@@ -2490,11 +2491,10 @@ class SourceCompilationUnitImpl
24902491
isInstanceMember: isInstanceMember,
24912492
containerName: containerName,
24922493
containerType: containerType,
2493-
libraryName: _sourceLibraryBuilder.indexedLibrary != null
2494-
? new LibraryName(_sourceLibraryBuilder.indexedLibrary!.reference)
2494+
libraryName: indexedLibrary != null
2495+
? new LibraryName(indexedLibrary!.reference)
24952496
: libraryName);
2496-
IndexedContainer? indexedContainer =
2497-
_indexedContainer ?? _sourceLibraryBuilder.indexedLibrary;
2497+
IndexedContainer? indexedContainer = _indexedContainer ?? indexedLibrary;
24982498
if (indexedContainer != null) {
24992499
if ((isExtensionMember || isExtensionTypeMember) &&
25002500
isInstanceMember &&

pkg/front_end/lib/src/source/source_library_builder.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
200200
final LibraryBuilder? _nameOrigin;
201201

202202
/// Index of the library we use references for.
203-
// TODO(johnniwinther): Move this to [SourceCompilationUnitImpl].
204-
final IndexedLibrary? indexedLibrary;
203+
IndexedLibrary? get indexedLibrary => compilationUnit.indexedLibrary;
205204

206205
/// Exports that can't be serialized.
207206
///
@@ -285,7 +284,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
285284
SourceLibraryBuilder? origin,
286285
this.library,
287286
this._nameOrigin,
288-
this.indexedLibrary,
287+
IndexedLibrary? indexedLibrary,
289288
{required this.isUnsupported,
290289
required bool isAugmentation,
291290
required bool isPatch,
@@ -317,7 +316,8 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
317316
this, libraryTypeParameterScopeBuilder,
318317
importUri: importUri,
319318
fileUri: fileUri,
320-
packageLanguageVersion: packageLanguageVersion);
319+
packageLanguageVersion: packageLanguageVersion,
320+
indexedLibrary: indexedLibrary);
321321
}
322322

323323
MergedLibraryScope get mergedScope {
@@ -427,6 +427,9 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
427427
@override
428428
bool get isPart => compilationUnit.isPart;
429429

430+
@override
431+
List<Export> get exporters => compilationUnit.exporters;
432+
430433
@override
431434
// Coverage-ignore(suite): Not run.
432435
Iterator<T> fullMemberIterator<T extends Builder>() =>

0 commit comments

Comments
 (0)