Skip to content

Commit 8c1fa6d

Browse files
alexmarkovCommit Queue
authored andcommitted
[tfa,aot,dart2wasm] Allow tree-shaking of extension type members independently of their tear-offs
ExtensionTypeMemberDescriptor.memberReference and ExtensionMemberDescriptor.memberReference are now nullable. TFA-based tree shaker can now set them to null when extension type member is not used and removed but corresponding lowered tear-off is still used and retained. Front-end never sets them to null and requires non-null memberReferences when consuming kernel. TEST=pkg/vm/testcases/transformations/type_flow/transformer/regress_flutter155624.dart Fixes flutter/flutter#155624 Change-Id: I71f98c02f4659ff72a8c1d7fc6c578e8b8e26d82 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401382 Reviewed-by: Johnni Winther <[email protected]> Reviewed-by: Slava Egorov <[email protected]> Reviewed-by: Srujan Gaddam <[email protected]> Reviewed-by: Ömer Ağacan <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent 5078a20 commit 8c1fa6d

File tree

21 files changed

+208
-91
lines changed

21 files changed

+208
-91
lines changed

pkg/_js_interop_checks/lib/src/transformations/export_checker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ extension ExtensionMemberDescriptorExtension on ExtensionMemberDescriptor {
250250
bool get isSetter => kind == ExtensionMemberKind.Setter;
251251
bool get isMethod => kind == ExtensionMemberKind.Method;
252252

253-
bool get isExternal => (memberReference.asProcedure).isExternal;
253+
bool get isExternal => (memberReference!.asProcedure).isExternal;
254254
}
255255

