Skip to content

D34-A: demand-site finalization — a Builder satisfies an owned demand for its built type; grander wrapper-elimination design goes to Eric #920

Done

Description

@ehartford

Ruling: docs/decisions.md D34 ('A should apply to all Builder patterns (or maybe something grander, maybe any form of wrapper like an Option or a Promise)').

Phase 1 (ruled, implementable now): builder finalization

At an owned-demand site — return position against a declared type, typed binding, argument to a typed param — a value whose type declares a canonical finalization to the demanded type satisfies the demand implicitly: a StringBuilder tail satisfies -> str without .to_str(). Mechanism sketch: a trait (working name Build[T]/Realize[T]: move fn realize() -> T) consulted by the demand-adjustment path D22 already runs (contextual materialization is precedent — this extends 'an annotation demands what it says' from views to finalizable wrappers). Finalization CONSUMES the wrapper; the transfer-is-explicit tension is accepted per the ruling — consuming a builder at a demand site is the builder's purpose.

Note the D34-C interaction: once ++ is efficient (#919) the StringBuilder case mostly evaporates; phase 1 still matters for every OTHER builder-pattern type (config builders, the derive(Builder) machinery, request builders).

Phase 2 (design brief REQUIRED before any implementation): the grander scope

Eric's 'any form of wrapper — Option or a Promise' generalizes to demand-driven ELIMINATION:

Each arm changes where programs can panic/suspend without a token in the source. The brief must lay out per-wrapper semantics, reference comparisons (Rust rejects all of these; Swift's implicit-unwrap optionals are widely considered a mistake; Kotlin/Scala implicit conversions cautionary tales), and a committed recommendation. No implementation past phase 1 until Eric blesses the specific arms.

Spec impact: normative wording for the demand-site rule (Eric's words only, per doctrine).

Activity

  1. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): still reproduces. A builder in a position that demands its built type is refused, and the error points at the binding rather than the return:

    use std.string.StringBuilder
    fn make() -> str:
        var b = StringBuilder.new()
        b.push_str("hi")
        b
    
    error: return type mismatch
     --> main.w:3:5
    3 |     var b = StringBuilder.new()
    

    post-release: phase 1 is a new demand-site rule in Sema; until it lands the user writes the finalizing call. (Its relation to D111's builder sentence is asked on #919.)

  2. added this to the post-v0.16.0 milestone on Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions