-
Notifications
You must be signed in to change notification settings - Fork 858
wasm-ctor-eval: Remove the start function when we succeed #8702
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
Draft
kripken
wants to merge
13
commits into
WebAssembly:main
Choose a base branch
from
kripken:ctor.start
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+289
−16
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
78adcb1
work
kripken 12ec38c
test
kripken 00f13fe
fix
kripken 6e64eed
test
kripken 6c4f119
work
kripken 796c111
test
kripken 059dbff
update existing tests
kripken f00a1c2
add keepalives to tests to avoid start removal making them remove too…
kripken c6ed677
Merge remote-tracking branch 'origin/main' into ctor.start
kripken e67476a
fix
kripken 18a9854
fix
kripken 437e645
revert
kripken 7e2142a
comment
kripken 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
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 |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| ;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. | ||
| ;; RUN: foreach %s %t wasm-ctor-eval --ctors=test --kept-exports=test --quiet -all -S -o - | filecheck %s | ||
|
|
||
| ;; We fail to eval away test (due to infinite recursion). As a result, we do | ||
| ;; not update either global - not the one it modifies or even the one that the | ||
| ;; start function modifies, and the start function remains as the start. | ||
| ;; TODO: We could perhaps eval away the start in such cases, even when nothing | ||
| ;; else gets optimized. | ||
|
|
||
| (module | ||
| ;; CHECK: (type $0 (func)) | ||
|
|
||
| ;; CHECK: (type $1 (func (result i32))) | ||
|
|
||
| ;; CHECK: (global $global1 (mut i32) (i32.const 0)) | ||
| (global $global1 (mut i32) (i32.const 0)) | ||
|
|
||
| ;; CHECK: (global $global2 (mut i32) (i32.const 0)) | ||
| (global $global2 (mut i32) (i32.const 0)) | ||
|
|
||
| ;; CHECK: (export "test" (func $test)) | ||
|
|
||
| ;; CHECK: (export "keepalive" (func $keepalive)) | ||
|
|
||
| ;; CHECK: (start $start) | ||
| (start $start) | ||
|
|
||
| ;; CHECK: (func $start (type $0) | ||
| ;; CHECK-NEXT: (global.set $global2 | ||
| ;; CHECK-NEXT: (i32.const 42) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| (func $start | ||
| (global.set $global2 | ||
| (i32.const 42) | ||
| ) | ||
| ) | ||
|
|
||
| ;; CHECK: (func $test (type $0) | ||
| ;; CHECK-NEXT: (call $test) | ||
| ;; CHECK-NEXT: (global.set $global1 | ||
| ;; CHECK-NEXT: (i32.const 1337) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| (func $test (export "test") | ||
| (call $test) | ||
| (global.set $global1 | ||
| (i32.const 1337) | ||
| ) | ||
| ) | ||
|
|
||
| ;; CHECK: (func $keepalive (type $1) (result i32) | ||
| ;; CHECK-NEXT: (i32.add | ||
| ;; CHECK-NEXT: (global.get $global1) | ||
| ;; CHECK-NEXT: (global.get $global2) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| (func $keepalive (export "keepalive") (result i32) | ||
| ;; Keep the globals alive to show changes. | ||
| (i32.add | ||
| (global.get $global1) | ||
| (global.get $global2) | ||
| ) | ||
| ) | ||
| ) |
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 |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| ;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. | ||
| ;; RUN: foreach %s %t wasm-ctor-eval --ctors=test --kept-exports=test --quiet -all -S -o - | filecheck %s | ||
|
|
||
| ;; The start function traps here, so we cannot eval anything. None of the | ||
| ;; globals should change. | ||
|
|
||
| (module | ||
| ;; CHECK: (type $0 (func)) | ||
|
|
||
| ;; CHECK: (type $1 (func (result i32))) | ||
|
|
||
| ;; CHECK: (global $global1 (mut i32) (i32.const 0)) | ||
| (global $global1 (mut i32) (i32.const 0)) | ||
|
|
||
| ;; CHECK: (global $global2 (mut i32) (i32.const 0)) | ||
| (global $global2 (mut i32) (i32.const 0)) | ||
|
|
||
| ;; CHECK: (export "test" (func $test)) | ||
|
|
||
| ;; CHECK: (export "keepalive" (func $keepalive)) | ||
|
|
||
| ;; CHECK: (start $start) | ||
| (start $start) | ||
|
|
||
| ;; CHECK: (func $start (type $0) | ||
| ;; CHECK-NEXT: (global.set $global2 | ||
| ;; CHECK-NEXT: (i32.const 42) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (unreachable) | ||
| ;; CHECK-NEXT: ) | ||
| (func $start | ||
| (global.set $global2 | ||
| (i32.const 42) | ||
| ) | ||
| (unreachable) | ||
| ) | ||
|
|
||
| ;; CHECK: (func $test (type $0) | ||
| ;; CHECK-NEXT: (global.set $global1 | ||
| ;; CHECK-NEXT: (i32.const 1337) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| (func $test (export "test") | ||
| (global.set $global1 | ||
| (i32.const 1337) | ||
| ) | ||
| ) | ||
|
|
||
| ;; CHECK: (func $keepalive (type $1) (result i32) | ||
| ;; CHECK-NEXT: (i32.add | ||
| ;; CHECK-NEXT: (global.get $global1) | ||
| ;; CHECK-NEXT: (global.get $global2) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| (func $keepalive (export "keepalive") (result i32) | ||
| ;; Keep the globals alive to show changes. | ||
| (i32.add | ||
| (global.get $global1) | ||
| (global.get $global2) | ||
| ) | ||
| ) | ||
| ) |
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 |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| ;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. | ||
| ;; RUN: foreach %s %t wasm-ctor-eval --ctors=t,s --kept-exports=t,s --quiet -all -S -o - | filecheck %s | ||
|
|
||
| ;; A corner case where we export the start function and consider it a ctor. | ||
| ;; That it executes twice should not cause an internal error. | ||
|
|
||
| (module | ||
| (rec | ||
| ;; CHECK: (rec | ||
| ;; CHECK-NEXT: (type $A (sub (shared (struct (field (mut (ref null $B))))))) | ||
| (type $A (sub (shared (struct (field (mut (ref null $B))))))) | ||
| ;; CHECK: (type $B (sub (shared (struct (field (mut (ref null (shared any)))))))) | ||
| (type $B (sub (shared (struct (field (mut (ref null (shared any)))))))) | ||
| ) | ||
|
|
||
| (global $global (ref $A) (struct.new $A | ||
| (struct.new_default $B) | ||
| )) | ||
|
|
||
| (export "s" (func $s)) | ||
|
|
||
| (export "t" (func $t)) | ||
|
|
||
| (start $s) | ||
|
|
||
| (func $s | ||
| (nop) | ||
| ) | ||
|
|
||
| (func $t | ||
| (nop) | ||
| ) | ||
| ) | ||
|
|
||
| ;; CHECK: (type $2 (func)) | ||
|
|
||
| ;; CHECK: (global $ctor-eval$global_3 (ref (exact $A)) (struct.new $A | ||
| ;; CHECK-NEXT: (ref.null (shared none)) | ||
| ;; CHECK-NEXT: )) | ||
|
|
||
| ;; CHECK: (global $ctor-eval$global_4 (ref (exact $B)) (struct.new $B | ||
| ;; CHECK-NEXT: (ref.null (shared none)) | ||
| ;; CHECK-NEXT: )) | ||
|
|
||
| ;; CHECK: (export "s" (func $s_4)) | ||
|
|
||
| ;; CHECK: (export "t" (func $t_3)) | ||
|
|
||
| ;; CHECK: (start $start) | ||
|
|
||
| ;; CHECK: (func $start (type $2) | ||
| ;; CHECK-NEXT: (struct.set $A 0 | ||
| ;; CHECK-NEXT: (global.get $ctor-eval$global_3) | ||
| ;; CHECK-NEXT: (global.get $ctor-eval$global_4) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
|
|
||
| ;; CHECK: (func $t_3 (type $2) | ||
| ;; CHECK-NEXT: (nop) | ||
| ;; CHECK-NEXT: ) | ||
|
|
||
| ;; CHECK: (func $s_4 (type $2) | ||
| ;; CHECK-NEXT: (nop) | ||
| ;; CHECK-NEXT: ) | ||
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 | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,68 @@ | ||||||
| ;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. | ||||||
| ;; RUN: foreach %s %t wasm-ctor-eval --ctors=test --kept-exports=test --quiet -all -S -o - | filecheck %s | ||||||
|
|
||||||
| ;; This code does the following: | ||||||
| ;; | ||||||
| ;; * start writes global2, and traps if global1 is set. | ||||||
| ;; * test sets global1. | ||||||
| ;; | ||||||
| ;; We must eval away the start function, when we eval away the other. That is, | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| ;; there should be no start function afterwards. Otherwise, if it remains as the | ||||||
| ;; start, it will trap when it reads the modified global. | ||||||
| ;; | ||||||
| ;; While doing so we must apply the changes of the start function, to global2. | ||||||
| ;; So both globals end up modified. | ||||||
|
|
||||||
| (module | ||||||
| ;; CHECK: (type $0 (func (result i32))) | ||||||
|
|
||||||
| ;; CHECK: (type $1 (func)) | ||||||
|
|
||||||
| ;; CHECK: (global $global1 (mut i32) (i32.const 1337)) | ||||||
| (global $global1 (mut i32) (i32.const 0)) | ||||||
|
|
||||||
| ;; CHECK: (global $global2 (mut i32) (i32.const 42)) | ||||||
| (global $global2 (mut i32) (i32.const 0)) | ||||||
|
|
||||||
| (start $start) | ||||||
|
|
||||||
| (func $start | ||||||
| (global.set $global2 | ||||||
| (i32.const 42) | ||||||
| ) | ||||||
| (if | ||||||
| (global.get $global1) | ||||||
| (then | ||||||
| (unreachable) | ||||||
| ) | ||||||
| ) | ||||||
| ) | ||||||
|
|
||||||
| (func $test (export "test") | ||||||
| (global.set $global1 | ||||||
| (i32.const 1337) | ||||||
| ) | ||||||
| ) | ||||||
|
|
||||||
| ;; CHECK: (export "test" (func $test_3)) | ||||||
|
|
||||||
| ;; CHECK: (export "keepalive" (func $keepalive)) | ||||||
|
|
||||||
| ;; CHECK: (func $keepalive (type $0) (result i32) | ||||||
| ;; CHECK-NEXT: (i32.add | ||||||
| ;; CHECK-NEXT: (global.get $global1) | ||||||
| ;; CHECK-NEXT: (global.get $global2) | ||||||
| ;; CHECK-NEXT: ) | ||||||
| ;; CHECK-NEXT: ) | ||||||
| (func $keepalive (export "keepalive") (result i32) | ||||||
| ;; Keep the globals alive to show changes. | ||||||
| (i32.add | ||||||
| (global.get $global1) | ||||||
| (global.get $global2) | ||||||
| ) | ||||||
| ) | ||||||
| ) | ||||||
|
|
||||||
| ;; CHECK: (func $test_3 (type $1) | ||||||
| ;; CHECK-NEXT: (nop) | ||||||
| ;; CHECK-NEXT: ) | ||||||
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.
Maybe have this perform some visible side effect like incrementing a global so we can see that it happens twice?
Could we also construct a similar case where optimization ends after the start function is called but before it is called again as an exported constructor?