Remove neutral unit global type cache

This commit is contained in:
udo
2026-07-16 19:31:06 +00:00
parent 8737f2747e
commit 91074ccec9
+7 -9
View File
@@ -658,9 +658,7 @@ class WasmWorker
public: public:
WasmWorkerConfig cfg; WasmWorkerConfig cfg;
explicit WasmWorker(WasmWorkerConfig config) : cfg(std::move(config)), engine(make_engine()), explicit WasmWorker(WasmWorkerConfig config) : cfg(std::move(config)), engine(make_engine())
unit_base_global_type(wasmtime::ValType::i32(), false),
unit_got_global_type(wasmtime::ValType::i32(), true)
{ {
} }
@@ -740,8 +738,6 @@ public:
} }
wasmtime::Engine engine; wasmtime::Engine engine;
wasmtime::GlobalType unit_base_global_type;
wasmtime::GlobalType unit_got_global_type;
std::optional<wasmtime::Module> core_module; std::optional<wasmtime::Module> core_module;
WasmDylinkInfo core_dylink; WasmDylinkInfo core_dylink;
@@ -1381,6 +1377,8 @@ private:
imports.reserve(mod->imports.size()); imports.reserve(mod->imports.size());
std::vector<std::pair<String, wasmtime::Global>> deferred_got; std::vector<std::pair<String, wasmtime::Global>> deferred_got;
deferred_got.reserve(mod->got_memory_imports); deferred_got.reserve(mod->got_memory_imports);
wasmtime::GlobalType base_global_type(wasmtime::ValType::i32(), false);
wasmtime::GlobalType got_global_type(wasmtime::ValType::i32(), true);
for(const auto& import : mod->imports) for(const auto& import : mod->imports)
{ {
const String& name = import.name; const String& name = import.name;
@@ -1405,7 +1403,7 @@ private:
if(import.kind == WasmUnitImportKind::MemoryBase || import.kind == WasmUnitImportKind::TableBase) if(import.kind == WasmUnitImportKind::MemoryBase || import.kind == WasmUnitImportKind::TableBase)
{ {
int32_t value = import.kind == WasmUnitImportKind::MemoryBase ? (int32_t)memory_base : (int32_t)table_base; int32_t value = import.kind == WasmUnitImportKind::MemoryBase ? (int32_t)memory_base : (int32_t)table_base;
auto global = wasmtime::Global::create(cx, worker.unit_base_global_type, wasmtime::Val(value)); auto global = wasmtime::Global::create(cx, base_global_type, wasmtime::Val(value));
if(!global) if(!global)
return("global create failed: " + String(global.err().message())); return("global create failed: " + String(global.err().message()));
imports.push_back(global.ok()); imports.push_back(global.ok());
@@ -1433,7 +1431,7 @@ private:
std::chrono::steady_clock::now() - resolve_start).count(); std::chrono::steady_clock::now() - resolve_start).count();
if(resolved) if(resolved)
{ {
auto global = wasmtime::Global::create(cx, worker.unit_got_global_type, wasmtime::Val((int32_t)address)); auto global = wasmtime::Global::create(cx, got_global_type, wasmtime::Val((int32_t)address));
if(!global) if(!global)
return("global create failed: " + String(global.err().message())); return("global create failed: " + String(global.err().message()));
imports.push_back(global.ok()); imports.push_back(global.ok());
@@ -1442,7 +1440,7 @@ private:
{ {
// provisional; self-resolved from the unit's own export // provisional; self-resolved from the unit's own export
// (plus its memory base) after instantiation // (plus its memory base) after instantiation
auto global = wasmtime::Global::create(cx, worker.unit_got_global_type, wasmtime::Val((int32_t)0)); auto global = wasmtime::Global::create(cx, got_global_type, wasmtime::Val((int32_t)0));
if(!global) if(!global)
return("global create failed: " + String(global.err().message())); return("global create failed: " + String(global.err().message()));
deferred_got.push_back({ name, global.ok() }); deferred_got.push_back({ name, global.ok() });
@@ -1463,7 +1461,7 @@ private:
error = place_funcref(*func, slot); error = place_funcref(*func, slot);
if(error != "") if(error != "")
return(error); return(error);
auto global = wasmtime::Global::create(cx, worker.unit_got_global_type, wasmtime::Val((int32_t)slot)); auto global = wasmtime::Global::create(cx, got_global_type, wasmtime::Val((int32_t)slot));
if(!global) if(!global)
return("global create failed: " + String(global.err().message())); return("global create failed: " + String(global.err().message()));
imports.push_back(global.ok()); imports.push_back(global.ok());