Skip to content

Commit 96c4e4c

Browse files
natebiggsCommit Queue
authored and
Commit Queue
committed
[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 <[email protected]> Commit-Queue: Nate Biggs <[email protected]>
1 parent e3e7ca8 commit 96c4e4c

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

pkg/dart2wasm/lib/code_generator.dart

+5-4
Original file line numberDiff line numberDiff line change
@@ -2001,9 +2001,10 @@ abstract class AstCodeGenerator
20012001
w.ValueType visitStaticSet(StaticSet node, w.ValueType expectedType) {
20022002
bool preserved = expectedType != voidMarker;
20032003
Member target = node.target;
2004-
w.ValueType paramType = target is Field
2005-
? translator.globals.getGlobalForStaticField(target).type.type
2006-
: translator.signatureForDirectCall(target.reference).inputs.single;
2004+
final reference =
2005+
target is Field ? target.setterReference! : target.reference;
2006+
w.ValueType paramType =
2007+
translator.signatureForDirectCall(reference).inputs.single;
20072008
translateExpression(node.value, paramType);
20082009
if (!preserved) {
20092010
call(node.targetReference);
@@ -2012,7 +2013,7 @@ abstract class AstCodeGenerator
20122013
w.Local temp = addLocal(paramType);
20132014
b.local_tee(temp);
20142015

2015-
call(node.targetReference);
2016+
call(reference);
20162017
b.local_get(temp);
20172018
return temp.type;
20182019
}

pkg/dart2wasm/lib/functions.dart

+3-4
Original file line numberDiff line numberDiff line change
@@ -478,12 +478,11 @@ w.FunctionType _makeFunctionType(
478478
final isGetter = target.isImplicitGetter;
479479
final isSetter = target.isImplicitSetter;
480480
if (isGetter || isSetter) {
481-
final global = translator.globals.getGlobalForStaticField(member);
482-
final globalType = global.type.type;
481+
final fieldType = translator.translateTypeOfField(member);
483482
if (isGetter) {
484-
return translator.typesBuilder.defineFunction(const [], [globalType]);
483+
return translator.typesBuilder.defineFunction(const [], [fieldType]);
485484
}
486-
return translator.typesBuilder.defineFunction([globalType], const []);
485+
return translator.typesBuilder.defineFunction([fieldType], const []);
487486
}
488487
}
489488

0 commit comments

Comments
 (0)