Skip to content

Commit c58e180

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Remove FragmentImpl.reference
Change-Id: If586b6f365770c752b7e6c3bd2ae39cd8bf394f7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435601 Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 7973eac commit c58e180

File tree

9 files changed

+34
-162
lines changed

9 files changed

+34
-162
lines changed

pkg/analysis_server/test/services/refactoring/agnostic/change_method_signature_test.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,7 @@ class AbstractChangeMethodSignatureTest extends AbstractContextTest {
116116

117117
String _elementToReferenceString(Element element) {
118118
var enclosingElement = element.enclosingElement;
119-
var reference = switch (element) {
120-
ElementImpl() =>
121-
element.reference ?? (element.firstFragment as FragmentImpl).reference,
122-
_ => null,
123-
};
119+
var reference = (element as ElementImpl).reference;
124120
if (reference != null) {
125121
return _referenceToString(reference);
126122
} else if (element is FormalParameterElement) {

pkg/analyzer/lib/src/dart/analysis/driver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ testFineAfterLibraryAnalyzerHook;
110110
// TODO(scheglov): Clean up the list of implicitly analyzed files.
111111
class AnalysisDriver {
112112
/// The version of data format, should be incremented on every format change.
113-
static const int DATA_VERSION = 476;
113+
static const int DATA_VERSION = 477;
114114

115115
/// The number of exception contexts allowed to write. Once this field is
116116
/// zero, we stop writing any new exception contexts in this process.

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,8 +1206,7 @@ mixin ConstVariableFragment implements FragmentImpl, ConstantEvaluationTarget {
12061206
if (library == null) {
12071207
throw StateError(
12081208
'[library: null][this: ($runtimeType) $this]'
1209-
'[enclosingElement: $enclosingElement3]'
1210-
'[reference: $reference]',
1209+
'[enclosingElement: $enclosingElement3]',
12111210
);
12121211
}
12131212
computeConstants(
@@ -2445,7 +2444,7 @@ abstract class ExecutableFragmentImpl extends _ExistingFragmentImpl
24452444

24462445
/// Initialize a newly created executable element to have the given [name] and
24472446
/// [offset].
2448-
ExecutableFragmentImpl({required super.nameOffset, super.reference});
2447+
ExecutableFragmentImpl({required super.nameOffset});
24492448

24502449
@override
24512450
List<Fragment> get children3 => [...typeParameters, ...parameters];
@@ -2710,14 +2709,6 @@ class ExtensionFragmentImpl extends InstanceFragmentImpl
27102709
return element.extendedType;
27112710
}
27122711

2713-
@override
2714-
String get identifier {
2715-
if (reference != null) {
2716-
return reference!.name;
2717-
}
2718-
return super.identifier;
2719-
}
2720-
27212712
@override
27222713
bool get isPrivate {
27232714
var name = name2;
@@ -3868,8 +3859,6 @@ abstract class FragmentImpl implements FragmentOrMember {
38683859
/// is the defining unit of the library.
38693860
FragmentImpl? enclosingElement3;
38703861

3871-
Reference? reference;
3872-
38733862
/// The offset of the name of this element in the file that contains the
38743863
/// declaration of this element.
38753864
int _nameOffset = 0;
@@ -3889,10 +3878,7 @@ abstract class FragmentImpl implements FragmentOrMember {
38893878

38903879
/// Initialize a newly created element to have the given [name] at the given
38913880
/// [_nameOffset].
3892-
FragmentImpl({required int nameOffset, this.reference})
3893-
: _nameOffset = nameOffset {
3894-
reference?.element = this;
3895-
}
3881+
FragmentImpl({required int nameOffset}) : _nameOffset = nameOffset;
38963882

38973883
/// The length of the element's code, or `null` if the element is synthetic.
38983884
int? get codeLength => _codeLength;
@@ -4558,8 +4544,7 @@ class GetterFragmentImpl extends PropertyAccessorFragmentImpl
45584544

45594545
GetterFragmentImpl({required super.name2, required super.nameOffset});
45604546

4561-
GetterFragmentImpl.forVariable(super.variable, {super.reference})
4562-
: super.forVariable();
4547+
GetterFragmentImpl.forVariable(super.variable) : super.forVariable();
45634548

45644549
@override
45654550
PropertyAccessorFragmentImpl? get correspondingGetter => null;
@@ -7054,14 +7039,10 @@ class LibraryImportImpl extends ElementDirectiveImpl implements LibraryImport {
70547039

70557040
/// The provider for the lazily created `loadLibrary` function.
70567041
final class LoadLibraryFunctionProvider {
7057-
final Reference fragmentReference;
70587042
final Reference elementReference;
70597043
TopLevelFunctionElementImpl? _element;
70607044

7061-
LoadLibraryFunctionProvider({
7062-
required this.fragmentReference,
7063-
required this.elementReference,
7064-
});
7045+
LoadLibraryFunctionProvider({required this.elementReference});
70657046

70667047
TopLevelFunctionElementImpl getElement(LibraryElementImpl library) {
70677048
return _element ??= _create(library);
@@ -7076,9 +7057,6 @@ final class LoadLibraryFunctionProvider {
70767057
fragment.returnType = library.typeProvider.futureDynamicType;
70777058
fragment.enclosingElement3 = library.definingCompilationUnit;
70787059

7079-
fragment.reference = fragmentReference;
7080-
fragmentReference.element = fragment;
7081-
70827060
return TopLevelFunctionElementImpl(elementReference, fragment)
70837061
..returnType = library.typeProvider.futureDynamicType;
70847062
}
@@ -8967,10 +8945,9 @@ sealed class PropertyAccessorFragmentImpl extends ExecutableFragmentImpl
89678945
/// Initialize a newly created synthetic property accessor element to be
89688946
/// associated with the given [variable].
89698947
PropertyAccessorFragmentImpl.forVariable(
8970-
PropertyInducingFragmentImpl variable, {
8971-
super.reference,
8972-
}) : name2 = variable.name2,
8973-
super(nameOffset: -1) {
8948+
PropertyInducingFragmentImpl variable,
8949+
) : name2 = variable.name2,
8950+
super(nameOffset: -1) {
89748951
isAbstract = variable is FieldFragmentImpl && variable.isAbstract;
89758952
isStatic = variable.isStatic;
89768953
isSynthetic = true;
@@ -9057,12 +9034,8 @@ sealed class PropertyAccessorFragmentImpl extends ExecutableFragmentImpl
90579034
/// Implicit getter for a [PropertyInducingFragmentImpl].
90589035
class PropertyAccessorFragmentImplImplicitGetter extends GetterFragmentImpl {
90599036
/// Create the implicit getter and bind it to the [property].
9060-
PropertyAccessorFragmentImplImplicitGetter(
9061-
super.property, {
9062-
Reference? reference,
9063-
}) : super.forVariable(reference: reference) {
9064-
reference?.element = this;
9065-
}
9037+
PropertyAccessorFragmentImplImplicitGetter(super.property)
9038+
: super.forVariable();
90669039

90679040
@override
90689041
FragmentImpl get enclosingElement3 {
@@ -9123,7 +9096,7 @@ class PropertyAccessorFragmentImplImplicitGetter extends GetterFragmentImpl {
91239096
/// Implicit setter for a [PropertyInducingFragmentImpl].
91249097
class PropertyAccessorFragmentImplImplicitSetter extends SetterFragmentImpl {
91259098
/// Create the implicit setter and bind it to the [property].
9126-
PropertyAccessorFragmentImplImplicitSetter(super.property, {super.reference})
9099+
PropertyAccessorFragmentImplImplicitSetter(super.property)
91279100
: super.forVariable();
91289101

91299102
@override
@@ -9442,11 +9415,6 @@ abstract class PropertyInducingFragmentImpl
94429415
}
94439416
}
94449417
}
9445-
9446-
void bindReference(Reference reference) {
9447-
this.reference = reference;
9448-
reference.element = this;
9449-
}
94509418
}
94519419

94529420
/// Common base class for all analyzer-internal classes that implement
@@ -9565,8 +9533,7 @@ class SetterFragmentImpl extends PropertyAccessorFragmentImpl
95659533

95669534
SetterFragmentImpl({required super.name2, required super.nameOffset});
95679535

9568-
SetterFragmentImpl.forVariable(super.variable, {super.reference})
9569-
: super.forVariable();
9536+
SetterFragmentImpl.forVariable(super.variable) : super.forVariable();
95709537

95719538
@override
95729539
PropertyAccessorFragmentImpl? get correspondingGetter => variable2?.getter;
@@ -10899,7 +10866,7 @@ mixin WrappedElementMixin implements ElementImpl {
1089910866

1090010867
abstract class _ExistingFragmentImpl extends FragmentImpl
1090110868
with _HasLibraryMixin {
10902-
_ExistingFragmentImpl({required super.nameOffset, super.reference});
10869+
_ExistingFragmentImpl({required super.nameOffset});
1090310870
}
1090410871

1090510872
/// An element that can be declared in multiple fragments.

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ class LibraryReader {
166166
_libraryElement.manifest = manifest;
167167

168168
_libraryElement.loadLibraryProvider = LoadLibraryFunctionProvider(
169-
fragmentReference: _readReference(),
170169
elementReference: _readReference(),
171170
);
172171

@@ -1073,7 +1072,6 @@ class LibraryReader {
10731072
var isDefault = _reader.readBool();
10741073
var isInitializingFormal = _reader.readBool();
10751074
var isSuperFormal = _reader.readBool();
1076-
var reference = _readOptionalReference();
10771075

10781076
var kindIndex = _reader.readByte();
10791077
var kind = ResolutionReader._formalParameterKind(kindIndex);
@@ -1125,10 +1123,6 @@ class LibraryReader {
11251123
parameterKind: kind,
11261124
);
11271125
}
1128-
if (reference != null) {
1129-
element.reference = reference;
1130-
reference.element = element;
1131-
}
11321126
}
11331127
idFragmentMap[id] = element;
11341128
ParameterElementFlags.read(_reader, element);

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,6 @@ class BundleWriter {
546546

547547
void _writeLoadLibraryFunctionReferences(LibraryElementImpl library) {
548548
var element = library.loadLibraryFunction2;
549-
_writeReference2(element.firstFragment.reference);
550549
_writeReference2(element.reference);
551550
}
552551

@@ -653,7 +652,6 @@ class BundleWriter {
653652
_sink.writeBool(element is ConstVariableFragment);
654653
_sink.writeBool(element.isInitializingFormal);
655654
_sink.writeBool(element.isSuperFormal);
656-
_writeOptionalReference(element.reference);
657655
_sink._writeFormalParameterKind(element);
658656
ParameterElementFlags.write(_sink, element);
659657

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

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,6 @@ class FragmentBuilder extends ThrowingAstVisitor<void> {
13741374
var functionExpression = node.functionExpression;
13751375
var body = functionExpression.body;
13761376

1377-
Reference reference;
13781377
ExecutableFragmentImpl executableFragment;
13791378
if (node.isGetter) {
13801379
var getterFragment = GetterFragmentImpl(
@@ -1385,7 +1384,6 @@ class FragmentBuilder extends ThrowingAstVisitor<void> {
13851384
getterFragment.isAugmentation = node.augmentKeyword != null;
13861385
getterFragment.isStatic = true;
13871386

1388-
reference = Reference.root(); // TODO(scheglov): remove this
13891387
getterFragment.enclosingElement3 = _unitElement;
13901388
executableFragment = getterFragment;
13911389

@@ -1400,7 +1398,6 @@ class FragmentBuilder extends ThrowingAstVisitor<void> {
14001398
setterFragment.isAugmentation = node.augmentKeyword != null;
14011399
setterFragment.isStatic = true;
14021400

1403-
reference = Reference.root(); // TODO(scheglov): remove this
14041401
setterFragment.enclosingElement3 = _unitElement;
14051402
executableFragment = setterFragment;
14061403

@@ -1416,7 +1413,7 @@ class FragmentBuilder extends ThrowingAstVisitor<void> {
14161413
fragment.isStatic = true;
14171414
executableFragment = fragment;
14181415

1419-
reference = _enclosingContext.addFunction(name, fragment);
1416+
_enclosingContext.addFunction(name, fragment);
14201417

14211418
fragment.enclosingElement3 = _unitElement;
14221419
_libraryBuilder.addTopFragment(fragment);
@@ -1434,7 +1431,7 @@ class FragmentBuilder extends ThrowingAstVisitor<void> {
14341431
_linker.elementNodes[executableFragment] = node;
14351432

14361433
_buildExecutableElementChildren(
1437-
reference: reference,
1434+
reference: Reference.root(), // TODO(scheglov): remove this
14381435
fragment: executableFragment,
14391436
formalParameters: functionExpression.parameters,
14401437
typeParameters: functionExpression.typeParameters,
@@ -2240,10 +2237,6 @@ class _EnclosingContext {
22402237
return _fields.toFixedList();
22412238
}
22422239

2243-
Reference get fragmentReference {
2244-
return fragment.reference!;
2245-
}
2246-
22472240
List<TopLevelFunctionFragmentImpl> get functions {
22482241
return _functions.toFixedList();
22492242
}
@@ -2335,11 +2328,8 @@ class _EnclosingContext {
23352328
_bindReference(reference, element);
23362329
}
23372330

2338-
Reference addFunction(String name, TopLevelFunctionFragmentImpl element) {
2331+
void addFunction(String name, TopLevelFunctionFragmentImpl element) {
23392332
_functions.add(element);
2340-
var containerName =
2341-
element.isAugmentation ? '@functionAugmentation' : '@function';
2342-
return _addReference(containerName, name, element);
23432333
}
23442334

23452335
Reference addGetter(String name, PropertyAccessorFragmentImpl element) {
@@ -2363,15 +2353,8 @@ class _EnclosingContext {
23632353
return _addReference(containerName, name, element);
23642354
}
23652355

2366-
Reference? addParameter(String? name, FormalParameterFragmentImpl element) {
2356+
void addParameter(String? name, FormalParameterFragmentImpl element) {
23672357
_parameters.add(element);
2368-
if (name == null) {
2369-
return null;
2370-
}
2371-
if (fragment.reference == null) {
2372-
return null;
2373-
}
2374-
return _addReference('@parameter', name, element);
23752358
}
23762359

23772360
void addPropertyAccessorSynthetic(PropertyAccessorFragmentImpl element) {
@@ -2385,16 +2368,8 @@ class _EnclosingContext {
23852368
return _addReference(containerName, name, element);
23862369
}
23872370

2388-
Reference addTopLevelVariable(
2389-
String name,
2390-
TopLevelVariableFragmentImpl element,
2391-
) {
2371+
void addTopLevelVariable(String name, TopLevelVariableFragmentImpl element) {
23922372
_topLevelVariables.add(element);
2393-
var containerName =
2394-
element.isAugmentation
2395-
? '@topLevelVariableAugmentation'
2396-
: '@topLevelVariable';
2397-
return _addReference(containerName, name, element);
23982373
}
23992374

24002375
void addTopLevelVariableSynthetic(
@@ -2422,15 +2397,12 @@ class _EnclosingContext {
24222397
String name,
24232398
FragmentImpl element,
24242399
) {
2425-
var containerRef = fragmentReference.getChild(containerName);
2426-
var reference = containerRef.addChild(name);
2427-
_bindReference(reference, element);
2428-
return reference;
2400+
// TODO(scheglov): remove this method
2401+
throw StateError('Should not be used');
24292402
}
24302403

24312404
void _bindReference(Reference reference, FragmentImpl fragment) {
2432-
reference.element = fragment;
2433-
fragment.reference = reference;
2434-
this.fragment.encloseElement(fragment);
2405+
// TODO(scheglov): remove this method
2406+
throw StateError('Should not be used');
24352407
}
24362408
}

0 commit comments

Comments
 (0)