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

Sourcemap support for wasm #27

Merged
merged 1 commit into from
Mar 27, 2024
Merged

Conversation

OlivierNicole
Copy link
Collaborator

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, so I’m opening this a draft for now.

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 OlivierNicole force-pushed the sourcemaps branch 2 times, most recently from 0dde597 to 273c77a Compare March 15, 2024 12:26
@vouillon
Copy link
Collaborator

For now, we can probably run the command wasm-merge -osm foo 2> /dev/null and not generate source maps if it fails. This would allow to merge this pull request without waiting for binaryen 118.

@OlivierNicole
Copy link
Collaborator Author

I did that.

Running dune fmt on this PR modifies some files that are not in the PR’s scope—including dune files—so I’m not sure whether to do it.

wat_file
output_file =
let sourcemap_file =
if Sys.command "wasm-merge -osm foo 2> /dev/null" <> 0 then None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if Sys.command "wasm-merge -osm foo 2> /dev/null" <> 0 then None
if Option.is_none sourcemap_file || Sys.command "wasm-merge -osm foo 2> /dev/null" <> 0 then None

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This would still call wasm-metadce with the -osm option though.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If sourcemap_file is None, one does not need to check for source map support, and wasm-metadce is not going to be called with the -osm option, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah yes, I was confused. Done.

@vouillon
Copy link
Collaborator

I did that.

Running dune fmt on this PR modifies some files that are not in the PR’s scope—including dune files—so I’m not sure whether to do it.

Thanks!
Indeed, I think I'm not very careful with dune files...
It seems there are still some large formatting changes in wa_wat_output.ml.

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 <jerome.vouillon@gmail.com>
@OlivierNicole
Copy link
Collaborator Author

OlivierNicole commented Mar 27, 2024

I rebased the PR and squashed the history as it looked a bit weird.

@vouillon vouillon merged commit d8bb665 into ocaml-wasm:main Mar 27, 2024
2 checks passed
@vouillon
Copy link
Collaborator

Thanks!

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.

None yet

2 participants