Skip to content

Conversation

@stevenfontanella
Copy link
Member

@stevenfontanella stevenfontanella commented Jan 11, 2026

Part of #8180. We currently replicate the existing behavior. In the future, we can also change ctor-eval to really simulate tables, and only use the EvallingRuntimeTable in the case of table imports. Removes existing pointer chasing logic that we repeat for each table operation (e.g. tableLoad, tableStore).

Allows us to fix spec tests where a table import becomes valid by resizing it in #8222.

@stevenfontanella stevenfontanella marked this pull request as ready for review January 21, 2026 01:37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure all the new files have the copyright header.

virtual const Table* tableMeta() const = 0;
};

class RealRuntimeTable : public RuntimeTable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer renaming RuntimeTable to RuntimeTableBase so we can name this one RuntimeTable.

Comment on lines -307 to -311
// Apply a reasonable limit on table size, 1GB, to avoid DOS on the
// interpreter.
if (newSize > 1024 * 1024 * 1024) {
return false;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably carry this over to the new implementation.

// of this instance and other instances.
std::map<Name, Literals*> allGlobals;

std::map<Name, RuntimeTable*> allTables;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason these maps need to be ordered?

Comment on lines +127 to +128
// wasm spec only allows const and global.get there
WASM_UNREACHABLE("invalid expr type");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer true. Let's add // TODO: Handle extended consts.

Comment on lines +119 to +121
// look in the proper range. if it instead gets a global, we rely on the
// fact that when not dynamically linking then the table is loaded at
// offset 0.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very Emscripten-specific assumption. Let's add a TODO to make this safer, perhaps by adding an opt-in Emscripten mode.

Comment on lines +137 to +138
// No segment had a value for this.
return Literal::makeNull(HeapTypes::func);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a TODO to handle non-function tables.

return table.initial;
}

virtual const Table* tableMeta() const override { return &table; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to move this part into the base class? I can't imagine we would ever want to override this to do anything but return a pointer to an underlying Table.


private:
Table table;
const bool& instanceInitialized;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why take a reference to a bool rather than just copying it in?

Comment on lines +182 to +188
[this, &instanceInitialized](Literal initial, Table table) {
return std::make_unique<EvallingRuntimeTable>(
table,
instanceInitialized,
this->wasm,
[this](Name name, Type type) { return makeFuncData(name, type); });
}) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😱

Is there a plan for avoiding callback hell here? It seems like pairing subclasses of ModuleRunnerBase with subclasses of RuntimeTable et. al. so that they all know about each other would let us avoid this indirection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants