Skip to content

may suspend params - #2527

Closed
ehartford wants to merge 8 commits into
listiter-viewfrom
may-suspend-params
Closed

ehartford wants to merge 8 commits into
listiter-viewfrom
may-suspend-params

Conversation

@ehartford

@ehartford ehartford commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

#2511 (§14.3 INVARIANT 5): a callable parameter or field suspends only when some caller or store hands it a callable that may. settle_callable_param_facts runs inside Sema's suspend fixpoint: every call Sema can attribute to a declared fn (direct, resolved generic or std.traits adapter, pipeline stage) marks (fn, parameter) for each callable argument that may suspend; every struct literal or field assignment marks (owner, field). A parameter or field answers that mark at a call site; a fn whose name escapes as a value, or any unattributed call that passes a may-suspend callable, keeps the old answer (may) for everything. Measured (-O3, 4M i64): fold through a fn parameter 8.4 ms → 1.49 ms (the concrete-loop floor); std.traits map|filter|fold 52 ms → 4.4 ms, within 5% of the retired intrinsics' 4.2 ms. 26 suspension fixtures green; gate green (515 s). Layer 2 of stack #2528; the D103 layer follows.

…lection literal's elements (D103, the missing demand sites)

D103 rules the conversion at every demand site; the implementation had
arguments, fields, annotated bindings, assignments, returns and if/match
arms, and lacked a block's tail under an Option return (the mismatch
branches only Ok-wrapped a Result) and a collection literal's elements
under a known Option element type. Both now call value_to_option_at_demand
before the mismatch. One fixture per demand site (behav_d103_site_*). D140
and D141 are recorded in the decision log (ruled 2026-10-21); their
implementation follows.
Eric Hartford added 7 commits October 21, 2026 01:15
…CE on a cast or ++ at the return)

check_return recorded the converted Option on the expression; MIR then
lowered a cast or a `++` at the Option ("unsupported cast in MIR" on
`return raw.unwrap() as Kind`, and on `return s ++ "!"` under Option[str]).
The record is the conversion (value_to_option_nodes); the node keeps `T`,
and check_body_explicit_value_results reads the record before comparing.
Fixture: behav_d103_site_return_cast.
…p, tools/sweep_some_at_option_demand.w)

Compiler-driven, never textual: the tool reads Sema's ceremony record
(`COMPILER check ROOT.w --ceremony-census`, pattern some-at-option-demand,
with byte spans) and removes a `Some(x)` only where Sema proved the demand
is Option[T] and x: T -- the condition D103 inserts it under -- so
`return Some(None)` under Option[Option[T]] is never touched; migrated
corpora (D112) and anything else are listed, not edited. Over src/main.w's
program: 9 sites in lib/std and src removed; the remaining src tail and
return sites that need this layer's Sema (the tail conversion, the
return-record fix) keep their Some until a seed carrying it is pinned,
since the pinned seed compiles src.
…ten one must match

Ruled by Eric 2026-10-21. collect_fn_decl resolves an omitted parameter
type of a trait impl's method from the trait's declaration, instantiated
for the impl (trait_impl_param_type: the same name, else the same
position among the non-receiver parameters; Self is the impl type); a
written type that differs is an error naming both. An untyped parameter
of any other fn is an error too -- it used to reach codegen as a missing
FnAbi type ("cannot lower FnAbi parameter"). The return half existed
(trait_impl_method_contract, #652); a generic impl's return is #2531.
Spec section 11.1; fixtures behav_d140_* (the static method is named
`unit`, #2520) and err_d140_*.
…d tail precedes the leaf checks

Ruled by Eric 2026-10-21 (amends D43, carves the case out of D103):
where a return type is inferred, a `None` return, tail or arm beside a
`T` joins to Option[T] (none_value_join, before compatibility, since a
bare None is compatible with every Option); `None` beside an `Option[U]`
is written (cannot infer: write the return type). Once the inferred
type is that Option, every T leaf converts (convert_body_values_to_option
after inference; a joined if/match arm converts at the join and the
per-arm acceptance reads the record). A bare `None` is typed at Option's
own declaration (is_bare_none_type).

Also: the tail of a function body converts to a demanded Option before
any leaf check reads the record -- a specialization's body is checked
with no return demand, so `&self.list[i]` under `-> Option[&T]` in
ListIter.next failed Sema in every program that touched it (seen as
`xs.iter() |> max() ?? 0` inferring Unit). ListIter.next now reads
`self.idx += 1` and `&self.list[i]`. Spec sections 9.1 and 4.9a; fixtures
behav_d141_* and err_d141_*; 210 behavior fixtures green.
…ed (audit:resolution read the node type)

The operand audit compared the node's own Sema type (T) with the MIR
operand (Option[T]) and reported four std tails as disagreements
(cstr_option_from_ptr, Regex.capture_index, Regex.captures_at,
Captures.get). The conversion is Sema's own adjustment, like the splat
and lane-conversion records beside it: the recorded Sema type is the
demanded Option.
…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).
… store hands it a callable that may (#2511, section 14.3 INVARIANT 5)

A call through a callable parameter was a may-suspend site whatever flowed
into it, and MIR polled with_fiber_wait_cancelled after every such call
(4.5x on a fold). settle_callable_param_facts runs inside the suspend
fixpoint: every call Sema can attribute to a declared fn (direct, resolved
generic or std.traits adapter, pipeline stage) marks (fn, parameter) for
each callable argument that may suspend; every struct literal or field
assignment marks (owner, field) the same way. A parameter or field answers
that mark at a call site; a fn whose name escapes as a value, or any
unattributed call that passes a may-suspend callable, keeps the old answer
(may) for everything. Measured (-O3, 4M i64): fold through a fn parameter
8.4 ms -> 1.49 ms (the concrete-loop floor); std.traits map|filter|fold
52 ms -> 4.4 ms, within 5% of the retired intrinsics' 4.2 ms. 26 suspension
fixtures green.
@ehartford

Copy link
Copy Markdown
Contributor Author

Rebased to the top of the stack (above #2536 and #2537); gh stack appends only at the top, so this layer continues in a new PR.

@ehartford ehartford closed this Oct 21, 2026
@ehartford
ehartford removed this pull request from stack #2528 October 21, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant