# How the new params collections decompile


You open a C# 13 assembly in Glass.NET, land on a call that your source wrote as `Sum(1, 2, 3)`, and a decompiler that has not caught up shows you something else entirely: a local of some type called `<>y__InlineArray3<int>`, an `initobj`, three stores through a helper, a `ReadOnlySpan<int>` materialized out of it, and only then the call. No array. No brackets. Why does a three-argument call look like a stack-allocation ritual?

Because in C# 13 `params` no longer means "array." It can mean span.

## The real question

For twenty years `params` had exactly one lowering: `params T[]` plus a heap array built with `newarr` at every call site. C# 13 added **params collections** — `params` may now apply to `ReadOnlySpan<T>`, `Span<T>`, or any collection type that a collection expression can target. The headline case is `params ReadOnlySpan<T>`, because it lets a variadic call avoid the heap array altogether: the compiler stack-allocates the arguments and passes a span over them.

That changes what a decompiler must read. The old reconstruction keyed off `newarr` and `System.ParamArrayAttribute`. A span-based params method has neither. If Glass only knows the old pattern, it cannot prove the call was variadic, so it prints the span plumbing verbatim — correct, but unreadable. Recovering `Sum(1, 2, 3)` means reasoning from a *different attribute* and a *different call-site shape*.

## The method signature

Start with the callee. Two overloads, old and new:

```csharp
using System.Runtime.CompilerServices;

static int SumArray(params int[] numbers)          // C# since forever
{
    int total = 0;
    foreach (int n in numbers) total += n;
    return total;
}

static int SumSpan(params ReadOnlySpan<int> numbers) // C# 13
{
    int total = 0;
    foreach (int n in numbers) total += n;
    return total;
}
```

In metadata, the only thing marking either parameter as `params` is a custom attribute. The old one is `System.ParamArrayAttribute`; the new one is `System.Runtime.CompilerServices.ParamCollectionAttribute`. They are distinct types in distinct namespaces, and that single fact is what the recovery hinges on.

