-
Notifications
You must be signed in to change notification settings - Fork 745
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
Fixes regarding explicit names #6466
Conversation
vouillon
commented
Apr 3, 2024
- only write explicit function names
- when merging modules, the name of types, globals and tags in all modules but the first were lost
o << U32LEB(emitted); | ||
writeEscapedName(curr->name.str); | ||
emitted++; | ||
std::vector<std::pair<Index, Function*>> functionsWithNames; |
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 is the very same code as for globals.
2738190
to
144a4cb
Compare
- only write explicit function names - when merging modules, the name of types, globals and tags in all modules but the first were lost
src/ir/module-utils.cpp
Outdated
@@ -48,6 +48,7 @@ Function* copyFunction(Function* func, | |||
std::optional<std::vector<Index>> fileIndexMap) { | |||
auto ret = std::make_unique<Function>(); | |||
ret->name = newName.is() ? newName : func->name; | |||
ret->hasExplicitName = func->hasExplicitName && !newName.is(); |
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.
Why not set it to true when newName.is()
?
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.
newName
is a generated name. For instance, some names like outlined-A$func-name
are generated during inlining. But maybe we can consider it is explicit enough?
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.
Ah, I see what you mean, good point. I guess it depends on the user expectation in this code. I think that we do want to keep such names, as we are copying a function, so we should copy the property of having an explicit name.
src/ir/module-utils.cpp
Outdated
@@ -48,6 +48,7 @@ Function* copyFunction(Function* func, | |||
std::optional<std::vector<Index>> fileIndexMap) { | |||
auto ret = std::make_unique<Function>(); | |||
ret->name = newName.is() ? newName : func->name; | |||
ret->hasExplicitName = newName.is() || func->hasExplicitName; |
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.
ret->hasExplicitName = newName.is() || func->hasExplicitName; | |
ret->hasExplicitName = func->hasExplicitName; |
I think it's better to just match the copied function. Their names may differ (if copied into the same module) but the property of having an explicit name seems like it should be the same, at least by default.
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.
Oh, indeed!
@@ -222,7 +231,6 @@ void copyModule(const Module& in, Module& out) { | |||
out.customSections = in.customSections; | |||
out.debugInfoFileNames = in.debugInfoFileNames; | |||
out.features = in.features; | |||
out.typeNames = in.typeNames; |
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.
Why did this move? The description of the function it was moved to is that it copies toplevel module items like Functions and Globals, and not metadata.
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.
So, you think I should rather put the code that copy type names in wasm-merge.cc
?
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.
Sorry, I don't see why my question, which was about the deletion of this line, is answered by something about wasm-merge
? What is the context I am missing?
From the standpoint of this file by itself (not thinking about wasm-merge
at all), this change seems surprising as I said - it looks like this code moved up to copyModuleItems
which I don't understand the motivation for.
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.
wasm-merge
currently does not copy type names from the input modules to the merged module. I added some code for that in copyModuleItems
. But then this line became unnecessary.
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 see, so wasm-merge uses copyModuleItems
and not copyModule
. The difference between those two decreases with this change, and the meaning of the difference becomes less clear to me. Perhaps we don't need two functions here at all, and there could just be a single function with maybe a set of options as to whether to copy exports, the start method, etc. (the things only in copyModule
). Anyhow, for this PR I think the change you made is good, but please add a TODO on copyModule
to remind us later, maybe something like TODO: merge this with copyModuleItems, and add options for copying exports and other things that are currently different between them, if we still need those differences
.
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.
Why did this change?
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.
The function name section is no longer written when there is no name.
test/lit/wasm-split/jspi.wast
Outdated
@@ -18,15 +18,15 @@ | |||
|
|||
;; PRIMARY: (import "env" "__load_secondary_module" (func $import$__load_secondary_module (param externref))) | |||
|
|||
;; PRIMARY: (import "placeholder" "0" (func $placeholder_0 (param i32) (result i32))) | |||
;; PRIMARY: (import "placeholder" "0" (func $fimport$1 (param i32) (result i32))) |
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 looks like a loss of a useful name. Perhaps it's better to keep 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.
It's useful in tests, but it's not useful for production. Are tests enough motivation?
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 think so. In production no names are shipped anyhow so adding more names in non-production builds has little downside, so long as they are meaningful, which looks like the case here.
… an explicit name
This seems to break some emscripten tests:
|
Looks like functions that previously had names now just have numbers? |
I guess dymCall-generating pass needs to set |
Yes, indeed, that would fix the issue. But I'm wondering whether emscripten really needs the internal names. Maybe you can just update the tests? On the other hand, the generated names are meaningful, so it also make sense to fix that in binaryen. |
Another fix might be to set @sbc100 I can look into fixing this but I am out today. |
The generated names are indeed meaningful/useful, at least for debugging. |
That sounds like a good fix.
|
…icitName. NFC This is temporary workaround for the current test failures on the emscripten waterfall. The real fix I believe will be to make `hasExplicitName` the default in these kinds of cases. See: #6466
|