Repository navigation
docs: mutual recursion lowering prereq + bootstrap.dag dissolution scope #467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -602,9 +602,73 @@ doesn't know about the grammar rules. | |
| thesis promise is "adding a new target costs one spec file." | ||
| True; writing that spec set is the investment. | ||
|
|
||
| ### §2.4 Mutual recursion lowering — prereq for complexity and general execution | ||
|
|
||
| The thesis's lowering table (INVARIANTS.md §"Recursive syntax is | ||
| sugar") commits to handling EVERY call pattern, including n-way | ||
| mutual recursion. The lowering for mutual recursion is: | ||
|
|
||
| > Mutual recursion (SCC) on children → `descend` over SCC-ordered | ||
| > nodes, bounded by |SCC|. | ||
|
|
||
| v3's `lower.rs` already detects mutual recursion at lowering time | ||
| (`compute_mutually_recursive` walks the call graph and returns a | ||
| `HashSet<String>` of cycle members). **But it currently REJECTS | ||
| mutual recursion** — the diagnostic says "mutual recursion is not | ||
| yet supported in v3." | ||
|
|
||
| The missing piece is the LOWERING step: transform the cycle into | ||
| bounded Loop nodes with descend semantics. For an SCC {A, B, C} | ||
| where A calls B calls C calls A (each on children of its input): | ||
|
|
||
| 1. Lowering detects the cycle via `compute_mutually_recursive` | ||
| (already done) | ||
| 2. Lowering orders the SCC members (topological sort of the | ||
| non-cycle edges, arbitrary but deterministic for cycle-internal | ||
| edges) | ||
| 3. For each function in the SCC, lowering replaces the recursive | ||
| call with a reference to the next function in the SCC order | ||
| 4. The outermost function becomes a `Loop` (bounded descend) | ||
| whose body is the SCC walk: each iteration calls one function, | ||
| and the bound is the structural descent evidence (children | ||
| get strictly smaller at each level) | ||
|
|
||
| Once lowering does this, the substrate carries the SCC structure | ||
| as bounded Loop nodes. Complexity reads `Loop.bound` and applies | ||
| the standard cost rule: `bound × cost(body)`. No SCC analysis | ||
| in complexity. No Tarjan's in complexity. The cycle detection is | ||
| in LOWERING (where it belongs), and the general SCC algorithm is | ||
| a library function in `std/graph.dag` (reusable by anything that | ||
| needs cycle detection). | ||
|
|
||
| **Prereq for:** | ||
| - The complexity port (complexity reads SCC cost from the | ||
| substrate; if lowering doesn't produce the bounded descend, | ||
| complexity has to reconstruct the SCC itself — which is the | ||
| v2 pattern we're dissolving) | ||
| - General language completeness — any `.dag` program with mutual | ||
| recursion should compile, not fail at lowering | ||
| - Self-hosting — the compiler's own pipeline stages may be | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BLOCKING: Treating lower<->infer as a likely mutual-recursion case contradicts Section 2.1's pipeline-as-DAG contract and the thesis's explicit dependency flow; stage composition should stay acyclic. |
||
| mutually recursive (e.g., lower calls infer for type-directed | ||
| lowering, infer calls lower for template expansion) | ||
|
|
||
| **Scope:** n-way mutual recursion (not just 2-way). The thesis's | ||
| lowering table says "mutual recursion (SCC) on children" without | ||
| a bound on the SCC size. A 3-function cycle, a 10-function cycle, | ||
| and a 2-function cycle all lower to the same bounded-descend | ||
| shape. | ||
|
|
||
| **Testing:** every SCC size from 2 to at least 5 should have a | ||
| test fixture. Each fixture: | ||
| - Compiles without diagnostics | ||
| - Produces a bounded Loop with the correct bound | ||
| - The bound is provably structural (|SCC| × |children|) | ||
| - A complexity lens walking the result reads the cost without | ||
| reconstruction | ||
|
|
||
| --- | ||
|
|
||
| ## §3. Stage 1 — `emit.dag` | ||
| ## §3. Stage 1 ��� `emit.dag` | ||
|
|
||
| **Current:** `src/v3/compiler/src/emit_rust.rs` (~340 lines | ||
| today; will grow as FieldBinding lookup lands in the reflection | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BLOCKING: This roadmap item understates the missing work: compute_mutually_recursive only yields a flat membership set, so the SCC partition/order fact still gets dropped before the lowering->complexity boundary (FACTS FLOW FORWARD).