Skip to content

compiler: add support for 'go' on func values #487

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 17, 2019

Conversation

aykevl
Copy link
Member

@aykevl aykevl commented Aug 10, 2019

This commit allows starting a new goroutine directly from a func value,
not just when the static callee is known.

This is necessary to support the whole time package, not just the
commonly used subset that was compiled with the SimpleDCE pass enabled.


This is the first commit of #466, splitting it off because it is useful in general and makes the PR somewhat smaller.

compiler/func.go Outdated
@@ -32,7 +32,7 @@ const (
// funcImplementation picks an appropriate func value implementation for the
// target.
func (c *Compiler) funcImplementation() funcValueImplementation {
if c.GOARCH == "wasm" {
if c.GOARCH == "wasm" || true {
Copy link
Member

Choose a reason for hiding this comment

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

I do not understand this line of code. Seems like the else cannot be reached?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh thank you! That's an oversight, will take a look.

Copy link
Member Author

@aykevl aykevl Aug 11, 2019

Choose a reason for hiding this comment

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

Thinking about how to fix this, because this change is necessary for this PR to work at all, because the old way (the "doubleword" implementation) cannot allow go on function pointers right now.
I see two options:

  1. Using the switch implementation everywhere (basically as this PR does, but in a cleaner way). No extra work is needed, binary sizes are sometimes increased slightly (within 1%). An additional quick benefit is that some limitations in the current goroutine implementation will be lifted as well, such as not being able to use function pointers of functions that do some async operation. This would also be fixed by option 2 but that is going to take longer.
  2. Implementing goroutines in a more traditional way. This requires an overhaul of the scheduler. This is a significant amount of work, and is not a portable solution: it won't work on WebAssembly (but will probably work significantly better on bare metal).

Perhaps the best way to proceed is to pick option 1 and later work towards revamping the scheduler on supported platforms.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, option 1 is the best option at this point.

Copy link
Member

Choose a reason for hiding this comment

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

Pinging to bring this back to top of queue, hopefully can be wrapped up soon.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, the best option would indeed have been 1, but then I got excited and implemented the stack-based scheduler in option 2 anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed now.

@aykevl aykevl force-pushed the implement-go-func-value branch 3 times, most recently from ae71543 to 238a91d Compare August 15, 2019 14:01
@aykevl aykevl force-pushed the implement-go-func-value branch from 238a91d to b8fb88c Compare August 16, 2019 18:08
@aykevl
Copy link
Member Author

aykevl commented Aug 16, 2019

This should now be ready for review/merge.

This commit allows starting a new goroutine directly from a func value,
not just when the static callee is known.

This is necessary to support the whole time package, not just the
commonly used subset that was compiled with the SimpleDCE pass enabled.
@aykevl aykevl force-pushed the implement-go-func-value branch from b8fb88c to 5fdbd3f Compare August 16, 2019 18:17
@deadprogram
Copy link
Member

Tested successfully with some of my more complex code. Works as expected now with new scheduler and go routines on functions.

Merging..

@deadprogram deadprogram merged commit bbc3046 into dev Aug 17, 2019
@deadprogram deadprogram deleted the implement-go-func-value branch August 17, 2019 09:52
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.

2 participants