-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Changes allowing threads to work in a wasm32-wasi environment #25890
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
Open
chung-leong
wants to merge
6
commits into
ziglang:master
Choose a base branch
from
chung-leong:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3dc4da2
Implemented changes allow threads to work in a wasm32-wasi env
chung-leong f257a46
Merge branch 'ziglang:master' into master
chung-leong 6d3fceb
Simplified wasi_thread_start()
chung-leong 6d3c1b3
Removed stack pointer inline functions and field
chung-leong 7bc5e1e
Moved Wasi thread finalization code into separate function
chung-leong 51cdefb
Merge branch 'master' into master
chung-leong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised this even compiles; you should not be able to introduce variables in a naked function.
__set_stack_pointeris called in two places and it's literally two lines of code. Just manually inline it and delete it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(fwiw, our current checks for this are doomed to never be correct, because we literally do not have enough information in ZIR for Sema to know there's a local variable; solving it would be quite a bit of effort, so I've been intentionally not bothering given that we're probably going to end up redesigning naked functions anyway)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works:
How do you to insert constants into an asm statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't mind having an extra function at release optimizations, we can actually use just use this one function to set the stack pointer and get rid of
__set_stack_pointer().__get_stack_pointer()can go too, since the main thread's stack pointer at the time of thread creation doesn't point to memory that the thread can safely use.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To answer my own question, I guess
std.fmt.comptimePrint()might be the solution here:Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x constraint isn't recognized, but i constraint works:
P.S. I didn't catch that the X is uppercase.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you tryAh, just saw your edit. So doesXorx? Constraints are case sensitive.Xwork?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I suggest going with that;
Xis supposed to be the "just pass this operand through to the assembler unmolested" constraint.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use of the
Xsaves us from having to explicitly export the non-naked function too. Nice.I've also taken the liberty to move the thread finalization code into a function in
WasiThread. I was working on emulating pthread functions and found that we need that code forpthread_cancel().