Skip to content

Commit 5acc62e

Browse files
committed
Runtime/wasm: fix method lookup, take 2
The method table contains the following. Index 0 contains the block's tag (0). Index 1 contains the number of public methods. Index 2 contains a mask. Then, we have each method followed by its tag. The table is completed with dummy non-integer values to reach a power-of-two size (not including the first three indices).
1 parent cd80102 commit 5acc62e

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
* Runtime: fix caml_string_concat when not using JS strings (#1874)
6060
* Runtime: consistent bigarray hashing across all architectures (#1977)
6161
* Runtime: fix caml_utf8_of_utf16 bug in high surrogate case (#2008)
62-
* Runtime/wasm: fix method lookup (#2034)
62+
* Runtime/wasm: fix method lookup (#2034, #2038)
6363
* Tools: fix jsoo_mktop and jsoo_mkcmis (#1877)
6464
* Toplevel: fix for when use-js-strings is disabled (#1997)
6565

runtime/wasm/obj.wat

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,11 @@
379379
(ref.i31 (i32.const 0)))
380380

381381
(global $method_cache (mut (ref $int_array))
382-
(array.new $int_array (i32.const 0) (i32.const 8)))
382+
(array.new $int_array (i32.const 4) (i32.const 8)))
383383

384384
(func (export "caml_get_public_method")
385-
(param $obj (ref eq)) (param (ref eq)) (param (ref eq)) (result (ref eq))
385+
(param $obj (ref eq)) (param $vtag (ref eq)) (param (ref eq))
386+
(result (ref eq))
386387
(local $meths (ref $block))
387388
(local $tag i32) (local $cacheid i32) (local $ofs i32)
388389
(local $li i32) (local $mi i32) (local $hi i32)
@@ -391,15 +392,14 @@
391392
(ref.cast (ref $block)
392393
(array.get $block
393394
(ref.cast (ref $block) (local.get $obj)) (i32.const 1))))
394-
(local.set $tag (i31.get_s (ref.cast (ref i31) (local.get 1))))
395395
(local.set $cacheid (i31.get_u (ref.cast (ref i31) (local.get 2))))
396396
(local.set $len (array.len (global.get $method_cache)))
397397
(if (i32.ge_s (local.get $cacheid) (local.get $len))
398398
(then
399399
(loop $size
400400
(local.set $len (i32.shl (local.get $len) (i32.const 1)))
401401
(br_if $size (i32.ge_s (local.get $cacheid) (local.get $len))))
402-
(local.set $a (array.new $int_array (i32.const 0) (local.get $len)))
402+
(local.set $a (array.new $int_array (i32.const 4) (local.get $len)))
403403
(array.copy $int_array $int_array
404404
(local.get $a) (i32.const 0)
405405
(global.get $method_cache) (i32.const 0)
@@ -409,16 +409,14 @@
409409
(array.get $int_array (global.get $method_cache) (local.get $cacheid)))
410410
(if (i32.lt_u (local.get $ofs) (array.len (local.get $meths)))
411411
(then
412-
(if (i32.eq (local.get $tag)
413-
(i31.get_s
414-
(ref.cast (ref i31)
415-
(array.get $block (local.get $meths)
416-
(local.get $ofs)))))
412+
(if (ref.eq (local.get $vtag)
413+
(array.get $block (local.get $meths) (local.get $ofs)))
417414
(then
418415
(return
419416
(array.get $block
420417
(local.get $meths)
421418
(i32.sub (local.get $ofs) (i32.const 1))))))))
419+
(local.set $tag (i31.get_s (ref.cast (ref i31) (local.get $vtag))))
422420
(local.set $li (i32.const 3))
423421
(local.set $hi
424422
(i32.add
@@ -450,11 +448,9 @@
450448
(array.set $int_array (global.get $method_cache) (local.get $cacheid)
451449
(i32.add (local.get $li) (i32.const 1)))
452450
(if (result (ref eq))
453-
(i32.eq (local.get $tag)
454-
(i31.get_s
455-
(ref.cast (ref i31)
456-
(array.get $block (local.get $meths)
457-
(i32.add (local.get $li) (i32.const 1))))))
451+
(ref.eq (local.get $vtag)
452+
(array.get $block (local.get $meths)
453+
(i32.add (local.get $li) (i32.const 1))))
458454
(then
459455
(array.get $block (local.get $meths) (local.get $li)))
460456
(else

0 commit comments

Comments
 (0)