[dart2wasm] Use field type instead of global type for static field type.
The calls to 'getGlobalForStaticField' eagerly generate the initializer constant for the associated field. In both these cases we don't need that just to get the type of the field. Instead we can use 'translateTypeOfField' directly (same as 'getGlobalForStaticField').
This also removes unnecessary nullness from the type when the field is lazily instantiated. The global type may be nullable even if the field type isn't.
Change-Id: Id369e07335fc5350524a1b8b6c04f19dd94f8b8a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401280
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
diff --git a/pkg/dart2wasm/lib/code_generator.dart b/pkg/dart2wasm/lib/code_generator.dart
index b15b5f0..bdea89f 100644
--- a/pkg/dart2wasm/lib/code_generator.dart
+++ b/pkg/dart2wasm/lib/code_generator.dart
@@ -2001,9 +2001,10 @@
w.ValueType visitStaticSet(StaticSet node, w.ValueType expectedType) {
bool preserved = expectedType != voidMarker;
Member target = node.target;
- w.ValueType paramType = target is Field
- ? translator.globals.getGlobalForStaticField(target).type.type
- : translator.signatureForDirectCall(target.reference).inputs.single;
+ final reference =
+ target is Field ? target.setterReference! : target.reference;
+ w.ValueType paramType =
+ translator.signatureForDirectCall(reference).inputs.single;
translateExpression(node.value, paramType);
if (!preserved) {
call(node.targetReference);
@@ -2012,7 +2013,7 @@
w.Local temp = addLocal(paramType);
b.local_tee(temp);
- call(node.targetReference);
+ call(reference);
b.local_get(temp);
return temp.type;
}
diff --git a/pkg/dart2wasm/lib/functions.dart b/pkg/dart2wasm/lib/functions.dart
index 4b93afc..bcc96f5 100644
--- a/pkg/dart2wasm/lib/functions.dart
+++ b/pkg/dart2wasm/lib/functions.dart
@@ -478,12 +478,11 @@
final isGetter = target.isImplicitGetter;
final isSetter = target.isImplicitSetter;
if (isGetter || isSetter) {
- final global = translator.globals.getGlobalForStaticField(member);
- final globalType = global.type.type;
+ final fieldType = translator.translateTypeOfField(member);
if (isGetter) {
- return translator.typesBuilder.defineFunction(const [], [globalType]);
+ return translator.typesBuilder.defineFunction(const [], [fieldType]);
}
- return translator.typesBuilder.defineFunction([globalType], const []);
+ return translator.typesBuilder.defineFunction([fieldType], const []);
}
}