Skip to content

Commit fcddbff

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Remove Reference.element (misnomer now), now FragmentImpl cannot have reference.
Change-Id: I928abfe136bda2bc49884f9ec79a8bcae772ac13 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435446 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent c58e180 commit fcddbff

File tree

6 files changed

+18
-175
lines changed

6 files changed

+18
-175
lines changed

pkg/analyzer/lib/src/summary2/ast_binary_reader.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ class AstBinaryReader {
283283

284284
AugmentedExpression _readAugmentedExpression() {
285285
var node = AugmentedExpressionImpl(augmentedKeyword: Tokens.augmented());
286-
node.fragment = _reader.readFragmentOrMember() as FragmentImpl?;
286+
// TODO(scheglov): restore when the feature is fully specified
287+
// node.fragment = _reader.readFragmentOrMember() as FragmentImpl?;
287288
_readExpressionResolution(node);
288289
return node;
289290
}
@@ -297,7 +298,8 @@ class AstBinaryReader {
297298
typeArguments: typeArguments,
298299
arguments: arguments,
299300
);
300-
node.fragment = _reader.readFragmentOrMember() as ExecutableFragmentImpl?;
301+
// TODO(scheglov): restore when the feature is fully specified
302+
// node.fragment = _reader.readFragmentOrMember() as ExecutableFragmentImpl?;
301303
_readExpressionResolution(node);
302304
return node;
303305
}

