Skip to content

D187 (#2965): returns borrow T from params N, M — a view of two origins - #3023

Merged
ehartford merged 1 commit into
mainfrom
d187-returns-borrow-params
Nov 3, 2026
Merged

ehartford merged 1 commit into
mainfrom
d187-returns-borrow-params

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Closes #2965. Closes #3019.

returns borrow T from params N, M (D187, §16.2b.6): a facade operation whose returned pointer is a part of either of two parameters states both, and the view is invalidated when either origin is.

  • Parser: from params <ref>, <ref> (a fifth clause operand).
  • Sema: returns_borrow_from2 beside the first origin, resolved and checked for its receipt the same way (a resource, a record view, a C string) and verified with the first once every resource is known. The rendered method's result is declared a view of both: the second "through what the view views" (D85's form), so a local view argument never pins the result to its binding. A presented call's text borrows from both. Contract rows say "and <param>, invalidated when either is".
  • Renderer: a *mut T parameter whose pointee is a record view presents as &T, passing the record's address, as a view's self crosses (Sema already counted it as receiving a record view; the renderer kept it raw).
  • Migrator: the proof unions two borrow sources on different paths ("borrow:N,M": locals, returns, callees through the argument map), carries borrow_from2, renders the clause, requires both origins modeled; a borrow of what the function also frees or retains is reported raw ("… but it frees param N, which a borrowed return cannot state"), where main counted it as presented without presenting it; the proof text no longer repeats an origin per return.

Two defects met on the way, fixed at their lines:

  • record_call_view_origins_args read "the shared dependency list did not grow" as "this argument has no origin": two arguments viewing one document pinned the result to the second argument's local.
  • D22: a record view of a Copy record loses its origin at an unannotated let through ? #3019: D144's "a binding of plain bits takes the value" copied a facade record view out of its document; a record a facade hands out as a view keeps the binding a view (type_carries_view).

The ruling's first fixture, libxml2's xmlAddChild, is not a two-origin borrow by the proof: it stores cur into the parent and frees it on the text-merge path, and its callee xmlInsertNode returns three sources. Under D51 the migrator keeps it raw; its honest clause would be a consume of param 1 by param 0 plus a borrow from param 0. With the real libxml2 the drafted facade is byte-identical to main's (no function qualifies yet: xmlTextMerge frees one node, the xmlAutomataNew* borrows are of unmodeled records), and the UAT program builds against it. Surfacing this rather than editing the UAT.

Fixtures: behav_d187_borrow_from_two_params (a pick of two nodes; fn either(a, b) -> Option[&tnode] from a, b; two nodes of one document), err_d187_two_origin_view_outlives_one (from a alone refused: "returns a view derived from b, which its from clause does not name"), behav_3019_record_view_of_plain_bits_stays_a_view. Conformance row D187 → implemented.

Corners filed as issues at Eric's request: #3022 (origin list, not a second scalar), #3020 (record views: declare every origin "through", self included), #3021 (§14.10 example vs recv: Option[T]).

Iterate tier: the new fixtures failed on the installed compiler (parser refusal); on the stage1 they pass; 437 view/origin/facade behavior and compile-error fixtures pass; ceremony census diff ok. Gate, :c-migrator-basic-tests --no-deps, :drop-audit reported below. Draft until the battery is green.

A facade operation whose returned pointer is a part of either of two
parameters states both: the parser admits `from params <ref>, <ref>`
(a fifth clause operand); Sema binds `returns_borrow_from2` beside the
first origin (resolved and checked for its receipt the same way: a
resource, a record view or a C string), verifies it with the first once
every resource is known, and declares the rendered method's result a
view of both — the second as "through what the view views" (D85's
form), so a local view argument never pins the result to its binding;
a presented call's text borrows from both; the contract rows say "and
<param>, invalidated when either is". The migrator's proof unions two
borrow sources on different paths ("borrow:N,M": locals, returns and
callees through the argument map), carries `borrow_from2`, renders the
clause, and requires both origins modeled; a borrow of what the
function also frees or retains is reported raw, never as a borrow
(libxml2's xmlTextMerge), and the proof text no longer repeats an
origin per return.

Two defects met on the way, fixed at their lines:
- record_call_view_origins_args read "the shared dependency list did
  not grow" as "this argument has no origin": two arguments viewing
  one document pinned the result to the second argument's local.
- #3019: D144's "a binding of plain bits takes the value" copied a
  facade record view out of its document; a record a facade hands out
  as a view keeps the binding a view (type_carries_view).
The renderer presents a `*mut T` parameter whose pointee is a record
view as `&T`, passing the record's address, as a view's self crosses.

The ruling's first fixture, libxml2's xmlAddChild, is not a two-origin
borrow by the proof (it stores cur into the parent and frees it on the
text-merge path; its callee xmlInsertNode returns three sources): it
stays raw. Fixtures: behav_d187_borrow_from_two_params (a pick of two
nodes, `from a, b`, two nodes of one document), err_d187 (`from a`
alone refused), behav_3019. Conformance row D187 → implemented.
@ehartford

Copy link
Copy Markdown
Contributor Author

Gate green on 67a583e (422 s, seed-driven); :c-migrator-basic-tests green (in the gate); :drop-audit green. Battery running.

@ehartford
ehartford marked this pull request as ready for review November 3, 2026 16:28
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery green on 67a583e (seed-driven gate, uat, battery-checks; out/battery/battery.log rc=0 green).

@ehartford
ehartford merged commit 1d555df into main Nov 3, 2026
@ehartford
ehartford deleted the d187-returns-borrow-params branch November 3, 2026 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant