Skip to content

Conversation

@yamt
Copy link
Contributor

@yamt yamt commented May 27, 2024

also, fix a crash on modules w/o imports.

@kripken
Copy link
Member

kripken commented May 29, 2024

I agree that the automatic behavior here can be hard to use. But we do need a solution for the case where "env" was minified, which that PR solved. How about making the automatic behavior customizable? We could perhaps allow not just --log-execution but also --log-execution=PREFIX, and in the second case that exact prefix would be used and nothing else (no automatic behavior). Would that work for your use case @yamt ?

If so then to implement it see e.g. ExtractFunction.cpp for an example of a pass that receives a parameter like that.

@yamt
Copy link
Contributor Author

yamt commented May 29, 2024

sure, making it an option works for me.
however, i don't understand why the automatic behavior is necessary in the first place.
probably because i'm not familiar with how minimization works.
can't you simply minimize after applying log-execute instrumentation?

@kripken
Copy link
Member

kripken commented May 29, 2024

You're right that a different order might work. But sometimes you want to add the logging after all optimizations have been done, maybe because the bug only shows itself then (maybe it's a bug in an optimization pass).

In general I've personally found this pass useful on various wasm files, optimized and not, and I'm not sure how other people are using the pass, so I'd rather not remove functionality.

@yamt
Copy link
Contributor Author

yamt commented May 29, 2024

You're right that a different order might work. But sometimes you want to add the logging after all optimizations have been done, maybe because the bug only shows itself then (maybe it's a bug in an optimization pass).

In general I've personally found this pass useful on various wasm files, optimized and not, and I'm not sure how other people are using the pass, so I'd rather not remove functionality.

ok. it makes sense.

@yamt yamt force-pushed the revert-log-execution-module-name branch from ce20d03 to 033d61d Compare May 30, 2024 00:17
@yamt
Copy link
Contributor Author

yamt commented May 30, 2024

i added the suggested option.

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.

Please add a test for this. It could be similar to this test file that I just opened a PR for,

https://github.com/WebAssembly/binaryen/pull/6634/files#diff-26883f6202548dd332237e9002be15d8e33b958bdbbb52eef03e0999e147dd6e

Maybe call it test/lit/passes/log-execution_arg.wast (adding _arg), and put a comment in it saying

;; Test the option to provide the module name as an argument.

Then you can just modify the wasm-opt command there. To update the expected output there use

./scripts/update_lit_checks.py test/lit/passes/log-execution_arg.wast

Name LOGGER("log_execution");

struct LogExecution : public WalkerPass<PostWalker<LogExecution>> {
IString logger_module;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
IString logger_module;
// The module name the logger function is imported from.
Name loggerModule;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

Aside from the comment, the diff also renamed the variable. loggerModule is more consistent with our naming conventions (compared to logger_module).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, i haven't noticed it. done.

@yamt yamt force-pushed the revert-log-execution-module-name branch from 033d61d to 08be7c2 Compare May 31, 2024 02:51
@yamt
Copy link
Contributor Author

yamt commented May 31, 2024

Please add a test for this. It could be similar to this test file that I just opened a PR for,

https://github.com/WebAssembly/binaryen/pull/6634/files#diff-26883f6202548dd332237e9002be15d8e33b958bdbbb52eef03e0999e147dd6e

Maybe call it test/lit/passes/log-execution_arg.wast (adding _arg), and put a comment in it saying

;; Test the option to provide the module name as an argument.

Then you can just modify the wasm-opt command there. To update the expected output there use

./scripts/update_lit_checks.py test/lit/passes/log-execution_arg.wast

done.
i needed --all-items to make it check the import.

@yamt yamt changed the title Revert "The name of the import object might not always be "env" (e.g.… LogExecution: optionally take a module name for the logger function May 31, 2024
@yamt yamt force-pushed the revert-log-execution-module-name branch from 08be7c2 to 8556a7e Compare May 31, 2024 02:53
(func $nopp
(nop)
)
;; CHECK: (func $intt (result i32)
Copy link
Member

Choose a reason for hiding this comment

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

I think it's ok to stop this test here. The first 25 lines show that it uses "foo" and that it emits a valid call to log_execution.

Copy link
Member

Choose a reason for hiding this comment

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

(That is, it doesn't need to be as comprehensive as the other test, as the focus here is just on the argument to the pass, which lines 1-25 test.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

are you suggesting to minimize the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

Yes, exactly.

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.

Looks good aside from those last comments.

@kripken kripken enabled auto-merge (squash) May 31, 2024 03:53
@kripken kripken merged commit 0c23394 into WebAssembly:main May 31, 2024
@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