Skip to content

Commit d4cad0f

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Restore element and typeArguments for typedef-based _FunctionTypeImplStrict.
[email protected] Change-Id: Ibc7fc53aba10661236f0d3f3361bf7f05882cc5e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106162 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 2eebc10 commit d4cad0f

15 files changed

Lines changed: 199 additions & 52 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
9393
/**
9494
* The version of data format, should be incremented on every format change.
9595
*/
96-
static const int DATA_VERSION = 81;
96+
static const int DATA_VERSION = 82;
9797

9898
/**
9999
* The number of exception contexts allowed to write. Once this field is

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

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,12 @@ abstract class FunctionTypeImpl extends TypeImpl implements FunctionType {
568568
factory FunctionTypeImpl.synthetic(DartType returnType,
569569
List<TypeParameterElement> typeFormals, List<ParameterElement> parameters,
570570
{Element element,
571+
List<DartType> typeArguments = const <DartType>[],
571572
NullabilitySuffix nullabilitySuffix = NullabilitySuffix.star}) {
572573
return new _FunctionTypeImplStrict._(returnType, typeFormals, parameters,
573-
element: element, nullabilitySuffix: nullabilitySuffix);
574+
element: element,
575+
typeArguments: typeArguments,
576+
nullabilitySuffix: nullabilitySuffix);
574577
}
575578

576579
FunctionTypeImpl._(Element element, String name, this.nullabilitySuffix)
@@ -3774,14 +3777,28 @@ class _FunctionTypeImplStrict extends FunctionTypeImpl {
37743777
@override
37753778
final List<ParameterElement> parameters;
37763779

3780+
@override
3781+
final List<DartType> typeArguments;
3782+
37773783
_FunctionTypeImplStrict._(this.returnType, this.typeFormals, this.parameters,
37783784
{Element element,
3785+
List<DartType> typeArguments,
37793786
NullabilitySuffix nullabilitySuffix = NullabilitySuffix.star})
3780-
: super._(element, null, nullabilitySuffix);
3787+
: typeArguments = typeArguments ?? const <DartType>[],
3788+
super._(element, null, nullabilitySuffix);
37813789

37823790
@override
37833791
List<TypeParameterElement> get boundTypeParameters => typeFormals;
37843792

3793+
@override
3794+
FunctionTypedElement get element {
3795+
var element = super.element;
3796+
if (element is GenericTypeAliasElement) {
3797+
return element.function;
3798+
}
3799+
return element;
3800+
}
3801+
37853802
@override
37863803
bool get isInstantiated => throw new UnimplementedError('TODO(paulberry)');
37873804

@@ -3803,9 +3820,6 @@ class _FunctionTypeImplStrict extends FunctionTypeImpl {
38033820
@override
38043821
List<FunctionTypeAliasElement> get prunedTypedefs => const [];
38053822

3806-
@override
3807-
List<DartType> get typeArguments => const [] /*TODO(paulberry)*/;
3808-
38093823
@override
38103824
List<TypeParameterElement> get typeParameters => const [] /*TODO(paulberry)*/;
38113825

@@ -3835,7 +3849,6 @@ class _FunctionTypeImplStrict extends FunctionTypeImpl {
38353849
returnType.substitute2(argumentTypes, parameterTypes),
38363850
const [],
38373851
_transformOrShare(parameters, transformParameter),
3838-
element: element,
38393852
nullabilitySuffix: nullabilitySuffix);
38403853
}
38413854

@@ -3894,16 +3907,23 @@ class _FunctionTypeImplStrict extends FunctionTypeImpl {
38943907
identical(parameters, newParameters)) {
38953908
return this;
38963909
}
3910+
3911+
var typeArguments = this.typeArguments.map(transformType).toList();
3912+
38973913
return new _FunctionTypeImplStrict._(
38983914
newReturnType, newTypeFormals, newParameters,
3899-
element: element, nullabilitySuffix: nullabilitySuffix);
3915+
element: element,
3916+
typeArguments: typeArguments,
3917+
nullabilitySuffix: nullabilitySuffix);
39003918
}
39013919

39023920
@override
39033921
TypeImpl withNullability(NullabilitySuffix nullabilitySuffix) {
39043922
if (this.nullabilitySuffix == nullabilitySuffix) return this;
39053923
return _FunctionTypeImplStrict._(returnType, typeFormals, parameters,
3906-
element: element, nullabilitySuffix: nullabilitySuffix);
3924+
element: element,
3925+
typeArguments: typeArguments,
3926+
nullabilitySuffix: nullabilitySuffix);
39073927
}
39083928

