Description
Backends such as dart2wasm assume that if TFA assigns a callCount
of 0
to a selector then all calls to that selector were devirtualized at the call site by emitting direct call metadata.
This is generally true, but TFA has an exception for list accesses on list constants, see summary_collector.dart
@override
TypeExpr visitInstanceInvocation(InstanceInvocation node) {
final receiverNode = node.receiver;
final receiver = _visit(receiverNode);
final args = _visitArguments(receiver, node.arguments);
final target = node.interfaceTarget;
if (receiverNode is ConstantExpression && node.name.text == '[]') {
Constant constant = receiverNode.constant;
if (constant is ListConstant) {
return _handleIndexingIntoListConstant(constant);
}
}
...
... _makeCall() ... - which populates `callSites[node] = Call(...)` ...
...
}
=> This makes summary collector not create a Call
object and not add an entry to callSites[node]
.
=> This in return will make TFADevirtualization.getDirectCall
not find the call site and not create DirectCallMetadata
=> Then we may end up having selector.callCount==0
for the []
selector but a call site that didn't get devirtualized information.
Of course backends could specialize this case, but I think it would be better for TFA to maintain the invariant that either all call sites have direct call metadata or the selector has callCount > 0
.
Side note: It also seems strange to have this special case for list constants, but not for other composites e.g. map/... constants