Skip to content

Commit fb0d94e

Browse files
committed
Bug 1546138 - Wasm: Implement 'ref.func'. r=bbouvier
This commit implements the 'ref.func' instruction by emitting an instance call to WasmInstanceObject::getExportedFunction. The referenced function must be used in an element segment to validate. See [1] for more details. [1] WebAssembly/reference-types#31 Differential Revision: https://phabricator.services.mozilla.com/D40586 UltraBlame original commit: 00e5548e9c435314beb0c572e1476330b06e1d6d
1 parent 1606a8b commit fb0d94e

14 files changed

+1474
-0
lines changed

js/src/jit-test/tests/wasm/gc/ref-func.js

Lines changed: 487 additions & 0 deletions
Large diffs are not rendered by default.

js/src/wasm/WasmAST.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,6 +2251,7 @@ MemoryGrow
22512251
MemorySize
22522252
Nop
22532253
Pop
2254+
RefFunc
22542255
RefNull
22552256
Return
22562257
SetGlobal
@@ -8801,6 +8802,61 @@ operand_
88018802
}
88028803
;
88038804
class
8805+
AstRefFunc
8806+
final
8807+
:
8808+
public
8809+
AstExpr
8810+
{
8811+
AstRef
8812+
func_
8813+
;
8814+
public
8815+
:
8816+
static
8817+
const
8818+
AstExprKind
8819+
Kind
8820+
=
8821+
AstExprKind
8822+
:
8823+
:
8824+
RefFunc
8825+
;
8826+
explicit
8827+
AstRefFunc
8828+
(
8829+
AstRef
8830+
func
8831+
)
8832+
:
8833+
AstExpr
8834+
(
8835+
Kind
8836+
ExprType
8837+
:
8838+
:
8839+
FuncRef
8840+
)
8841+
func_
8842+
(
8843+
func
8844+
)
8845+
{
8846+
}
8847+
AstRef
8848+
&
8849+
func
8850+
(
8851+
)
8852+
{
8853+
return
8854+
func_
8855+
;
8856+
}
8857+
}
8858+
;
8859+
class
88048860
AstRefNull
88058861
final
88068862
:

js/src/wasm/WasmBaselineCompile.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32909,6 +32909,12 @@ emitMemorySize
3290932909
;
3291032910
MOZ_MUST_USE
3291132911
bool
32912+
emitRefFunc
32913+
(
32914+
)
32915+
;
32916+
MOZ_MUST_USE
32917+
bool
3291232918
emitRefNull
3291332919
(
3291432920
)
@@ -47205,6 +47211,62 @@ bool
4720547211
BaseCompiler
4720647212
:
4720747213
:
47214+
emitRefFunc
47215+
(
47216+
)
47217+
{
47218+
uint32_t
47219+
lineOrBytecode
47220+
=
47221+
readCallSiteLineOrBytecode
47222+
(
47223+
)
47224+
;
47225+
uint32_t
47226+
funcIndex
47227+
;
47228+
if
47229+
(
47230+
!
47231+
iter_
47232+
.
47233+
readRefFunc
47234+
(
47235+
&
47236+
funcIndex
47237+
)
47238+
)
47239+
{
47240+
return
47241+
false
47242+
;
47243+
}
47244+
if
47245+
(
47246+
deadCode_
47247+
)
47248+
{
47249+
return
47250+
true
47251+
;
47252+
}
47253+
pushI32
47254+
(
47255+
funcIndex
47256+
)
47257+
;
47258+
return
47259+
emitInstanceCall
47260+
(
47261+
lineOrBytecode
47262+
SASigFuncRef
47263+
)
47264+
;
47265+
}
47266+
bool
47267+
BaseCompiler
47268+
:
47269+
:
4720847270
emitRefNull
4720947271
(
4721047272
)
@@ -56563,6 +56625,24 @@ uint16_t
5656356625
Op
5656456626
:
5656556627
:
56628+
RefFunc
56629+
)
56630+
:
56631+
CHECK_NEXT
56632+
(
56633+
emitRefFunc
56634+
(
56635+
)
56636+
)
56637+
;
56638+
break
56639+
;
56640+
case
56641+
uint16_t
56642+
(
56643+
Op
56644+
:
56645+
:
5656656646
RefNull
5656756647
)
5656856648
:

js/src/wasm/WasmBuiltins.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,25 @@ _END
913913
;
914914
const
915915
SymbolicAddressSignature
916+
SASigFuncRef
917+
=
918+
{
919+
SymbolicAddress
920+
:
921+
:
922+
FuncRef
923+
_RoN
924+
_FailOnInvalidRef
925+
2
926+
{
927+
_PTR
928+
_I32
929+
_END
930+
}
931+
}
932+
;
933+
const
934+
SymbolicAddressSignature
916935
SASigPostBarrier
917936
=
918937
{
@@ -4795,6 +4814,28 @@ case
47954814
SymbolicAddress
47964815
:
47974816
:
4817+
FuncRef
4818+
:
4819+
*
4820+
abiType
4821+
=
4822+
Args_General2
4823+
;
4824+
return
4825+
FuncCast
4826+
(
4827+
Instance
4828+
:
4829+
:
4830+
funcRef
4831+
*
4832+
abiType
4833+
)
4834+
;
4835+
case
4836+
SymbolicAddress
4837+
:
4838+
:
47984839
PostBarrier
47994840
:
48004841
*
@@ -5484,6 +5525,12 @@ case
54845525
SymbolicAddress
54855526
:
54865527
:
5528+
FuncRef
5529+
:
5530+
case
5531+
SymbolicAddress
5532+
:
5533+
:
54875534
PostBarrier
54885535
:
54895536
case

js/src/wasm/WasmBuiltins.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ SASigTableSize
200200
extern
201201
const
202202
SymbolicAddressSignature
203+
SASigFuncRef
204+
;
205+
extern
206+
const
207+
SymbolicAddressSignature
203208
SASigPostBarrier
204209
;
205210
extern

js/src/wasm/WasmFrameIter.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7353,6 +7353,23 @@ case
73537353
SymbolicAddress
73547354
:
73557355
:
7356+
FuncRef
7357+
:
7358+
return
7359+
"
7360+
call
7361+
to
7362+
native
7363+
func
7364+
.
7365+
ref
7366+
function
7367+
"
7368+
;
7369+
case
7370+
SymbolicAddress
7371+
:
7372+
:
73567373
PostBarrier
73577374
:
73587375
return

0 commit comments

Comments
 (0)