39093929
@override

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,12 @@ abstract class _TypeSubstitutor extends DartTypeVisitor<DartType> {
318318
inner.invertVariance();
319319

320320
var returnType = inner.visit(type.returnType);
321+
var typeArguments = type.typeArguments.map(visit).toList();
321322

322323
if (this.useCounter == before) return type;
323324

324325
return FunctionTypeImpl.synthetic(returnType, typeFormals, parameters,
325-
element: type.element);
326+
element: type.element, typeArguments: typeArguments);
326327
}
327328

328329
@override

pkg/analyzer/lib/src/summary/format.dart

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16036,6 +16036,7 @@ class LinkedNodeTypeBuilder extends Object
1603616036
List<LinkedNodeTypeFormalParameterBuilder> _functionFormalParameters;
1603716037
LinkedNodeTypeBuilder _functionReturnType;
1603816038
int _functionTypedef;
16039+
List<LinkedNodeTypeBuilder> _functionTypedefTypeArguments;
1603916040
List<LinkedNodeTypeTypeParameterBuilder> _functionTypeParameters;
1604016041
int _genericTypeAliasReference;
1604116042
List<LinkedNodeTypeBuilder> _genericTypeAliasTypeArguments;
@@ -16071,6 +16072,14 @@ class LinkedNodeTypeBuilder extends Object
1607116072
this._functionTypedef = value;
1607216073
}
1607316074

