Skip to content

Commit 1bf7d08

Browse files
authored
[Strings] Add the string heaptype to core fuzzer places (#6527)
With this we emit strings spontaneously (as opposed to just getting them from initial contents). The relevant -ttf test has been tweaked slightly to show the impact of this change: now there are some string.new/const in the output.
1 parent 42db73a commit 1bf7d08

File tree

4 files changed

+67
-62
lines changed

4 files changed

+67
-62
lines changed

scripts/fuzz_opt.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,8 @@ def get_random_opts():
16801680
# some features depend on other features, so if a required feature is
16811681
# disabled, its dependent features need to be disabled as well.
16821682
IMPLIED_FEATURE_OPTS = {
1683-
'--disable-reference-types': ['--disable-gc'],
1683+
'--disable-reference-types': ['--disable-gc', '--disable-strings'],
1684+
'--disable-gc': ['--disable-strings'],
16841685
}
16851686

16861687
print('''

src/tools/fuzzing/fuzzing.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,18 +2537,12 @@ Expression* TranslateToFuzzReader::makeBasicRef(Type type) {
25372537
// Choose a subtype we can materialize a constant for. We cannot
25382538
// materialize non-nullable refs to func or i31 in global contexts.
25392539
Nullability nullability = getSubType(type.getNullability());
2540-
HeapType subtype;
2541-
switch (upTo(3)) {
2542-
case 0:
2543-
subtype = HeapType::i31;
2544-
break;
2545-
case 1:
2546-
subtype = HeapType::struct_;
2547-
break;
2548-
case 2:
2549-
subtype = HeapType::array;
2550-
break;
2551-
}
2540+
auto subtype = pick(FeatureOptions<HeapType>()
2541+
.add(FeatureSet::ReferenceTypes | FeatureSet::GC,
2542+
HeapType::i31,
2543+
HeapType::struct_,
2544+
HeapType::array)
2545+
.add(FeatureSet::Strings, HeapType::string));
25522546
return makeConst(Type(subtype, nullability));
25532547
}
25542548
case HeapType::eq: {
@@ -3994,7 +3988,10 @@ Type TranslateToFuzzReader::getSingleConcreteType() {
39943988
Type(HeapType::struct_, Nullable),
39953989
Type(HeapType::struct_, NonNullable),
39963990
Type(HeapType::array, Nullable),
3997-
Type(HeapType::array, NonNullable)));
3991+
Type(HeapType::array, NonNullable))
3992+
.add(FeatureSet::Strings,
3993+
Type(HeapType::string, Nullable),
3994+
Type(HeapType::string, NonNullable)));
39983995
}
39993996

40003997
Type TranslateToFuzzReader::getReferenceType() {
@@ -4017,7 +4014,10 @@ Type TranslateToFuzzReader::getReferenceType() {
40174014
Type(HeapType::struct_, Nullable),
40184015
Type(HeapType::struct_, NonNullable),
40194016
Type(HeapType::array, Nullable),
4020-
Type(HeapType::array, NonNullable)));
4017+
Type(HeapType::array, NonNullable))
4018+
.add(FeatureSet::Strings,
4019+
Type(HeapType::string, Nullable),
4020+
Type(HeapType::string, NonNullable)));
40214021
}
40224022

40234023
Type TranslateToFuzzReader::getEqReferenceType() {
@@ -4137,12 +4137,15 @@ HeapType TranslateToFuzzReader::getSubType(HeapType type) {
41374137
case HeapType::any:
41384138
assert(wasm.features.hasReferenceTypes());
41394139
assert(wasm.features.hasGC());
4140-
return pick(HeapType::any,
4141-
HeapType::eq,
4142-
HeapType::i31,
4143-
HeapType::struct_,
4144-
HeapType::array,
4145-
HeapType::none);
4140+
return pick(FeatureOptions<HeapType>()
4141+
.add(FeatureSet::GC,
4142+
HeapType::any,
4143+
HeapType::eq,
4144+
HeapType::i31,
4145+
HeapType::struct_,
4146+
HeapType::array,
4147+
HeapType::none)
4148+
.add(FeatureSet::Strings, HeapType::string));
41464149
case HeapType::eq:
41474150
assert(wasm.features.hasReferenceTypes());
41484151
assert(wasm.features.hasGC());
Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
11
total
2-
[exports] : 5
3-
[funcs] : 8
4-
[globals] : 1
2+
[exports] : 4
3+
[funcs] : 5
4+
[globals] : 14
55
[imports] : 5
66
[memories] : 1
77
[memory-data] : 20
88
[table-data] : 1
99
[tables] : 1
10-
[tags] : 2
11-
[total] : 674
12-
[vars] : 41
13-
ArrayCopy : 1
14-
ArrayGet : 3
15-
ArrayLen : 4
16-
ArrayNew : 5
10+
[tags] : 1
11+
[total] : 710
12+
[vars] : 35
13+
ArrayGet : 1
14+
ArrayLen : 1
15+
ArrayNew : 16
1716
ArrayNewFixed : 1
18-
ArraySet : 1
19-
AtomicFence : 1
20-
AtomicNotify : 3
2117
AtomicRMW : 1
22-
Binary : 84
23-
Block : 75
24-
Break : 12
25-
Call : 21
26-
Const : 133
27-
Drop : 6
28-
GlobalGet : 24
29-
GlobalSet : 24
30-
I31Get : 3
31-
If : 21
18+
Binary : 77
19+
Block : 57
20+
Break : 8
21+
Call : 33
22+
Const : 159
23+
Drop : 7
24+
GlobalGet : 17
25+
GlobalSet : 14
26+
I31Get : 2
27+
If : 19
3228
Load : 22
33-
LocalGet : 65
34-
LocalSet : 50
35-
Loop : 6
36-
Nop : 4
37-
Pop : 7
38-
RefAs : 7
29+
LocalGet : 66
30+
LocalSet : 37
31+
Loop : 3
32+
MemoryFill : 1
33+
Nop : 7
34+
Pop : 4
35+
RefAs : 14
3936
RefCast : 3
40-
RefFunc : 2
41-
RefI31 : 7
42-
RefIsNull : 2
43-
RefNull : 11
37+
RefEq : 1
38+
RefFunc : 4
39+
RefI31 : 9
40+
RefIsNull : 3
41+
RefNull : 26
4442
RefTest : 2
45-
Return : 8
46-
Select : 3
43+
Return : 9
44+
SIMDExtract : 3
45+
StringConst : 2
46+
StringNew : 1
4747
StructGet : 1
48-
StructNew : 3
49-
StructSet : 2
48+
StructNew : 27
49+
Throw : 1
5050
Try : 5
51-
TupleExtract : 3
52-
TupleMake : 4
53-
Unary : 21
54-
Unreachable : 13
51+
TupleExtract : 15
52+
TupleMake : 9
53+
Unary : 15
54+
Unreachable : 7

test/passes/translate-to-fuzz_all-features_metrics_noprint.wast

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ h e r e
77
d0
88
0.753538467597066
99
2.2339337309978227
10+
3.14159
1011
.................
1112
lorem ipsum whatever
1213

0 commit comments

Comments
 (0)