CoHDL
  1. Blog
  2. CoHDL 0.7.1

CoHDL 0.7.1: Array Elements
in Helper Calls

An array element can be passed to an instance-typed helper just like a scalar instance. Its trait constraints, physical identity, and pin obligations follow it through the call.

Compiler v0.7.1 was released on . This post fills a gap in our release coverage.

Issue #41 exposed a gap in instance-array support: passing an indexed pin worked, but passing the whole element to a helper could fail. The 0.7.1 patch resolves an argument such as xs[0] to the actual instance, including when the helper takes impl Trait or an explicit trait-bound generic parameter.

The helper receives one real element

In this excerpt from the regression case, Element is a two-pin test device implementing TwoPin. Each call joins that element's A and B terminals:

Array-element helper calls (excerpt)
fn tie(x: impl TwoPin) {
    net _: x.A, x.B
}

design Demo {
    inst xs: [Element; 2]
    tie(xs[0])
    tie(xs[1])
}

The two calls produce separate nets. Neither argument loses its array index, and the result matches the netlist from equivalent explicitly declared scalar instances. The same helper calls also compose inside other functions and subdesigns.

Selectors are checked at the call site

An out-of-bounds index names the valid range. Passing a bare array, indexing a scalar instance, or using range/list fan-out as an instance argument is rejected: an instance parameter receives one element. Trait bounds, concrete device matching, and final pin obligations continue to be checked.

Regression coverage checks both supported parameter forms, nested calls, separate connectivity, and byte-identical netlists against explicit-instance equivalents. Thanks to ZhangHanDong for the reproduction and analysis that led to the fix.

Get the update

Install the latest compiler, which includes these changes:

cohdl self-update

For a new installation, follow the getting-started guide. The v0.7.1 release page has this version's platform archives and checksums; the full comparison records the source changes.