Skip to content

Commit dcd410e

Browse files
chloestefantsovaCommit Queue
authored andcommitted
[analyzer][cfe] Remove TypeStructure variable from shared classes
Part of #54902 Change-Id: Ia70f2afd321e9b4a4762b6ed860611dee1399d87 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404622 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Chloe Stefantsova <[email protected]>
1 parent e8fdee8 commit dcd410e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1658
-2238
lines changed

pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5336,7 +5336,7 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
53365336
required Type knownType,
53375337
bool matchFailsIfWrongType = true,
53385338
bool matchMayFailEvenIfCorrectType = false}) {
5339-
if (knownType is SharedInvalidTypeStructure) {
5339+
if (knownType is SharedInvalidType) {
53405340
_unmatched = _join(_unmatched!, _current);
53415341
return false;
53425342
}

pkg/_fe_analyzer_shared/lib/src/type_inference/shared_inference_log.dart

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,7 @@ class GenericInferenceState<TypeParameter extends Object> extends State {
121121
/// This class defines methods that the analyzer or CFE can use to instrument
122122
/// their type inference logic. The implementations are found in
123123
/// [SharedInferenceLogWriterImpl].
124-
abstract interface class SharedInferenceLogWriter<
125-
TypeStructure extends SharedTypeStructure<TypeStructure>,
126-
Type extends SharedTypeStructure<Type>,
127-
TypeParameterStructure extends SharedTypeParameterStructure<
128-
TypeStructure>> {
124+
abstract interface class SharedInferenceLogWriter {
129125
/// If [inProgress] is `true`, verifies that generic type inference is in
130126
/// progress; otherwise, verifies that generic type inference is not in
131127
/// progress.
@@ -150,18 +146,18 @@ abstract interface class SharedInferenceLogWriter<
150146

151147
/// Called when generic type inference starts collecting constraints by
152148
/// attempting to match one type schema against another.
153-
void enterConstraintGeneration(
154-
ConstraintGenerationSource source, Type p, Type q);
149+
void enterConstraintGeneration(ConstraintGenerationSource source,
150+
covariant SharedType p, covariant SharedType q);
155151

156152
/// Called when type inference begins inferring a collection element.
157153
void enterElement(Object node);
158154

159155
/// Called when type inference begins inferring an expression.
160-
void enterExpression(Object node, Type contextType);
156+
void enterExpression(Object node, covariant SharedType contextType);
161157

162158
/// Called when type inference begins inferring an AST node associated with
163159
/// extension override syntax.
164-
void enterExtensionOverride(Object node, Type contextType);
160+
void enterExtensionOverride(Object node, covariant SharedType contextType);
165161

166162
/// Called when type inference has discovered that a construct that uses
167163
/// method invocation syntax (e.g. `x.f()`) is actually an invocation of a
@@ -172,7 +168,7 @@ abstract interface class SharedInferenceLogWriter<
172168

173169
/// Called when generic type inference begins.
174170
void enterGenericInference(
175-
List<TypeParameterStructure> typeFormals, Type template);
171+
List<SharedTypeParameter> typeFormals, covariant SharedType template);
176172

177173
/// Called when type inference begins inferring the left hand side of an
178174
/// assignment.
@@ -202,7 +198,9 @@ abstract interface class SharedInferenceLogWriter<
202198

203199
/// Called when generic type inference ends.
204200
void exitGenericInference(
205-
{bool aborted = false, bool failed = false, List<Type>? finalTypes});
201+
{bool aborted = false,
202+
bool failed = false,
203+
covariant List<SharedType>? finalTypes});
206204

207205
/// Called when type inference has finished inferring the left hand side of an
208206
/// assignment.
@@ -236,26 +234,23 @@ abstract interface class SharedInferenceLogWriter<
236234

237235
/// Records a constraint that was generated during the process of matching one
238236
/// type schema to another.
239-
void recordGeneratedConstraint(
240-
TypeParameterStructure parameter,
241-
MergedTypeConstraint<TypeStructure, TypeParameterStructure, Object, Type,
242-
Object>
243-
constraint);
237+
void recordGeneratedConstraint(SharedTypeParameter parameter,
238+
MergedTypeConstraint<Object, SharedType, Object> constraint);
244239

245240
/// Records that type inference has resolved a method name.
246241
void recordLookupResult(
247242
{required Object expression,
248-
required Type type,
243+
required SharedType type,
249244
required Object? target,
250245
required String methodName});
251246

252247
/// Records the preliminary types chosen during either a downwards or a
253248
/// horizontal inference step.
254-
void recordPreliminaryTypes(List<Type> types);
249+
void recordPreliminaryTypes(List<SharedType> types);
255250

256251
/// Called when type inference is inferring an expression, and assigns the
257252
/// expression a static type.
258-
void recordStaticType(Object expression, Type type);
253+
void recordStaticType(Object expression, SharedType type);
259254
}
260255

261256
/// Implementation of the interface log writer.
@@ -267,13 +262,8 @@ abstract interface class SharedInferenceLogWriter<
267262
/// from classes derived from [SharedInferenceLogWriterImpl], but these methods
268263
/// are not exposed in [SharedInferenceLogWriter] so that they won't be called
269264
/// accidentally on their own.
270-
abstract class SharedInferenceLogWriterImpl<
271-
TypeStructure extends SharedTypeStructure<TypeStructure>,
272-
Type extends SharedTypeStructure<Type>,
273-
TypeParameterStructure extends SharedTypeParameterStructure<
274-
TypeStructure>>
275-
implements
276-
SharedInferenceLogWriter<TypeStructure, Type, TypeParameterStructure> {
265+
abstract class SharedInferenceLogWriterImpl
266+
implements SharedInferenceLogWriter {
277267
/// A stack of [State] objects representing the calls that have been made to
278268
/// `enter...` methods without any matched `exit...` method.
279269
///
@@ -403,7 +393,7 @@ abstract class SharedInferenceLogWriterImpl<
403393

404394
@override
405395
void enterConstraintGeneration(
406-
ConstraintGenerationSource source, Type p, Type q) {
396+
ConstraintGenerationSource source, SharedType p, SharedType q) {
407397
checkCall(
408398
method: 'enterConstraintGeneration',
409399
arguments: [source, p, q],
@@ -425,15 +415,15 @@ abstract class SharedInferenceLogWriterImpl<
425415
}
426416

427417
@override
428-
void enterExpression(Object node, Type contextType) {
418+
void enterExpression(Object node, SharedType contextType) {
429419
pushState(new ExpressionState(
430420
writer: this,
431421
message: 'INFER EXPRESSION ${describe(node)} IN CONTEXT $contextType',
432422
nodeSet: [node]));
433423
}
434424

435425
@override
436-
void enterExtensionOverride(Object node, Type contextType) {
426+
void enterExtensionOverride(Object node, SharedType contextType) {
437427
pushState(new State(
438428
kind: StateKind.extensionOverride,
439429
writer: this,
@@ -452,13 +442,12 @@ abstract class SharedInferenceLogWriterImpl<
452442

453443
@override
454444
void enterGenericInference(
455-
List<TypeParameterStructure> typeFormals, Type template) {
445+
List<SharedTypeParameter> typeFormals, SharedType template) {
456446
if (state.kind == StateKind.genericInference) {
457447
fail('Tried to start generic inference when already in progress');
458448
}
459449
String typeFormalNames = [
460-
for (TypeParameterStructure typeFormal in typeFormals)
461-
typeFormal.displayName
450+
for (SharedTypeParameter typeFormal in typeFormals) typeFormal.displayName
462451
].join(', ');
463452
pushState(new GenericInferenceState(
464453
writer: this,
@@ -548,7 +537,9 @@ abstract class SharedInferenceLogWriterImpl<
548537

549538
@override
550539
void exitGenericInference(
551-
{bool aborted = false, bool failed = false, List<Type>? finalTypes}) {
540+
{bool aborted = false,
541+
bool failed = false,
542+
List<SharedType>? finalTypes}) {
552543
if ((aborted ? 1 : 0) + (failed ? 1 : 0) + (finalTypes != null ? 1 : 0) !=
553544
1) {
554545
fail('Must specify exactly one of aborted=true, failed=true, '
@@ -677,11 +668,8 @@ abstract class SharedInferenceLogWriterImpl<
677668
}
678669

679670
@override
680-
void recordGeneratedConstraint(
681-
TypeParameterStructure parameter,
682-
MergedTypeConstraint<TypeStructure, TypeParameterStructure, Object, Type,
683-
Object>
684-
constraint) {
671+
void recordGeneratedConstraint(SharedTypeParameter parameter,
672+
MergedTypeConstraint<Object, SharedType, Object> constraint) {
685673
checkCall(
686674
method: 'recordGeneratedConstraint',
687675
arguments: [parameter, constraint],
@@ -694,7 +682,7 @@ abstract class SharedInferenceLogWriterImpl<
694682
@override
695683
void recordLookupResult(
696684
{required Object expression,
697-
required Type type,
685+
required SharedType type,
698686
required Object? target,
699687
required String methodName}) {
700688
checkCall(
@@ -713,7 +701,7 @@ abstract class SharedInferenceLogWriterImpl<
713701
}
714702

715703
@override
716-
void recordPreliminaryTypes(List<Type> types) {
704+
void recordPreliminaryTypes(List<SharedType> types) {
717705
checkCall(
718706
method: 'recordPreliminaryTypes',
719707
arguments: [types],
@@ -727,7 +715,7 @@ abstract class SharedInferenceLogWriterImpl<
727715
}
728716

729717
@override
730-
void recordStaticType(Object expression, Type type) {
718+
void recordStaticType(Object expression, SharedType type) {
731719
checkCall(
732720
method: 'recordStaticType',
733721
arguments: [expression, type],

0 commit comments

Comments
 (0)