From f7e9f851ac744f262079b43cf9e1b08030195173 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 2 Apr 2026 15:27:14 -0700 Subject: [PATCH 1/8] try --- src/wasm-traversal.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h index a3bdc5a3905..5cfb7b43db5 100644 --- a/src/wasm-traversal.h +++ b/src/wasm-traversal.h @@ -36,7 +36,10 @@ namespace wasm { // A generic visitor, defaulting to doing nothing on each visit -template struct Visitor { +template struct Visitor { + // Capture the parameter in something we can access later. + using ReturnType = ReturnType_; + // Expression visitors #define DELEGATE(CLASS_TO_VISIT) \ ReturnType visit##CLASS_TO_VISIT(CLASS_TO_VISIT* curr) { \ @@ -352,7 +355,14 @@ struct PostWalker : public Walker { #define DELEGATE_ID curr->_id #define DELEGATE_START(id) \ - self->pushTask(SubType::doVisit##id, currp); \ + if constexpr (&SubType::visit##id != \ + &Visitor::visit##id || \ +&SubType::doVisit##id != \ + &Visitor::doVisit##id) { \ + self->pushTask(SubType::doVisit##id, currp); \ + } \ [[maybe_unused]] auto* cast = curr->cast(); #define DELEGATE_GET_FIELD(id, field) cast->field From c25a1553174434f113f7881e2e5d8dd8860410da Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 2 Apr 2026 15:27:20 -0700 Subject: [PATCH 2/8] format --- src/wasm-traversal.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h index 5cfb7b43db5..63c827543f9 100644 --- a/src/wasm-traversal.h +++ b/src/wasm-traversal.h @@ -356,11 +356,11 @@ struct PostWalker : public Walker { #define DELEGATE_START(id) \ if constexpr (&SubType::visit##id != \ - &Visitor::visit##id || \ -&SubType::doVisit##id != \ - &Visitor::doVisit##id) { \ + &Visitor::visit##id || \ + &SubType::doVisit##id != \ + &Visitor:: \ + doVisit##id) { \ self->pushTask(SubType::doVisit##id, currp); \ } \ [[maybe_unused]] auto* cast = curr->cast(); From d597eb0ff75419372c3f4c34c350ad4b02cb7ab0 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 2 Apr 2026 15:27:44 -0700 Subject: [PATCH 3/8] format --- src/wasm-traversal.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h index 63c827543f9..3bb0f572513 100644 --- a/src/wasm-traversal.h +++ b/src/wasm-traversal.h @@ -357,9 +357,9 @@ struct PostWalker : public Walker { #define DELEGATE_START(id) \ if constexpr (&SubType::visit##id != \ &Visitor::visit##id || \ + typename SubType::ReturnType>::visit##id || \ &SubType::doVisit##id != \ - &Visitor:: \ + &Visitor:: \ doVisit##id) { \ self->pushTask(SubType::doVisit##id, currp); \ } \ From e66deb7a3fa86b0a6d76ca1681b9c3a1bc82700c Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 2 Apr 2026 15:27:50 -0700 Subject: [PATCH 4/8] format --- src/wasm-traversal.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h index 3bb0f572513..8680863f4fd 100644 --- a/src/wasm-traversal.h +++ b/src/wasm-traversal.h @@ -357,10 +357,10 @@ struct PostWalker : public Walker { #define DELEGATE_START(id) \ if constexpr (&SubType::visit##id != \ &Visitor::visit##id || \ + typename SubType::ReturnType>::visit##id || \ &SubType::doVisit##id != \ - &Visitor:: \ - doVisit##id) { \ + &Visitor::doVisit##id) { \ self->pushTask(SubType::doVisit##id, currp); \ } \ [[maybe_unused]] auto* cast = curr->cast(); From 5992083c4f07aeb701703438c92e5d6e00663cc5 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 2 Apr 2026 15:31:50 -0700 Subject: [PATCH 5/8] format --- src/wasm-traversal.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h index 8680863f4fd..75d6debad17 100644 --- a/src/wasm-traversal.h +++ b/src/wasm-traversal.h @@ -359,8 +359,7 @@ struct PostWalker : public Walker { &Visitor::visit##id || \ &SubType::doVisit##id != \ - &Visitor::doVisit##id) { \ + &Walker::doVisit##id) { \ self->pushTask(SubType::doVisit##id, currp); \ } \ [[maybe_unused]] auto* cast = curr->cast(); From 58fb7ef0a4183ccad3a616d09749ccf97fc07e0b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 2 Apr 2026 16:31:53 -0700 Subject: [PATCH 6/8] comment --- src/wasm-traversal.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h index 75d6debad17..12a6c31a240 100644 --- a/src/wasm-traversal.h +++ b/src/wasm-traversal.h @@ -354,6 +354,15 @@ struct PostWalker : public Walker { #define DELEGATE_ID curr->_id + // Don't push empty tasks, that is, functions that we just push to the + // stack, pop, and then nothing happens when we call the empty function. The + // default visitFoo() in Visitor is empty, and the static doVisitFoo() in + // Walker just calls it, so if neither have been changed, we know that + // nothing will run. + // + // Note that we check Visitor<..> and not VisitorType. Only Visitor is the + // actual top type we know has empty visitors, while VisitorType could be + // anything. #define DELEGATE_START(id) \ if constexpr (&SubType::visit##id != \ &Visitor Date: Fri, 3 Apr 2026 09:43:01 -0700 Subject: [PATCH 7/8] workaround.for.gcc.11 --- src/wasm-traversal.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h index 12a6c31a240..775adda6df2 100644 --- a/src/wasm-traversal.h +++ b/src/wasm-traversal.h @@ -363,6 +363,23 @@ struct PostWalker : public Walker { // Note that we check Visitor<..> and not VisitorType. Only Visitor is the // actual top type we know has empty visitors, while VisitorType could be // anything. + // + // Unfortunately we must avoid this in gcc 11 and earlier, as they error on + // these function pointers not being constexpr. Remove the constexpr there. + // Note that even if this ends up being a runtime check, it should be faster + // than pushing empty tasks, as the check is much faster than the push/pop/ + // call, and a large number of our calls (most, perhaps) are not overridden. +#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 11 +#define DELEGATE_START(id) \ + if (&SubType::visit##id != \ + &Visitor::visit##id || \ + &SubType::doVisit##id != \ + &Walker::doVisit##id) { \ + self->pushTask(SubType::doVisit##id, currp); \ + } \ + [[maybe_unused]] auto* cast = curr->cast(); +#else #define DELEGATE_START(id) \ if constexpr (&SubType::visit##id != \ &Visitor { self->pushTask(SubType::doVisit##id, currp); \ } \ [[maybe_unused]] auto* cast = curr->cast(); +#endif #define DELEGATE_GET_FIELD(id, field) cast->field From e3aa683fa66a2749d147d420ce1bf6d6d65afc04 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 3 Apr 2026 10:13:33 -0700 Subject: [PATCH 8/8] format --- src/wasm-traversal.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h index 775adda6df2..b01ed9b8fef 100644 --- a/src/wasm-traversal.h +++ b/src/wasm-traversal.h @@ -372,10 +372,8 @@ struct PostWalker : public Walker { #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 11 #define DELEGATE_START(id) \ if (&SubType::visit##id != \ - &Visitor::visit##id || \ - &SubType::doVisit##id != \ - &Walker::doVisit##id) { \ + &Visitor::visit##id || \ + &SubType::doVisit##id != &Walker::doVisit##id) { \ self->pushTask(SubType::doVisit##id, currp); \ } \ [[maybe_unused]] auto* cast = curr->cast();