-
Notifications
You must be signed in to change notification settings - Fork 989
Namespaced Wasm Imports so they don't conflict across modules, or reserved LLVM IR #1661
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
Conversation
Oops, looks like my fork got a little weird, Let me force push to this branch based on my current branch 😄 EDIT: Ah! The actual issue was that I tried to merge into EDIT2: This is now for real good to go! 😄 🎉 |
Hello @torch2424 thanks for this contribution. Looks like there are some problems with the CI build: https://app.circleci.com/pipelines/github/tinygo-org/tinygo/4409/workflows/09f56573-cf9f-4d30-af51-fc15dfc75753/jobs/24355/parallel-runs/0/steps/0-121?invite=true It appears that you need to run Separately, please make sure you rebase off of the most current Thank you! |
7a97d65
to
226b52e
Compare
Hello @deadprogram Thanks for the tips! 😄
So I tried running Though, I am a bit confused why this would be happening? As I don't know why the test output is incorrectly formatted for the fix that I made? 🤔
I made sure to do that! Looking at my branch, I am now rebased on top of: torch2424@e76729c . Which seems to match up with what is at the HEAD of |
So I did some digging around the makefile, and I just had to run the fmt in the makefile, Things are starting to pass in the CI, so I think this is good to go @deadprogram ! 😄 🎉 |
compiler/symbol.go
Outdated
wasmImportNameAttr := c.ctx.CreateStringAttribute("wasm-import-name", info.importName) | ||
llvmFn.AddFunctionAttr(wasmImportNameAttr) |
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.
Perhaps this needs an extra check that info.importName
is not unset (an empty string)?
compiler/symbol.go
Outdated
if info.module == "" { | ||
info.linkName = info.importName | ||
} else { | ||
info.linkName = fmt.Sprintf("tinygo_wasm_import_%s_%s", info.module, info.importName) |
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.
You are here introducing an order dependency between //go:wasm-module
and //export
: using //export
before //go:wasm-module
would change the behavior which is probably not expected.
Also, you're setting info.importName
for all systems, not just WebAssembly? I guess LLVM will ignore it but it doesn't seem clean to me.
Instead of this if/else, I would move this if/else right after the for loop (putting parts[1]
in a temporary variable). Something like this:
if info.module != "" {
// WebAssembly import
info.importName = importName
} else {
info.linkName = importName
}
Note, in particular, that this doesn't change the link name. I think that's fine (and perhaps better): a TinyGo function name is unlikely to conflict with a name from another programming language with names such as main.someExportedName
or github.com/user/pkg/subpkg.someFunction
.
Thanks for the review @aykevl ! 😄 So I addressed the first comment! and then for the second suggestion I tried moving it after the for loop, but then I get runtime panics (I added a screenshot), and I couldn't figure out why that was happening. 🤔 But! I was going to start heading out for the day, so I just pushed up where I'm at. But no worries, I'm sure I'll figure out what is going on. 😄 Once everything is good to go I'll add a mention 😄 👍 |
@deadprogram @aykevl Alright! So I fixed the bug I had yesterday! 😄 🎉 I saw the CI was passing, but then found an uneeded comment, removed it, and then re-ran So I think this is good to go! 😄 |
This is some great work @torch2424 thank you for all of the updates to feedback. Would you prefer that I squash the commits before merging, or would you like to do that yourself? |
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.
Looks good to me!
compiler/symbol.go
Outdated
if decl, ok := f.Syntax().(*ast.FuncDecl); ok && decl.Doc != nil { | ||
|
||
// Our importName for a wasm module (if we are compiling to wasm), or llvm link name | ||
var importName string = "" |
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.
Just a nitpick: this can be declared slightly shorter as follows:
importName := ""
or like this:
var importName string
Ah! My apologies, been handling some family stuff as of lately! 😄
First, thank you for the kind words! 😄 🎉 Please feel free to squash this, I'd very much appreciate it 😄 Thank you for the review. Made the suggested change, this should be good to go! 😄 🎉 |
Thank you so very much for all the effort on this contribution. Now squash/merging. |
@deadprogram @aykevl Yay! Thank you very much for the review, and squashing / merging! 😄 🎉 |
closes #1643
closes #1559
Kind of relates to #1647
Doesn't fix, but puts on the right path I think, for relates to #1648
So this PR was opened from a discussion in the tinygo slack: https://gophers.slack.com/archives/CDJD3SUP6/p1614201204223100 . Involving a conflict with wasm imports with the name of
write
. Which conflicts with the LLVM IR@write
, and requires decoupling the LLVM IR symbol, and thewasm-import-name
.I tested this pr with the following code: https://github.com/torch2424/tinygo-compiler-playground (Which also contains the output LLVM IR of this current PR) , and ran the tests:
go test -target=wasm
andmake wasmtest
.Screenshots of tests and things