Commit 503072d
unify type-expression lowering into a single pass
`&`/`and` (intersection), `or` (union), `not` (negation) and callable types
(`(A) -> B`, Protocol synthesis) now lower through one pass (callable.rs). the
separate intersection/not_type forward passes and their Fragment-template
lowerer are gone — callable's rewrite gains the boolop cases and reuses the
shared chain-flatten helpers, so `&`/`and`/`or`/`not` are defined in one place.
this composes the per-leaf lowerings inside every type-form and context: a
`float` / literal / `dynamic` arm inside an intersection, union arm, callable
arg/return, or generic subscript is now wrapped (`JustFloat` / `Literal[…]` /
`Any`) instead of leaking raw with an orphan import — by routing re-emitted
leaves through the shared `rewrite_type_expr` composer and materialising narrow
edits through `Fragment::Src` passthrough.
it also closes three composed-position gaps found by sandpit triangulation
(`by check` passes, the transpiled python crashed):
- the `< 3.12` generics polyfill (`TypeVar(bound=)`, `TypeAliasType`) spliced its
payload through a leaf-only rewriter, leaking raw `&`/`not`; it now routes
through the full lowerer (`callable::lower_type_expr_full`), matching native
- a synthesized `Protocol` class is hoisted to module top; its `__call__`
annotations are now forward-reference strings, so they never evaluate a name
defined later (was a runtime `NameError`)
- a `typeof` nested under a structural type-form (`&`/`or`/`not`/`?`/arrow) is
skipped by the typeof AST fold, whose statement re-render would otherwise
drop the lowerer's wide edit and leak the operator raw
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 4d1dcc2 commit 503072d
12 files changed
Lines changed: 618 additions & 383 deletions
File tree
- crates/by_transforms/src/transforms
- docs/basedpython/features
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
376 | 376 | | |
377 | 377 | | |
378 | 378 | | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | 379 | | |
389 | 380 | | |
390 | 381 | | |
| |||
396 | 387 | | |
397 | 388 | | |
398 | 389 | | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
399 | 407 | | |
400 | 408 | | |
401 | 409 | | |
| |||
425 | 433 | | |
426 | 434 | | |
427 | 435 | | |
428 | | - | |
429 | | - | |
430 | 436 | | |
431 | 437 | | |
432 | 438 | | |
| |||
525 | 531 | | |
526 | 532 | | |
527 | 533 | | |
528 | | - | |
529 | | - | |
530 | 534 | | |
531 | 535 | | |
532 | 536 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
| 46 | + | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
| 40 | + | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
281 | | - | |
| 281 | + | |
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
289 | | - | |
290 | | - | |
291 | | - | |
| 289 | + | |
| 290 | + | |
292 | 291 | | |
293 | 292 | | |
294 | 293 | | |
| |||
600 | 599 | | |
601 | 600 | | |
602 | 601 | | |
603 | | - | |
| 602 | + | |
604 | 603 | | |
605 | 604 | | |
606 | 605 | | |
| |||
1440 | 1439 | | |
1441 | 1440 | | |
1442 | 1441 | | |
1443 | | - | |
1444 | | - | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
1445 | 1447 | | |
1446 | 1448 | | |
1447 | 1449 | | |
1448 | 1450 | | |
1449 | 1451 | | |
1450 | 1452 | | |
1451 | | - | |
| 1453 | + | |
1452 | 1454 | | |
1453 | 1455 | | |
1454 | 1456 | | |
| |||
1531 | 1533 | | |
1532 | 1534 | | |
1533 | 1535 | | |
1534 | | - | |
| 1536 | + | |
| 1537 | + | |
1535 | 1538 | | |
1536 | 1539 | | |
1537 | 1540 | | |
1538 | 1541 | | |
1539 | | - | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
1540 | 1586 | | |
1541 | 1587 | | |
1542 | 1588 | | |
| |||
0 commit comments