Repository navigation
Description
Restated (2026-10-25 triage)
The per-constructor owns:/borrows: annotations this issue was built on are superseded by D51's facade language (resources with drop F, retains, convention profiles; §16.2b) and D121 (facades drafted from evidence). What remains is still real: CoreFoundation's reference-counted type family — every +1 object from any Create/Copy function must reach CFRelease, and CFRetain adds a reference across many concrete types. D51 names the mechanism ("A trusted convention profile may make that interpretation for an API family", ruling §39/§59; spec §16.2b.12): a CoreFoundation convention profile. None exists: no profile, facade or registry fact in src/, lib/ or build/ names CFRetain or CFRelease; CoreFoundation appears only in the link-flag tests (link_framework_args_test.w, the :no-host-toolchain stub).
Measured against §16.2b.12 (convention profiles) and §16.2b.15 (facade provenance).
Original report
Summary
The unsafe half of this work is complete: C resource names never cause
automatic cleanup, and generated cleanup is expressed through proven-ownership
wrappers with Drop. The annotation and curated-ownership paths have also
shipped. The one remaining increment is reference-counted type-family
modeling.
Current state (revalidated 2026-07-15)
Completed:
- 1373e45 removed heuristic scope-local auto-defer.
- ed5f0b3 added regressions proving a create/destroy name pair neither creates
an owning wrapper nor runs cleanup at scope exit. - Curated owning wrappers, safe borrowing wrappers, and explicit
owns:/borrows: import annotations are implemented and tested. - Cleanup is Drop on the owning wrapper; raw C functions remain available and
no MirLower defer is synthesized. - 16a25bc added link: "framework:CoreFoundation", so the intended
CoreFoundation pilot is now testable end to end.
The remaining gap is broader than per-constructor owns: metadata.
CoreFoundation release functions apply to a type family: CFRetain accepts a
CFTypeRef from many concrete constructors and every +1 reference must later
call CFRelease. The current per-constructor wrapper tables do not model that
shared family contract.
There is also a traceability mismatch: docs/requirements.md marks
16.2.2.23 complete even though family-level retain/release modeling is still
open. That checkbox must either be re-scoped explicitly to the shipped
per-constructor path or reopened until this issue lands.
Remaining implementation
- Add a curated ownership-family table mapping compatible C reference types to
their release operation. - Generate one shared owning reference wrapper per family (for example a
CRef-style CoreFoundation wrapper), rather than one incompatible wrapper per
constructor. - Make +1 constructors, copy/create functions, and CFRetain produce an owned
wrapper whose Drop invokes the family release function exactly once. - Keep borrowing accessors non-owning; they must not acquire Drop merely
because their C type belongs to the family. - Preserve the raw surface and the rule that names alone never establish
ownership.
Acceptance criteria
- A real CoreFoundation constructor returns an owned family wrapper and drops
through CFRelease exactly once. - CFRetain creates an independently owned +1 reference; moving or dropping
either wrapper cannot double-release the other. - A borrowing accessor produces no-Drop access.
- Name-only retain/release candidates still produce no owning wrapper.
- The requirements entry for 16.2.2.23 accurately describes the implemented
scope. - Full build, fixpoint, and test gates pass.
Traceability
- Specification §16.2a, Proven ownership cleanup
- docs/requirements.md 16.2.2.11 through 16.2.2.27
Activity
ehartford commentedon Jun 9, 2026
Partial implementation landed in 1373e45. The unsafe name-heuristic auto-defer path is removed, and docs/completed/c-import-auto-methods.md now treats destructor-name matches as suggestions only. This closes the unsound cleanup behavior, but the proven-ownership generated Drop wrapper surface is not implemented yet, so this issue should stay open for that remaining positive feature work. Verification for the landed safety slice: with build, with build :fixpoint, with build :test, and with build :test-green.
Add c_import destroy-heuristic regression tests (toward #357)
ehartford commentedon Jun 17, 2026
Added regression tests pinning the removal half (commit ed5f0b3):
test/compile_errors/err_c_import_destroy_heuristic_no_owning_wrapper.w— awidget_create/widget_destroypair imports with a raw surface; the constructor call requiresunsafe(no auto-generated safe owning constructor from the*_destroyname heuristic).test/behavior/behav_c_import_destroy_heuristic_no_auto_defer.w— a created handle leaving scope does not auto-callwidget_destroy(observed via caller-owned storage); explicit cleanup still works.This closes the "no regression tests pinning the removal" gap noted in the issue body.
Still open (the positive path): ownership-evidence surface (explicit annotation; author/imported metadata; proving header analysis; curated convention) generating owning
Dropwrapper types, plus refcount-aware modeling (+1 constructor vs borrowing accessor). That is a substantial new subsystem and remains the bulk of this issue.Replace blanket const char* modeling with curated overlay evidence (#379
#357: generate proven-ownership owning wrappers for curated c_import …
Update Phase 8 docs: drop/move cluster + #357 first increment shipped
ehartford commentedon Jul 2, 2026
Progress: three of the four planned increments are shipped.
4a77a123): a curated function that borrows an owned C resource gets a safe wrapper taking&COwned_<ctor>, forwarding.handle()internally — pilot: readdir/rewinddir over opendir's DIR. Owned handles now cross back into C with zero raw-pointer exposure.f2b13386):c_import(..., owns: ["ctor -> dtor"], borrows: ["fn(pi) -> ctor"])— the §16.3c explicit-annotation source. Outranks the curated tables, participates in the translation cache key. Fixtures annotate un-curated libc pairs (getcwd→free, telldir(0)→opendir).Remaining: refcount modeling. Blocked on a real test vehicle: CoreFoundation needs
-frameworklinking (verified: CF symbols don't link from c_import today) and GLib isn't on the host. The +1-constructor half is already expressible viaowns:(e.g.CFStringCreateWithCString -> CFRelease); what's genuinely new is retain functions over type FAMILIES (CFRetain takes any CFTypeRef — per-constructor tables don't fit). Design sketch: a curated family table (family → release fn) with a sharedCRef_<family>wrapper type; retain returns a second owned reference. Deferred until framework/library linking gives it a testable pilot.ehartford commentedon Jul 3, 2026
Framework-linking prerequisite shipped (
16a25bc0):c_import(..., link: "framework:CoreFoundation")now emits-framework CoreFoundation(Link.wlink_stage_lib_args; loud error on non-macOS; plain libs unchanged). Verified end-to-end — a modeled c_import callingCFStringGetTypeID()links and runs. This unblocks the CoreFoundation refcount-modeling pilot: CFRetain/CFRelease/CFStringCreate* now LINK (previously the CF symbols didn't resolve at all).Remaining #357 work (refcount modeling, the last increment): with CF now linkable, the pilot can proceed. Current raw-path state: CFRetain/CFRelease are RAW (require unsafe) because CFTypeRef isn't modeled. The design (from earlier scoping): a curated type-FAMILY table (any CFTypeRef → CFRelease) with a shared
CRef_<family>owning wrapper where +1 constructors (CFStringCreate*, CFRetain) return an owned ref whose Drop calls CFRelease, and borrowing accessors (CFGetRetainCount etc.) don't. This differs from the per-constructor Box/Rc wrappers already shipped because the release fn is shared across a whole type family. Greenfield; its own cycle.c_import: curated borrow-params — owned handles cross back into C saf…
c_import: owns:/borrows: annotation evidence surface (#357)
docs: sync implementation plan checkboxes with shipped #348/#357/#604/#…
Link: support link: "framework:Name" for Apple frameworks (#357 prereq)
Modeled C stage 4c: the toolchain libc facade replaces Mechanism A; o…
Modeled C stage 4c: toolchain libc facade replaces Mechanism A; owns:…
[-]Replace heuristic c_import auto-defer with proven-ownership Drop wrappers[/-][+]CoreFoundation's reference-counted type family: model it as a D51 convention profile[/+]ehartford commentedon Oct 25, 2026
Triage 2026-10-25,
with v0.15.3.0(main a261b65): still open. No convention profile, facade clause or registry fact models CoreFoundation's retain/release family:post-release: a modeled-C campaign item (a profile for an API family, D51 §59), and nothing in the standard library or the release UATs imports CoreFoundation objects.
test/contract: check in ok_357_corefoundation_profile.expected snapsh…
Wave 2b: CCodegen place-walk unification (#651), hermetic offline wit…