From 9acc42b2e951c7b993b42049f6f878b435691ef8 Mon Sep 17 00:00:00 2001 From: Duncan Tourolle Date: Sat, 9 May 2026 09:54:40 +0200 Subject: [PATCH] Fix fanout naming for debug graph --- include/kpn/fanout.hpp | 7 ++++--- include/kpn/main_thread_node.hpp | 4 ++-- include/kpn/static_network.hpp | 32 +++++++++++++++++++++++++++++--- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/include/kpn/fanout.hpp b/include/kpn/fanout.hpp index c73b7f3..7fb1dc0 100644 --- a/include/kpn/fanout.hpp +++ b/include/kpn/fanout.hpp @@ -51,9 +51,10 @@ public: using return_tuple = detail::repeat_tuple_t; using return_raw = return_tuple; - static constexpr std::size_t input_count = 1; - static constexpr std::size_t output_count = N; - static constexpr std::size_t unique_tag = Id; + static constexpr std::size_t input_count = 1; + static constexpr std::size_t output_count = N; + static constexpr std::size_t unique_tag = Id; + static constexpr bool is_fanout_node = true; explicit FanoutNode(std::size_t fifo_capacity = 5) : fifo_capacity_(fifo_capacity) diff --git a/include/kpn/main_thread_node.hpp b/include/kpn/main_thread_node.hpp index 852340c..a5c328e 100644 --- a/include/kpn/main_thread_node.hpp +++ b/include/kpn/main_thread_node.hpp @@ -101,9 +101,9 @@ public: } template - InputPort input() { + InputPort input() { static_assert(I < input_count, "input index out of range"); - return {*this}; + return {static_cast(*this)}; } template diff --git a/include/kpn/static_network.hpp b/include/kpn/static_network.hpp index bacdf54..490815b 100644 --- a/include/kpn/static_network.hpp +++ b/include/kpn/static_network.hpp @@ -72,6 +72,8 @@ std::string node_display_name() { constexpr std::string_view lbl = node_label_v; if constexpr (!lbl.empty()) { return std::string(lbl); + } else if constexpr (requires { NodeT::is_fanout_node; NodeT::unique_tag; }) { + return "fanout[" + std::to_string(NodeT::unique_tag) + "]"; } else if constexpr (requires { NodeT::unique_tag; }) { return "node[" + std::to_string(NodeT::unique_tag) + "]"; } else { @@ -261,6 +263,29 @@ auto make_network(Edges&&... edges) { return ptr; }; + // Pre-pass: build fanout_id → source display name map so fanout nodes + // can be named after the node feeding them (e.g. "capture_fanout"). + std::map fanout_src_name; + [&](tmp::TypeList) { + ([&](SE) { + using DstNode = typename SE::dst_node_t; + using SrcNode = typename SE::src_node_t; + if constexpr (requires { DstNode::is_fanout_node; }) + fanout_src_name.emplace(DstNode::unique_tag, node_display_name()); + }(SEs{}), ...); + }(ExpandedEdges{}); + + // Helper: display name for any node type, resolving fanouts to "src_fanout". + auto node_name = [&]() -> std::string { + if constexpr (requires { NodeT::is_fanout_node; }) { + auto it = fanout_src_name.find(NodeT::unique_tag); + return it != fanout_src_name.end() ? it->second + "_fanout" + : node_display_name(); + } else { + return node_display_name(); + } + }; + std::vector> channel_probes; auto wire_one = [&](SE) { @@ -275,9 +300,9 @@ auto make_network(Edges&&... edges) { if (src && dst) { auto& ch = dst->template input_channel(); src->template set_output_channel(&ch); - std::string ch_name = node_display_name() + ":" + std::to_string(SrcIdx) + std::string ch_name = node_name.template operator()() + ":" + std::to_string(SrcIdx) + " \xe2\x86\x92 " // UTF-8 → - + node_display_name() + ":" + std::to_string(DstIdx); + + node_name.template operator()() + ":" + std::to_string(DstIdx); channel_probes.push_back(std::make_unique>(ch, ch_name)); } }; @@ -291,8 +316,9 @@ auto make_network(Edges&&... edges) { std::vector fanout_node_names; std::apply([&](auto&... fn) { ([&](auto& node) { + using NodeT = std::decay_t; fanout_ptrs.push_back(static_cast(&node)); - fanout_node_names.push_back(node_display_name>()); + fanout_node_names.push_back(node_name.template operator()()); }(fn), ...); }, *fanout_storage);