Commit e30e2b0
rsscript: add tuples, destructuring, and generic match/field inference
Tuples desugar at parse time to synthetic `__TupleN` generic structs, so the
checker, HIR, both backends, and the formatter handle them via existing
machinery:
- Literals `(a, b)`, types `(Int, String)`, and `.itemN` field access.
- Tuple patterns in `match` (binding, wildcard, and literal element patterns),
lowered to `__TupleN { itemK: .. }` struct patterns.
- `let (a, b) = expr` destructuring (`_` skips an element), expanded to a
temporary plus per-element field reads.
- `read (a, b)` and `manage (a, b)` operands now parse as tuple literals.
- The formatter renders the synthetic `__TupleN` forms back as tuple syntax for
literals, types, patterns, and destructuring (idempotent round-trip).
Fixing tuple parity surfaced several pre-existing generic-struct gaps, fixed
here so both backends agree (they benefit all generic structs, not just tuples):
- rust_lower: by-ref match field bindings are rebound to owned values (deref
`Copy`, clone others) so the arm body sees owned fields — previously only
`Some`/`Ok` payloads were handled, so `match read s { S { x } => f(x) }`
failed to compile.
- reg_vm: plain (non-variant) struct patterns are now supported in the general
refutable matcher, including literal element patterns.
- checker + HIR: generic field-access, match-binding, and literal-pattern type
checks substitute the scrutinee's concrete arguments for the type's
parameters (`item0` on `__Tuple2<Int, String>` resolves to `Int`, not `A`);
generic construction also infers parameters from scalar literal arguments.
Covered by `tests/fixtures/pass/tuples.rss`, the `parity_tuple_*` and
`parity_generic_struct_match_and_field_inference` VM/compiled parity tests, and
a formatter round-trip test. Full suite green (1032 tests); clippy clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 75c47bd commit e30e2b0
12 files changed
Lines changed: 1295 additions & 52 deletions
File tree
- crates/rsscript
- src
- checks
- reg_vm
- rust_lower
- syntax
- tests
- fixtures/pass
- vm_eval_parity
- docs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
2041 | 2042 | | |
2042 | 2043 | | |
2043 | 2044 | | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
2044 | 2053 | | |
2045 | 2054 | | |
2046 | 2055 | | |
2047 | 2056 | | |
2048 | 2057 | | |
2049 | 2058 | | |
2050 | | - | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
2051 | 2062 | | |
2052 | 2063 | | |
2053 | 2064 | | |
| |||
2120 | 2131 | | |
2121 | 2132 | | |
2122 | 2133 | | |
| 2134 | + | |
| 2135 | + | |
| 2136 | + | |
| 2137 | + | |
| 2138 | + | |
| 2139 | + | |
| 2140 | + | |
| 2141 | + | |
| 2142 | + | |
| 2143 | + | |
| 2144 | + | |
| 2145 | + | |
| 2146 | + | |
| 2147 | + | |
2123 | 2148 | | |
2124 | 2149 | | |
2125 | 2150 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
339 | | - | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
340 | 346 | | |
341 | 347 | | |
342 | 348 | | |
| |||
511 | 517 | | |
512 | 518 | | |
513 | 519 | | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
514 | 523 | | |
515 | 524 | | |
516 | 525 | | |
| |||
681 | 690 | | |
682 | 691 | | |
683 | 692 | | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
684 | 722 | | |
685 | 723 | | |
686 | 724 | | |
| |||
790 | 828 | | |
791 | 829 | | |
792 | 830 | | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
793 | 858 | | |
794 | 859 | | |
795 | 860 | | |
| |||
1025 | 1090 | | |
1026 | 1091 | | |
1027 | 1092 | | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
1028 | 1096 | | |
1029 | 1097 | | |
1030 | 1098 | | |
| |||
1045 | 1113 | | |
1046 | 1114 | | |
1047 | 1115 | | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
1048 | 1139 | | |
1049 | 1140 | | |
1050 | 1141 | | |
| |||
1175 | 1266 | | |
1176 | 1267 | | |
1177 | 1268 | | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
1178 | 1276 | | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
1179 | 1294 | | |
1180 | 1295 | | |
1181 | 1296 | | |
| |||
1739 | 1854 | | |
1740 | 1855 | | |
1741 | 1856 | | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
1742 | 1897 | | |
1743 | 1898 | | |
1744 | 1899 | | |
| |||
0 commit comments