From 892e6a8b53f7312bd007e2614ac7534521e472d9 Mon Sep 17 00:00:00 2001 From: Martin Kustermann Date: Wed, 10 Jun 2026 15:59:53 -0700 Subject: [PATCH] [dart2wasm] Pass on @pragma('wasm:prefer-inline') to wasm-opt Now that we have a way to tell binaryen to inline functions (see [0], which added support for `(@binaryen.inline <0...127>)` annotations) we can tell it to inline functions that were annotated with `@pragma('wasm:prefer-inline')` Since binaryen sometimes can devirtualize call sites that TFA cannot, it can then inline those devirtualized calls. [0] https://github.com/WebAssembly/binaryen/issues/7972 Change-Id: I139bd43976a1ddb83afe756d4fbac09419f7199e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/510822 Reviewed-by: Srujan Gaddam Commit-Queue: Martin Kustermann --- pkg/dart2wasm/lib/functions.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/dart2wasm/lib/functions.dart b/pkg/dart2wasm/lib/functions.dart index 9614c4b97e9..cb85cf473ed 100644 --- a/pkg/dart2wasm/lib/functions.dart +++ b/pkg/dart2wasm/lib/functions.dart @@ -112,6 +112,10 @@ class FunctionCollector { (target == member.reference || target.isBodyReference); } + final bool alwaysInline = + util.getWasmPreferInlinePragma(translator.coreTypes, member) ?? false; + final int? inlineHint = neverInline ? 0 : (alwaysInline ? 127 : null); + // If this function is a `@pragma('wasm:import', '.')` we // import the function and return it. if (member.reference == target && member.annotations.isNotEmpty) { @@ -137,7 +141,7 @@ class FunctionCollector { "$importName (import)", ) ..isPure = hasPureAnnotation - ..inlineHint = neverInline ? 0 : null; + ..inlineHint = inlineHint; } } @@ -166,7 +170,7 @@ class FunctionCollector { final function = module.functions.define(ftype, getFunctionName(target)) ..isPure = hasPureAnnotation && !target.isCheckedEntryReference - ..inlineHint = neverInline ? 0 : null; + ..inlineHint = inlineHint; if (exportName != null) { // Add weak exports to the module as we now know they're used. Strong // exports have already been added.