Repository navigation
Sema: a generic function that calls itself binds to its instance in flight (#2533) - #2537
Merged
Merged
Conversation
…light (#2533) check_generic_call filled generic_specialization_cache only after the body check returned, so the recursive call inside the body found no entry and instantiated the same key again without end: the if-tail form overflowed the stack (rc 139, no diagnostic), the return form survived a cutoff after hundreds of body checks. lldb cycle: check_fn_body_concrete -> check_fn_body_with_sig_at -> ... -> check_generic_call -> check_fn_body_concrete, 735 body checks before EXC_BAD_ACCESS at the stack top. A specialization key in flight is recorded before its body check. A call that meets its own instance takes the declared return type for the instance and binds to the signature the body check added before it began; with no annotation it reads Unit, as a non-generic recursive call does under D43 today (#2535 is the extension).
Closed
ehartford
marked this pull request as ready for review
October 21, 2026 20:53
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A generic function that calls itself (#2533)
Eric's generic quicksort (
fn quicksort[T](xs: List[T]) -> List[T]) exited the compiler with 139 and no diagnostic. Any generic free function that calls itself did:check_generic_callfilled the specialization cache only after the body check returned, so the recursive call inside the body instantiated the same key again without end. lldb showed the cyclecheck_fn_body_concrete → check_fn_body_with_sig_at → … → check_generic_call → check_fn_body_concrete, 735 body checks before the fault at the stack top. The explicit-return form survived only because a cutoff ended it after hundreds of checks.A specialization key in flight is recorded before its body check. A call that meets its own instance takes the declared return type for the instance and binds to the signature the body check added before it began; with no annotation it reads Unit, exactly as a non-generic recursive call does under D43 today (#2535 is the extension to inferred recursion).
Fixture
behav_generic_fn_calls_itself.w(crashes the installed compiler, passes here). The quicksort as Eric wrote it runs with this layer.Also filed from the quicksort: #2534 (a pipeline over a
Listor slice does not iterate it; a slice has noiter()), #2535 (D43 for a recursive body).Closes #2533.