Repository navigation
Sema: a callable parameter or field suspends only when some caller hands it a callable that may (#2511) - #2538
Merged
Merged
Conversation
… 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.
added 2 commits
October 21, 2026 16:33
…end walk it exposed
The battery's ten reds all came from the std adapters standing where the
list-iterator intrinsics stood. Each is a gap the intrinsic had covered, or
a compiler hole it had hidden:
- A closure whose body calls a named function took that callee's return
type over the expected `-> Unit` (the partial-application guess outranked
the demand), so `for_each(n => sink(n))` and a generic `fn(&T) -> Unit`
callback refused a closure returning a value; the demand now wins
(behav_closure_call_body_under_unit_callback).
- `collect[HashMap]`, `collect[BTreeMap]` and `collect[String]` over an
Iter[T] implementor: std builders (iter_collect_hashmap/btreemap/string
with `_views` twins), the element shape judged at the call with the
diagnostics the fixtures expect; the method spelling
`it.collect[List[i32]]()` dispatches to std as the pipeline one does.
- `peekable` on an Iter implementor says "not implemented yet" (§13.3), as
it does on the built-in iterators.
- A closure holding `self` by place passed to `iter_map`: the callee stores
it only in its ephemeral result (a Mapped over a view of this frame),
which cannot outlive the captures, so it is not an escape; a callee that
writes a global still is.
- `in` reads a view of a Copy value through every layer (D139), in Sema
and in the array-literal lowering.
- `flat_map` over a function that builds a collection (`s.split(" ")`):
iter_flat_map_into over IntoIter; both flat-map adapters hold the
iterator being drained with explicit ownership (an Option payload
matched out of a field is a copy, #2541) and live in std.collections.
- `enumerate() |> collect[List]()` and `unzip` over views store values:
iter_collect_pair_views, iter_unzip_views; min_by/max_by over views take
the comparator by value (D111).
- `filter`, `take_while`, `drop_while`, `any`, `all`, `none`, `find`,
`position` over an iterator of views hand the predicate the view itself
(`_views` twins), never a view of the view.
- A `T` at an `Option[T]` demand converts when `T` is itself an Option
(`ListIntoIter[Option[i32]].next`); a bare `None` never wraps (D141).
- audit:resolution records a D103-converted operand with the Option Sema
demanded.
The #2019 cancellation fixture then found the suspend walk itself:
- a callable held in a field answers from the stores for the body's own
fact (a parameter's caller-answers rule has no caller for a field);
- a generic fn or method resolved by its own symbol (`i.next()` on an
`I: Iter[T]` receiver) maps to its template declaration for the fact;
- the walk reads a `return`'s value from d0 (it read d1, NK_UNARY's slot,
so nothing under `return` was walked), and enters `loop:` and `do-while`
(da_loop_field_callable_cancel: main resumes a cancelled caller past
`return (self.f)(x)`).
`x in list` is `list.contains(x)`, whose parameter observes the key: a view is already the argument it takes. The D139 read-through added for `*x in [2, 4]` (an array literal compares values) also applied there and handed the call a value where it expected a reference (an ICE in MIR, behav_2009_membership_view_operand). The read is now limited to the array-literal, range and str lowerings.
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.
#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_factsruns 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.traitsmap|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.The ListIter layer's parity with the retired intrinsics (second commit)
The first battery on this stack went red on ten fixtures, every one a place where the std adapters now stand where the list-iterator intrinsics stood. The commit closes each gap and the compiler holes the intrinsics had hidden:
-> Unit(the partial-application guess outranked the demand);for_each(n => sink(n))and a user genericfn(&T) -> Unitcallback refused it on main too;collect[HashMap|BTreeMap|String]over an Iter[T] implementor, the method spellingit.collect[List[i32]](),peekable's §13.3 wording,inover a view (D139),flat_mapover a built collection (IntoIter),enumerate+collectandunzipover views, by-value comparators formin_by/max_byover views, and_viewstwins for every predicate adapter so the predicate sees&T, never&&T;selfby place passed to an adapter that stores it only in its ephemeral result is not an escape;Tat anOption[T]demand converts whenTis itself an Option (a generic body's instance);return's value is read from d0 (nothing underreturnwas walked, on main too), andloop:/do-whileare entered. Fixtureda_loop_field_callable_cancel.wresumes a cancelled caller on main.Filed: #2541 (an Option payload matched out of a field binds a copy; a mutation on it is lost).