Skip to content

Fix closure errors with MINIMAL_RUNTIME + USE_PTHREADS. NFC. #14936

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
Aug 24, 2021

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Aug 24, 2021

No description provided.

@sbc100 sbc100 force-pushed the minimal_runtime_pthread_closure branch from cccf6d3 to 1cebd87 Compare August 24, 2021 18:59
@sbc100 sbc100 requested review from kripken and juj August 24, 2021 19:28
@@ -108,7 +108,7 @@ if (!ENVIRONMENT_IS_PTHREAD) {
#if USE_PTHREADS
} else {
#if MODULARIZE
updateGlobalBufferAndViews({{{EXPORT_NAME}}}.buffer);
updateGlobalBufferAndViews(Module.buffer);
Copy link
Member

Choose a reason for hiding this comment

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

Why is this changed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Without this it fails closure compiler with MyModule not defined. I think this is because closure runs before modularization so at the point of closure compiler MyModule (the EXPORT_NAME) does not exist.

However Module.buffer works just fine here because the modularized code starts with

function(MyModule) {                                                             
  MyModule = MyModule || {};                                                     
                                                                                 
                                                                                 
                                                                                 
var Module = MyModule;  

Copy link
Member

Choose a reason for hiding this comment

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

I see, sounds good. And closure will remove the extra var anyhow.

@sbc100 sbc100 force-pushed the minimal_runtime_pthread_closure branch from 1cebd87 to 47f0c92 Compare August 24, 2021 21:44
@sbc100 sbc100 merged commit 246209c into main Aug 24, 2021
@sbc100 sbc100 deleted the minimal_runtime_pthread_closure branch August 24, 2021 23:32
@@ -1884,6 +1884,7 @@ def default_setting(name, new_default):
'_emscripten_tls_init',
'_pthread_self',
'_pthread_testcancel',
'_exit',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does adding to this list pin down the function from being DCEd if not used? exit() is not used always in pthreads builds?

Copy link
Collaborator Author

@sbc100 sbc100 Aug 26, 2021

Choose a reason for hiding this comment

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

Yes, this entire like of functions cannot be DCEd in USE_PTHREADS builds.

However _exit is not special here. Just like all the other functions here is used by library_ptheads.js in general, but might be used in a given application. For example, imagine an application that builds with USE_PTHREADS but never actually creates in any threads.. all of the functions in this list would essentially be unused but also prevented from DCE.

I guess we want some other notion of EXPORTED_FUNCTIONS that also allows for DCE, but I don't know if that exists.

Perhaps we could add something like EXPORTED_FUNCTIONS_FOR_POSSIBLE_INTERNAL_JS_USAGE_ONLY?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Or maybe just POSSIBLY_USED_FUNCTIONS?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The reference to _exit is from the exitProcess handling code, and I wonder if we could if that out when EXIT_RUNTIME is not set... that would be a good solution I think. On the other hand the proc_exit library functions (of which exit is an alias) is just a single line of code on MINIMAL_RUNTIME and given that USE_PTHREADS brings in many hundreds of extra lines of code (IIUC) it maybe not that urgent to fix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, I think I wrong, please ignore those previous replies.

Adding to EXPORTED_FUNCTIONS does not prevent DCE, because we don't consider them USER_EXPORTED_FUNCTIONS. Only USER_EXPORTED_FUNCTIONS are prevented from DCE.

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