Skip to content

cimport: exempt stores of a resource pointer into its own exclusively owned sub-record (#3124) - #3648

Merged
ehartford merged 1 commit into
mainfrom
own-state-store-proof
Nov 27, 2026
Merged

ehartford merged 1 commit into
mainfrom
own-state-store-proof

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Implements Eric's ruling on #3124 (2026-11-25, D235): a store of a resource's pointer is not retention when all four conditions hold:

  1. Target reachability: the store's target is a field of a record reachable only through a field R.F of the resource's own record (directly via r->F->owner = r, via a local loaded from r->F, or via a helper g(dst, src) that stores src only into dst, transitively).
  2. Destruction: every public unary destroyer of R destroys r->F (directly, through helpers, or through a slot destroyer such as Curl_close(&data)).
  3. No escape: every unit of the package was read, and no function returns R.F (or a pointer into it, including conditional expressions e ? e->F : NULL), passes R.F (or a pointer into it) to a retaining callee, takes &r->F outside a proven slot destroyer / fresh out-param, or stores R.F anywhere else.
  4. Exclusivity: every non-null write to R.F assigns only a fresh allocation or restores its own previously loaded value, never copies from another resource or parameter, and destroys the old record on any non-constructor overwrite.

Report-only verification across 23 libraries (#3115 list)

Ran report-only across all 23 buildable libraries before enabling verdicts (6,170 functions, 2,500+ record-pointer fields; summary posted on #3124):

  • 17 fields passed all 4 strict conditions (libxml2: 7, libcurl: 5, raylib: 5), 0 false positives.
  • Shared/escaping fields (expat's XML_ParserStruct.m_dtd, libcurl's Curl_easy.multi_easy, libevent's evhttp_connection.bufev, libxml2's _xmlTextReader.*) were all rejected cleanly.
  • 0 existing library verdicts flipped.

Changes

  • src/CImport.with: record rfset, rfload, rfsink, rfaddr, rfsubsink, rfescape, rfcall, paramstoreinto, and localstoreinto ownership evidence (including conditional-op escape traversal).
  • src/CiIR.with: store owned_subrecord_fields on CiProject.
  • src/CiFacadeDraft.with: prove exclusively owned sub-record fields under all 4 conditions (fd_prove_owned_fields_3124) and re-run retention/returns exempting proven self-owned stores.
  • test/internals/conan_facade_self_owned_store_test.with: positive coverage (self-registering constructor, direct/local/1-hop/2-hop helper stores, overwrite-with-free, destroyer self-store) and negative coverage (cross-handle store, cross-handle helper, mixed helper calls, Condition 2 no-free, Condition 3 return & global escape, Condition 4 shared & unfreed overwrite).

Closes #3124.

@ehartford

Copy link
Copy Markdown
Contributor Author

Battery & :release-checks verdict on d56727608:

  • with run tools/battery.with: GREEN (rc=0, wall=1285s; verified via with run tools/verdict.with out/battery/battery.log)
  • src/main build :release-checks: GREEN (wall=901.2s, stage2 == stage3 over all 16 units of the compiler, EMIT-C OK, EMIT-C FIXPOINT)

@ehartford
ehartford marked this pull request as ready for review November 27, 2026 07:57
@ehartford
ehartford merged commit f169c2a into main Nov 27, 2026
1 check passed
@ehartford
ehartford deleted the own-state-store-proof branch November 27, 2026 07:57
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