-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
SizedIter
wrapper type (#611)
Adds a new wrapper type `SizedIter` to the standard library that annotates an iterator with a static size hint. This will be used for example in array comprehensions to infer the size of the resulting array. The type gets erased when lowering to Hugr. Updates the `range` function to emit such a size hint when the range stop is given by a static number. For example the expression `range(10)` is typed as `SizedIter[Range, 10]` whereas `range(n + 1)` is typed as `Range`. Currently, this is implemented via a `CustomCallChecker`, but in the future we could use function overloading and `Literal` types to implement this in Guppy source: ```python @guppy.overloaded def range[n: nat](stop: Literal[n]) -> SizedIter[Range, n]: return SizedIter(Range(0, stop)) @guppy.overloaded def range(stop: int) -> Range: return Range(0, stop) ``` Closes #610.
- Loading branch information
Showing
6 changed files
with
144 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters