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
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.

Copy link
Member Author

@stevenfontanella stevenfontanella Jan 21, 2026

Choose a reason for hiding this comment

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

I wanted to give the interface the more canonical name since code should usually use the interface rather than the concrete implementation. I feel that giving the interface the name RuntimeTableBase is misleading because it implies that it isn't actually a RuntimeTable, and Base sounds like a base class instead of an interface.

I don't mind much either way. Another option is to hide RealRuntimeTable entirely by putting it in a source file and only exposing a factory function that returns unique_ptr<RuntimeTable>. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

I wanted to give the interface the more canonical name since code should usually use the interface rather than the concrete implementation.

Ok, that makes sense 👍

Another option is to hide RealRuntimeTable entirely by putting it in a source file and only exposing a factory function that returns unique_ptr. WDYT?

That sounds fine, too. I don't have a strong preference here.


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?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's set to true after instantiation link. I retained this logic from before, I think the intention is that tables may be mutated during instantiation by element segments, but not after.

Before it looked like this, now we need to capture a bool& because it's not a member anymore.

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have two ideas but they would increase the footprint of this PR so I was planning to leave them for the next PR. For the outer callback, we don't need this as a param to ModuleRunnerBase, instead ctor-eval only needs to use EvallingRuntimeTable for imported tables, and we can return EvallingRuntimeTable from the ImportResolver. For non-imported tables we can use the real implementation that's already there in ModuleRunner.

For the inner callback of makeFuncData, I'm hoping this will go away once I do the refactorings for functions / function imports, but I'm not sure yet how it will turn out. Another option is to take the EvallingModuleRunner as an input instead of just the function but we'd need to move EvallingModuleRunner into its own header for that (because then EvallingRuntimeTable references EvallingModuleRunner and EvallingModuleRunner references EvallingRuntimeTable), and another downside is that it makes it harder to decouple from EvallingModuleRunner.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, sgtm as long as we can simplify this eventually.

@stevenfontanella stevenfontanella merged commit a77c558 into main Jan 22, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants