Repository navigation
Facade: void * destroyers accept object pointers; destroys without drop is an error - #1279
Merged
Merged
Conversation
added 2 commits
September 22, 2026 08:40
…n (ruling §61 under C's conversion rule) A destroyer parameter of type void * (*mut c_void / *const c_void after c_import) accepts *mut T, *const T and typedef'd pointers chased through their aliases; never a function pointer (C does not convert one to void *) and never a by-value representation. Exact type otherwise. The rule is one helper, facade_void_ptr_accepts, read by facade_accepts_repr (drop, destroys, init, preinit) and by the in-place-shape check in verify_facade_destroyer, and destroyed_by now verifies the same rule for the callable's first parameter against the consumed parameter. The renderer casts the representation to a void-pointer destroyer's parameter spelling, since With converts *const T to *mut c_void only explicitly. Tests: behav_c_facade_void_destroyer (counting void*/const void* destroyers over *mut, *const and typedef'd reprs, plus a destroys), err_c_facade_void_destroyer_fn_pointer, err_c_facade_void_destroyer_by_value, err_c_facade_destroyed_by_wrong_param; err_c_facade_destroyer_wrong_repr still fails.
…never half-model unsafely) A value of such a resource dropped while live would leak silently, so Sema reports it at the resource (ruling, Eric 2026-09-22). When exactly one destroys operation is unary the diagnostic adds a help line naming it as 'drop <op>'; when several are, it lists them; when none is, it says every destroyer takes further arguments and a drop must be named or the representation modeled differently. The renderer emits nothing for a resource without a drop, as for one without a destruction contract. Must-consume linear resources are a future ruling and are not modeled. Tests: err_c_facade_destroys_without_drop (the help line), err_c_facade_destroys_without_drop_no_unary, and c_facade_destroys_with_drop (the drop-named form compiles).
Contributor
Author
|
Battery on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two modeled-C facade rulings (Eric, 2026-09-22), one commit each.
Ruling 1 —
void *destroyer accepts every object pointer representationRuling §61 "the destroyer accepts the representation" is C's own conversion rule: a destroyer parameter of type
void *(*mut c_void/*const c_voidafter c_import) accepts*mut T,*const Tand typedef'd pointers chased through their aliases; it does not accept a function-pointer representation (C does not convert one tovoid *) or a by-value representation. Exact type otherwise.facade_void_ptr_accepts(src/SemaFacade.w), read byfacade_accepts_repr(drop, destroys, init, preinit) and by the in-place-shape check inverify_facade_destroyer(avoid *destroyer is no longer mistaken forinflateEnd(z_stream *)).destroyed_bynow verifies the same rule: the callable's first parameter takes the consumed parameter. New diagnostic:fn 'db_register': destroyed_by param 2: extern "C" fn(i32) -> Unit destroy does not take the consumed param 1: *mut c_void app as its first parameter (§16.2b.9, §16.2b.13)self.repr as *mut c_void): With converts*const Tto*mut c_voidonly explicitly.resource 'Hook': 'release' does not take the representation as its first parameter (§16.2b.13).Tests:
behav_c_facade_void_destroyer.w(countingvoid*/const void*destroyers over*mut db,*const db,typedef db* dbp, plus adestroyswith avoid*first parameter — each object counts its destruction: exactly one),err_c_facade_void_destroyer_fn_pointer.w,err_c_facade_void_destroyer_by_value.w,err_c_facade_destroyed_by_wrong_param.w;err_c_facade_destroyer_wrong_repr.wstill fails as before.Ruling 2 —
destroysoperations with nodropis a compile errorA value dropped while live would leak silently (never half-model unsafely). Reported at the resource:
resource 'Database' has 'destroys' operations but no 'drop' — never half-model unsafely: a value dropped while live would leak silently (§16.2b.3)= help: name the unary destroyer as the drop operation: 'drop db_close'name one unary destroyer as the drop operation: 'drop a', 'drop b'resource 'Database' has 'destroys' operations but no 'drop'; every destroyer takes further arguments, so name a 'drop' operation or model the representation differently — never half-model unsafely: a value dropped while live would leak silently (§16.2b.3)The renderer emits nothing for a resource without
drop(Sema names it). Higher RAII / must-consume linear resources are not implemented (future ruling).Tests:
err_c_facade_destroys_without_drop.w(asserts the help line),err_c_facade_destroys_without_drop_no_unary.w,test/phase/c_facade_destroys_with_drop.w(the drop-named form compiles).Verification
with check src/main.wper commit;build :dev; onout/bootstrap/bin/with-stage1: allbehav_c_facade_*,err_c_facade_*,c_facade_*tests (49 files) green plus the guardserr_c_import_destroy_heuristic_no_owning_wrapper.wanderr_c_import_uncurated_ptr_return_raw.w.err_c_import_raw_call_requires_unsafe.wis red on stage1 only through #1273 (<stdlib.h>mistranslation,div_tby value); the installed compiler passes it and a spelled-prototype twin (void free(void*);free(null)) is rejected by stage1 with the expected error. Battery not run.