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

J2CL: use a more future proof naming convention for once functions #6173

Merged
merged 5 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/passes/J2CLOpts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace wasm {

namespace {

bool isOnceFunction(Function* f) { return f->name.hasSubstring("_@once@_"); }
bool isOnceFunction(Function* f) { return f->name.hasSubstring("_<once>_"); }

using AssignmentCountMap = std::unordered_map<Name, Index>;

Expand Down
22 changes: 12 additions & 10 deletions test/lit/passes/j2cl-inline.wast
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.

;; RUN: foreach %s %t wasm-opt --no-inline=*_@once@_* --optimize-j2cl --inlining --vacuum --optimize-level=3 -all -S -o - | filecheck %s
;; NOTE: In real world example no-inline would use _<once>_ but there is escaping problem in a multi-platform
;; way in lit so we are working around it by using no-inline with a different pattern that matches same method.
;; RUN: foreach %s %t wasm-opt --no-inline=*clinit* --optimize-j2cl --inlining --vacuum --optimize-level=3 -all -S -o - | filecheck %s

;; Only trivial once functions are inlined
(module

;; A once function that has become empty
(func $clinit-trivial-1_@once@_@Foo )
(func $clinit-trivial-1_<once>_@Foo )

;; A once function that just calls another
(func $clinit-trivial-2_@once@_@Bar
(call $clinit-trivial-1_@once@_@Foo)
(func $clinit-trivial-2_<once>_@Bar
(call $clinit-trivial-1_<once>_@Foo)
)

;; CHECK: (type $0 (func))
Expand All @@ -19,7 +21,7 @@
(global $$class-initialized@Zoo (mut i32) (i32.const 0))

;; Not hoisted but trivial.
;; CHECK: (func $clinit-non-trivial_@once@_@Zoo (type $0)
;; CHECK: (func $clinit-non-trivial_<once>_@Zoo (type $0)
;; CHECK-NEXT: (if
;; CHECK-NEXT: (global.get $$class-initialized@Zoo)
;; CHECK-NEXT: (return)
Expand All @@ -28,19 +30,19 @@
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $clinit-non-trivial_@once@_@Zoo
(func $clinit-non-trivial_<once>_@Zoo
(if (global.get $$class-initialized@Zoo)
(return)
)
(global.set $$class-initialized@Zoo (i32.const 1))
)

;; CHECK: (func $main (type $0)
;; CHECK-NEXT: (call $clinit-non-trivial_@once@_@Zoo)
;; CHECK-NEXT: (call $clinit-non-trivial_<once>_@Zoo)
;; CHECK-NEXT: )
(func $main
(call $clinit-trivial-1_@once@_@Foo)
(call $clinit-trivial-2_@once@_@Bar)
(call $clinit-non-trivial_@once@_@Zoo)
(call $clinit-trivial-1_<once>_@Foo)
(call $clinit-trivial-2_<once>_@Bar)
(call $clinit-non-trivial_<once>_@Zoo)
)
)
24 changes: 12 additions & 12 deletions test/lit/passes/j2cl.wast
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
(global $field-i32@Foo (mut i32) (i32.const 0))
(global $field-f64@Foo (mut f64) (f64.const 0))

;; CHECK: (func $clinit_@once@_@Foo (type $0)
;; CHECK: (func $clinit_<once>_@Foo (type $0)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $clinit_@once@_@Foo
(func $clinit_<once>_@Foo
(global.set $field-i32@Foo (i32.const 1))
(global.set $field-f64@Foo (f64.const 1))
)
Expand Down Expand Up @@ -48,14 +48,14 @@
;; CHECK: (global $field3@Foo anyref (global.get $field1@Foo))
(global $field3@Foo (mut anyref) (ref.null none))

;; CHECK: (func $clinit_@once@_@Foo (type $1)
;; CHECK: (func $clinit_<once>_@Foo (type $1)
;; CHECK-NEXT: (global.set $field2@Foo
;; CHECK-NEXT: (struct.new $A
;; CHECK-NEXT: (global.get $referredFieldMut@Foo)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $clinit_@once@_@Foo
(func $clinit_<once>_@Foo
;; Referred field is immutable, should hoist
(global.set $field1@Foo (struct.new $A (
global.get $referredField@Foo)
Expand Down Expand Up @@ -85,15 +85,15 @@

(global $field-any@Foo (mut anyref) (struct.new $A))

;; CHECK: (func $clinit_@once@_@Foo (type $1)
;; CHECK: (func $clinit_<once>_@Foo (type $1)
;; CHECK-NEXT: (global.set $field-i32@Foo
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: (global.set $field-any@Foo
;; CHECK-NEXT: (struct.new_default $A)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $clinit_@once@_@Foo
(func $clinit_<once>_@Foo
(global.set $field-i32@Foo (i32.const 1))
(global.set $field-any@Foo (struct.new $A))
)
Expand All @@ -107,10 +107,10 @@
;; CHECK: (global $field@Foo i32 (i32.const 1))
(global $field@Foo (mut i32) (i32.const 0))

;; CHECK: (func $clinit_@once@_@Foo (type $0)
;; CHECK: (func $clinit_<once>_@Foo (type $0)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $clinit_@once@_@Foo
(func $clinit_<once>_@Foo
(global.set $field@Foo (i32.const 1))
)
)
Expand All @@ -123,12 +123,12 @@
;; CHECK: (global $$class-initialized@Foo (mut i32) (i32.const 0))
(global $$class-initialized@Foo (mut i32) (i32.const 0))

;; CHECK: (func $clinit_@once@_@Foo (type $0)
;; CHECK: (func $clinit_<once>_@Foo (type $0)
;; CHECK-NEXT: (global.set $$class-initialized@Foo
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $clinit_@once@_@Foo
(func $clinit_<once>_@Foo
(global.set $$class-initialized@Foo (i32.const 1))
)
)
Expand All @@ -141,12 +141,12 @@
;; CHECK: (global $field@Foo (mut i32) (i32.const 0))
(global $field@Foo (mut i32) (i32.const 0))

;; CHECK: (func $clinit_@once@_@Bar (type $0)
;; CHECK: (func $clinit_<once>_@Bar (type $0)
;; CHECK-NEXT: (global.set $field@Foo
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $clinit_@once@_@Bar
(func $clinit_<once>_@Bar
;; Note that $clinit is @Bar and field is @Foo.
(global.set $field@Foo (i32.const 1))
)
Expand Down
Loading