Skip to content

Detect and report late assignment of Module API elements #23629

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

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Feb 8, 2025

We had some bug reports recently when we switched to using async/await
in MODULUARIZE mode. One of the side effects was the --post-js code
then runs after module instantiation and startup, which means assignment
of properties like onRuntimeInitialized is too late if it happens in
--post-js.

This was always the case for sync instantiation mode.

When assertions are enabled, we now detect this too-late-assignment and abort
with a useful error.

Code size regression in this PR, as expected, only for debug builds.

See #23626 and #23420

@sbc100 sbc100 force-pushed the late_module_assignment branch from 602f717 to 7a690c5 Compare February 8, 2025 17:11
@sbc100 sbc100 changed the title Late module assignment Detect and report late assignment of Module API elements Feb 8, 2025
@sbc100 sbc100 requested a review from kripken February 8, 2025 17:12
@sbc100
Copy link
Collaborator Author

sbc100 commented Feb 8, 2025

CC @sgbeal

@sgbeal
Copy link

sgbeal commented Feb 8, 2025

CC @sgbeal

Thank you for the heads up! i'll keep an eye out for any fallout on our end.

When assertions are enabled, we now detect this too-late-assignment and abort with a useful error.

What happens when asserts are not enabled? Does that make such usage "legal but possibly ill-advised" or "undefined behavior"?

@sbc100
Copy link
Collaborator Author

sbc100 commented Feb 8, 2025

CC @sgbeal

Thank you for the heads up! i'll keep an eye out for any fallout on our end.

When assertions are enabled, we now detect this too-late-assignment and abort with a useful error.

What happens when asserts are not enabled? Does that make such usage "legal but possibly ill-advised" or "undefined behavior"?

The same thing that happens today: nothing at all. The assignment will go undetected and un-used.

@sbc100
Copy link
Collaborator Author

sbc100 commented Feb 8, 2025

CC @sgbeal

Thank you for the heads up! i'll keep an eye out for any fallout on our end.

When assertions are enabled, we now detect this too-late-assignment and abort with a useful error.

What happens when asserts are not enabled? Does that make such usage "legal but possibly ill-advised" or "undefined behavior"?

The same thing that happens today: nothing at all. The assignment will go undetected and un-used.

When we try to detect such API misused, or change the behaviour of emscripten like this, we normally focus on reported these errors only when assertions are enabled, to avoid increasing code size in release builds.

We had some bug reports recently when we switched to using async/await
in MODULUARIZE mode.  One of the side effects was the `--post-js` code
then runs after module instantiation and startup, which means assignment
of properties like `onRuntimeInitialized` is too late if it happens in
`--post-js`.

This was always the case for sync instantiation too.

We now detect this too-late-assignment at abort with a useful error.

See emscripten-core#23626 and emscripten-core#23420
@sbc100 sbc100 force-pushed the late_module_assignment branch from 7a690c5 to 7e3e35c Compare February 8, 2025 17:39
@sbc100 sbc100 requested a review from brendandahl February 8, 2025 22:01
@sbc100 sbc100 enabled auto-merge (squash) February 8, 2025 22:02
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Good idea!

@sbc100 sbc100 merged commit 06efef8 into emscripten-core:main Feb 11, 2025
29 checks passed
@sbc100 sbc100 deleted the late_module_assignment branch February 11, 2025 00:01
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