Skip to content

Commit cfe7c54

Browse files
authored
[jspi] Remove module splitting changes. (#8529)
Emscripten has changed to use the regular way of splitting with a Proxy and no longer needs this. emscripten-core/emscripten#26396 Fixes #8424
1 parent 3c4012f commit cfe7c54

8 files changed

Lines changed: 2 additions & 198 deletions

File tree

src/ir/module-splitting.cpp

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
// from the IR before splitting.
7474
//
7575
#include "ir/module-splitting.h"
76-
#include "asmjs/shared-constants.h"
7776
#include "ir/export-utils.h"
7877
#include "ir/find_all.h"
7978
#include "ir/module-utils.h"
@@ -87,8 +86,6 @@ namespace wasm::ModuleSplitting {
8786

8887
namespace {
8988

90-
static const Name LOAD_SECONDARY_STATUS = "load_secondary_module_status";
91-
9289
template<class F> void forEachElement(Module& module, F f) {
9390
ModuleUtils::iterActiveElementSegments(module, [&](ElementSegment* segment) {
9491
Name base = "";
@@ -328,12 +325,10 @@ struct ModuleSplitter {
328325

329326
// Other helpers
330327
void exportImportFunction(Name func, const std::set<Module*>& modules);
331-
Expression* maybeLoadSecondary(Builder& builder, Expression* callIndirect);
332328
Name getTrampoline(Name funcName);
333329

334330
// Main splitting steps
335331
void classifyFunctions();
336-
void setupJSPI();
337332
void moveSecondaryFunctions();
338333
void thunkExportedSecondaryFunctions();
339334
void indirectReferencesToSecondaryFunctions();
@@ -346,9 +341,6 @@ struct ModuleSplitter {
346341
: config(config), primary(primary), tableManager(primary),
347342
exportedPrimaryFuncs(initExportedPrimaryFuncs(primary)) {
348343
classifyFunctions();
349-
if (config.jspi) {
350-
setupJSPI();
351-
}
352344
moveSecondaryFunctions();
353345
thunkExportedSecondaryFunctions();
354346
indirectReferencesToSecondaryFunctions();
@@ -359,25 +351,6 @@ struct ModuleSplitter {
359351
}
360352
};
361353

362-
void ModuleSplitter::setupJSPI() {
363-
// Add an imported function to load the secondary module.
364-
auto import = Builder::makeFunction(
365-
ModuleSplitting::LOAD_SECONDARY_MODULE,
366-
Type(Signature(Type::none, Type::none), NonNullable, Inexact),
367-
{});
368-
import->module = ENV;
369-
import->base = ModuleSplitting::LOAD_SECONDARY_MODULE;
370-
primary.addFunction(std::move(import));
371-
Builder builder(primary);
372-
// Add a global to track whether the secondary module has been loaded yet.
373-
primary.addGlobal(builder.makeGlobal(LOAD_SECONDARY_STATUS,
374-
Type::i32,
375-
builder.makeConst(int32_t(0)),
376-
Builder::Mutable));
377-
primary.addExport(builder.makeExport(
378-
LOAD_SECONDARY_STATUS, LOAD_SECONDARY_STATUS, ExternalKind::Global));
379-
}
380-
381354
std::unique_ptr<Module> ModuleSplitter::initSecondary(const Module& primary) {
382355
// Create the secondary module and copy trivial properties.
383356
auto secondary = std::make_unique<Module>();
@@ -449,12 +422,7 @@ void ModuleSplitter::classifyFunctions() {
449422
configSecondaryFuncs.insert(funcs.begin(), funcs.end());
450423
}
451424
for (auto& func : primary.functions) {
452-
// In JSPI mode exported functions cannot be moved to the secondary
453-
// module since that would make them async when they may not have the JSPI
454-
// wrapper. Exported JSPI functions can still benefit from splitting though
455-
// since only the JSPI wrapper stub will remain in the primary module.
456425
if (func->imported() || !configSecondaryFuncs.count(func->name) ||
457-
(config.jspi && ExportUtils::isExported(primary, *func)) ||
458426
segmentReferrers.count(func->name)) {
459427
primaryFuncs.insert(func->name);
460428
} else {
@@ -571,20 +539,6 @@ void ModuleSplitter::thunkExportedSecondaryFunctions() {
571539
}
572540
}
573541

574-
Expression* ModuleSplitter::maybeLoadSecondary(Builder& builder,
575-
Expression* callIndirect) {
576-
if (!config.jspi) {
577-
return callIndirect;
578-
}
579-
// Check if the secondary module is loaded and if it isn't, call the
580-
// function to load it.
581-
auto* loadSecondary = builder.makeIf(
582-
builder.makeUnary(EqZInt32,
583-
builder.makeGlobalGet(LOAD_SECONDARY_STATUS, Type::i32)),
584-
builder.makeCall(ModuleSplitting::LOAD_SECONDARY_MODULE, {}, Type::none));
585-
return builder.makeSequence(loadSecondary, callIndirect);
586-
}
587-
588542
// Helper to walk expressions in segments but NOT in globals.
589543
template<typename Walker>
590544
static void walkSegments(Walker& walker, Module* module) {
@@ -720,13 +674,12 @@ void ModuleSplitter::indirectCallsToSecondaryFunctions() {
720674
auto tableSlot =
721675
parent.tableManager.getSlot(curr->target, func->type.getHeapType());
722676

723-
replaceCurrent(parent.maybeLoadSecondary(
724-
builder,
677+
replaceCurrent(
725678
builder.makeCallIndirect(tableSlot.tableName,
726679
tableSlot.makeExpr(parent.primary),
727680
curr->operands,
728681
func->type.getHeapType(),
729-
curr->isReturn)));
682+
curr->isReturn));
730683
}
731684
};
732685
CallIndirector callIndirector(*this);

src/ir/module-splitting.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848

4949
namespace wasm::ModuleSplitting {
5050

51-
static const Name LOAD_SECONDARY_MODULE("__load_secondary_module");
52-
5351
struct Config {
5452
// A vector of set of functions to split into that secondary. Each function
5553
// set belongs to a single secondary module. All others are kept in the
@@ -77,9 +75,6 @@ struct Config {
7775
// false, the original function names will be used (after `newExportPrefix`)
7876
// as the new export names.
7977
bool minimizeNewExportNames = false;
80-
// When JSPI support is enabled the secondary module loading is handled by an
81-
// imported function.
82-
bool jspi = false;
8378
};
8479

8580
struct Results {

src/tools/wasm-split/split-options.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,6 @@ WasmSplitOptions::WasmSplitOptions()
256256
[&](Options* o, const std::string& argument) {
257257
placeholderNamespacePrefix = argument;
258258
})
259-
.add("--jspi",
260-
"",
261-
"Transform the module to support asynchronously loading the secondary "
262-
"module before any placeholder functions have been called.",
263-
WasmSplitOption,
264-
{Mode::Split},
265-
Options::Arguments::Zero,
266-
[&](Options* o, const std::string& argument) { jspi = true; })
267259
.add(
268260
"--export-prefix",
269261
"",

src/tools/wasm-split/split-options.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ struct WasmSplitOptions : ToolOptions {
5050
bool emitBinary = true;
5151
bool symbolMap = false;
5252
bool placeholderMap = false;
53-
bool jspi = false;
5453
bool stripDebug = false;
5554

5655
// TODO: Remove this. See the comment in wasm-binary.h.

src/tools/wasm-split/wasm-split.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,6 @@ void splitModule(const WasmSplitOptions& options) {
308308
std::cerr << "warning: not keeping any functions in the primary module\n";
309309
}
310310

311-
if (options.jspi) {
312-
// The load secondary module function must be kept in the main module.
313-
keepFuncs.insert(ModuleSplitting::LOAD_SECONDARY_MODULE);
314-
splitFuncs.erase(ModuleSplitting::LOAD_SECONDARY_MODULE);
315-
}
316-
317311
// If warnings are enabled, check that any functions are being split out.
318312
if (!options.quiet && splitFuncs.size() == 0) {
319313
std::cerr
@@ -352,7 +346,6 @@ void splitModule(const WasmSplitOptions& options) {
352346
setCommonSplitConfigs(config, options);
353347
config.secondaryFuncs.push_back(std::move(splitFuncs));
354348
config.secondaryNames.push_back("deferred");
355-
config.jspi = options.jspi;
356349
auto splitResults = ModuleSplitting::splitFunctions(wasm, config);
357350
auto& secondary = *splitResults.secondaries.begin();
358351

test/lit/help/wasm-split.test

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@
9494
;; CHECK-NEXT: --placeholder-namespace [split, multi-split] The same as
9595
;; CHECK-NEXT: --placeholder-namespace-prefix.
9696
;; CHECK-NEXT:
97-
;; CHECK-NEXT: --jspi [split] Transform the module to support
98-
;; CHECK-NEXT: asynchronously loading the secondary
99-
;; CHECK-NEXT: module before any placeholder functions
100-
;; CHECK-NEXT: have been called.
101-
;; CHECK-NEXT:
10297
;; CHECK-NEXT: --export-prefix [split, multi-split] An identifying
10398
;; CHECK-NEXT: prefix to prepend to new export names
10499
;; CHECK-NEXT: created by module splitting.

test/lit/wasm-split/jspi-secondary-export.wast

Lines changed: 0 additions & 59 deletions
This file was deleted.

test/lit/wasm-split/jspi.wast

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)