summaryrefslogtreecommitdiff
path: root/src/tools/fuzzing
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2023-04-19 17:22:28 -0700
committerGitHub <noreply@github.com>2023-04-19 17:22:28 -0700
commit9e5961792a91774962815d58c5c73bfb5612e27c (patch)
tree5f076b905041cc31c0cb58b298f010cbe0a4e226 /src/tools/fuzzing
parent7cd2396dacf276750a3e27320d6b9d2af6f939d9 (diff)
downloadbinaryen-9e5961792a91774962815d58c5c73bfb5612e27c.tar.gz
binaryen-9e5961792a91774962815d58c5c73bfb5612e27c.tar.bz2
binaryen-9e5961792a91774962815d58c5c73bfb5612e27c.zip
Remove the ability to construct basic types in a TypeBuilder (#5678)
This capability was originally introduced to support calculating LUBs in the equirecursive type system, but has not been needed for anything except tests since the equirecursive type system was removed. Since building basic heap types is no longer useful and was a source of significant complexity, remove the APIs that allowed it and the tests that used those APIs. Also remove test/example/type-builder.cpp, since a significant portion of it tested the removed APIs and the rest is already better tested in test/gtest/type-builder.cpp.
Diffstat (limited to 'src/tools/fuzzing')
-rw-r--r--src/tools/fuzzing/heap-types.cpp81
1 files changed, 5 insertions, 76 deletions
diff --git a/src/tools/fuzzing/heap-types.cpp b/src/tools/fuzzing/heap-types.cpp
index e58c7f51d..26cc518be 100644
--- a/src/tools/fuzzing/heap-types.cpp
+++ b/src/tools/fuzzing/heap-types.cpp
@@ -40,12 +40,10 @@ struct HeapTypeGeneratorImpl {
// Top-level kinds, chosen before the types are actually constructed. This
// allows us to choose HeapTypes that we know will be subtypes of data or func
// before we actually generate the types.
- using BasicKind = HeapType::BasicHeapType;
struct SignatureKind {};
struct StructKind {};
struct ArrayKind {};
- using HeapTypeKind =
- std::variant<BasicKind, SignatureKind, StructKind, ArrayKind>;
+ using HeapTypeKind = std::variant<SignatureKind, StructKind, ArrayKind>;
std::vector<HeapTypeKind> typeKinds;
// For each type, the index one past the end of its recursion group, used to
@@ -83,7 +81,7 @@ struct HeapTypeGeneratorImpl {
builder[i].subTypeOf(builder[super]);
supertypeIndices[i] = super;
subtypeIndices[super].push_back(i);
- typeKinds.push_back(getSubKind(typeKinds[super]));
+ typeKinds.push_back(typeKinds[super]);
}
}
@@ -110,11 +108,7 @@ struct HeapTypeGeneratorImpl {
// Create the heap types.
for (; index < builder.size(); ++index) {
auto kind = typeKinds[index];
- if (auto* basic = std::get_if<BasicKind>(&kind)) {
- // The type is already determined.
- builder[index] = *basic;
- } else if (!supertypeIndices[index] ||
- builder.isBasic(*supertypeIndices[index])) {
+ if (!supertypeIndices[index]) {
// No nontrivial supertype, so create a root type.
if (std::get_if<SignatureKind>(&kind)) {
builder[index] = generateSignature();
@@ -365,9 +359,7 @@ struct HeapTypeGeneratorImpl {
// the builder.
if (rand.oneIn(candidates.size() * 8)) {
auto* kind = &typeKinds[it->second];
- if (auto* basic = std::get_if<BasicKind>(kind)) {
- return HeapType(*basic).getBottom();
- } else if (std::get_if<SignatureKind>(kind)) {
+ if (std::get_if<SignatureKind>(kind)) {
return HeapType::nofunc;
} else {
return HeapType::none;
@@ -434,9 +426,7 @@ struct HeapTypeGeneratorImpl {
candidates.push_back(HeapType::func);
return rand.pick(candidates);
} else {
- // A constructed basic type. Fall through to add all of the basic
- // supertypes as well.
- type = *std::get_if<BasicKind>(kind);
+ WASM_UNREACHABLE("unexpected kind");
}
}
// This is not a constructed type, so it must be a basic type.
@@ -576,70 +566,9 @@ struct HeapTypeGeneratorImpl {
return StructKind{};
case 2:
return ArrayKind{};
- case 3:
- return BasicKind{generateBasicHeapType()};
}
WASM_UNREACHABLE("unexpected index");
}
-
- HeapTypeKind getSubKind(HeapTypeKind super) {
- if (rand.oneIn(16)) {
- // Occasionally go directly to the bottom type.
- if (auto* basic = std::get_if<BasicKind>(&super)) {
- return HeapType(*basic).getBottom();
- } else if (std::get_if<SignatureKind>(&super)) {
- return HeapType::nofunc;
- } else if (std::get_if<StructKind>(&super)) {
- return HeapType::none;
- } else if (std::get_if<ArrayKind>(&super)) {
- return HeapType::none;
- }
- WASM_UNREACHABLE("unexpected kind");
- }
- if (auto* basic = std::get_if<BasicKind>(&super)) {
- if (rand.oneIn(8)) {
- return super;
- }
- switch (*basic) {
- case HeapType::func:
- return SignatureKind{};
- case HeapType::ext:
- case HeapType::i31:
- return super;
- case HeapType::any:
- if (rand.oneIn(5)) {
- return HeapType::eq;
- }
- [[fallthrough]];
- case HeapType::eq:
- switch (rand.upTo(3)) {
- case 0:
- return HeapType::i31;
- case 1:
- return StructKind{};
- case 2:
- return ArrayKind{};
- }
- WASM_UNREACHABLE("unexpected index");
- case HeapType::struct_:
- return StructKind{};
- case HeapType::array:
- return ArrayKind{};
- case HeapType::string:
- case HeapType::stringview_wtf8:
- case HeapType::stringview_wtf16:
- case HeapType::stringview_iter:
- case HeapType::none:
- case HeapType::noext:
- case HeapType::nofunc:
- return super;
- }
- WASM_UNREACHABLE("unexpected kind");
- } else {
- // Signature and Data types can only have Signature and Data subtypes.
- return super;
- }
- }
};
} // anonymous namespace