Repository navigation
Commit 5c58e38
Represent array and list literals with spreads with a Pexp_spread node
The parser no longer turns [a, ...b] and list{...a, b} into calls of
Primitive_array.spread and Primitive_list.spread marked with res.spread.
Pexp_spread keeps the items and spreads in source order, and the type
checker gives it a Texp_spread node. Translation emits new Parray_spread
and Plist_spread primitives that compile to the same runtime calls. A list
literal whose only spread is its tail stays a chain of ::.
Before (rescript):
let x = [...[1, 2], 3, ...[]]
let y = @attr list{...xs, ...list{}, 1}
After (rescript):
let x = [...[1, 2], 3, ...[]]
let y = @attr list{...xs, ...list{}, 1}
Source: the old formatter printed [1, 2, 3, ] and list{...xs, , 1}
without the attribute; the new one prints the input unchanged
(tests/syntax_tests/data/printer/expr).
Review: Why do the generated item groups have ghost locations? The v0
encoding has no marker on them, and the ghost flag tells a group of items
from an array or list literal that is spread. A call built by a PPX with
real locations decodes to spreads only, which concatenates the same values.
Review: Why does the typed node hold the concatenated parts rather than the
elements? The parts are the arrays and cons chains the runtime call takes,
so the items keep the errors of array and list literals and translation
needs no list building of its own.
Area: syntax printer typechecker lambda codegen analysis reanalyze tests
Output: unchanged, tests/tests JS byte-identical after a rebuild; a
combinatorial harness of all item/spread sequences up to length 4 compiles
to identical JS with the old and new bsc
Formatting: changed spreads of array and list literals and attributes on
literals with spreads are kept; comments in list spreads stay in place
Formats: ast cmt
PPX: unchanged wire: the v0 encoding is the res.spread call it was, decoded
back to Pexp_spread (ast-mapping fixture SpreadLiterals.res)
Editor: unchanged: pipe completion types the literal as the runtime call;
SpreadLiterals.res covers AST dump, hints, highlighting and completion
Tests: +tests/syntax_tests/data/ast-mapping/SpreadLiterals.res
+tests/analysis_tests/tests/src/SpreadLiterals.res
+tests/build_tests/super_errors/fixtures/array_spread_type_mismatch.res
+tests/build_tests/super_errors/fixtures/list_spread_type_mismatch.res
+tests/build_tests/super_errors/fixtures/array_spread_annotation_mismatch.res
~tests/ounit_tests/ounit_ast_mapper0_tests.ml
~tests/syntax_tests/data/printer/expr/array.res
~tests/syntax_tests/data/printer/expr/list.res
~tests/syntax_tests/data/printer/comments/array.res
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EUpL6dKCiSwAeriDGRHqNr
Signed-off-by: Christoph Knittel <ck@cca.io>1 parent 1eb91bb commit 5c58e38
61 files changed
Lines changed: 761 additions & 294 deletions
File tree
- analysis
- reanalyze/src
- src
- changes
- compiler
- core
- ext
- ml
- syntax/src
- tests
- analysis_tests/tests/src
- expected
- build_tests/super_errors
- expected
- fixtures
- ounit_tests
- syntax_tests/data
- ast-mapping
- expected
- parsing
- grammar/expressions/expected
- recovery/expression/expected
- printer
- comments
- expected
- expr
- expected
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
995 | 995 | | |
996 | 996 | | |
997 | 997 | | |
| 998 | + | |
| 999 | + | |
998 | 1000 | | |
999 | 1001 | | |
1000 | 1002 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
65 | 67 | | |
66 | 68 | | |
67 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
234 | 246 | | |
235 | 247 | | |
236 | 248 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
225 | 242 | | |
226 | 243 | | |
227 | 244 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
63 | | - | |
64 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | 260 | | |
269 | 261 | | |
270 | 262 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
0 commit comments