11#pragma once
22
33#include < memory>
4- #include < string_view >
4+ #include < string >
55#include < unordered_map>
66#include < vector>
77
1010#include " barretenberg/vm2/tracegen/lib/lookup_into_bitwise.hpp"
1111#include " barretenberg/vm2/tracegen/lib/lookup_into_indexed_by_clk.hpp"
1212#include " barretenberg/vm2/tracegen/lib/lookup_into_p_decomposition.hpp"
13+ #include " barretenberg/vm2/tracegen/lib/multi_permutation_builder.hpp"
1314#include " barretenberg/vm2/tracegen/lib/permutation_builder.hpp"
1415#include " barretenberg/vm2/tracegen/lib/test_interaction_builder.hpp"
1516
@@ -22,15 +23,26 @@ enum class InteractionType {
2223 LookupIntoIndexedByClk,
2324 LookupIntoPDecomposition,
2425 Permutation,
26+ MultiPermutation,
2527};
2628
2729class InteractionDefinition {
2830 public:
2931 InteractionDefinition () = default ;
3032
31- template <typename InteractionSettings, InteractionType type> InteractionDefinition& add ()
33+ // Old format with InteractionSettings first. TODO: Migrate.
34+ template <typename InteractionSettings, InteractionType type> InteractionDefinition& add (auto &&... args)
3235 {
33- interactions[InteractionSettings::NAME] = get_interaction_factory<InteractionSettings, type>();
36+ std::string name = std::string (InteractionSettings::NAME);
37+ interactions[name] = get_interaction_factory<type, InteractionSettings>(std::forward<decltype (args)>(args)...);
38+ return *this ;
39+ }
40+
41+ template <InteractionType type, typename ... InteractionSettings> InteractionDefinition& add (auto &&... args)
42+ {
43+ std::string name = (std::string (InteractionSettings::NAME) + ...);
44+ interactions[name] =
45+ get_interaction_factory<type, InteractionSettings...>(std::forward<decltype (args)>(args)...);
3446 return *this ;
3547 }
3648
@@ -39,55 +51,61 @@ class InteractionDefinition {
3951 // Stricter/more assertive jobs for testing.
4052 std::vector<std::unique_ptr<InteractionBuilderInterface>> get_all_test_jobs () const ;
4153
42- std::unique_ptr<InteractionBuilderInterface> get_job (std::string_view interaction_name) const ;
43- std::unique_ptr<InteractionBuilderInterface> get_test_job (std::string_view interaction_name) const ;
54+ std::unique_ptr<InteractionBuilderInterface> get_job (const std::string& interaction_name) const ;
55+ std::unique_ptr<InteractionBuilderInterface> get_test_job (const std::string& interaction_name) const ;
4456 template <typename InteractionSettings> std::unique_ptr<InteractionBuilderInterface> get_test_job () const
4557 {
46- return get_test_job (InteractionSettings::NAME);
58+ return get_test_job (std::string ( InteractionSettings::NAME) );
4759 }
4860
4961 private:
5062 using Factory = std::function<std::unique_ptr<InteractionBuilderInterface>(bool strict)>;
51- std::unordered_map<std::string_view , Factory> interactions;
63+ std::unordered_map<std::string , Factory> interactions;
5264
53- template <typename InteractionSettings, InteractionType type> static Factory get_interaction_factory ()
65+ template <InteractionType type, typename ... InteractionSettings>
66+ static Factory get_interaction_factory (auto &&... args)
5467 {
5568 if constexpr (type == InteractionType::LookupGeneric) {
56- return [](bool ) {
69+ return [args... ](bool ) {
5770 // This class always checks.
58- return std::make_unique<LookupIntoDynamicTableGeneric<InteractionSettings>>();
71+ return std::make_unique<LookupIntoDynamicTableGeneric<InteractionSettings... >>(args... );
5972 };
6073 } else if constexpr (type == InteractionType::LookupIntoBitwise) {
61- return [](bool strict) {
62- return strict ? std::make_unique<AddChecksToBuilder<LookupIntoBitwise<InteractionSettings>>>()
63- : std::make_unique<LookupIntoBitwise<InteractionSettings>>();
74+ return [args... ](bool strict) {
75+ return strict ? std::make_unique<AddChecksToBuilder<LookupIntoBitwise<InteractionSettings... >>>(args... )
76+ : std::make_unique<LookupIntoBitwise<InteractionSettings... >>(args... );
6477 };
6578 } else if constexpr (type == InteractionType::LookupIntoIndexedByClk) {
66- return [](bool strict) {
67- return strict ? std::make_unique<AddChecksToBuilder<LookupIntoIndexedByClk<InteractionSettings>>>()
68- : std::make_unique<LookupIntoIndexedByClk<InteractionSettings>>();
79+ return [args...](bool strict) {
80+ return strict ? std::make_unique<AddChecksToBuilder<LookupIntoIndexedByClk<InteractionSettings...>>>(
81+ args...)
82+ : std::make_unique<LookupIntoIndexedByClk<InteractionSettings...>>(args...);
6983 };
7084 } else if constexpr (type == InteractionType::LookupIntoPDecomposition) {
71- return [](bool strict) {
72- return strict ? std::make_unique<AddChecksToBuilder<LookupIntoPDecomposition<InteractionSettings>>>()
73- : std::make_unique<LookupIntoPDecomposition<InteractionSettings>>();
85+ return [args...](bool strict) {
86+ return strict ? std::make_unique<AddChecksToBuilder<LookupIntoPDecomposition<InteractionSettings...>>>(
87+ args...)
88+ : std::make_unique<LookupIntoPDecomposition<InteractionSettings...>>(args...);
7489 };
7590 } else if constexpr (type == InteractionType::LookupSequential) {
76- return [](bool ) {
91+ return [args... ](bool ) {
7792 // This class always checks.
78- return std::make_unique<LookupIntoDynamicTableSequential<InteractionSettings>>();
93+ return std::make_unique<LookupIntoDynamicTableSequential<InteractionSettings... >>(args... );
7994 };
8095 } else if constexpr (type == InteractionType::Permutation) {
81- return [](bool strict) {
82- return strict ? std::make_unique<CheckingPermutationBuilder<InteractionSettings>>()
83- : std::make_unique<PermutationBuilder<InteractionSettings>>();
96+ return [args... ](bool strict) {
97+ return strict ? std::make_unique<CheckingPermutationBuilder<InteractionSettings... >>(args... )
98+ : std::make_unique<PermutationBuilder<InteractionSettings... >>(args... );
8499 };
100+ } else if constexpr (type == InteractionType::MultiPermutation) {
101+ return
102+ [args...](bool ) { return std::make_unique<MultiPermutationBuilder<InteractionSettings...>>(args...); };
85103 } else {
86104 throw std::runtime_error (" Interaction type not supported: " + std::to_string (static_cast <int >(type)));
87105 }
88106 }
89107
90- const Factory& get_job_internal (std::string_view interaction_name) const ;
108+ const Factory& get_job_internal (const std::string& interaction_name) const ;
91109};
92110
93111} // namespace bb::avm2::tracegen
0 commit comments