Skip to content

facade: conform to D134, per-call borrow origins, detaches param N, text utf8 - #2422

Merged
ehartford merged 4 commits into
mainfrom
d134-impl
Oct 15, 2026
Merged

ehartford merged 4 commits into
mainfrom
d134-impl

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Conformance to D134 (spec v7.34, #2421), three commits:

  • Borrowed<R> renders as BorrowedR[Origin], the origin bound at each call; the borrowed view's impl carries the borrow-returning lends (a borrow through a borrow views that borrow, D122); Sema no longer refuses two items borrowing R from different resources. User code naming the type spells its origin (BorrowedDatabase[Statement]); the old one-origin error pin is removed.
  • text utf8 at the facade level: text returns present as Option[str], validated at the boundary with CStr.to_str; a violation panics naming the C function and the byte; text return bytes keeps an item at bytes.
  • detaches param N: a move method of the borrowed view yielding DetachedR[Origin], owned (Drop runs the resource's drop), carrying the lends, holding a view of its origin.
  • with migrate --facade now drafts every proven borrow; the selfhost program uses the presented names.

Tests: behav_c_facade_borrow_per_value_origin, behav_c_facade_detaches, behav_d134_text_utf8, behav_d134_text_utf8_violation_panics; every facade behavior and compile-error test green under stage1 except pending_producer_warns, which asserts no warnings and fails only under stage1's two std warnings. Gate green; :c-migrator-basic-tests green with the release binary (the #2420 gate log never ran that target). Battery: pending.

Eric Hartford added 4 commits October 15, 2026 09:01
…owed<R>` renders as `BorrowedR[Origin] ephemeral { origin: &Origin, repr }`, the origin type bound at each call by what the constructing method hands it (self, a parameter, a parent view), so a Node borrowed from a Doc and one from an owned Node are one type; a borrow-returning lend's result type is inferred from its tail so the one text serves the resource's impl and its view's, and the view's impl now carries those lends (a borrow through a borrow views that borrow, D122). Sema no longer refuses two items borrowing R from different resources. User code naming the type spells its origin (`BorrowedDatabase[Statement]`). Test behav_c_facade_borrow_per_value_origin over c_facade_tree.h: root from the document, child from an owned node.
…ll, so the draft states every proven borrow of a representation whatever its origins; the "several origin types" withholding and its report lines go. The selfhost program calls the presented names (Doc.open, Node.new, n.attr, d.root, d.count).
…. A facade declares `text utf8` once and every `text return, owned, freed by F` presents as Option[str]: the bytes are validated at the boundary (CStr.to_str) and copied, F runs on the pointer, and a return that is not UTF-8 panics naming the C function and the byte, nothing repaired; `text return bytes` keeps an item at Option[List[u8]]. `detaches param N` renders as a move method of the borrowed view yielding `DetachedR[Origin]`: owned (its Drop runs the resource's drop operation), carrying the resource's lends, and holding a view of the origin it was taken out of, so it is destroyed before the origin and cannot escape it; the call goes through the view and invalidates the origin's views by the default. Sema accepts both clauses (a detached parameter is a pointer one resource receives). The pin of the old one-origin rule (err_c_facade_borrowed_return_two_origins) goes; two expectation lines follow the new item list and the generic borrowed type. Tests: behav_d134_text_utf8, behav_d134_text_utf8_violation_panics, behav_c_facade_detaches (nd_unlink in c_facade_tree.h).
…acts for them — the call effect that invalidates the origin's views, the view-of-param summary of a borrow taken through the view — are kept by the method's effective name and replayed on each instantiation (facade_note_generic / facade_replay_generic, hooked in check_generic_method_body_concrete); a generic method has no signature until a call instantiates it, and every lookup by `BorrowedR.m` found nothing, so an operation through a view touched nothing (err_c_facade_parent_borrow_invalidates_parent_views stopped failing). Two more generic-instance facts: `BorrowedR[Origin]` names its origin as a type argument and holds a view, not the resource (facade_type_holds_resource); a borrow taken through a view views the view's origin, never the view (a view of a view nested the origin type once per call and instantiation never ended). The renderer spells the origin type on every borrow-returning lend so Sema reads the declared result, and publicizes methods of a generic impl. WITH_DEBUG_FACADE_POISON=1 prints what each modeled-C call could invalidate and which guard kept a binding; both new flags are in deep-debugging-tools.md. The tree fixtures state `preserves param 0` on their reads, as §16.2b.7 asks.
@ehartford

Copy link
Copy Markdown
Contributor Author

Fourth commit, 43ff354: the first battery was red on two invalidation pins (err_1977_borrowed_resource_after_step, err_c_facade_parent_borrow_invalidates_parent_views). Root cause: a borrowed view's methods are now methods of a generic impl, which have no signature until instantiation, so every facade lookup by BorrowedR.m found nothing and an operation through a view touched nothing. Fix: the facts are kept by the method's effective name and replayed on each instantiation (facade_note_generic / facade_replay_generic, hooked in check_generic_method_body_concrete). Also: a borrow through a view views the view's origin, never the view (a view of a view nested the origin type per call and instantiation never ended); BorrowedR[Origin] holds a view, not the resource its type argument names; generic impl methods are publicized. WITH_DEBUG_FACADE_POISON=1 found it and is documented. Gate green on 43ff354; battery running.

@ehartford

Copy link
Copy Markdown
Contributor Author

Battery on 43ff354 under the pinned seed: GREEN, wall 288 s (with run tools/battery.w in the branch worktree).

@ehartford
ehartford marked this pull request as ready for review October 15, 2026 19:43
@ehartford
ehartford merged commit 068b1ec into main Oct 15, 2026
@ehartford
ehartford deleted the d134-impl branch October 15, 2026 19:43
ehartford added a commit that referenced this pull request Oct 15, 2026
…ded go (D111: a str is a value, a push copies it; a consuming List parameter never needs a call-site `move`). Main's ceremony census was red after #2361 merged under #2422: clone-call in src 537 -> 543, move-arg 847 -> 854; this brings both under the bar. (#2423)

Co-authored-by: Eric Hartford <[email protected]>
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