-
Notifications
You must be signed in to change notification settings - Fork 830
Stub out all imports in ctor-eval #8115
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
Merged
+90
−68
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ea2f435
Stub out all imports in ctor-eval
stevenfontanella e1cef5b
Update comment to make it clear how stubbed imported globals work
stevenfontanella 8c8b209
Remove an extra map lookup
stevenfontanella b81af35
Don't generate stubs for WASI functions
stevenfontanella 759b45c
Generate stubs for WASI functions. They are still needed
stevenfontanella 899fb04
Make global test reference an unneeded global
stevenfontanella File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| (module | ||
| (import "import" "global" (global $imported i32)) | ||
| (func $test1 (export "test1") | ||
| ;; This should be safe to eval in theory, but the imported global stops us, | ||
| ;; so this function will not be optimized out. | ||
| ;; TODO: perhaps if we never use that global that is ok? | ||
| (func $use-global (export "use-global") (result i32) | ||
| (global.get $imported) | ||
| ) | ||
stevenfontanella marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ;; The imported global isn't used in the ctor, | ||
| ;; so we're free to remove it completely. | ||
| (func $test1 (export "test1")) | ||
stevenfontanella marked this conversation as resolved.
Show resolved
Hide resolved
stevenfontanella marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| (module | ||
| (type $0 (func)) | ||
| (export "test1" (func $test1)) | ||
| (func $test1 (type $0) | ||
| (nop) | ||
| (type $0 (func (result i32))) | ||
| (import "import" "global" (global $imported i32)) | ||
| (export "use-global" (func $use-global)) | ||
| (func $use-global (type $0) (result i32) | ||
| (global.get $imported) | ||
| ) | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What is the advantage of this variant-based visiting, replacing
iterImported*functions with oneiterImports? (I'm not opposed to it, necessarily, I just don't see an obvious reason so I think I may be missing something.)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 not a big difference, I mainly did this because there is some work in common for all imports (the first few lines of this function). If we were to use the iterImported* functions, we'd need to introduce a helper function and call it in the body of each one. Also this way forces us to deal with all types of imports which makes it clear to the reader which ones are handled (e.g. Tags are not handled which was implicit before but is explicit now which I think is a small plus).
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 don't we want to handle tags? That seems like it was probably an accidental omission before. (Or do we not have a hook for aborting the execution if an imported tag is used? In that case maybe aborting early in the presence of imported tags is intentional.)
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.
Good question about tags @tlively , but @stevenfontanella otherwise that all sounds good, thanks for the explanation.
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.
My impression is that ctor-eval won't work at all on any ctor that references an imported tag: https://github.com/WebAssembly/binaryen/blob/main/src/tools/wasm-ctor-eval.cpp#L327. I guess this is the best we can do unless the tag is somehow referenced in a way that doesn't matter at all? Or as you mentioned, if the same tag is used to throw and catch, then it doesn't matter what the imported value was.