Commit ae039a7
committed
Implement typed keyword argument stages and &key support
This commit introduces first-class keyword arguments into Coalton's
function type system and syntax.
Keyword arguments are all-optional. A keyword with a default has
visible binder type T. A keyword without a default has visible binder
type (Optional T). Omitted no-default keywords are treated as None,
making omission and explicit None equivalent for those keys.
Some amount of row polymphism is supported: calling a function that
has more keyword arguments than supplied (e.g., through high-order
gymnastics) will automatically eta-expand into a call with all
arguments supplied.
Type representation: add keyword-stage and entry nodes to parser and
typechecker type ASTs, with pretty-printer support and parser support
for keyword stages in declared types. Unification now understands
keyword stages via closed-row matching logic. Environment metadata and
related plumbing are extended so keyword parameters survive inference,
diagnostics, and documentation paths.
Syntax: add &key support for named definitions and anonymous fn
argument lists; add keyword argument parsing at call sites. Enforce
ordering and validity rules (keywords after positional arguments, no
duplicates, malformed pairs rejected). Add targeted diagnostics for
invalid placement, duplicate binders, malformed call syntax, unknown
keys, and declaration/definition keyword-stage mismatch.
Compilation strategy: preserve a simple runtime model by lowering
keyword stages to ordinary positional calls in canonical keyword
order. Defaulted visible binders are computed from hidden Optional
physical parameters (Some provided value, None uses default
expression). No-default binders flow as Optional directly. This keeps
runtime/codegen on standard lambdas and applications.
Tests: extend parser/type inference/runtime coverage for keyword
syntax and behavior, including nested keyword-lambda regression cases;
update user and internals docs with keyword-stage syntax/semantics and
lowering rationale. Verified with full test run (make test).1 parent 7ffbd50 commit ae039a7
File tree
25 files changed
+2174
-407
lines changed- docs
- internals
- src
- codegen
- doc
- parser
- typechecker
- tests
- test-files
25 files changed
+2174
-407
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
66 | 72 | | |
67 | 73 | | |
68 | 74 | | |
69 | 75 | | |
70 | 76 | | |
71 | 77 | | |
| 78 | + | |
| 79 | + | |
72 | 80 | | |
73 | 81 | | |
74 | 82 | | |
| |||
110 | 118 | | |
111 | 119 | | |
112 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
113 | 133 | | |
114 | 134 | | |
115 | 135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
200 | 241 | | |
201 | 242 | | |
202 | 243 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
14 | 44 | | |
15 | 45 | | |
16 | 46 | | |
| |||
37 | 67 | | |
38 | 68 | | |
39 | 69 | | |
40 | | - | |
41 | | - | |
| 70 | + | |
| 71 | + | |
42 | 72 | | |
43 | 73 | | |
44 | 74 | | |
| |||
53 | 83 | | |
54 | 84 | | |
55 | 85 | | |
56 | | - | |
57 | | - | |
| 86 | + | |
| 87 | + | |
58 | 88 | | |
59 | 89 | | |
60 | 90 | | |
| |||
71 | 101 | | |
72 | 102 | | |
73 | 103 | | |
74 | | - | |
75 | | - | |
| 104 | + | |
| 105 | + | |
76 | 106 | | |
77 | 107 | | |
78 | 108 | | |
| |||
84 | 114 | | |
85 | 115 | | |
86 | 116 | | |
87 | | - | |
88 | | - | |
| 117 | + | |
| 118 | + | |
89 | 119 | | |
90 | 120 | | |
91 | 121 | | |
92 | 122 | | |
93 | 123 | | |
94 | 124 | | |
95 | 125 | | |
96 | | - | |
97 | | - | |
| 126 | + | |
| 127 | + | |
98 | 128 | | |
99 | 129 | | |
100 | 130 | | |
| |||
123 | 153 | | |
124 | 154 | | |
125 | 155 | | |
126 | | - | |
127 | | - | |
| 156 | + | |
| 157 | + | |
128 | 158 | | |
129 | 159 | | |
130 | 160 | | |
| |||
142 | 172 | | |
143 | 173 | | |
144 | 174 | | |
145 | | - | |
146 | | - | |
| 175 | + | |
| 176 | + | |
147 | 177 | | |
148 | 178 | | |
149 | 179 | | |
| |||
156 | 186 | | |
157 | 187 | | |
158 | 188 | | |
159 | | - | |
160 | | - | |
| 189 | + | |
| 190 | + | |
161 | 191 | | |
162 | 192 | | |
163 | 193 | | |
| |||
205 | 235 | | |
206 | 236 | | |
207 | 237 | | |
208 | | - | |
209 | | - | |
| 238 | + | |
| 239 | + | |
210 | 240 | | |
211 | 241 | | |
212 | 242 | | |
| |||
230 | 260 | | |
231 | 261 | | |
232 | 262 | | |
233 | | - | |
| 263 | + | |
234 | 264 | | |
235 | 265 | | |
236 | 266 | | |
| |||
246 | 276 | | |
247 | 277 | | |
248 | 278 | | |
249 | | - | |
| 279 | + | |
250 | 280 | | |
251 | 281 | | |
252 | 282 | | |
| |||
256 | 286 | | |
257 | 287 | | |
258 | 288 | | |
259 | | - | |
| 289 | + | |
260 | 290 | | |
261 | 291 | | |
262 | 292 | | |
| |||
274 | 304 | | |
275 | 305 | | |
276 | 306 | | |
277 | | - | |
| 307 | + | |
278 | 308 | | |
279 | 309 | | |
280 | 310 | | |
281 | 311 | | |
282 | 312 | | |
283 | 313 | | |
284 | | - | |
| 314 | + | |
285 | 315 | | |
286 | 316 | | |
287 | 317 | | |
| |||
296 | 326 | | |
297 | 327 | | |
298 | 328 | | |
299 | | - | |
| 329 | + | |
300 | 330 | | |
301 | 331 | | |
302 | 332 | | |
| |||
308 | 338 | | |
309 | 339 | | |
310 | 340 | | |
311 | | - | |
312 | | - | |
| 341 | + | |
| 342 | + | |
313 | 343 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
243 | 257 | | |
244 | 258 | | |
245 | 259 | | |
246 | 260 | | |
247 | 261 | | |
248 | 262 | | |
249 | | - | |
250 | | - | |
251 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
252 | 268 | | |
253 | | - | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
254 | 275 | | |
255 | | - | |
256 | 276 | | |
257 | 277 | | |
| 278 | + | |
258 | 279 | | |
259 | 280 | | |
260 | 281 | | |
| |||
277 | 298 | | |
278 | 299 | | |
279 | 300 | | |
280 | | - | |
281 | | - | |
282 | | - | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
283 | 304 | | |
284 | 305 | | |
285 | 306 | | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
286 | 315 | | |
287 | 316 | | |
288 | 317 | | |
| |||
0 commit comments