Commit 402be90
authored
Currently, `typeSize` reports inconsistent values for standard tuple
types (e.g., `(A, B)`) compared to their semantically equivalent
recursive pair encodings (e.g., `A *: B *: EmptyTuple`).
This discrepancy arises because `TupleN` is represented as a flat
`AppliedType`, whereas the nested encoding forms a deeper tree
structure. As `typeSize` is often used as a heuristic for complexity or
optimization limits, this inconsistency can lead to divergent behavior
in the compiler depending on how a tuple is represented syntactically.
This PR modifies `TypeSizeAccumulator` to canonicalize `TupleN` types
into their recursive `*:` representation before calculating their size.
This ensures that the size metric is consistent regardless of whether
the tuple is represented as a flat `AppliedType` or a nested structural
type.
I have added a new unit test in `TypesTest` that asserts `Tuple3[Int,
Boolean, Double]` and `Int *: Boolean *: Double *: EmptyTuple` both
yield identical `typeSize` equal to 3.
Thanks to @mbovel for providing the unit test that effectively
reproduces this issue and validates the fix.
Fixes #24730
File tree
3 files changed
+22
-2
lines changed- compiler
- src/dotty/tools/dotc/core
- test/dotty/tools/dotc
- core
- typer
3 files changed
+22
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7125 | 7125 | | |
7126 | 7126 | | |
7127 | 7127 | | |
| 7128 | + | |
| 7129 | + | |
7128 | 7130 | | |
7129 | 7131 | | |
7130 | 7132 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
| 53 | + | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| |||
0 commit comments