risingwavelabs/risingwave · error

SIMD optimization for {n} arguments

Error message

SIMD optimization for {n} arguments

What it means

The macro's vectorized (SIMD) fast path is implemented only for 1- and 2-argument functions; for any other arity it hits an explicit `todo!` panic noting SIMD optimization is unimplemented for N arguments.

Source

Thrown at src/expr/macro/src/gen.rs:590

                1 => quote! {
                    let c = #ret_array_type::from_iter_bitmap(
                        a0.raw_iter().map(|a| #fn_name(a)),
                        a0.null_bitmap().clone()
                    );
                    Arc::new(c.into())
                },
                2 => quote! {
                    // allow using `zip` for performance
                    #[allow(clippy::disallowed_methods)]
                    let c = #ret_array_type::from_iter_bitmap(
                        a0.raw_iter()
                            .zip(a1.raw_iter())
                            .map(|(a, b)| #fn_name #generic(a, b)),
                        a0.null_bitmap() & a1.null_bitmap(),
                    );
                    Arc::new(c.into())
                },
                n => todo!("SIMD optimization for {n} arguments"),
            }
        } else {
            // no optimization
            let let_variadic = variadic.then(|| {
                quote! {
                    let variadic_row = variadic_input.row_at_unchecked_vis(i);
                }
            });
            quote! {
                let mut builder = #builder_type::with_type(input.capacity(), self.context.return_type.clone());

                if input.is_vis_compacted() {
                    for i in 0..input.capacity() {
                        #(let #inputs = unsafe { #arrays.value_at_unchecked(i) };)*
                        #let_variadic
                        #append_output
                    }
                } else {

View on GitHub (pinned to 6469eb736d)

Solutions

  1. Remove the SIMD optimization annotation from functions with >2 arguments so the general path is used
  2. Implement the `n =>` arm to fall back to the non-SIMD loop instead of todo!
  3. Keep SIMD-optimized declarations limited to unary and binary functions

Example fix

// before
n => todo!("SIMD optimization for {n} arguments"),
// after
n => generate_general_vectorized_code(n), // fall back to per-row loop
Defensive patterns

Strategy: validation

Validate before calling

fn simd_supported(num_args: usize) -> bool { matches!(num_args, 1 | 2) }

Try / catch

if !simd_supported(fn_args) {
    use_general_path(fn, args); // avoid the todo! path
}

Prevention

When it happens

Trigger: Marking a scalar function with vectorized/SIMD optimization (`is_viscalar`-style declaration) where the function takes more than 2 arguments, causing codegen to emit `todo!` for that arity.

Common situations: Writing a 3-argument arithmetic-like function (e.g. `clamp`, `nvl3`) and marking it SIMD-optimized; copy-pasting the optimization annotation from a 2-arg function.

Related errors


AI-assisted analysis of risingwavelabs/risingwave@6469eb736d (2026-09-11). Data as JSON: /api/errors/9aaf2a6aa8cb36ec. Report an issue: GitHub.