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

feat(compiler): Call known functions across module boundaries #1175

Merged
merged 5 commits into from
Apr 21, 2022

Conversation

ospencer
Copy link
Member

This PR uses regular calls where possible between modules. This should be fairly significant for performance, as direct calls are much faster than call_indirects. Additionally, Binaryen can now provide better optimizations after linking.

@ospencer ospencer requested a review from a team March 22, 2022 04:55
@ospencer ospencer self-assigned this Mar 22, 2022
Copy link
Member

@peblair peblair left a comment

Choose a reason for hiding this comment

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

Still wrapping my head around this, but I've left some initial thoughts

stdlib/sys/file.gr Show resolved Hide resolved
compiler/src/middle_end/linearize.re Show resolved Hide resolved
compiler/src/linking/link.re Outdated Show resolved Hide resolved
compiler/src/codegen/comp_utils.re Outdated Show resolved Hide resolved
Copy link
Member

@marcusroberts marcusroberts left a comment

Choose a reason for hiding this comment

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

Wow, that's a lot of work. I'm not going to spot problems, but I can say the approach looks good to me.

@ospencer ospencer force-pushed the oscar/call-known-across-modules branch from 7447bb8 to 19e7a76 Compare April 15, 2022 22:46
@ospencer ospencer requested a review from peblair April 15, 2022 22:55
Copy link
Member

@peblair peblair left a comment

Choose a reason for hiding this comment

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

This seems good IMO. One question before merging, but that's it.

compiler/src/codegen/transl_anf.re Show resolved Hide resolved
Copy link
Member

@phated phated left a comment

Choose a reason for hiding this comment

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

Snapshots look great!! I had a few questions/comments.

compiler/src/codegen/comp_utils.re Show resolved Hide resolved
compiler/src/codegen/comp_utils.re Show resolved Hide resolved
compiler/src/codegen/comp_utils.re Show resolved Hide resolved
compiler/src/codegen/comp_utils.re Outdated Show resolved Hide resolved
compiler/src/codegen/comp_utils.re Show resolved Hide resolved
compiler/src/codegen/compcore.re Show resolved Hide resolved
mimp_used: true,
},
],
)
| FunctionShape(_) =>
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain FunctionShape to me a bit? Since it seems like we're adding support that we didn't have before

Copy link
Member Author

Choose a reason for hiding this comment

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

Of course! Imports take one of two shapes, GlobalShape or FunctionShape, corresponding to wasm globals or wasm functions. Imports that happen via foreign wasm are either GlobalShape or FunctionShape, and before this PR, Grain imports were only GlobalShape, meaning that imported functions were only ever imported as values—the closure for the function. This meant that the only way the function could be called was via a call_indirect.

This change allows us say that we're importing an actual Grain webassembly function (and its closure), so we can call it via a regular call instruction rather than having to pull the pointer from the closure.

compiler/src/linking/link.re Outdated Show resolved Hide resolved
stdlib/sys/file.gr Show resolved Hide resolved
@ospencer ospencer requested a review from phated April 21, 2022 03:27
Copy link
Member

@phated phated left a comment

Choose a reason for hiding this comment

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

Excellent! ❤️

@ospencer ospencer merged commit b2d7440 into main Apr 21, 2022
@ospencer ospencer deleted the oscar/call-known-across-modules branch April 21, 2022 14:57
@github-actions github-actions bot mentioned this pull request May 16, 2022
@github-actions github-actions bot mentioned this pull request May 31, 2022
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.

4 participants