Skip to content

Consuming same-type pointer producer with null status returns Result[R, E] carrying R in good state (D241) - #3641

Merged
ehartford merged 1 commit into
mainfrom
consumes-same-producer
Nov 26, 2026
Merged

ehartford merged 1 commit into
mainfrom
consumes-same-producer

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Implements #3121 (D241, delegated under D237/D98 from D235's ruling; spec v7.97).

  • Parser & AST (src/Ast.with, src/Parser.with): added null status <status_value> fn clause (FacadeStatusClause.NullStatus), accepting TokenKind.TK_KW_NULL at clause head and reusing parse_facade_status().
  • Sema (src/Sema.with, src/SemaFacade.with): allows consumes param N on a direct-return pointer producer of its own resource R when null status CONST is stated; refuses omitting null status (the facade never invents a status), refuses consuming same-type producers on dependent resources (ephemeral values cannot live in errors), refuses stray null status on non-consuming / non-producer functions, and skips the consumed same-type parameter in facade_producer_parents.
  • Facade rendering (src/compiler/FacadeRender.with): renders move fn <name>(...) -> Result[R, E] (and its consuming imported-name forwarder) returning Err(E.FailedWithResource(CONST, R { repr: prev, live: true })) on NULL — R itself in a good state with self.live = false before the C call so Drop runs exactly once on both paths. Supports both <R>Error and shared facade error types (FailedWith<R>).
  • Spec & decision log: docs/spec/016_ffi.md §16.2b.4, docs/spec/031_contract-language.md §31.5 & §31.8.3, docs/spec/README.md (v7.97), docs/meetings/2026-11-26-D241-consuming-same-type-pointer-producer.md, docs/meetings/README.md.
  • Tests: test/behavior/behav_3121_consumes_same_producer.with (real C slist fixture verifying append, OOM NULL returning original list intact in good state, subsequent append on recovered list, and zero leaks), test/behavior/behav_3121_libcurl_slist_new.with (real curl_slist_append with param 0 fixed null), test/compile_errors/err_3121_consumes_same_producer_no_null_status.with, and test/compile_errors/err_3121_null_status_stray.with.

closes #3121

…R, E] carrying R in good state (D241, closes #3121)
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery and :release-checks GREEN on 9e41c6647 (WITH_CODEGEN_EMIT_WIDTH=2):

  • with run tools/verdict.with out/battery/battery.log -> rc=0 green (battery: GREEN (9e41c6647))
  • WITH=$PWD/src/main src/main build :release-checks -> survey: all targets green, [fixpoint] stage2 == stage3 over all 16 units of the compiler, EMIT-C OK, EMIT-C FIXPOINT, all 6 rt-bundle-*-fixpoint, issue61-regression + all 5 invariance-*, all 6 *-wo-drift (wall 1525.3s).

@ehartford
ehartford marked this pull request as ready for review November 26, 2026 22:52
@ehartford
ehartford merged commit 978c96f into main Nov 26, 2026
1 check passed
@ehartford
ehartford deleted the consumes-same-producer branch November 26, 2026 22:52
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