carbon-lang icon indicating copy to clipboard operation
carbon-lang copied to clipboard

Constraints on variadic pack arity, template phase arity and constant time query operations on packs

Open CJ-Johnson opened this issue 8 months ago • 0 comments
trafficstars

Doc: https://docs.google.com/document/d/1bAG5UHqMw7i8Yoyv1wiIhG2dNlu5vLgOYvWyttYLges/

In case we decide we want to expand on the current variadics design to support symbolic phase pack arity constraints, template phase artity, and constant time query operations on a pack, I'm creating this as a long-term issue so the doc doesn't get lost and is hopefully eventually picked up as a proposal.

class Array(T:! type, N:! u32) {
  fn Make(...[== N] each t: T) -> Self {
    return {
      // In order for this line to compile, the constraint above must be applied.
      // Without the constraint, the type checker would have no way of
      // knowing if the pack was the same size as the backing array.
      .backing_array = (... each t),
    };
  }

  // ...
}

CJ-Johnson avatar Mar 09 '25 20:03 CJ-Johnson