summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-04-29 11:39:46 -0700
committerGitHub <noreply@github.com>2021-04-29 11:39:46 -0700
commit59cc7e3d0a25051177a5c98d8c8bbe5f68c51da8 (patch)
tree0a378adc046123db98fb09b9c7cbe48b175db8ec
parenta4c7866f5e133c58ebbf09715a705d514209dac1 (diff)
downloadbinaryen-59cc7e3d0a25051177a5c98d8c8bbe5f68c51da8.tar.gz
binaryen-59cc7e3d0a25051177a5c98d8c8bbe5f68c51da8.tar.bz2
binaryen-59cc7e3d0a25051177a5c98d8c8bbe5f68c51da8.zip
[Wasm GC] Add a print limit in TypePrinter (#3850)
This is similar to the limit in TypeNamePrinter in Print.cpp. This limit affects the printed type when debugging with std::cout << type etc., which just prints the structure and not the name.
-rw-r--r--src/wasm/wasm-type.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp
index 52af20847..6f9671fcd 100644
--- a/src/wasm/wasm-type.cpp
+++ b/src/wasm/wasm-type.cpp
@@ -209,6 +209,21 @@ struct TypePrinter {
private:
template<typename T, typename F> std::ostream& printChild(T curr, F printer);
+
+ // FIXME: This hard limit on how many times we call print() avoids extremely
+ // large outputs, which can be inconveniently large in some cases, but
+ // we should have a better mechanism for this.
+ static const size_t MaxPrints = 100;
+
+ size_t prints = 0;
+
+ bool exceededLimit() {
+ if (prints >= MaxPrints) {
+ return true;
+ }
+ prints++;
+ return false;
+ }
};
// Helper for hashing the shapes of TypeInfos and HeapTypeInfos. Keeps track of
@@ -1502,6 +1517,9 @@ bool TypeBounder::lub(const Rtt& a, const Rtt& b, Rtt& out) {
template<typename T, typename F>
std::ostream& TypePrinter::printChild(T curr, F printer) {
+ if (exceededLimit()) {
+ return os << "..!";
+ }
auto it = depths.find(curr.getID());
if (it != depths.end()) {
assert(it->second <= currDepth);