Skip to content

D142 and D143: a pipeline iterates a sequence, a slice has iter(), a self-calling function infers its return (#2534, #2535) - #2542

Merged
ehartford merged 2 commits into
mainfrom
briefs-2534-2535
Oct 22, 2026
Merged

ehartford merged 2 commits into
mainfrom
briefs-2534-2535

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

D142 and D143 (#2534, #2535), as ruled 2026-10-21

Eric's quicksort, as he wrote it, is the fixture for the pair: with its return type (behav_d142_pipeline_over_sequence.w) and without (behav_d143_recursive_inferred_return.w).

D142 (§13.5). A sequence on the left of |> iterates by the rule for uses; a slice has iter() (std's SliceIter[T] through slice_iter, since no impl can name a slice type); collecting views of value elements builds a list of the values (D111 + D139), which the literal [pivot] with a view pivot now follows too. Sema records the inserted .iter() under the pipeline node with the same for_iter_* records a for loop uses, and MIR calls it before the stage.

D143 (§9.1). A package-local function with no return type that calls itself: a first silent pass with its own calls open (Never) lets the other paths decide the type; the second pass checks the body under it as the demand, and a self-call path that disagrees is named with the decided type. The three limits Eric stated: a pub fn declares its return type (Law 6); the re-check must agree, naming the arm; mutual recursion is written, naming the cycle. Fixtures: err_d143_every_path_recursive.w, err_d143_pub_recursive_declares.w, err_d143_mutual_recursion.w, err_d143_self_call_path_disagrees.w.

Decision records D142 and D143 in docs/meetings/, index updated; spec words in docs/spec/013_iteration.md (§13.5) and docs/spec/009_functions.md (§9.1).

Closes #2534. Closes #2535.

Eric Hartford added 2 commits October 21, 2026 20:47
…ter(), and a self-calling function infers its return from the other paths

Eric ruled both briefs (#2534, #2535) yes, with one amendment each; the
quicksort as he wrote it is the fixture for the pair, annotated and not.

D142 (§13.5): a sequence on the left of `|>` iterates by the rule `for`
uses — when the stage is no method of the value but is one of the
iterator its `.iter()` returns, Sema records the inserted `.iter()`
(pipeline_implicit_iter, the for_iter_* records keyed by the pipeline
node) and MIR calls it, the stage reading the iterator wherever it read
the piped expression. A slice has `iter()`: std's `slice_iter`
(`SliceIter[T]`, since no `impl` can name a slice type), for the spelled
call, `for`, and `|>`. Collecting views of value elements builds values
(D111, D139): `iter_collect_views` did already; a collection literal's
elements with no outer demand now follow the same owned-demand rule, so
`[pivot]` with `pivot: &isize` is a `List[isize]`, never borrows into the
matched place.

D143 (§9.1): a package-local function without a return type whose body
calls itself is checked twice. A first, silent pass with its own calls open
(`Never`; `++` now takes the other side's type from a Never operand as `+`
did) lets the other paths decide the type; the second pass checks the body
under that type as its demand (`[] => []` takes it), and a self-call path
that disagrees is named with the decided type (a disagreement the first
pass sees in an arm join is reported after it the same way). Every path a
self-call: "write `->`". A `pub fn` declares its return type (Law 6).
Mutual recursion with neither type written is refused naming the cycle.
Today's "returns Unit" for the self-call was the compiler choosing a type
for an arm, which D43 forbids.

Spec words in §13.5 and §9.1; decision records D142, D143.
The ceremony audit flags the written `-> str` on the recursive
json_to_string once D143 infers a self-calling function's return from its
other paths; the example tracks the spec (Eric, 2026-09-22).
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on ea9eaa8: gate, uat and battery-checks under the pinned seed, logs in out/battery/.

@ehartford
ehartford marked this pull request as ready for review October 22, 2026 00:58
@ehartford
ehartford merged commit 920b95b into main Oct 22, 2026
@ehartford
ehartford deleted the briefs-2534-2535 branch October 22, 2026 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant