Skip to content

Commit 8c28617

Browse files
authored
[Custom Descriptors] Update wasm-ctor-eval (#7689)
Update wasm-ctor-eval to serialize descriptor operands to struct.new for those allocations that need them.
1 parent b52f669 commit 8c28617

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

scripts/test/fuzzing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
'heap2local-desc.wast',
125125
'minimize-rec-groups-desc.wast',
126126
'precompute-desc.wast',
127+
'gc-desc.wast',
127128
# TODO: fix split_wast() on tricky escaping situations like a string ending
128129
# in \\" (the " is not escaped - there is an escaped \ before it)
129130
'string-lifting-section.wast',

src/tools/wasm-ctor-eval.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface {
850850
} else {
851851
// This is the first usage of this data. Generate a struct.new /
852852
// array.new for it.
853-
auto& values = value.getGCData()->values;
853+
auto& values = data->values;
854854
std::vector<Expression*> args;
855855

856856
// The initial values for this allocation may themselves be GC
@@ -876,10 +876,15 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface {
876876
args.push_back(getSerialization(value));
877877
}
878878

879+
Expression* desc = nullptr;
880+
if (data->desc.getGCData()) {
881+
desc = getSerialization(data->desc);
882+
}
883+
879884
Expression* init;
880885
auto heapType = type.getHeapType();
881886
if (heapType.isStruct()) {
882-
init = builder.makeStructNew(heapType, args);
887+
init = builder.makeStructNew(heapType, args, desc);
883888
} else if (heapType.isArray()) {
884889
// TODO: for repeated identical values, can use ArrayNew
885890
init = builder.makeArrayNewFixed(heapType, args);

test/lit/ctor-eval/gc-desc.wast

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
2+
;; RUN: wasm-ctor-eval %s --ctors=ctor --kept-exports=ctor --quiet -all -S -o - | filecheck %s
3+
4+
(module
5+
(rec
6+
;; CHECK: (rec
7+
;; CHECK-NEXT: (type $struct (sub (descriptor $desc (struct))))
8+
(type $struct (sub (descriptor $desc (struct))))
9+
;; CHECK: (type $desc (describes $struct (struct)))
10+
(type $desc (describes $struct (struct)))
11+
)
12+
;; CHECK: (type $2 (func))
13+
14+
;; CHECK: (global $ctor-eval$global_2 (ref (exact $desc)) (struct.new_default $desc))
15+
16+
;; CHECK: (global $ctor-eval$global (ref (exact $struct)) (struct.new_default $struct
17+
;; CHECK-NEXT: (global.get $ctor-eval$global_2)
18+
;; CHECK-NEXT: ))
19+
20+
;; CHECK: (global $global (ref $struct) (global.get $ctor-eval$global))
21+
(global $global (export "g") (ref $struct)
22+
(struct.new $struct
23+
(struct.new $desc)
24+
)
25+
)
26+
27+
;; Export some arbitrary ctor so we do anything at all.
28+
(func $ctor (export "ctor")
29+
(nop)
30+
)
31+
)
32+
;; CHECK: (export "g" (global $global))
33+
34+
;; CHECK: (export "ctor" (func $ctor_1))
35+
36+
;; CHECK: (func $ctor_1 (type $2)
37+
;; CHECK-NEXT: (nop)
38+
;; CHECK-NEXT: )

0 commit comments

Comments
 (0)