Skip to content

Intrinsic: js.called#8324

Merged
kripken merged 14 commits intoWebAssembly:mainfrom
kripken:js.called
Feb 13, 2026
Merged

Intrinsic: js.called#8324
kripken merged 14 commits intoWebAssembly:mainfrom
kripken:js.called

Conversation

@kripken
Copy link
Member

@kripken kripken commented Feb 13, 2026

When a function is annotated with this:

(@binaryen.js.called)
(func $foo ..)

then it is assumed to be called from JS (if a reference is taken).
In closed world, we assume such references are not actually
called from the outside, and this annotation can be used to mark
the exceptions that are.

Such functions are not normally exported, but "js called" in
that JS may call them, but not other wasm code (so rec
group type identity does not matter).

@kripken kripken requested a review from tlively February 13, 2026 00:47
@kripken
Copy link
Member Author

kripken commented Feb 13, 2026

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.

LGTM % comments

std::vector<Name> getConfigureAllFunctions();

// Returns the names of all functions that are JS-called. That includes ones
// in configureAll (which we look through the module for), and also those
Copy link
Member

Choose a reason for hiding this comment

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

Are we still planning to eventually phase out this special handling for configureAll? I think we should to make the usage more consistent across different configureAll usage patterns.

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 think we were discussing removing it, yeah. Once all our users are marking the functions with jsCalled, we can do that.

// configureAll functions are signature-called, and must also not be
// modified.
for (auto func : Intrinsics(*module).getConfigureAllFunctions()) {
// Signature-called functions must also not be modified.
Copy link
Member

Choose a reason for hiding this comment

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

In principle we could still remove a suffix of the parameters, although I'm not sure whether that comes with a performance overhead. Maybe worth checking on that and adding a TODO if there would be no downside.

Copy link
Member Author

Choose a reason for hiding this comment

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

Adding a TODO

// configureAll functions are signature-called, which means their params
// must not be refined.
for (auto func : Intrinsics(*module).getConfigureAllFunctions()) {
// Signature-called functions must not have params refined.
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 retire the "signature-called" terminology?

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 am torn about that. On the one hand the spec is "js interop" so this is all for JS, but otoh at least this concept could make sense to other embedder languages, so it feels better to be more general.

Copy link
Member Author

Choose a reason for hiding this comment

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

So perhaps sig.called makes sense and not js.called, but the lack of a concrete other language makes me unsure. And js.called is easier to grasp, I think.

;; RUN: foreach %s %t wasm-opt --remove-unused-module-elements --closed-world -all -S -o - | filecheck %s

(module
(@binaryen.js.called)
Copy link
Member

Choose a reason for hiding this comment

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

I think the latest changes to the update script should put this annotation down with the function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updating.

@@ -0,0 +1,24 @@
;; RUN: wasm-opt -all %s -S -o - | filecheck %s
Copy link
Member

Choose a reason for hiding this comment

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

This can use the update script now.

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.

@bashor
Copy link

bashor commented Feb 13, 2026

@kripken could you please release a new version of binaryen as soon as this PR is merged?

Merge remote-tracking branch 'origin/main' into js.called
@kripken
Copy link
Member Author

kripken commented Feb 13, 2026

@bashor sure, no problem.

@kripken kripken merged commit 0b8851e into WebAssembly:main Feb 13, 2026
17 checks passed
@kripken kripken deleted the js.called branch February 13, 2026 18:57
@kripken
Copy link
Member Author

kripken commented Feb 13, 2026

@bashor version 126 is released!

@bashor
Copy link

bashor commented Feb 16, 2026

@kripken supper! Thanks a lot!

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