16075+
@override
16076+
List<LinkedNodeTypeBuilder> get functionTypedefTypeArguments =>
16077+
_functionTypedefTypeArguments ??= <LinkedNodeTypeBuilder>[];
16078+
16079+
set functionTypedefTypeArguments(List<LinkedNodeTypeBuilder> value) {
16080+
this._functionTypedefTypeArguments = value;
16081+
}
16082+
1607416083
@override
1607516084
List<LinkedNodeTypeTypeParameterBuilder> get functionTypeParameters =>
1607616085
_functionTypeParameters ??= <LinkedNodeTypeTypeParameterBuilder>[];
@@ -16147,6 +16156,7 @@ class LinkedNodeTypeBuilder extends Object
1614716156
{List<LinkedNodeTypeFormalParameterBuilder> functionFormalParameters,
1614816157
LinkedNodeTypeBuilder functionReturnType,
1614916158
int functionTypedef,
16159+
List<LinkedNodeTypeBuilder> functionTypedefTypeArguments,
1615016160
List<LinkedNodeTypeTypeParameterBuilder> functionTypeParameters,
1615116161
int genericTypeAliasReference,
1615216162
List<LinkedNodeTypeBuilder> genericTypeAliasTypeArguments,
@@ -16159,6 +16169,7 @@ class LinkedNodeTypeBuilder extends Object
1615916169
: _functionFormalParameters = functionFormalParameters,
1616016170
_functionReturnType = functionReturnType,
1616116171
_functionTypedef = functionTypedef,
16172+
_functionTypedefTypeArguments = functionTypedefTypeArguments,
1616216173
_functionTypeParameters = functionTypeParameters,
1616316174
_genericTypeAliasReference = genericTypeAliasReference,
1616416175
_genericTypeAliasTypeArguments = genericTypeAliasTypeArguments,
@@ -16173,6 +16184,7 @@ class LinkedNodeTypeBuilder extends Object
1617316184
void flushInformative() {
1617416185
_functionFormalParameters?.forEach((b) => b.flushInformative());
1617516186
_functionReturnType?.flushInformative();
16187+
_functionTypedefTypeArguments?.forEach((b) => b.flushInformative());
1617616188
_functionTypeParameters?.forEach((b) => b.flushInformative());
1617716189
_genericTypeAliasTypeArguments?.forEach((b) => b.flushInformative());
1617816190
_interfaceTypeArguments?.forEach((b) => b.flushInformative());
@@ -16222,11 +16234,20 @@ class LinkedNodeTypeBuilder extends Object
1622216234
signature.addInt(
1622316235
this._nullabilitySuffix == null ? 0 : this._nullabilitySuffix.index);
1622416236
signature.addInt(this._functionTypedef ?? 0);
16237+
if (this._functionTypedefTypeArguments == null) {
16238+
signature.addInt(0);
16239+
} else {
16240+
signature.addInt(this._functionTypedefTypeArguments.length);
16241+
for (var x in this._functionTypedefTypeArguments) {
16242+
x?.collectApiSignature(signature);
16243+
}
16244+
}
1622516245
}
1622616246

1622716247
fb.Offset finish(fb.Builder fbBuilder) {
1622816248
fb.Offset offset_functionFormalParameters;
1622916249
fb.Offset offset_functionReturnType;
16250+
fb.Offset offset_functionTypedefTypeArguments;
1623016251
fb.Offset offset_functionTypeParameters;
1623116252
fb.Offset offset_genericTypeAliasTypeArguments;
1623216253
fb.Offset offset_interfaceTypeArguments;
@@ -16238,6 +16259,13 @@ class LinkedNodeTypeBuilder extends Object
1623816259
if (_functionReturnType != null) {
1623916260
offset_functionReturnType = _functionReturnType.finish(fbBuilder);
1624016261
}
16262+
if (!(_functionTypedefTypeArguments == null ||
16263+
_functionTypedefTypeArguments.isEmpty)) {
16264+
offset_functionTypedefTypeArguments = fbBuilder.writeList(
16265+
_functionTypedefTypeArguments
16266+
.map((b) => b.finish(fbBuilder))
16267+
.toList());
16268+
}
1624116269
if (!(_functionTypeParameters == null || _functionTypeParameters.isEmpty)) {
1624216270
offset_functionTypeParameters = fbBuilder.writeList(
1624316271
_functionTypeParameters.map((b) => b.finish(fbBuilder)).toList());
@@ -16263,6 +16291,9 @@ class LinkedNodeTypeBuilder extends Object
1626316291
if (_functionTypedef != null && _functionTypedef != 0) {
1626416292
fbBuilder.addUint32(11, _functionTypedef);
1626516293
}
16294+
if (offset_functionTypedefTypeArguments != null) {
16295+
fbBuilder.addOffset(12, offset_functionTypedefTypeArguments);
16296+
}
1626616297
if (offset_functionTypeParameters != null) {
1626716298
fbBuilder.addOffset(2, offset_functionTypeParameters);
1626816299
}
@@ -16314,6 +16345,7 @@ class _LinkedNodeTypeImpl extends Object
1631416345
List<idl.LinkedNodeTypeFormalParameter> _functionFormalParameters;
1631516346
idl.LinkedNodeType _functionReturnType;
1631616347
int _functionTypedef;
16348+
List<idl.LinkedNodeType> _functionTypedefTypeArguments;
1631716349
List<idl.LinkedNodeTypeTypeParameter> _functionTypeParameters;
1631816350
int _genericTypeAliasReference;
1631916351
List<idl.LinkedNodeType> _genericTypeAliasTypeArguments;
@@ -16348,6 +16380,14 @@ class _LinkedNodeTypeImpl extends Object
1634816380
return _functionTypedef;
1634916381
}
1635016382

16383+
@override
16384+
List<idl.LinkedNodeType> get functionTypedefTypeArguments {
16385+
_functionTypedefTypeArguments ??=
16386+
const fb.ListReader<idl.LinkedNodeType>(const _LinkedNodeTypeReader())
16387+
.vTableGet(_bc, _bcOffset, 12, const <idl.LinkedNodeType>[]);
16388+
return _functionTypedefTypeArguments;
16389+
}
16390+
1635116391
@override
1635216392
List<idl.LinkedNodeTypeTypeParameter> get functionTypeParameters {
1635316393
_functionTypeParameters ??=
@@ -16426,6 +16466,10 @@ abstract class _LinkedNodeTypeMixin implements idl.LinkedNodeType {
1642616466
if (functionReturnType != null)
1642716467
_result["functionReturnType"] = functionReturnType.toJson();
1642816468
if (functionTypedef != 0) _result["functionTypedef"] = functionTypedef;
16469+
if (functionTypedefTypeArguments.isNotEmpty)
16470+
_result["functionTypedefTypeArguments"] = functionTypedefTypeArguments
16471+
.map((_value) => _value.toJson())
16472+
.toList();
1642916473
if (functionTypeParameters.isNotEmpty)
1643016474
_result["functionTypeParameters"] =
1643116475
functionTypeParameters.map((_value) => _value.toJson()).toList();
@@ -16454,6 +16498,7 @@ abstract class _LinkedNodeTypeMixin implements idl.LinkedNodeType {
1645416498
"functionFormalParameters": functionFormalParameters,
1645516499
"functionReturnType": functionReturnType,
1645616500
"functionTypedef": functionTypedef,
16501+
"functionTypedefTypeArguments": functionTypedefTypeArguments,
1645716502
"functionTypeParameters": functionTypeParameters,
1645816503
"genericTypeAliasReference": genericTypeAliasReference,
1645916504
"genericTypeAliasTypeArguments": genericTypeAliasTypeArguments,

pkg/analyzer/lib/src/summary/format.fbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,6 +1999,8 @@ table LinkedNodeType {
19991999
/// The typedef this function type is created for.
20002000
functionTypedef:uint (id: 11);
20012001

2002+
functionTypedefTypeArguments:[LinkedNodeType] (id: 12);
2003+
20022004
functionTypeParameters:[LinkedNodeTypeTypeParameter] (id: 2);
20032005

20042006
genericTypeAliasReference:uint (id: 8);

pkg/analyzer/lib/src/summary/idl.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,9 @@ abstract class LinkedNodeType extends base.SummaryClass {
19071907
@Id(11)
19081908
int get functionTypedef;
19091909

1910+
@Id(12)
1911+
List<LinkedNodeType> get functionTypedefTypeArguments;
1912+
19101913
@Id(2)
19111914
List<LinkedNodeTypeTypeParameter> get functionTypeParameters;
19121915

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,6 @@ class AstBinaryReader {
831831
question:
832832
AstBinaryFlags.hasQuestion(data.flags) ? _Tokens.QUESTION : null,
833833
);
834-
node.type = _readType(data.genericFunctionType_type);
835834

836835
// Create the node element, so now type parameter elements are available.
837836
LazyAst.setGenericFunctionTypeId(node, id);
@@ -849,6 +848,7 @@ class AstBinaryReader {
849848
}
850849
node.returnType = readNode(data.genericFunctionType_returnType);
851850
node.parameters = _readNode(data.genericFunctionType_formalParameters);
851+
node.type = _readType(data.genericFunctionType_type);
852852

853853
return node;
854854
}

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -890,24 +890,21 @@ class LinkedUnitContext {
890890
_typeParameters.remove(--_nextSyntheticTypeParameterId);
891891
}
892892

893-
var element = bundleContext.elementOfIndex(linkedType.functionTypedef);
894-
if (element is GenericTypeAliasElementImpl) {
895-
GenericTypeAliasElementImpl aliasElement = element;
896-
if (getHasTypedefSelfReference(aliasElement.linkedNode)) {
897-
element = null;
898-
} else {
899-
element = aliasElement.function;
900-
}
901-
}
902-
903893
var nullabilitySuffix = _nullabilitySuffix(linkedType.nullabilitySuffix);
904894

895+
GenericTypeAliasElement typedefElement;
896+
List<DartType> typedefTypeArguments = const <DartType>[];
897+
if (linkedType.functionTypedef != 0) {
898+
typedefElement =
899+
bundleContext.elementOfIndex(linkedType.functionTypedef);
900+
typedefTypeArguments =
901+
linkedType.functionTypedefTypeArguments.map(readType).toList();
902+
}
903+
905904
return FunctionTypeImpl.synthetic(
906-
returnType,
907-
typeParameters,
908-
formalParameters,
909-
element: element,
910-
).withNullability(nullabilitySuffix);
905+
returnType, typeParameters, formalParameters,
906+
element: typedefElement, typeArguments: typedefTypeArguments)
907+
.withNullability(nullabilitySuffix);
911908
} else if (kind == LinkedNodeTypeKind.interface) {
912909
var element = bundleContext.elementOfIndex(linkedType.interfaceClass);
913910
var nullabilitySuffix = _nullabilitySuffix(linkedType.nullabilitySuffix);

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,17 @@ class LinkingBundleContext {
167167
typeParameterBuilders[i].bound = writeType(typeParameter.bound);
168168
}
169169

170-
GenericTypeAliasElement typeAliasElement;
171-
{
172-
var element = type.element;
173-
if (element is GenericTypeAliasElement) {
174-
typeAliasElement = element;
175-
} else if (element?.enclosingElement is GenericTypeAliasElement) {
176-
typeAliasElement = element.enclosingElement;
177-
}
170+
Element typedefElement;
171+
List<DartType> typedefTypeArguments = const <DartType>[];
172+
if (type.element is GenericTypeAliasElement) {
173+
typedefElement = type.element;
174+
typedefTypeArguments = type.typeArguments;
175+
}
176+
// TODO(scheglov) Cleanup to always use GenericTypeAliasElement.
177+
if (type.element is GenericFunctionTypeElement &&
178+
type.element.enclosingElement is GenericTypeAliasElement) {
179+
typedefElement = type.element.enclosingElement;
180+
typedefTypeArguments = type.typeArguments;
178181
}
179182

180183
var result = LinkedNodeTypeBuilder(
@@ -188,7 +191,9 @@ class LinkingBundleContext {
188191
.toList(),
189192
functionReturnType: writeType(type.returnType),
190193
functionTypeParameters: typeParameterBuilders,
191-
functionTypedef: indexOfElement(typeAliasElement),
194+
functionTypedef: indexOfElement(typedefElement),
195+
functionTypedefTypeArguments:
196+
typedefTypeArguments.map(writeType).toList(),
192197
nullabilitySuffix: _nullabilitySuffix(type),
193198
);
194199

0 commit comments

Comments
 (0)