[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>
This commit is contained in:
Nate Biggs
2024-12-17 15:59:28 -08:00
committed by Commit Queue
parent e3e7ca846a
commit 96c4e4c81f
2 changed files with 8 additions and 8 deletions
+5 -4
View File
@@ -2001,9 +2001,10 @@ abstract class AstCodeGenerator
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 @@ abstract class AstCodeGenerator
w.Local temp = addLocal(paramType);
b.local_tee(temp);
call(node.targetReference);
call(reference);
b.local_get(temp);
return temp.type;
}
+3 -4
View File
@@ -478,12 +478,11 @@ w.FunctionType _makeFunctionType(
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 []);
}
}