Commit 186fd8b
fix(resolve): two-pass — forward-declare top-level names (#135 slice 11)
#135 slice 11 (discovered during slice 8). The resolver was single-pass:
`resolve_decl` defined a name then immediately resolved its body, and
the program entry points folded `resolve_decl` over decls in source
order. So any reference to a top-level function defined *later* in the
file failed with `UndefinedVariable` — e.g. collections.affine
`binary_search` → `binary_search_helper`, reproducible even without
`module`. Mutual recursion was impossible.
Fix: standard two-pass name resolution. New `pre_register_decl` /
`pre_register_program` declares every top-level name (fn, type + enum
constructors, effect + ops, trait, const) before any body is resolved;
wired into all three entry points (`resolve_program`,
`resolve_and_typecheck_module`, `resolve_program_with_loader`).
`Symbol.define` is `Hashtbl.replace`-based so the existing in-body
re-definition is idempotent — no double-define hazard.
Effect: forward references and **mutual recursion** now resolve;
collections.affine advances RESOLVE → TYPECHECK (a distinct later
defect). Self-recursion verified non-regressed. 3 regression tests;
full suite green (233), zero regressions from this resolver change.
Advances #135. Refs #128, #135.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 582546a commit 186fd8b
2 files changed
Lines changed: 72 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
488 | 488 | | |
489 | 489 | | |
490 | 490 | | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
491 | 533 | | |
492 | 534 | | |
493 | 535 | | |
| 536 | + | |
494 | 537 | | |
495 | 538 | | |
496 | 539 | | |
| |||
506 | 549 | | |
507 | 550 | | |
508 | 551 | | |
509 | | - | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
510 | 555 | | |
511 | 556 | | |
512 | 557 | | |
| |||
753 | 798 | | |
754 | 799 | | |
755 | 800 | | |
756 | | - | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
757 | 804 | | |
758 | 805 | | |
759 | 806 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3380 | 3380 | | |
3381 | 3381 | | |
3382 | 3382 | | |
| 3383 | + | |
| 3384 | + | |
| 3385 | + | |
| 3386 | + | |
| 3387 | + | |
| 3388 | + | |
| 3389 | + | |
| 3390 | + | |
| 3391 | + | |
| 3392 | + | |
| 3393 | + | |
| 3394 | + | |
| 3395 | + | |
| 3396 | + | |
| 3397 | + | |
| 3398 | + | |
| 3399 | + | |
| 3400 | + | |
| 3401 | + | |
| 3402 | + | |
3383 | 3403 | | |
3384 | 3404 | | |
3385 | 3405 | | |
| |||
3437 | 3457 | | |
3438 | 3458 | | |
3439 | 3459 | | |
| 3460 | + | |
| 3461 | + | |
| 3462 | + | |
3440 | 3463 | | |
3441 | 3464 | | |
3442 | 3465 | | |
| |||
0 commit comments