```il
.method private hidebysig static int32 SumArray(int32[] numbers) cil managed
{
  .param [1]
  .custom instance void [System.Runtime]System.ParamArrayAttribute::.ctor() = ( 01 00 00 00 )
  // ...
}

.method private hidebysig static int32
        SumSpan(valuetype [System.Runtime]System.ReadOnlySpan`1<int32> numbers) cil managed
{
  .param [1]
  .custom instance void
          [System.Runtime]System.Runtime.CompilerServices.ParamCollectionAttribute::.ctor() = ( 01 00 00 00 )
  // ...
}
```

A decompiler that does not recognize `ParamCollectionAttribute` sees `SumSpan` as an ordinary method taking a `ReadOnlySpan<int>`, with a mystery attribute attached. Everything downstream follows from whether it knows that attribute means `params`.

## The synthesized buffer type

Now the call site. The compiler needs somewhere to put the three arguments. For a span params call it does *not* allocate `int[]` — it synthesizes a one-field value type and relies on C# 12's inline-array feature to treat that single field as a fixed-size block. For three elements you get:

```il
.class private sequential ansi sealed beforefieldinit '<>y__InlineArray3`1'<T>
       extends [System.Runtime]System.ValueType
{
  .custom instance void
          [System.Runtime]System.Runtime.CompilerServices.InlineArrayAttribute::.ctor(int32) = ( 01 00 03 00 00 00 00 00 )
  .field private !T _element0
}
```

Read the attribute blob: `InlineArrayAttribute(3)`. The struct has *one* field, `_element0`, but the `[InlineArray(3)]` marker tells the runtime to lay it out as three contiguous `T` slots. The element count is baked into both the attribute argument and the type's own name — `<>y__InlineArray3` — and nowhere else. The name is compiler-internal and unspeakable in C#; you will never have written it.

## The call site

Here is `SumSpan(1, 2, 3)` as emitted. Watch the arguments go into the buffer one slot at a time, then a span is taken over the whole thing:

```il
.locals init (valuetype '<>y__InlineArray3`1'<int32> V_0)
ldloca.s   V_0
initobj    valuetype '<>y__InlineArray3`1'<int32>
ldloca.s   V_0
ldc.i4.0
call       !!1& '<PrivateImplementationDetails>'::InlineArrayElementRef<valuetype '<>y__InlineArray3`1'<int32>, int32>(!!0&, int32)
ldc.i4.1
stind.i4
ldloca.s   V_0
ldc.i4.1
call       !!1& '<PrivateImplementationDetails>'::InlineArrayElementRef<valuetype '<>y__InlineArray3`1'<int32>, int32>(!!0&, int32)
ldc.i4.2
stind.i4
ldloca.s   V_0
ldc.i4.2
call       !!1& '<PrivateImplementationDetails>'::InlineArrayElementRef<valuetype '<>y__InlineArray3`1'<int32>, int32>(!!0&, int32)
ldc.i4.3
stind.i4
ldloca.s   V_0
ldc.i4.3
call       valuetype [System.Runtime]System.ReadOnlySpan`1<!!1> '<PrivateImplementationDetails>'::InlineArrayAsReadOnlySpan<valuetype '<>y__InlineArray3`1'<int32>, int32>(!!0&, int32)
call       int32 C::SumSpan(valuetype [System.Runtime]System.ReadOnlySpan`1<int32>)
```

`initobj` zeroes the stack buffer; each argument is written through `InlineArrayElementRef`, which returns a managed reference to slot *i*; `InlineArrayAsReadOnlySpan` wraps the filled buffer in a `ReadOnlySpan<int>` of length 3; the final `call` passes that span. No `newobj`, no GC allocation — the buffer lives on the stack.

Contrast the old array path for `SumArray(1, 2, 3)`, which does hit the heap:

```il
ldc.i4.3
newarr     [System.Runtime]System.Int32
dup
ldc.i4.0
ldc.i4.1
stelem.i4
dup
ldc.i4.1
ldc.i4.2
stelem.i4
dup
ldc.i4.2
ldc.i4.3
stelem.i4
call       int32 C::SumArray(int32[])
```

`newarr` allocates, `stelem` fills, done. Two completely different shapes that a user wrote identically.

<figure class="my-8"><svg viewBox="0 0 760 300" role="img" aria-label="A params collection call stack-allocates a compiler-generated inline-array buffer and passes a read-only span over it with no heap allocation, while the old params array call allocates a heap array with newarr; the decompiler reads ParamCollectionAttribute to fold either back to the same variadic call." style="width:100%;height:auto;font-family:system-ui,sans-serif"><defs><marker id="pa" markerWidth="9" markerHeight="9" refX="7" refY="3" orient="auto"><path d="M0 0l6 3-6 3z" fill="#64748b"/></marker></defs><rect x="300" y="12" width="160" height="46" rx="7" fill="#eef2ff" stroke="#6366f1"/><text x="380" y="33" text-anchor="middle" fill="#6366f1" font-size="13" font-weight="600">Sum(1, 2, 3)</text><text x="380" y="50" text-anchor="middle" fill="#64748b" font-size="11">what the author wrote</text><rect x="30" y="100" width="300" height="60" rx="6" fill="#ecfeff" stroke="#0891b2"/><text x="180" y="122" text-anchor="middle" fill="#0891b2" font-size="12" font-weight="600">params ReadOnlySpan&lt;int&gt;</text><text x="180" y="140" text-anchor="middle" fill="#64748b" font-size="11">stack [InlineArray(3)] buffer</text><text x="180" y="154" text-anchor="middle" fill="#10b981" font-size="11">no heap allocation</text><rect x="430" y="100" width="300" height="60" rx="6" fill="#fef2f2" stroke="#ef4444"/><text x="580" y="122" text-anchor="middle" fill="#b91c1c" font-size="12" font-weight="600">params int[]</text><text x="580" y="140" text-anchor="middle" fill="#64748b" font-size="11">newarr → heap array</text><text x="580" y="154" text-anchor="middle" fill="#64748b" font-size="11">ParamArrayAttribute</text><rect x="30" y="200" width="300" height="42" rx="6" fill="#f0fdf4" stroke="#10b981"/><text x="180" y="226" text-anchor="middle" fill="#10b981" font-size="11" font-weight="600">ParamCollectionAttribute on .param [1]</text><rect x="430" y="200" width="300" height="42" rx="6" fill="#f0fdf4" stroke="#10b981"/><text x="580" y="226" text-anchor="middle" fill="#10b981" font-size="11" font-weight="600">ParamArrayAttribute on .param [1]</text><rect x="250" y="262" width="260" height="34" rx="7" fill="#eef2ff" stroke="#6366f1"/><text x="380" y="284" text-anchor="middle" fill="#6366f1" font-size="12" font-weight="600">Glass folds back to Sum(1, 2, 3)</text><path d="M340 58 L180 100" fill="none" stroke="#64748b" stroke-width="1.5" marker-end="url(#pa)"/><path d="M420 58 L580 100" fill="none" stroke="#64748b" stroke-width="1.5" marker-end="url(#pa)"/><path d="M180 160 L180 200" fill="none" stroke="#64748b" stroke-width="1.5" marker-end="url(#pa)"/><path d="M580 160 L580 200" fill="none" stroke="#64748b" stroke-width="1.5" marker-end="url(#pa)"/><path d="M180 242 L300 266" fill="none" stroke="#64748b" stroke-width="1.5" marker-end="url(#pa)"/><path d="M580 242 L460 266" fill="none" stroke="#64748b" stroke-width="1.5" marker-end="url(#pa)"/></svg><figcaption class="text-sm text-muted mt-2">Two lowerings — a stack inline-array buffer and a heap array — reconstruct to the same variadic call. The attribute on the parameter is what lets Glass fold each one back.</figcaption></figure>

## How Glass folds it back

Glass treats the span params call as a pattern match gated on the parameter's attribute, not on any opcode. To rewrite a call into variadic form it confirms, in order:

1. **The callee's last parameter carries `ParamCollectionAttribute`** (for the span form) or `ParamArrayAttribute` (for the classic array form). This is the switch. Without one of these attributes the method is not variadic and the call is printed as written.
2. **The call site builds the argument the expected way.** For `ParamCollectionAttribute` over a `ReadOnlySpan<T>`, Glass looks for an `initobj` of a `<>y__InlineArrayN` local followed by the `InlineArrayElementRef` stores and an `InlineArrayAsReadOnlySpan` wrap. The `N` in the type name, and the `[InlineArray(N)]` argument, give the element count.
3. **Each slot's stored value is recoverable** — here `ldc.i4.1/2/3`. Glass reads the values written through the per-slot `InlineArrayElementRef` refs in index order and treats them as the variadic arguments.

When all three hold, Glass drops the buffer local, the helper calls, and the span, and prints `SumSpan(1, 2, 3)`. The synthesized `<>y__InlineArray3<int>` type is recognized as compiler-internal and suppressed from the decompiled output — it is never shown as a type you could have declared. For the array form the match is simpler: `newarr`, a run of `stelem`, and the `ParamArrayAttribute` on the parameter, folded to the same `SumArray(1, 2, 3)`.

In the IL view you can see the evidence yourself: open the callee, look at `.param [1]`, and read the `.custom` line. `ParamCollectionAttribute` tells you the parameter is a C# 13 span params; `ParamArrayAttribute` tells you it is the classic array params. That one attribute token is the whole signal.

## When it breaks

The honest limits are worth stating plainly.

A decompiler that only knows `ParamArrayAttribute` will never fold the span form. It has no rule that says "an inline-array buffer plus a span wrap is a variadic call," so it faithfully prints the buffer local, the three `InlineArrayElementRef` stores, and the span. That output is *correct* — it recompiles — but it exposes the plumbing the language was hiding. This is exactly the "weird struct and a span" that sends people looking for an explanation.

The buffer type names are compiler-internal. `<>y__InlineArray3<int>` is unspeakable in C# and its name is not contractual; a future compiler could change it. Glass matches on the shape — an `[InlineArray(N)]` value type with a single field, filled by the recognized helpers — rather than on the literal name, so it survives a rename, but a genuinely novel lowering shape would fall through to the raw rendering.

And the two params forms are not interchangeable at the call site even though they fold to the same text. You can pass an explicit `int[]` to `SumArray` where the array *is* the whole argument list; you cannot hand an arbitrary heap array to a `params ReadOnlySpan<int>` the same way, because the span form is built for stack buffers and `stackalloc`-style lifetimes. When Glass shows you `SumSpan(1, 2, 3)`, read it as a span params call, not as sugar for an array you can substitute freely.

## Takeaway

C# 13 params collections give you a variadic call with no heap array: the arguments go into a stack-allocated `[InlineArray(N)]` buffer and the callee receives a `ReadOnlySpan<T>` over it. The only durable signal that the call was variadic is `System.Runtime.CompilerServices.ParamCollectionAttribute` on the parameter — a different attribute from the classic `System.ParamArrayAttribute`, and the thing an older decompiler misses. Glass reads that attribute, recognizes the inline-array call-site shape, and renders `M(1, 2, 3)` while hiding the compiler-internal buffer. When you see the raw span-over-buffer plumbing in some other tool, you are looking at the mechanism the attribute was meant to let you ignore.

