Skip to content

Conversation

@kripken
Copy link
Member

@kripken kripken commented Dec 8, 2025

To do this, refactor the table scanning code out of Directize into TableUtils. Then
when we see a CallIndirect in RemoveUnusedModuleElements, we no longer
automatically assume it could call anything whose reference was taken: if we see
the table is not modified, then only the table's known contents might be called.

That is, before: CallIndirect implied we could call anything of that type, in that
table. But also, we assumed other things might be written into the table at
runtime, so anything whose reference was taken was callable. After: We know
which tables do not have new entries written into them.

@kripken
Copy link
Member Author

kripken commented Dec 9, 2025

Measuring on Dart, I see a small benefit here. Probably it is small as other devirtualization etc. mechanisms already handle most things.

@kripken kripken requested a review from tlively December 9, 2025 23:52
@kripken
Copy link
Member Author

kripken commented Dec 16, 2025

friendly nonurgent ping @tlively

Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

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

Sorry, looks like I've had this comment pending for a while but never published it. Will take a fresh look as well.

Comment on lines 129 to 131
// Whether we can assume that the initial contents are immutable. See the
// toplevel comment.
bool initialContentsImmutable = false;
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure which comment this is referring to, and I'm not sure just by reading this how initialContentsImmutable differs from mayBeModified.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, good point, I moved code but not all the dependent comments 😄 Fixed.

I also clarified how the properties tie into each other.

}
}
if (hasUnmodifiableTable) {
using TablesWithSet = std::unordered_set<Name>;
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 do an early return here when !hasUnmodifiableTable to decrease the indentation below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

)
(table.set $table
(i32.const 7)
(ref.func $foo-not-in-table)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe write a null here to show that the optimization is still inhibited.

Copy link
Member Author

Choose a reason for hiding this comment

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

That would change the test: without taking a reference of this function, we can't verify that the reference matters. As the test says later down for that function

    ;; The reference taken of this function might be table.set'ed, so we can do
    ;; nothing here.

We could separate the reference from the table.set, put a null in the latter and drop the reference, I guess, but I'm not sure if that adds anything?

Copy link
Member

Choose a reason for hiding this comment

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

We could separate the reference from the table.set, put a null in the latter and drop the reference, I guess, but I'm not sure if that adds anything?

I think we should do this. It better demonstrates that we're not looking at precisely what is set, but rather that there is a set at all.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, done.

@kripken kripken merged commit 98b720d into WebAssembly:main Dec 16, 2025
17 checks passed
@kripken kripken deleted the directize.gen branch December 16, 2025 22:42
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.

2 participants