pkg/analyzer/lib/src/summary2/ast_binary_writer.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ class AstBinaryWriter extends ThrowingAstVisitor<void> {
9494
@override
9595
void visitAugmentedExpression(covariant AugmentedExpressionImpl node) {
9696
_writeByte(Tag.AugmentedExpression);
97-
_sink.writeFragmentOrMember(node.fragment);
97+
// TODO(scheglov): restore when the feature is fully specified
98+
// _sink.writeFragmentOrMember(node.fragment);
9899
_storeExpression(node);
99100
}
100101

@@ -103,7 +104,8 @@ class AstBinaryWriter extends ThrowingAstVisitor<void> {
103104
_writeByte(Tag.AugmentedInvocation);
104105
_writeOptionalNode(node.typeArguments);
105106
_writeNode(node.arguments);
106-
_sink.writeFragmentOrMember(node.fragment);
107+
// TODO(scheglov): restore when the feature is fully specified
108+
// _sink.writeFragmentOrMember(node.fragment);
107109
_storeExpression(node);
108110
}
109111

pkg/analyzer/lib/src/summary2/bundle_reader.dart

Lines changed: 2 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,40 +1535,15 @@ class ResolutionReader {
15351535

15361536
late LibraryFragmentImpl currentLibraryFragment;
15371537

1538-
/// The stack of [TypeParameterElementImpl]s and [FormalParameterImpl] that
1539-
/// are available in the scope of [readFragmentOrMember] and [readType].
1538+
/// The stack of [TypeParameterElementImpl]s and [FormalParameterElementImpl]s
1539+
/// that are available in the scope of [readElement] and [readType].
15401540
///
15411541
/// This stack is shared with the client of the reader, and update mostly
15421542
/// by the client. However it is also updated during [_readFunctionType].
15431543
final List<ElementImpl> _localElements = [];
15441544

15451545
ResolutionReader(this._elementFactory, this._referenceReader, this._reader);
15461546

1547-
void applyToFormalParameterFragments(
1548-
List<FormalParameterFragmentImpl> parameters,
1549-
) {
1550-
for (var parameter in parameters) {
1551-
parameter.metadata = _readMetadata(unitElement: currentLibraryFragment);
1552-
_readTypeParameters2(
1553-
currentLibraryFragment,
1554-
this,
1555-
parameter.typeParameters,
1556-
);
1557-
applyToFormalParameterFragments(parameter.parameters);
1558-
parameter.type = readRequiredType();
1559-
if (parameter is ConstVariableFragment) {
1560-
var defaultParameter = parameter as ConstVariableFragment;
1561-
var initializer = readOptionalExpression();
1562-
if (initializer != null) {
1563-
defaultParameter.constantInitializer = initializer;
1564-
}
1565-
}
1566-
if (parameter is FieldFormalParameterFragmentImpl) {
1567-
parameter.field = readFragmentOrMember() as FieldFragmentImpl?;
1568-
}
1569-
}
1570-
}
1571-
15721547
LibraryElementImpl libraryOfUri(Uri uri) {
15731548
return _elementFactory.libraryOfUri2(uri);
15741549
}
@@ -1639,44 +1614,6 @@ class ResolutionReader {
16391614
return _reader.readEnum(values);
16401615
}
16411616

1642-
FragmentOrMember? readFragmentOrMember() {
1643-
var memberFlags = _reader.readByte();
1644-
var fragment = _readFragmentImpl();
1645-
1646-
if (fragment == null) {
1647-
return null;
1648-
}
1649-
1650-
if (memberFlags == Tag.RawElement) {
1651-
return fragment;
1652-
}
1653-
1654-
if (memberFlags == Tag.MemberWithTypeArguments) {
1655-
var enclosing = fragment.enclosingElement3 as InstanceFragmentImpl;
1656-
1657-
var firstFragment = enclosing.element.firstFragment;
1658-
var declarationTypeParameters =
1659-
firstFragment.typeParameters.map((tp) => tp.asElement2).toList();
1660-
1661-
var substitution = Substitution.empty;
1662-
var typeArguments = _readTypeList();
1663-
if (typeArguments.isNotEmpty) {
1664-
substitution = Substitution.fromPairs2(
1665-
declarationTypeParameters,
1666-
typeArguments,
1667-
);
1668-
}
1669-
1670-
if (fragment is ExecutableFragmentImpl) {
1671-
return ExecutableMember.from2(fragment, substitution);
1672-
} else {
1673-
fragment as FieldFragmentImpl;
1674-
return FieldMember.from2(fragment, substitution);
1675-
}
1676-
}
1677-
1678-
throw UnimplementedError('memberFlags: $memberFlags');
1679-
}
16801617

16811618
Map<K, V> readMap<K, V>({
16821619
required K Function() readKey,
@@ -1960,20 +1897,6 @@ class ResolutionReader {
19601897
});
19611898
}
19621899

1963-
FragmentImpl? _readFragmentImpl() {
1964-
var index = _reader.readUInt30();
1965-
1966-
if ((index & 0x1) == 0x1) {
1967-
// TODO(scheglov): remove?
1968-
throw UnimplementedError();
1969-
}
1970-
1971-
var referenceIndex = index >> 1;
1972-
var reference = _referenceReader.referenceOfIndex(referenceIndex);
1973-
1974-
return _elementFactory.elementOfReference(reference);
1975-
}
1976-
19771900
String? _readFragmentName() {
19781901
return _reader.readOptionalStringReference();
19791902
}
@@ -2091,19 +2014,6 @@ class ResolutionReader {
20912014
return typeParameters;
20922015
}
20932016

2094-
void _readTypeParameters2(
2095-
LibraryFragmentImpl unitElement,
2096-
ResolutionReader reader,
2097-
List<TypeParameterFragmentImpl> typeParameters,
2098-
) {
2099-
reader._addTypeParameters(typeParameters);
2100-
for (var typeParameter in typeParameters) {
2101-
typeParameter.metadata = reader._readMetadata(unitElement: unitElement);
2102-
typeParameter.bound = reader.readType();
2103-
typeParameter.defaultType = reader.readType();
2104-
}
2105-
}
2106-
21072017
static ParameterKind _formalParameterKind(int encoding) {
21082018
if (encoding == Tag.ParameterKindRequiredPositional) {
21092019
return ParameterKind.REQUIRED;

pkg/analyzer/lib/src/summary2/bundle_writer.dart

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -997,29 +997,6 @@ class ResolutionSink extends _SummaryDataWriter {
997997
}
998998
}
999999

1000-
// TODO(scheglov): Triage places where we write elements.
1001-
// Some of then cannot be members, e.g. type names.
1002-
void writeFragmentOrMember(FragmentOrMember? element) {
1003-
if (element == null) {
1004-
writeByte(Tag.RawElement);
1005-
writeUInt30(0);
1006-
} else if (element is Member) {
1007-
var declaration = element.declaration;
1008-
1009-
var typeArguments = _enclosingClassTypeArguments(
1010-
declaration.asElement2!,
1011-
element.substitution.map,
1012-
);
1013-
1014-
writeByte(Tag.MemberWithTypeArguments);
1015-
_writeFragmentImpl(declaration);
1016-
_writeTypeList(typeArguments);
1017-
} else {
1018-
writeByte(Tag.RawElement);
1019-
_writeFragmentImpl(element as FragmentImpl);
1020-
}
1021-
}
1022-
10231000
void writeOptionalTypeList(List<DartType>? types) {
10241001
if (types != null) {
10251002
writeBool(true);
@@ -1128,13 +1105,6 @@ class ResolutionSink extends _SummaryDataWriter {
11281105
}
11291106
}
11301107

1131-
void _writeFragmentImpl(FragmentImpl element) {
1132-
// TODO(scheglov): remove?
1133-
throw UnimplementedError();
1134-
// var elementIndex = _indexOfElement(element);
1135-
// writeUInt30(elementIndex);
1136-
}
1137-
11381108
void _writeFragmentName(Fragment fragment) {
11391109
_writeOptionalStringReference(fragment.name2);
11401110
}

pkg/analyzer/lib/src/summary2/linked_element_factory.dart

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import 'package:analyzer/src/fine/library_manifest.dart';
1414
import 'package:analyzer/src/summary2/bundle_reader.dart';
1515
import 'package:analyzer/src/summary2/export.dart';
1616
import 'package:analyzer/src/summary2/reference.dart';
17-
import 'package:analyzer/src/utilities/extensions/element.dart';
1817
import 'package:analyzer/src/utilities/uri_cache.dart';
1918
import 'package:meta/meta.dart';
2019

@@ -155,37 +154,10 @@ class LinkedElementFactory {
155154

156155
void dispose() {
157156
for (var libraryReference in rootReference.children) {
158-
_disposeLibrary(libraryReference.element);
157+
_disposeLibrary(libraryReference.element2);
159158
}
160159
}
161160

162-
// TODO(scheglov): Why would this method return `null`?
163-
FragmentImpl? elementOfReference(Reference reference) {
164-
if (reference.element case var element?) {
165-
return element;
166-
}
167-
if (reference.parent == null) {
168-
return null;
169-
}
170-
171-
if (reference.isLibrary) {
172-
var uri = uriCache.parse(reference.name);
173-
createLibraryElementForReading(uri);
174-
return null;
175-
}
176-
177-
var element = reference.element;
178-
if (element == null) {
179-
throw StateError('Expected existing element: $reference');
180-
}
181-
return element;
182-
}
183-
184-
// TODO(scheglov): Why would this method return `null`?
185-
Element? elementOfReference2(Reference reference) {
186-
return elementOfReference(reference)?.asElement2;
187-
}
188-
189161
Element elementOfReference3(Reference reference) {
190162
if (reference.element2 case var element?) {
191163
return element;
@@ -214,15 +186,6 @@ class LinkedElementFactory {
214186
return element;
215187
}
216188

217-
bool hasLibrary(Uri uri) {
218-
// We already have the element, linked or read.
219-
if (rootReference['$uri']?.element is LibraryElementImpl) {
220-
return true;
221-
}
222-
// No element yet, but we know how to read it.
223-
return _libraryReaders[uri] != null;
224-
}
225-
226189
LibraryElementImpl? libraryOfUri(Uri uri) {
227190
var reference = rootReference.getChild('$uri');
228191
if (reference.element2 case LibraryElementImpl element) {
@@ -254,7 +217,7 @@ class LinkedElementFactory {
254217
_libraryReaders.remove(uri);
255218
libraryManifests.remove(uri);
256219
var libraryReference = rootReference.removeChild('$uri');
257-
_disposeLibrary(libraryReference?.element);
220+
_disposeLibrary(libraryReference?.element2);
258221
}
259222

260223
analysisSession.classHierarchy.removeOfLibraries(uriSet);
@@ -306,5 +269,5 @@ class LinkedElementFactory {
306269
libraryElement.hasTypeProviderSystemSet = true;
307270
}
308271

309-
void _disposeLibrary(FragmentImpl? libraryElement) {}
272+
void _disposeLibrary(ElementImpl? libraryElement) {}
310273
}

pkg/analyzer/lib/src/summary2/reference.dart

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analyzer/dart/element/element.dart';
65
import 'package:analyzer/src/dart/element/element.dart';
76
import 'package:meta/meta.dart';
87

9-
/// Indirection between a name and the corresponding [FragmentImpl].
8+
/// Indirection between a name and the corresponding [ElementImpl].
109
///
1110
/// References are organized in a prefix tree.
12-
/// Each reference knows its parent, children, and the [FragmentImpl].
11+
/// Each reference knows its parent, children, and the [ElementImpl].
1312
///
1413
/// Library:
1514
/// URI of library
@@ -24,7 +23,7 @@ import 'package:meta/meta.dart';
2423
/// "@method"
2524
/// Name of the method
2625
///
27-
/// There is only one reference object per [FragmentImpl].
26+
/// There is only one reference object per [ElementImpl].
2827
class Reference {
2928
/// The name of the container used for duplicate declarations.
3029
static const _defName = '@def';
@@ -35,11 +34,8 @@ class Reference {
3534
/// The simple name of the reference in its [parent].
3635
String name;
3736

38-
/// The corresponding [FragmentImpl], or `null` if a named container.
39-
FragmentImpl? element;
40-
41-
/// The corresponding [Element], or `null` if a named container.
42-
Element? element2;
37+
/// The corresponding [ElementImpl], or `null` if a named container.
38+
ElementImpl? element2;
4339

4440
/// Temporary index used during serialization and linking.
4541
int? index;

0 commit comments

Comments
 (0)