[tensor-shapes] Should we allow multiple splats?
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
Research direction
Start by tracing how type variable tuples, IntTuple shapes, and tuple unpack forms are represented and handled. Compare the existing tuple and IntTuple paths, then determine whether a shared representation can support multiple splats without making them diverge. Done means the design is agreed and multiple splats are supported consistently, with coverage for the examples described in the issue.
Written by the indexing model from the issue text.
Description
One of the things I noticed when I implemented support for IntTuple[*Elements[S], N] was that the limitation on type var tuple that there can only be one splat is artificial: we define type var tuple in a way where syntactically there can only be one in scope at a time (or at least mostly; I guess you could have one in scope at each of a class and method boundary but that's pretty artificial).
As a result, all the python type checkers I've looked at define unpack forms with only one splat.
But that's a completely artificial limitation, it makes perfect sense to splat arbitrarily many tuples into a new tuple, for example if we allow tuple splats in general then this is sensible:
def f[A: tuple, B: tuple](a: A, x: int, b: B) -> tuple[*Elements[A], int, *Elements[B]]
At the moment I'm not actually trying to support Elements for normal tuple anyway, but the same pattern can happen with IntTuple for shapes (and does happen - for example a sufficiently large cross-product might do this).
To handle this we'd have to change the representation to something like an array of tagged slots that can either be normal types or splatted types.
It is possible to make this change for just IntTuple without changing tuple, which would be less invasive, although the resulting implementation would be less coherent (ideally I don't want the types diverging too much). That's the main blocker: this isn't high enough priority for me to want to change tuple right now, but I also don't want the structures to diverge.
Inspired by a question from @TimothyEDawson in https://github.com/facebook/pyrefly/discussions/4807
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 521
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from facebook/pyrefly
-
Difficulty 2/5 Half a day Newbie friendliness 68/100
-
typechecking
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
False positive `unexpected-keyword` for inherited SQLAlchemy mapped columns in `Update.values()` Opensqlalchemy typechecking
Difficulty 3/5 1-2 days Newbie friendliness 72/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
All issues in facebook/pyrefly
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
enhancement remote
Difficulty 2/5 1-3 hours Newbie friendliness 68/100