Skip to content

One C function, two constructors: a producer's second presentation is a producer, and a parentless value of a parented type is free (D214, part of #3122) - #3589

Merged
ehartford merged 3 commits into
mainfrom
d214-two-items
Nov 24, 2026
Merged

ehartford merged 3 commits into
mainfrom
d214-two-items

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Part of #3122, which stays open for the version floor, the rename with wording and the blessing of the §16.2b.11 words.

Now writable (the rest of D214's ruling):

fn mime_init
    of Mime
    rename from_easy
fn mime_init
    rename new
    param 0 fixed null    // a null parent makes an independent mime
…
let tied = Mime.from_easy(e).unwrap()    // cannot outlive e
fn solo() -> Mime: Mime.new().unwrap()   // borrows from nothing

Two changes.

  1. Facade. Two presentations of one function already existed (ruling Amendment 3: each later item gets its own declaration linked to the same C symbol). A producer's second presentation was treated as an operation on the parent. The resource that names the function in from now gets the same clause for the presentation's declaration, so every rule that reads a resource's producers reads both.

  2. Checker. With one parented constructor the type is ephemeral { parent: Option[&Easy], … }, and Mime.new().unwrap() was refused as "a view into a temporary Option[Mime]". The rule at fault treated the result of any builtin method as a view of its receiver when the result had no origins of its own. unwrap consumes its receiver (the compiler's own receiver-mode table says so) and hands back a value: it carries what the carrier carried and views nothing of the carrier, which is gone. That is now what is recorded, for a by-value receiver and a by-value result of a consuming builtin only; a reference result, a borrowed receiver, and a non-consuming method keep the old rule.

Tests.

  • behav_d214_both_constructors: both constructors; the parentless value returned from a function.
  • err_d214_parented_value_outlives_parent: the parented value still cannot outlive its parent.
  • The 148 existing tests about views into temporaries and ephemeral values pass.

Evidence at beea3c8. :native-compile-error-tests, :behavior-tests, :validate-all-tests, pre-checks green; battery green; linux-aarch64 container leg green (:build, :behavior-tests, :native-compile-error-tests); :release-checks survey: all targets green.

Eric Hartford added 3 commits November 24, 2026 05:51
…rce (D214, #3122) — the checker still refuses the parentless value of a type that also has a parented constructor
…ed: Option[Mime].unwrap() of a parentless value is no view of the temporary (D214, part of #3122)
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