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

Add sourcemap support to wasm-metadce and wasm-merge #6372

Merged
merged 7 commits into from
Mar 6, 2024

Conversation

vouillon
Copy link
Contributor

@vouillon vouillon commented Mar 2, 2024

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.

Copy link
Member

@kripken kripken left a 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.

@@ -23,17 +24,46 @@

namespace wasm::ModuleUtils {

static void updateLocationSet(std::set<Function::DebugLocation>& locations,
std::vector<Index>* indexMap) {
Copy link
Member

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:

Suggested change
std::vector<Index>* indexMap) {
std::vector<Index>& indexMap) {

@@ -23,17 +24,46 @@

namespace wasm::ModuleUtils {

static void updateLocationSet(std::set<Function::DebugLocation>& locations,
Copy link
Member

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.

Function* copyFunction(Function* func,
Module& out,
Name newName,
std::vector<Index>* indexMap) {
Copy link
Member

Choose a reason for hiding this comment

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

We prefer this pattern:

Suggested change
std::vector<Index>* indexMap) {
std::optional<std::vector<Index>> indexMap = std::nullopt) {

Function* copyFunction(Function* func,
Module& out,
Name newName,
std::vector<Index>* indexMap) {
Copy link
Member

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?

// have proper names for, and can just copy.
ModuleUtils::copyModuleItems(input, merged);
ModuleUtils::copyModuleItems(input, merged, &indexMap);
Copy link
Member

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.

Copy link
Contributor Author

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);
}
Copy link
Member

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.

Copy link
Contributor Author

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.

@vouillon vouillon changed the title Add source support to wasm-metadce and wasm-merge Add sourcemap support to wasm-metadce and wasm-merge Mar 5, 2024
Copy link
Member

@kripken kripken left a 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);
Copy link
Member

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.)

Copy link
Contributor Author

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...

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Great, thanks!

@kripken kripken merged commit f44912b into WebAssembly:main Mar 6, 2024
14 checks passed
OlivierNicole added a commit to OlivierNicole/wasm_of_ocaml that referenced this pull request Mar 8, 2024
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.
OlivierNicole added a commit to OlivierNicole/wasm_of_ocaml that referenced this pull request Mar 8, 2024
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.
OlivierNicole added a commit to OlivierNicole/wasm_of_ocaml that referenced this pull request Mar 9, 2024
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]>
OlivierNicole added a commit to OlivierNicole/wasm_of_ocaml that referenced this pull request Mar 15, 2024
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]>
OlivierNicole added a commit to OlivierNicole/wasm_of_ocaml that referenced this pull request Mar 27, 2024
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]>
@gkdn gkdn mentioned this pull request Aug 31, 2024
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