summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@chromium.org>2021-10-18 16:57:12 -0700
committerGitHub <noreply@github.com>2021-10-18 23:57:12 +0000
commitbe02d3f0f2689475f31c4523010eed58f39d27cb (patch)
treee62d8f8d15547a54c6c3c40a5752c7f08e4379cd
parentf0a8de302b85441deb8864c9e20c561c934e27b8 (diff)
downloadbinaryen-be02d3f0f2689475f31c4523010eed58f39d27cb.tar.gz
binaryen-be02d3f0f2689475f31c4523010eed58f39d27cb.tar.bz2
binaryen-be02d3f0f2689475f31c4523010eed58f39d27cb.zip
Update to C++17 and use std::optional for getSuperType (#4203)
This sets the C++ standard variable in the build to C++17, and makes use of std::optional (a C++17 library feature) in one place, to test that it's working.
-rw-r--r--CMakeLists.txt2
-rw-r--r--scripts/test/shared.py2
-rw-r--r--src/ir/module-utils.h10
-rw-r--r--src/ir/struct-utils.h9
-rw-r--r--src/ir/subtypes.h13
-rw-r--r--src/ir/type-updating.cpp5
-rw-r--r--src/passes/Print.cpp5
-rw-r--r--src/wasm-type.h7
-rw-r--r--src/wasm/wasm-binary.cpp7
-rw-r--r--src/wasm/wasm-type.cpp9
10 files changed, 32 insertions, 37 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 336f54342..113aeb901 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,7 +6,7 @@ include(GNUInstallDirs)
# The C++ standard whose features are required to build Binaryen.
# Keep in sync with scripts/test/shared.py cxx_standard
-set(CXX_STANDARD 14)
+set(CXX_STANDARD 17)
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release")
diff --git a/scripts/test/shared.py b/scripts/test/shared.py
index 82e4fe03e..d86d802d3 100644
--- a/scripts/test/shared.py
+++ b/scripts/test/shared.py
@@ -25,7 +25,7 @@ import sys
# The C++ standard whose features are required to build Binaryen.
# Keep in sync with CMakeLists.txt CXX_STANDARD
-cxx_standard = 14
+cxx_standard = 17
def parse_args(args):
diff --git a/src/ir/module-utils.h b/src/ir/module-utils.h
index 13fa76fff..69c454410 100644
--- a/src/ir/module-utils.h
+++ b/src/ir/module-utils.h
@@ -597,15 +597,15 @@ inline void collectHeapTypes(Module& wasm,
counts.note(child);
}
}
- HeapType super;
- if (ht.getSuperType(super)) {
- if (!counts.count(super)) {
- newTypes.insert(super);
+
+ if (auto super = ht.getSuperType()) {
+ if (!counts.count(*super)) {
+ newTypes.insert(*super);
// We should unconditionally count supertypes, but while the type system
// is in flux, skip counting them to keep the type orderings in nominal
// test outputs more similar to the orderings in the equirecursive
// outputs. FIXME
- counts.note(super);
+ counts.note(*super);
}
}
}
diff --git a/src/ir/struct-utils.h b/src/ir/struct-utils.h
index b052a15f7..442d990fb 100644
--- a/src/ir/struct-utils.h
+++ b/src/ir/struct-utils.h
@@ -222,13 +222,12 @@ private:
auto& infos = combinedInfos[type];
// Propagate shared fields to the supertype.
- HeapType superType;
- if (type.getSuperType(superType)) {
- auto& superInfos = combinedInfos[superType];
- auto& superFields = superType.getStruct().fields;
+ if (auto superType = type.getSuperType()) {
+ auto& superInfos = combinedInfos[*superType];
+ auto& superFields = superType->getStruct().fields;
for (Index i = 0; i < superFields.size(); i++) {
if (superInfos[i].combine(infos[i])) {
- work.push(superType);
+ work.push(*superType);
}
}
}
diff --git a/src/ir/subtypes.h b/src/ir/subtypes.h
index 661eaf119..64697e2a3 100644
--- a/src/ir/subtypes.h
+++ b/src/ir/subtypes.h
@@ -57,12 +57,12 @@ struct SubTypes {
std::vector<HeapType> getAllSuperTypes(HeapType type) {
std::vector<HeapType> ret;
while (1) {
- HeapType super;
- if (!type.getSuperType(super)) {
+ auto super = type.getSuperType();
+ if (!super) {
return ret;
}
- ret.push_back(super);
- type = super;
+ ret.push_back(*super);
+ type = *super;
}
}
@@ -71,9 +71,8 @@ struct SubTypes {
private:
// Add a type to the graph.
void note(HeapType type) {
- HeapType super;
- if (type.getSuperType(super)) {
- typeSubTypes[super].push_back(type);
+ if (auto super = type.getSuperType()) {
+ typeSubTypes[*super].push_back(type);
}
}
diff --git a/src/ir/type-updating.cpp b/src/ir/type-updating.cpp
index c69cbe1be..d3ecf7ad6 100644
--- a/src/ir/type-updating.cpp
+++ b/src/ir/type-updating.cpp
@@ -65,9 +65,8 @@ void GlobalTypeRewriter::update() {
}
// Apply a super, if there is one
- HeapType super;
- if (type.getSuperType(super)) {
- typeBuilder.setSubType(i, typeIndices[super]);
+ if (auto super = type.getSuperType()) {
+ typeBuilder.setSubType(i, typeIndices[*super]);
}
}
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 96a1abe73..34fe92ff6 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -2515,9 +2515,8 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
}
// Module-level visitors
void printSupertypeOr(HeapType curr, std::string noSuper) {
- HeapType super;
- if (curr.getSuperType(super)) {
- TypeNamePrinter(o, currModule).print(super);
+ if (auto super = curr.getSuperType()) {
+ TypeNamePrinter(o, currModule).print(*super);
} else {
o << noSuper;
}
diff --git a/src/wasm-type.h b/src/wasm-type.h
index a673b936f..4c401be6b 100644
--- a/src/wasm-type.h
+++ b/src/wasm-type.h
@@ -19,6 +19,7 @@
#include "support/name.h"
#include "wasm-features.h"
+#include <optional>
#include <ostream>
#include <vector>
@@ -382,12 +383,12 @@ public:
const Struct& getStruct() const;
Array getArray() const;
- // Return whether there is a nontrivial (i.e. non-basic) nominal supertype and
- // store it in `out` if there is. Nominal types (in the sense of isNominal,
+ // If there is a nontrivial (i.e. non-basic) nominal supertype, return it,
+ // else an empty optional. Nominal types (in the sense of isNominal,
// i.e. Milestone 4 nominal types) may always have supertypes and other types
// may have supertypes in `TypeSystem::Nominal` mode but not in
// `TypeSystem::Equirecursive` mode.
- bool getSuperType(HeapType& out) const;
+ std::optional<HeapType> getSuperType() const;
// Whether this is a nominal type in the sense of being a GC Milestone 4
// nominal type. Although all non-basic HeapTypes are nominal in
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 9c8b83325..6ce2c7979 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -251,12 +251,11 @@ void WasmBinaryWriter::writeTypes() {
WASM_UNREACHABLE("TODO GC type writing");
}
if (nominal) {
- HeapType super;
- bool hasSuper = type.getSuperType(super);
- if (!hasSuper) {
+ auto super = type.getSuperType();
+ if (!super) {
super = type.isFunction() ? HeapType::func : HeapType::data;
}
- writeHeapType(super);
+ writeHeapType(*super);
}
}
finishSection(start);
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp
index 284a7e23b..94c6e96c6 100644
--- a/src/wasm/wasm-type.cpp
+++ b/src/wasm/wasm-type.cpp
@@ -1206,16 +1206,15 @@ Array HeapType::getArray() const {
return getHeapTypeInfo(*this)->array;
}
-bool HeapType::getSuperType(HeapType& out) const {
+std::optional<HeapType> HeapType::getSuperType() const {
if (isBasic()) {
- return false;
+ return {};
}
HeapTypeInfo* super = getHeapTypeInfo(*this)->supertype;
if (super != nullptr) {
- out = HeapType(uintptr_t(super));
- return true;
+ return HeapType(uintptr_t(super));
}
- return false;
+ return {};
}
bool HeapType::isNominal() const {