Skip to content

Commit

Permalink
TFP (#75)
Browse files Browse the repository at this point in the history
* implemet multi tag, found bug at suspend16 for forgetting meta-continuation

* forgor one test

* only the control flow structure for failed suspend16 test

* push wast file

* newMk doesn't work also

* push wast file

* revert nested resume

* some refactor; add test spec

* revert accidental change

* use the right remaining stack

* rebase on Dinghong's version

* check point

* refactoring

* minor refactor

* handler

* refactor eval, taking only single inst

* try catch

* rebase Dinghong's tests

* some clean up

* unify value repr for cont

* test case: throw -> resume -> throw -> no resume

* initial impl for wasmfx

* unreachable not trap

* rm redundant case

* fix call ref

* create tfp only, delete trail, simplify handlers

* simplify contV, comment on handler

* this brnach only runs tfp, not fx

* reflect fix of return_call in #76

* drafting sem for fused eval

* rm comment

* support for loop

Co-authored-by:  Jiaaaaatai <[email protected]

* first try with return_call.wast

* look at return_call.wast failure

* even odd had the same problem, ignore ASSERT_INVALID

* forgor

* rm wasmfx conflictst

* both FX and TFP in CI

---------

Co-authored-by: ahuoguo <[email protected]>
Co-authored-by: butterunderflow <[email protected]>
Co-authored-by: Alex Bai <[email protected]>
  • Loading branch information
4 people authored Jan 30, 2025
1 parent 7aebeb5 commit 1b69018
Show file tree
Hide file tree
Showing 21 changed files with 4,282 additions and 3,070 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/scala.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ jobs:
sbt 'testOnly gensym.TestLibrary'
sbt 'testOnly gensym.wasm.TestEval'
sbt 'testOnly gensym.wasm.TestScriptRun'
sbt 'testOnly gensym.wasm.TestFx'
sbt 'testOnly gensym.wasm.TestTFP'
sbt 'testOnly gensym.wasm.TestFX'
24 changes: 24 additions & 0 deletions benchmarks/wasm/count.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(module
(type (;0;) (func (param i32) (result i32)))
(type (;1;) (func))
(func (;0;) (type 0) (param i32) (result i32)
local.get 0
i32.eqz
if (result i32) ;; label = @1
local.get 0
else
local.get 0
i32.const 1
i32.sub
return_call 0
end
)
(func (;1;) (type 1)
;; TODO: now setting it to 100K will result in stack overflow
i32.const 10000 ;; it will not terminate when it's 1mil
;; TODO: this doesn't seem like an error in our semantics
;; but something about sbt. But why?
call 0
)
(start 1)
)
40 changes: 40 additions & 0 deletions benchmarks/wasm/for_loop.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
(module
(func $for_loop (result i32)
(local i32)
(local i32)

for
(
;; init
i32.const 0
local.set 0
i32.const 0
local.set 1
|
;; cond
local.get 1
i32.const 10
i32.gt_s
i32.eqz
|
;; post
local.get 1
i32.const 1
i32.add
local.set 1
)

;; es
local.get 0
local.get 1
i32.add
local.set 0

local.get 0


)

(export "for_loop" (func 0))

)
33 changes: 33 additions & 0 deletions benchmarks/wasm/return_call.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
(module
(type (;0;) (func (param i64) (result i32)))
(type (;1;) (func))
(func (;0;) (type 0) (param i64) (result i32)
local.get 0
i64.eqz
if (result i32) ;; label = @1
i32.const 44
else
local.get 0
i64.const 1
i64.sub
return_call 1
end
)
(func (;1;) (type 0) (param i64) (result i32)
local.get 0
i64.eqz
if (result i32) ;; label = @1
i32.const 99
else
local.get 0
i64.const 1
i64.sub
return_call 0
end
)
(func (;2;) (type 1)
i64.const 100000
call 0
)
(start 2)
)
194 changes: 194 additions & 0 deletions benchmarks/wasm/spectest/return_call.bin.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
(module definition binary
"\00\61\73\6d\01\00\00\00\01\c8\80\80\80\00\0e\60"
"\00\01\7f\60\00\01\7e\60\00\01\7d\60\00\01\7c\60"
"\01\7f\01\7f\60\01\7e\01\7e\60\01\7d\01\7d\60\01"
"\7c\01\7c\60\02\7d\7f\01\7f\60\02\7f\7e\01\7e\60"
"\02\7c\7d\01\7d\60\02\7e\7c\01\7c\60\02\7e\7e\01"
"\7e\60\01\7e\01\7f\03\9d\80\80\80\00\1c\00\01\02"
"\03\04\05\06\07\08\09\0a\0b\00\01\02\03\00\01\02"
"\03\00\01\02\03\0c\05\0d\0d\07\d8\81\80\80\00\10"
"\08\74\79\70\65\2d\69\33\32\00\0c\08\74\79\70\65"
"\2d\69\36\34\00\0d\08\74\79\70\65\2d\66\33\32\00"
"\0e\08\74\79\70\65\2d\66\36\34\00\0f\0e\74\79\70"
"\65\2d\66\69\72\73\74\2d\69\33\32\00\10\0e\74\79"
"\70\65\2d\66\69\72\73\74\2d\69\36\34\00\11\0e\74"
"\79\70\65\2d\66\69\72\73\74\2d\66\33\32\00\12\0e"
"\74\79\70\65\2d\66\69\72\73\74\2d\66\36\34\00\13"
"\0f\74\79\70\65\2d\73\65\63\6f\6e\64\2d\69\33\32"
"\00\14\0f\74\79\70\65\2d\73\65\63\6f\6e\64\2d\69"
"\36\34\00\15\0f\74\79\70\65\2d\73\65\63\6f\6e\64"
"\2d\66\33\32\00\16\0f\74\79\70\65\2d\73\65\63\6f"
"\6e\64\2d\66\36\34\00\17\07\66\61\63\2d\61\63\63"
"\00\18\05\63\6f\75\6e\74\00\19\04\65\76\65\6e\00"
"\1a\03\6f\64\64\00\1b\0a\80\83\80\80\00\1c\85\80"
"\80\80\00\00\41\b2\02\0b\85\80\80\80\00\00\42\e4"
"\02\0b\87\80\80\80\00\00\43\00\20\73\45\0b\8b\80"
"\80\80\00\00\44\00\00\00\00\00\c8\ae\40\0b\84\80"
"\80\80\00\00\20\00\0b\84\80\80\80\00\00\20\00\0b"
"\84\80\80\80\00\00\20\00\0b\84\80\80\80\00\00\20"
"\00\0b\84\80\80\80\00\00\20\01\0b\84\80\80\80\00"
"\00\20\01\0b\84\80\80\80\00\00\20\01\0b\84\80\80"
"\80\00\00\20\01\0b\84\80\80\80\00\00\12\00\0b\84"
"\80\80\80\00\00\12\01\0b\84\80\80\80\00\00\12\02"
"\0b\84\80\80\80\00\00\12\03\0b\86\80\80\80\00\00"
"\41\20\12\04\0b\87\80\80\80\00\00\42\c0\00\12\05"
"\0b\89\80\80\80\00\00\43\c3\f5\a8\3f\12\06\0b\8d"
"\80\80\80\00\00\44\3d\0a\d7\a3\70\3d\fa\3f\12\07"
"\0b\8b\80\80\80\00\00\43\66\66\00\42\41\20\12\08"
"\0b\89\80\80\80\00\00\41\20\42\c0\00\12\09\0b\92"
"\80\80\80\00\00\44\00\00\00\00\00\00\50\40\43\00"
"\00\00\42\12\0a\0b\90\80\80\80\00\00\42\c0\00\44"
"\66\66\66\66\66\06\50\40\12\0b\0b\97\80\80\80\00"
"\00\20\00\50\04\7e\20\01\05\20\00\42\01\7d\20\00"
"\20\01\7e\12\18\0b\0b\92\80\80\80\00\00\20\00\50"
"\04\7e\20\00\05\20\00\42\01\7d\12\19\0b\0b\92\80"
"\80\80\00\00\20\00\50\04\7f\41\2c\05\20\00\42\01"
"\7d\12\1b\0b\0b\93\80\80\80\00\00\20\00\50\04\7f"
"\41\e3\00\05\20\00\42\01\7d\12\1a\0b\0b"
)
(module instance)
(assert_return (invoke "type-i32") (i32.const 0x132))
(assert_return (invoke "type-i64") (i64.const 0x164))
;; (assert_return (invoke "type-f32") (f32.const 0x1.e64p+11))
;; (assert_return (invoke "type-f64") (f64.const 0x1.ec8p+11))
(assert_return (invoke "type-first-i32") (i32.const 0x20))
(assert_return (invoke "type-first-i64") (i64.const 0x40))
;; (assert_return (invoke "type-first-f32") (f32.const 0x1.51eb_86p+0))
;; (assert_return (invoke "type-first-f64") (f64.const 0x1.a3d7_0a3d_70a3_dp+0))
(assert_return (invoke "type-second-i32") (i32.const 0x20))
(assert_return (invoke "type-second-i64") (i64.const 0x40))
(assert_return (invoke "type-second-f32") (f32.const 0x1p+5))
;; (assert_return (invoke "type-second-f64") (f64.const 0x1.0066_6666_6666_6p+6))
(assert_return
(invoke "fac-acc" (i64.const 0x0) (i64.const 0x1))
(i64.const 0x1)
)
(assert_return
(invoke "fac-acc" (i64.const 0x1) (i64.const 0x1))
(i64.const 0x1)
)
(assert_return
(invoke "fac-acc" (i64.const 0x5) (i64.const 0x1))
(i64.const 0x78)
)
(assert_return (invoke "count" (i64.const 0x0)) (i64.const 0x0))
(assert_return (invoke "count" (i64.const 0x3e8)) (i64.const 0x0))
;; See `count.wat` for why this is commented out
;; (assert_return (invoke "count" (i64.const 0xf_4240)) (i64.const 0x0))
(assert_return (invoke "even" (i64.const 0x0)) (i32.const 0x2c))
(assert_return (invoke "even" (i64.const 0x1)) (i32.const 0x63))
(assert_return (invoke "even" (i64.const 0x64)) (i32.const 0x2c))
(assert_return (invoke "even" (i64.const 0x4d)) (i32.const 0x63))
;; See `return_call.wat` for why these are commented out
;; (assert_return (invoke "even" (i64.const 0xf_4240)) (i32.const 0x2c))
;; (assert_return (invoke "even" (i64.const 0xf_4241)) (i32.const 0x63))
(assert_return (invoke "odd" (i64.const 0x0)) (i32.const 0x63))
(assert_return (invoke "odd" (i64.const 0x1)) (i32.const 0x2c))
(assert_return (invoke "odd" (i64.const 0xc8)) (i32.const 0x63))
(assert_return (invoke "odd" (i64.const 0x4d)) (i32.const 0x2c))
;; (assert_return (invoke "odd" (i64.const 0xf_4240)) (i32.const 0x63))
;; (assert_return (invoke "odd" (i64.const 0xf_423f)) (i32.const 0x2c))
(assert_invalid
(module binary
"\00\61\73\6d\01\00\00\00\01\88\80\80\80\00\02\60"
"\00\01\7f\60\00\00\03\83\80\80\80\00\02\00\01\0a"
"\93\80\80\80\00\02\86\80\80\80\00\00\12\01\41\00"
"\0b\82\80\80\80\00\00\0b"
)
"type mismatch"
)
(assert_invalid
(module binary
"\00\61\73\6d\01\00\00\00\01\89\80\80\80\00\02\60"
"\00\01\7f\60\00\01\7e\03\83\80\80\80\00\02\00\01"
"\0a\95\80\80\80\00\02\86\80\80\80\00\00\12\01\41"
"\00\0b\84\80\80\80\00\00\42\01\0b"
)
"type mismatch"
)
(assert_invalid
(module binary
"\00\61\73\6d\01\00\00\00\01\88\80\80\80\00\02\60"
"\00\00\60\01\7f\00\03\83\80\80\80\00\02\00\01\0a"
"\91\80\80\80\00\02\84\80\80\80\00\00\12\01\0b\82"
"\80\80\80\00\00\0b"
)
"type mismatch"
)
(assert_invalid
(module binary
"\00\61\73\6d\01\00\00\00\01\89\80\80\80\00\02\60"
"\00\00\60\02\7c\7f\00\03\83\80\80\80\00\02\00\01"
"\0a\91\80\80\80\00\02\84\80\80\80\00\00\12\01\0b"
"\82\80\80\80\00\00\0b"
)
"type mismatch"
)
(module definition binary
"\00\61\73\6d\01\00\00\00\01\84\80\80\80\00\01\60"
"\00\00\03\83\80\80\80\00\02\00\00\0a\93\80\80\80"
"\00\02\86\80\80\80\00\00\41\01\12\01\0b\82\80\80"
"\80\00\00\0b"
)
(module instance)
(module definition binary
"\00\61\73\6d\01\00\00\00\01\84\80\80\80\00\01\60"
"\00\00\03\83\80\80\80\00\02\00\00\0a\9c\80\80\80"
"\00\02\8f\80\80\80\00\00\44\00\00\00\00\00\00\00"
"\40\41\01\12\01\0b\82\80\80\80\00\00\0b"
)
(module instance)
(assert_invalid
(module binary
"\00\61\73\6d\01\00\00\00\01\89\80\80\80\00\02\60"
"\00\00\60\02\7f\7f\00\03\83\80\80\80\00\02\00\01"
"\0a\94\80\80\80\00\02\87\80\80\80\00\00\01\41\01"
"\12\01\0b\82\80\80\80\00\00\0b"
)
"type mismatch"
)
(assert_invalid
(module binary
"\00\61\73\6d\01\00\00\00\01\89\80\80\80\00\02\60"
"\00\00\60\02\7f\7f\00\03\83\80\80\80\00\02\00\01"
"\0a\94\80\80\80\00\02\87\80\80\80\00\00\41\01\01"
"\12\01\0b\82\80\80\80\00\00\0b"
)
"type mismatch"
)
(assert_invalid
(module binary
"\00\61\73\6d\01\00\00\00\01\89\80\80\80\00\02\60"
"\00\00\60\02\7f\7c\00\03\83\80\80\80\00\02\00\01"
"\0a\9c\80\80\80\00\02\8f\80\80\80\00\00\44\00\00"
"\00\00\00\00\f0\3f\41\01\12\01\0b\82\80\80\80\00"
"\00\0b"
)
"type mismatch"
)
(assert_invalid
(module binary
"\00\61\73\6d\01\00\00\00\01\89\80\80\80\00\02\60"
"\00\00\60\02\7c\7f\00\03\83\80\80\80\00\02\00\01"
"\0a\9c\80\80\80\00\02\8f\80\80\80\00\00\41\01\44"
"\00\00\00\00\00\00\f0\3f\12\01\0b\82\80\80\80\00"
"\00\0b"
)
"type mismatch"
)
(assert_invalid
(module binary
"\00\61\73\6d\01\00\00\00\01\84\80\80\80\00\01\60"
"\00\00\03\82\80\80\80\00\01\00\0a\8a\80\80\80\00"
"\01\84\80\80\80\00\00\12\01\0b"
)
"unknown function"
)
(assert_invalid
(module binary
"\00\61\73\6d\01\00\00\00\01\84\80\80\80\00\01\60"
"\00\00\03\82\80\80\80\00\01\00\0a\8e\80\80\80\00"
"\01\88\80\80\80\00\00\12\94\98\db\e2\03\0b"
)
"unknown function"
)
Loading

0 comments on commit 1b69018

Please sign in to comment.