From 26da655ddfc68ef9502f1ffdb82ccbd6fa0b22ed Mon Sep 17 00:00:00 2001 From: Martin Kustermann Date: Fri, 23 May 2025 05:38:08 -0700 Subject: [PATCH] [dart2wasm] Remove duplicate code to call references MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I304729f6ed19a75de16ddced15b3f47f894e9c49 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/430740 Reviewed-by: Ömer Ağacan Commit-Queue: Martin Kustermann --- pkg/dart2wasm/lib/code_generator.dart | 12 +----------- pkg/dart2wasm/lib/translator.dart | 15 +++++++++------ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/pkg/dart2wasm/lib/code_generator.dart b/pkg/dart2wasm/lib/code_generator.dart index efe3c7b0974..833d0e58101 100644 --- a/pkg/dart2wasm/lib/code_generator.dart +++ b/pkg/dart2wasm/lib/code_generator.dart @@ -689,17 +689,7 @@ abstract class AstCodeGenerator } List call(Reference target) { - final targetModule = translator.moduleForReference(target); - final isLocalModuleCall = targetModule == b.module; - final name = translator.functions.getFunctionName(target); - - if (isLocalModuleCall) { - b.comment('Direct call to $name'); - return b.invoke(translator.directCallTarget(target)); - } else { - b.comment('Direct call to $name (across modules)'); - return translator.callReference(target, b); - } + return translator.callReference(target, b); } @override diff --git a/pkg/dart2wasm/lib/translator.dart b/pkg/dart2wasm/lib/translator.dart index 3b2fb6860c5..cb6d8a1a492 100644 --- a/pkg/dart2wasm/lib/translator.dart +++ b/pkg/dart2wasm/lib/translator.dart @@ -553,16 +553,19 @@ class Translator with KernelNodes { } } - /// Gets the function associated with [reference] and calls its using - /// [callFunction]. + /// Calls the function referred to in [reference] either directly or via a + /// cross-module call. + /// + /// When performing a direct call it may inline the target if allowed and + /// beneficial. List callReference( Reference reference, w.InstructionsBuilder b) { - final function = functions.getFunction(reference); - final targetModule = function.enclosingModule; - if (targetModule == b.module) { + final targetModule = moduleForReference(reference); + final isLocalModuleCall = targetModule == b.module; + if (isLocalModuleCall) { return b.invoke(directCallTarget(reference)); } - return callFunction(function, b); + return callFunction(functions.getFunction(reference), b); } late final WasmFunctionImporter _importedFunctions =