-
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
Add sourcemap support to wasm-metadce and wasm-merge #6372
Conversation
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.
Thanks, this is great!
Overall this looks good aside from some comments and suggestions.
src/ir/module-utils.cpp
Outdated
@@ -23,17 +24,46 @@ | |||
|
|||
namespace wasm::ModuleUtils { | |||
|
|||
static void updateLocationSet(std::set<Function::DebugLocation>& locations, | |||
std::vector<Index>* indexMap) { |
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 would be better I think:
std::vector<Index>* indexMap) { | |
std::vector<Index>& indexMap) { |
@@ -23,17 +24,46 @@ | |||
|
|||
namespace wasm::ModuleUtils { | |||
|
|||
static void updateLocationSet(std::set<Function::DebugLocation>& locations, |
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.
Please add a comment explaining what this function does.
src/ir/module-utils.cpp
Outdated
Function* copyFunction(Function* func, | ||
Module& out, | ||
Name newName, | ||
std::vector<Index>* indexMap) { |
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.
We prefer this pattern:
std::vector<Index>* indexMap) { | |
std::optional<std::vector<Index>> indexMap = std::nullopt) { |
src/ir/module-utils.cpp
Outdated
Function* copyFunction(Function* func, | ||
Module& out, | ||
Name newName, | ||
std::vector<Index>* indexMap) { |
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 could be fileIndexMap
to clarify what it refers to?
src/tools/wasm-merge.cpp
Outdated
// have proper names for, and can just copy. | ||
ModuleUtils::copyModuleItems(input, merged); | ||
ModuleUtils::copyModuleItems(input, merged, &indexMap); |
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 could be wrong, but the issue of mapping filename indices is potentially present in all calls of copyFunction
, unless the entire module is cloned. That is, we can call copyFunction
to copy a function from an arbitrary module to another. Given that, perhaps the above logic should be in module-utils
so that all users use it? We may not have another user atm in the codebase, but doing it that way would avoid needing to refactor and maybe missing a bug if we do in the future.
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!
if (outputSourceMapFilename.size()) { | ||
writer.setSourceMapFilename(outputSourceMapFilename); | ||
writer.setSourceMapUrl(outputSourceMapUrl); | ||
} |
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.
Please add a test for wasm-metadce
too.
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 have also updated the test for wasm-metadce
to test the -ism
and -osm
flags as well.
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.
Great! Just one last comment.
for (auto& curr : in.functions) { | ||
copyFunction(curr.get(), out); | ||
copyFunction(curr.get(), out, Name(), fileIndexMap); |
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.
For efficiency, how about only passing a non-nullopt fileIndexMap
if !in.debugInfoFileNames.empty()
- ? That is, when the input has no debug info, we can avoid this work.
(fileIndexMap
can be a std::optional
that is only set if we have work to do, so when we don't it'll be nullopt.)
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 have also added a test at the beginning of debug::copyDebugInfo
to just return if there is nothing to copy. This seems more foolproof than putting the test outside of the function...
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.
Great, thanks!
Implement mapping between source and wasm locations. To work, this requires a version of Binaryen compiled with Jérôme's patch WebAssembly/binaryen#6372. Single-stepping can jump around in slightly surprising ways in the OCaml code, due to the different order of operations in wasm. This could be improved by modifying Binaryen to support “no location” annotations. Another future improvement can be to support mapping Wasm identifiers to OCaml ones.
Implement mapping between source and wasm locations. To work, this requires a version of Binaryen compiled with Jérôme's patch WebAssembly/binaryen#6372. Single-stepping can jump around in slightly surprising ways in the OCaml code, due to the different order of operations in wasm. This could be improved by modifying Binaryen to support “no location” annotations. Another future improvement can be to support mapping Wasm identifiers to OCaml ones.
Implement mapping between source and wasm locations. To work, this requires a version of Binaryen compiled with Jérôme's patch WebAssembly/binaryen#6372. Single-stepping can jump around in slightly surprising ways in the OCaml code, due to the different order of operations in wasm. This could be improved by modifying Binaryen to support “no location” annotations. Another future improvement can be to support mapping Wasm identifiers to OCaml ones. Co-authored-by: Jérôme Vouillon <[email protected]>
Implement mapping between source and wasm locations. To work, this requires a version of Binaryen compiled with Jérôme's patch WebAssembly/binaryen#6372. Single-stepping can jump around in slightly surprising ways in the OCaml code, due to the different order of operations in wasm. This could be improved by modifying Binaryen to support “no location” annotations. Another future improvement can be to support mapping Wasm identifiers to OCaml ones. Co-authored-by: Jérôme Vouillon <[email protected]>
Implement mapping between source and wasm locations. To work, this requires a version of Binaryen compiled with Jérôme's patch WebAssembly/binaryen#6372. Single-stepping can jump around in slightly surprising ways in the OCaml code, due to the different order of operations in wasm. This could be improved by modifying Binaryen to support “no location” annotations. Another future improvement can be to support mapping Wasm identifiers to OCaml ones. Co-authored-by: Jérôme Vouillon <[email protected]>
This adds appropriate command line arguments.
In the case of wasm-merge, a bit of work was also needed to copy the debug information when copying functions.