Skip to content

Commit a93219a

Browse files
committed
[dart2js] Generate empty method bodies for external effect members.
The new @pragma('external-effect') causes the removal of invocations, including arguments, of any annotated member. This means the codegen builder shouldn't see any calls to these methods. In a normal dart2js compilation this would mean we don't try to build bodies for the members. However, when running codegen in sharded mode, we have to be more conservative and assume another shard may need the member. Therefore one shard will still try to generate these methods. We can just emit an empty member as the linker will exclude the unused method from the final JS code. Change-Id: I28a82267f692f6a4921fe3b5207a7284f3fc8e0a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/500001 Reviewed-by: Stephen Adams <sra@google.com>
1 parent 470f6e9 commit a93219a

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

pkg/compiler/lib/src/ssa/builder.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,11 +2051,19 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault<void>
20512051
if (_buildSpecialRuntimeEqualsMethod(function, functionNode)) return;
20522052
}
20532053

2054-
// `external` functions in `dart:_foreign_helper` are queued for compilation
2055-
// in a modular or staged compile, so just generate an empty function. The
2056-
// actual call sites for these methods are recognized and replaced, so the
2057-
// method generated here is never called.
2058-
if (_commonElements.isForeignHelper(function)) {
2054+
final member = _elementMap.getMemberContextNode(function);
2055+
2056+
// `external` functions in `dart:_foreign_helper` or annotated with
2057+
// `@pragma('external-effect')` are queued for compilation in a modular or
2058+
// staged compile, so just generate an empty function. The actual call sites
2059+
// for these methods are recognized and replaced, so the method generated
2060+
// here is never called.
2061+
if (_commonElements.isForeignHelper(function) ||
2062+
(member != null &&
2063+
ir.ExternalEffect.isAnnotatedWithExternalEffect(
2064+
member,
2065+
closedWorld.elementMap.coreTypes,
2066+
))) {
20592067
_openFunction(
20602068
function,
20612069
functionNode: functionNode,

0 commit comments

Comments
 (0)