256256
extension ProcedureExtension on Procedure {

pkg/_js_interop_checks/lib/src/transformations/js_util_optimizer.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ class ExtensionIndex {
981981
if (_processedExtensionLibraries.contains(library)) return;
982982
for (var extension in library.extensions) {
983983
for (var descriptor in extension.memberDescriptors) {
984-
var reference = descriptor.memberReference;
984+
var reference = descriptor.memberReference!;
985985
var onType = extension.onType;
986986
bool isInteropOnType = false;
987987
Annotatable? cls;
@@ -1127,7 +1127,7 @@ class ExtensionIndex {
11271127
for (var extensionType in library.extensionTypeDeclarations) {
11281128
if (isInteropExtensionType(extensionType)) {
11291129
for (var descriptor in extensionType.memberDescriptors) {
1130-
final reference = descriptor.memberReference;
1130+
final reference = descriptor.memberReference!;
11311131
_extensionTypeMemberIndex[reference] = descriptor;
11321132
_extensionTypeIndex[reference] = extensionType;
11331133
final tearOffReference = descriptor.tearOffReference;

pkg/_js_interop_checks/lib/src/transformations/shared_interop_transformer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ class SharedInteropTransformer extends Transformer {
563563
break;
564564
default:
565565
for (final descriptor in interopTypeDecl.memberDescriptors) {
566-
final descriptorNode = descriptor.memberReference.node;
566+
final descriptorNode = descriptor.memberReference!.node;
567567
if (descriptorNode is Procedure &&
568568
_extensionIndex.isLiteralConstructor(descriptorNode)) {
569569
_diagnosticReporter.report(

pkg/_js_interop_checks/lib/src/transformations/static_interop_mock_validator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class StaticInteropMockValidator {
222222
// setters return their return and parameter types, respectively.
223223
DartType _getTypeOfDescriptor(ExtensionMemberDescriptor interopDescriptor) {
224224
// CFE creates static procedures for each extension member.
225-
var interopMember = interopDescriptor.memberReference.asProcedure;
225+
var interopMember = interopDescriptor.memberReference!.asProcedure;
226226

227227
if (interopDescriptor.isGetter) {
228228
return interopMember.function.returnType;
@@ -365,7 +365,7 @@ class StaticInteropMockValidator {
365365
_descriptorToExtensionName[descriptor] =
366366
extension.isUnnamedExtension ? '<unnamed>' : extension.name;
367367
var name = js_interop.getJSName(
368-
descriptor.memberReference.asMember,
368+
descriptor.memberReference!.asMember,
369369
);
370370
if (name.isEmpty) name = descriptor.name.text;
371371
exportNameToDescriptors!

pkg/dart2wasm/lib/record_class_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class _RecordClassGenerator {
139139
.singleWhere((e) => e.name == 'WasmArrayExt')
140140
.memberDescriptors
141141
.singleWhere((member) => member.name.text == '[]')
142-
.memberReference
142+
.memberReference!
143143
.node as Procedure;
144144

145145
late final Constructor wasmArrayLiteralConstructor =

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ class DillExtensionBuilder extends ExtensionBuilderImpl
4242
switch (descriptor.kind) {
4343
case ExtensionMemberKind.Method:
4444
if (descriptor.isStatic) {
45-
Procedure procedure = descriptor.memberReference.asProcedure;
45+
Procedure procedure = descriptor.memberReference!.asProcedure;
4646
nameSpace.addLocalMember(
4747
name.text,
4848
new DillExtensionStaticMethodBuilder(
4949
procedure, descriptor, libraryBuilder, this),
5050
setter: false);
5151
} else {
52-
Procedure procedure = descriptor.memberReference.asProcedure;
52+
Procedure procedure = descriptor.memberReference!.asProcedure;
5353
Procedure? tearOff = descriptor.tearOffReference?.asProcedure;
5454
assert(tearOff != null, "No tear found for ${descriptor}");
5555
nameSpace.addLocalMember(
@@ -60,31 +60,31 @@ class DillExtensionBuilder extends ExtensionBuilderImpl
6060
}
6161
break;
6262
case ExtensionMemberKind.Getter:
63-
Procedure procedure = descriptor.memberReference.asProcedure;
63+
Procedure procedure = descriptor.memberReference!.asProcedure;
6464
nameSpace.addLocalMember(
6565
name.text,
6666
new DillExtensionGetterBuilder(
6767
procedure, descriptor, libraryBuilder, this),
6868
setter: false);
6969
break;
7070
case ExtensionMemberKind.Field:
71-
Field field = descriptor.memberReference.asField;
71+
Field field = descriptor.memberReference!.asField;
7272
nameSpace.addLocalMember(
7373
name.text,
7474
new DillExtensionFieldBuilder(
7575
field, descriptor, libraryBuilder, this),
7676
setter: false);
7777
break;
7878
case ExtensionMemberKind.Setter:
79-
Procedure procedure = descriptor.memberReference.asProcedure;
79+
Procedure procedure = descriptor.memberReference!.asProcedure;
8080
nameSpace.addLocalMember(
8181
name.text,
8282
new DillExtensionSetterBuilder(
8383
procedure, descriptor, libraryBuilder, this),
8484
setter: true);
8585
break;
8686
case ExtensionMemberKind.Operator:
87-
Procedure procedure = descriptor.memberReference.asProcedure;
87+
Procedure procedure = descriptor.memberReference!.asProcedure;
8888
nameSpace.addLocalMember(
8989
name.text,
9090
new DillExtensionOperatorBuilder(

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ class DillExtensionTypeDeclarationBuilder
7979
switch (descriptor.kind) {
8080
case ExtensionTypeMemberKind.Method:
8181
if (descriptor.isStatic) {
82-
Procedure procedure = descriptor.memberReference.asProcedure;
82+
Procedure procedure = descriptor.memberReference!.asProcedure;
8383
nameSpace.addLocalMember(
8484
name.text,
8585
new DillExtensionTypeStaticMethodBuilder(
8686
procedure, descriptor, libraryBuilder, this),
8787
setter: false);
8888
} else {
89-
Procedure procedure = descriptor.memberReference.asProcedure;
89+
Procedure procedure = descriptor.memberReference!.asProcedure;
9090
Procedure? tearOff = descriptor.tearOffReference?.asProcedure;
9191
assert(tearOff != null, "No tear found for ${descriptor}");
9292
nameSpace.addLocalMember(
@@ -97,39 +97,39 @@ class DillExtensionTypeDeclarationBuilder
9797
}
9898
break;
9999
case ExtensionTypeMemberKind.Getter:
100-
Procedure procedure = descriptor.memberReference.asProcedure;
100+
Procedure procedure = descriptor.memberReference!.asProcedure;
101101
nameSpace.addLocalMember(
102102
name.text,
103103
new DillExtensionTypeGetterBuilder(
104104
procedure, descriptor, libraryBuilder, this),
105105
setter: false);
106106
break;
107107
case ExtensionTypeMemberKind.Field:
108-
Field field = descriptor.memberReference.asField;
108+
Field field = descriptor.memberReference!.asField;
109109
nameSpace.addLocalMember(
110110
name.text,
111111
new DillExtensionTypeFieldBuilder(
112112
field, descriptor, libraryBuilder, this),
113113
setter: false);
114114
break;
115115
case ExtensionTypeMemberKind.Setter:
116-
Procedure procedure = descriptor.memberReference.asProcedure;
116+
Procedure procedure = descriptor.memberReference!.asProcedure;
117117
nameSpace.addLocalMember(
118118
name.text,
119119
new DillExtensionTypeSetterBuilder(
120120
procedure, descriptor, libraryBuilder, this),
121121
setter: true);
122122
break;
123123
case ExtensionTypeMemberKind.Operator:
124-
Procedure procedure = descriptor.memberReference.asProcedure;
124+
Procedure procedure = descriptor.memberReference!.asProcedure;
125125
nameSpace.addLocalMember(
126126
name.text,
127127
new DillExtensionTypeOperatorBuilder(
128128
procedure, descriptor, libraryBuilder, this),
129129
setter: false);
130130
break;
131131
case ExtensionTypeMemberKind.Constructor:
132-
Procedure procedure = descriptor.memberReference.asProcedure;
132+
Procedure procedure = descriptor.memberReference!.asProcedure;
133133
Procedure? tearOff = descriptor.tearOffReference?.asProcedure;
134134
nameSpace.addConstructor(
135135
name.text,
@@ -138,7 +138,7 @@ class DillExtensionTypeDeclarationBuilder
138138
break;
139139
case ExtensionTypeMemberKind.Factory:
140140
case ExtensionTypeMemberKind.RedirectingFactory:
141-
Procedure procedure = descriptor.memberReference.asProcedure;
141+
Procedure procedure = descriptor.memberReference!.asProcedure;
142142
Procedure? tearOff = descriptor.tearOffReference?.asProcedure;
143143
nameSpace.addConstructor(
144144
name.text,

pkg/front_end/lib/src/kernel/exhaustiveness.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class CfeTypeOperations implements TypeOperations<DartType> {
199199
fieldTypes[new NameKey(descriptor.name.text)] =
200200
functionType.returnType;
201201
case ExtensionTypeMemberKind.Getter:
202-
Procedure member = descriptor.memberReference.asProcedure;
202+
Procedure member = descriptor.memberReference!.asProcedure;
203203
FunctionType functionType = member.getterType as FunctionType;
204204
if (extensionTypeDeclaration.typeParameters.isNotEmpty) {
205205
functionType = FunctionTypeInstantiator.instantiate(

pkg/front_end/lib/src/testing/id_testing_utils.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,8 @@ List<String> extensionMethodDescriptorToText(
911911
}
912912

913913
return [
914-
descriptorToText(descriptor.memberReference, forTearOff: false),
914+
if (descriptor.memberReference != null)
915+
descriptorToText(descriptor.memberReference!, forTearOff: false),
915916
if (descriptor.tearOffReference != null)
916917
descriptorToText(descriptor.tearOffReference!, forTearOff: true),
917918
];

pkg/kernel/binary.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ type CanonicalName {
147147

148148
type ComponentFile {
149149
UInt32 magic = 0x90ABCDEF;
150-
UInt32 formatVersion = 121;
150+
UInt32 formatVersion = 122;
151151
Byte[10] shortSdkHash;
152152
List<String> problemsAsJson; // Described in problems.md.
153153
Library[] libraries;
@@ -358,8 +358,8 @@ type ExtensionMemberDescriptor {
358358
Name name;
359359
ExtensionMemberKind kind;
360360
Byte flags (isStatic);
361-
MemberReference member;
362-
MemberReference tearOff;
361+
MemberReference member; // May be NullReference.
362+
MemberReference tearOff; // May be NullReference.
363363
}
364364

365365
type ExtensionTypeDeclaration extends Node {
@@ -384,8 +384,8 @@ type ExtensionTypeMemberDescriptor {
384384
Name name;
385385
ExtensionTypeMemberKind kind;
386386
Byte flags (isStatic);
387-
MemberReference member;
388-
MemberReference tearOff;
387+
MemberReference member; // May be NullReference.
388+
MemberReference tearOff; // May be NullReference.
389389
}
390390

391391
abstract type Member extends Node {}

0 commit comments

Comments
 (0)