@@ -289,55 +289,6 @@ struct AggResultWithOutputWrapper {
289289 }
290290};
291291
292- // Wraps T(const State&) or optional<T>(const State&) -> vef_vdf_func_t
293- template <typename State, auto Func>
294- struct AggResultWrapper {
295- static void invoke (vef_context_t *, vef_vdf_args_t *args,
296- vef_vdf_result_t *result) {
297- const auto &state = *static_cast <State *>(args->user_data );
298- write_result (Func (state), result);
299- }
300-
301- private:
302- template <typename T>
303- static void write_result (const std::optional<T> &val,
304- vef_vdf_result_t *result) {
305- if (!val.has_value ()) {
306- result->type = VEF_RESULT_NULL ;
307- } else {
308- write_scalar (*val, result);
309- }
310- }
311-
312- template <typename T>
313- static void write_result (const T &val, vef_vdf_result_t *result) {
314- write_scalar (val, result);
315- }
316-
317- static void write_scalar (long long v, vef_vdf_result_t *r) {
318- r->int_value = v;
319- r->type = VEF_RESULT_VALUE ;
320- }
321-
322- static void write_scalar (double v, vef_vdf_result_t *r) {
323- r->real_value = v;
324- r->type = VEF_RESULT_VALUE ;
325- }
326-
327- static void write_scalar (const std::string &v, vef_vdf_result_t *r) {
328- if (v.size () > r->max_str_len ) {
329- r->type = VEF_RESULT_ERROR ;
330- snprintf (r->error_msg , VEF_MAX_ERROR_LEN ,
331- " aggregate result (%zu bytes) exceeds buffer (%zu bytes)" ,
332- v.size (), r->max_str_len );
333- return ;
334- }
335- memcpy (r->str_buf , v.data (), v.size ());
336- r->actual_len = v.size ();
337- r->type = VEF_RESULT_VALUE ;
338- }
339- };
340-
341292// =============================================================================
342293// Wrapper Template
343294// =============================================================================
@@ -861,8 +812,6 @@ struct FuncBuilder {
861812 buffer_size_ (0 ),
862813 prerun_ (nullptr ),
863814 postrun_ (nullptr ),
864- clear_ (nullptr ),
865- accumulate_ (nullptr ),
866815 deterministic_ (false ) {}
867816
868817 const char *name_;
@@ -871,8 +820,6 @@ struct FuncBuilder {
871820 size_t buffer_size_;
872821 vef_prerun_func_t prerun_;
873822 vef_postrun_func_t postrun_;
874- vef_vdf_clear_func_t clear_;
875- vef_vdf_accumulate_func_t accumulate_;
876823 bool deterministic_;
877824
878825 constexpr FuncBuilder<Func, NumParams> &returns (const char *t) {
@@ -887,8 +834,6 @@ struct FuncBuilder {
887834 next.buffer_size_ = buffer_size_;
888835 next.prerun_ = prerun_;
889836 next.postrun_ = postrun_;
890- next.clear_ = clear_;
891- next.accumulate_ = accumulate_;
892837 next.deterministic_ = deterministic_;
893838 for (size_t i = 0 ; i < NumParams; ++i) {
894839 next.param_types_ [i] = param_types_[i];
@@ -919,74 +864,17 @@ struct FuncBuilder {
919864 return *this ;
920865 }
921866
922- // TODO(villagesql-beta): remove .clear(), .accumulate(), and .state() from
923- // FuncBuilder once all callers have migrated to make_aggregate_func, which
924- // validates all three callback signatures against State at compile time.
925- // Raw vef_vdf_clear_func_t / vef_vdf_accumulate_func_t are accepted here
926- // for backward compatibility with existing extensions.
927- template <auto Fn>
928- constexpr FuncBuilder<Func, NumParams> &clear () {
929- if constexpr (std::is_same_v<decltype (Fn), vef_vdf_clear_func_t >) {
930- clear_ = Fn;
931- } else {
932- using Params = typename FuncParamTypes<decltype (Fn)>::type;
933- using State = std::remove_reference_t <std::tuple_element_t <0 , Params>>;
934- clear_ = &agg_clear_wrapper<State, Fn>;
935- }
936- return *this ;
937- }
938-
939- template <auto Fn>
940- constexpr FuncBuilder<Func, NumParams> &accumulate () {
941- if constexpr (std::is_same_v<decltype (Fn), vef_vdf_accumulate_func_t >) {
942- accumulate_ = Fn;
943- } else {
944- using Params = typename FuncParamTypes<decltype (Fn)>::type;
945- using State = std::remove_reference_t <std::tuple_element_t <0 , Params>>;
946- accumulate_ = &AggAccumulateWrapper<State, Fn, NumParams>::invoke;
947- }
948- return *this ;
949- }
950-
951- template <typename State>
952- constexpr FuncBuilder<Func, NumParams> &state () {
953- prerun_ = &auto_prerun<State>;
954- postrun_ = &auto_postrun<State>;
955- return *this ;
956- }
957-
958867 constexpr StaticFuncDesc<NumParams> build () const {
959868 static_assert (NumParams <= kMaxParams ,
960869 " Too many parameters (max is kMaxParams)" );
961- if ((clear_ == nullptr ) != (accumulate_ == nullptr )) {
962- config_error__aggregate_must_set_both_clear_and_accumulate ();
963- }
964870
965871 using AllParams = typename FuncParamTypes<decltype (Func)>::type;
966872 using UniquePTuple = typename unique_params_types<AllParams>::type;
967873
968874 FuncWithMetadata meta{};
969- if constexpr (std::is_same_v<decltype (Func), vef_vdf_func_t >) {
970- // Raw vef_vdf_func_t: passed through for backward compatibility.
971- // TODO(villagesql-beta): remove once all callers use make_aggregate_func.
972- meta.f = Func;
973- } else if constexpr (std::tuple_size_v<AllParams> == 1 &&
974- std::is_lvalue_reference_v<
975- std::tuple_element_t <0 , AllParams>> &&
976- std::is_const_v<std::remove_reference_t <
977- std::tuple_element_t <0 , AllParams>>>) {
978- // Typed aggregate result: T(const State&) or optional<T>(const State&).
979- using State = std::remove_const_t <
980- std::remove_reference_t <std::tuple_element_t <0 , AllParams>>>;
981- meta.f = &AggResultWrapper<State, Func>::invoke;
982- } else {
983- // Typed scalar VDF.
984- meta.f = &Wrapper<Func, NumParams>::invoke;
985- }
875+ meta.f = &Wrapper<Func, NumParams>::invoke;
986876 meta.prerun = prerun_;
987877 meta.postrun = postrun_;
988- meta.clear = clear_;
989- meta.accumulate = accumulate_;
990878 meta.return_type = to_vef_type (return_type_);
991879 meta.num_params = NumParams;
992880 meta.buffer_size = buffer_size_;
@@ -1007,9 +895,9 @@ struct FuncBuilder {
1007895// AggFuncBuilder
1008896// =============================================================================
1009897//
1010- // Builder for aggregate VDFs. Prefer make_aggregate_func<State, &result_fn>()
1011- // over make_func() + .state<>() for aggregates: the State type is explicit,
1012- // and clear/accumulate signatures are validated against State at compile time.
898+ // Builder for aggregate VDFs. Use make_aggregate_func<State, &result_fn>().
899+ // The State type is explicit, and clear/accumulate signatures are validated
900+ // against State at compile time.
1013901
1014902template <typename State, auto Func, size_t NumParams>
1015903struct AggFuncBuilder {
@@ -1155,14 +1043,11 @@ constexpr AggFuncBuilder<State, Func, 0> make_aggregate_func(const char *name) {
11551043}
11561044
11571045// make_func<&impl>("name")
1158- // TODO(villagesql-beta): remove the vef_vdf_func_t exception below once all
1159- // callers have migrated to make_aggregate_func.
11601046template <auto Func>
11611047constexpr FuncBuilder<Func, 0 > make_func (const char *name) {
11621048 using AllParams = typename FuncParamTypes<decltype (Func)>::type;
11631049 static_assert (
1164- std::is_same_v<decltype (Func), vef_vdf_func_t > ||
1165- std::tuple_size_v<AllParams> == 0 ||
1050+ std::tuple_size_v<AllParams> == 0 ||
11661051 !is_context_param<std::tuple_element_t <0 , AllParams>>::value,
11671052 " vsql make_func: deprecated vef_context_t* first parameter not "
11681053 " supported; use a typed function or make_aggregate_func (see "
0 commit comments