Skip to content

Facade: returns borrow T from parent T of param N (D85, #2003) - #2027

Merged
ehartford merged 2 commits into
fix-2024from
impl-2003
Oct 3, 2026
Merged

ehartford merged 2 commits into
fix-2024from
impl-2003

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Implements D85 (spec §16.2b.6, #2003): returns borrow T from parent T of param N.

Design

  • Parse (Parser.w): from parent <Resource> of param <ref>; the RETURNS_BORROW clause carries a 4th op, the parent symbol (0 for the existing forms).
  • Verify (SemaFacade.w verify_facade_parent_borrow): the parent is resolved through the argument resource's declared borrows clauses. Errors: the resource declares no borrows parent; it declares none of the named type; the borrowed type is not the parent's type; a producer of the argument's resource does not state exactly one parent of that type (no parent field to read on every value). The C return must be the parent's representation. A parent borrow and a from param borrow of the same resource are not mixed (one Borrowed<R>, one origin rule).
  • Render (FacadeRender.w): Borrowed<R> holds origin: &R and the presented method fills it from the argument's parent field (self.parent). Dependency derivation is now one function (facade_render_item_deps) read by both the resource's type and the parent field.
  • Accept (Sema): the presented method's declared summary views through the argument (facade_declare_view_through_param, kept across the body check), so the borrow's origin is the parent's origin, not the statement: st.step() no longer poisons it, and it may outlive the statement but not the connection. Operations through it are operations on the parent's origin: a call whose touched argument is a parent borrow also poisons the views of what it views (facade_apply_call_touches). A parent borrow is not itself poisoned by calls on the parent (it is the parent, living as long as its origin). The fact is the stated clause (facade_type_is_parent_borrow reads the contract), never the type's shape.
  • Contract view / audit (AnalysisContract.w): the resource's view row and the fn's returns row name the parent and the param it is read through; the audit fails when a parent-borrow item's presented method does not view through that param (the fact acceptance reads).

lib/facades/sqlite3.w is unchanged: it has no sqlite3_db_handle item, no program needs one, and adding it would edit the byte-identical copy in examples/c-interop (an example is Eric's contract). The clause is exercised by fixtures.

Tests (each failed on the base stage1 first)

  • test/behavior/behav_c_facade_parent_borrow.w (runs over inline C): b.changes() after st.step(); the borrow returned past the statement's scope.
  • test/contract/ok_parent_borrow.w + .expected (sqlite-shaped, sqlite3_db_handle).
  • test/compile_errors/err_c_facade_parent_borrow_{undeclared,wrong_parent,type_mismatch,producer_without_parent,mixed_forms}.w — the refusals.
  • test/compile_errors/err_c_facade_parent_borrow_statement_view_dies.w — a column_text view of the statement still dies across step.
  • test/compile_errors/err_c_facade_parent_borrow_invalidates_parent_views.w — b.changes() invalidates an errmsg view of db.
  • test/compile_errors/err_c_facade_parent_borrow_outlives_parent.w — the borrow cannot outlive the connection.
  • err_1977_borrowed_resource_after_step.w (the from param form) still refused.

Verification

@ehartford
ehartford changed the base branch from main to fix-2024 October 3, 2026 11:27
@ehartford
ehartford added this pull request to stack #2032 October 3, 2026 11:27
@ehartford
ehartford marked this pull request as ready for review October 3, 2026 15:13
@ehartford
ehartford merged commit 657c819 into main Oct 3, 2026
@ehartford
ehartford deleted the impl-2003 branch October 3, 2026 15:13
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