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 =