Skip to content

D103 at every demand site; D140 impl signatures from the trait; D141 None joins T into Option[T] - #2536

Merged
ehartford merged 6 commits into
listiter-viewfrom
d103-option
Oct 21, 2026
Merged

ehartford merged 6 commits into
listiter-viewfrom
d103-option

Conversation

@ehartford

@ehartford ehartford commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

D103 at every demand site, D140 and D141

Eric's review of mut fn next() -> Option[&T] in the new ListIter body asked why Some(&self.list[i]) had to be written. D103 already rules it ("a value converts to Option[T] at an Option demand"), so the missing sites are bugs, and two questions it raised became rulings (blessed 2026-10-21):

  • D103 sites. A function's tail and a collection literal's elements now convert at the demand like a binding, an assignment, an argument, a field and a return did. A D103-converted return keeps the node's own type (an ICE on return x as Kind and on ++ at the return). tools/sweep_some_at_option_demand.w is the compiler-driven sweep: it asks --ceremony-census for the some-at-option-demand spans and removes exactly those (a regex sweep had changed Some(i) => patterns and would silently change Some(None) under Option[Option[T]]). The sites the pinned seed cannot yet compile without Some( (tails and returns in src/) keep it until the next seed.
  • D140 (§11.1). A method in an impl of a trait may omit its parameter and return types; they are the trait's declaration, instantiated for the impl. If written, they must match it. trait_impl_param_type in SemaDecl.w maps by name, else by position among the non-receiver parameters.
  • D141 (§9.1). Where a return type is inferred, branches of type T and None join to Option[T]. A branch already of type Option[T] beside None does not join (Option[Option[T]] would be a second meaning) and the type must be written. The conversion never solves a type variable.
  • audit:resolution records a D103-converted operand with the Option Sema demanded, the way it records a splat or lane conversion; the operand audit had read the node's own type and reported four std tails.

Spec words: §4.9a (sites, D141 pointer), §9.1 (D141), §11.1 (D140); decision records D140, D141 in docs/meetings/.

Fixtures: behav_d103_site_{tail,return,arm,binding,assign,arg,field,element,if_tail,return_cast}.w, behav_d140_impl_signature_from_trait.w, err_d140_written_type_must_match_trait.w, behav_d141_inferred_return_none_join.w, err_d141_none_beside_option_is_written.w.

Filed on the way: #2520 (trait-name collision), #2524 (?? on a view of Option), #2525 (a regex literal starting with =), #2531 (generic trait impl with an omitted return has no demand), #2532 (D93 chaining of [] by use).

Eric Hartford added 6 commits October 21, 2026 00:19
…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.
…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.
@ehartford ehartford mentioned this pull request Oct 21, 2026
@ehartford
ehartford added this pull request to stack #2539 October 21, 2026 17:20
@ehartford ehartford changed the title d103 option D103 at every demand site; D140 impl signatures from the trait; D141 None joins T into Option[T] Oct 21, 2026
@ehartford
ehartford marked this pull request as ready for review October 21, 2026 20:53
@ehartford
ehartford merged commit e5d6608 into main Oct 21, 2026
@ehartford
ehartford deleted the d103-option branch October 21, 2026 20:53
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