noir icon indicating copy to clipboard operation
noir copied to clipboard

feat: `..` in tuple pattern

Open asterite opened this issue 11 months ago • 2 comments

Description

Problem

No issue, but:

  • with this we could move forward with #8420 without ever introducing a breaking change (we can add , .. in the existing code where the new tuple element will show up before merging that PR)
  • I guess it's something we were going to eventually implement, so...

Summary

I decided to implement this to unblock #8420 because I thought it was going to be easy: "just" parse the new syntax, then ignore the extra elements. But in the end it was a bit more complex:

  • I initially thought that ".." could only show up at the end of a tuple pattern, but in reality it can show up in any part of it
  • The ".." logic must also be applied during monomorphization in a couple of places, and for the interpreter

That said, besides that it was relatively straight-forward.

I included a big test that proves this is working well in many cases.

Additional Context

  • There was a pattern_to_string function that replicated the logic of turning a pattern into a string, so I removed it
  • I took the opportunity to extract some code into helper functions to reduce the size of some big functions
  • I noticed some methods were unused so I removed them

Documentation

Check one:

  • [ ] No documentation needed.
  • [x] Documentation included in this PR.
  • [ ] [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist

  • [x] I have tested the changes locally.
  • [x] I have formatted the changes with Prettier and/or cargo fmt on default settings.

asterite avatar May 14 '25 17:05 asterite

🚀 Deployed on https://6842f4169e46c02365b9d593--noir-docs.netlify.app

github-actions[bot] avatar May 14 '25 17:05 github-actions[bot]

FYI @noir-lang/developerrelations on Noir doc changes.

github-actions[bot] avatar Jun 06 '25 14:06 github-actions[bot]