Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[embind] Simplify createNamedFunction. NFC #20479

Merged
merged 2 commits into from
Oct 18, 2023

Conversation

RReverser
Copy link
Collaborator

Slight improvement of createNamedFunction on top of #18748: we can avoid extra JS trampoline by setting name of the function directly.

This is only supported via "configuring" it by Object.defineProperty rather than plain assignment, but otherwise has exactly same effect - it sets debug name of the function in-place.

Also, ever since #18748 switched away from eval, there is no requirement for the function name to be "legal" - we can set it to the plain demangled string, making debug names even more readable.

Further simplification of createNamedFunction on top of emscripten-core#18748: we can avoid extra JS wrapper by setting `name` of the function directly.

This is only supported via "configuring" it by `Object.defineProperty` rather than plain assignment, but otherwise has exactly same effect - it sets debug name of the function in-place.

Also, ever since emscripten-core#18748 switched away from `eval`, there is no requirement for the function name to be "legal" - we can set it to the plain demangled string, making debug names even more readable.
@RReverser RReverser requested a review from sbc100 October 18, 2023 01:07
@sbc100 sbc100 changed the title Simplify createNamedFunction. NFC [embind] Simplify createNamedFunction. NFC Oct 18, 2023
@sbc100 sbc100 requested a review from brendandahl October 18, 2023 03:41
@sbc100 sbc100 added the embind label Oct 18, 2023
Copy link
Collaborator

@sbc100 sbc100 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

}[name];
return Object.defineProperty(body, 'name', {
value: name
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you do this whole thing with an arrow function. skipping the return and the outer curly braces?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Does the old version of this function return a new object while the new version mutates the function in place, is that right/ok?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As far as I can tell from usages, it should be fine - we only use it with newly created function which is why we want to have a unique name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can you do this whole thing with an arrow function. skipping the return and the outer curly braces?

Hm arrow functions for libraries seem somewhat rare in the codebase generally. If it's something we want more of, maybe worth running a separate codemod step over all libs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed this one to arrow function for now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

They should be fairly common these days. I've been converting them over time, where possible.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I just meant we should probably do a single codemod run (see my ast-grep comment in the other PR).

@RReverser RReverser enabled auto-merge (squash) October 18, 2023 11:46
@RReverser RReverser merged commit 94f726a into emscripten-core:main Oct 18, 2023
2 checks passed
@RReverser RReverser deleted the rename-func branch October 19, 2023 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants