Skip to content

D194 (#3010): retained pointer cases of a variadic contract; census patterns for list-new, list-annotation, index-loop, numbered-kind-const - #3063

Merged
ehartford merged 3 commits into
mainfrom
d194-retained-pointer-case
Nov 7, 2026
Merged

ehartford merged 3 commits into
mainfrom
d194-retained-pointer-case

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

D194 (Eric, 2026-11-07, #3010): a retained pointer case of a variadic contract borrows caller-managed storage, held under §16.2b.9's retained-borrow window. Spec §16.2b.5 "Retained pointer cases", §16.2b.9 one sentence, changelog v7.39, decision log entry and index line.

case CURLOPT_POSTFIELDS: &str retains by param 0 length param CURLOPT_POSTFIELDSIZE_LARGE as curl_off_t until curl_easy_reset
case OPT_BODY: &CString retains by param 0 until OPT_CLEAR

Compiler.

  • Parser.w: the case line takes length param CONST as T and until A, B after retains by param N; the until names are the case node's trailing extras (its count is the node's).
  • Sema.w / SemaFacade.w: the slot records its form (FacadeRetainedForm.Text for &CString / &CStr, .Sized for &[u8] / &str), its length option and its until names. Refused with the fix named: str in the slot; a sized case without length param; a text case with one; the length option listed as a case of its own (D51 §9); a sized case on an operation without ok; an until name that is neither a case of the operation nor a modeled operation of the resource. A retained setter is a pair op (FOREIGN_PAIR_RETAIN) under its case; each until target's pair op releases that case's bit.
  • FacadeRender.w: the method takes the borrow and passes its pointer; a sized case sets the length option first (value.len() as T, overflow checked as buffers are) and the pointer only when the status is the operation's ok.
  • ForeignPairState.w / MirForeignPairs.w: the state gains a retention set (slot, origin, pending release guard) beside the callback pair. A retention is added by its setter whatever the status, replaced when the same case is set again, released by until ops on their success edge only (a failed COPYPOSTFIELDS leaves the old pointer in the library), cleared by the abandonment path and by destruction, kept across helper calls. retains_any / retains_origin read it, so the existing escape, expire and move checks cover it: the handle is ephemeral through perform, and a CString that dies or moves while held is refused at its setter, naming the storage and the setter.
  • MirLower.w (found by the build, fixed): a comprehension over an element of a List[List[T]] (refs[i], self.refs[i]) was lowered with a deref projection on the element (Sema types the access as a view; the place is the element) and refused as invalid MIR. lower_comprehension_list now asks the place's own type, as lower_sequence_place does (ICE: slicing a list element in place (parts[0][..n]) — "slice base does not resolve to a concrete place type" #2578). Reproduces on main's installed compiler and the seed, so ForeignPairState.borrow keeps a seed-bound & until a post-fix seed.

libcurl facade. CURLOPT_POSTFIELDS is the sized &str case over CURLOPT_POSTFIELDSIZE_LARGE, quoted from the manual; COPYPOSTFIELDS is not listed (it reads the same stale size). The Rust sentence is in the facade's comment.

Fixtures. behav_c_facade_retained_pointer_case.w (check-only: body bound before the handle through two runs; released by an until case then returned; reset then returned; a sized str with an interior NUL), behav_comprehension_over_element_list.w (runs), err_c_facade_retained_pointer_{escapes,storage_dies,str,sized_without_length,length_listed,until_unknown}.w; err_c_facade_variadic_callback_escapes.w expects the generalized wording.

Boy-scouting in the files touched (Eric, 2026-11-07: "fix shitty code when you see it"): the FACADE_VARIADIC_* integer kinds are the enum FacadeVariadicKind; ForeignPairState.w iterates its lists and uses [], comprehensions and let throughout; the pairs_list_* helpers are comprehensions; inferable return types and widening casts removed from the new code. Ceremony census: len-cast in src falls 272 → 270.

Second commit: ceremony census patterns (Eric, 2026-11-07: "can this be added to the ceremony census checks"). Four lexical patterns: list-new (List.new(); an empty list is [], D93), list-annotation (: List[T] = [] / = List.new()), index-loop (for i in 0..xs.len():), numbered-kind-const (runs of consecutively numbered const KIND: i32 = n). A new pattern has no bar, so build/ceremony-allowances.tsv grants the tree's counts at the pattern's birth (src: 4328 / 2902 / 2133 / 205) until the next reseed records them. The Sema-driven rewriter that burns them down is #3061 (design in the issue). The tool's own var x: List[str] = List.new() are let x = [].

Filed: #3060 ([] in an if branch is not typed from the other branch), #3061 (with fix-ceremony), #3062 (a bare variant shorthand under an Option demand in an assignment or if branch; three Some(.Kind) in SemaFacade.w are granted against it).

Flagged for Eric (rules that forced an explicit spelling): a shift count must be unsigned, so 1 << i over an i32 index needs as u32 (foreign_slot_bit); under the pre-D183 seed an i32 loop index over len() needs as i32 (removed from the new code here, legacy in the neighbours).

Eric Hartford added 3 commits November 7, 2026 00:45
…caller-managed storage

§16.2b.5 "Retained pointer cases", §16.2b.9, changelog v7.39, decision log.
`case CONST: &CString retains by param N [length param CONST as T] [until A, B]`:
Parser takes the two clauses; Sema classifies the storage (text / sized),
checks the length option, resolves `until` to the case or operation that
releases, and refuses `str`, a sized case without a length, a listed
length option, a sized case without `ok`, and an unknown `until`; the
renderer passes the borrow's pointer, a sized case setting the length
first and the pointer only on `ok`; the pair flow holds the storage under
the case (released by `until` on the success edge only, replaced on a
re-set, cleared by abandon and destruction) so the handle is ephemeral
through `perform` and a dying or moving storage is refused at its setter.
libcurl: CURLOPT_POSTFIELDS as the sized `&str` case over
CURLOPT_POSTFIELDSIZE_LARGE.

Found by the build and fixed: a comprehension over an element of a
`List[List[T]]` was lowered with a deref projection on the element
(MirLower.w lower_comprehension_list asks the place's type now, as
lower_sequence_place does); ForeignPairState.borrow keeps a seed-bound `&`.
`FACADE_VARIADIC_*` kinds are the enum FacadeVariadicKind; ForeignPairState.w
iterates its lists and uses `[]`, comprehensions and `let` throughout.
Filed #3060, #3062.
…-const

Eric, 2026-11-07: "these patterns of bad ceremony … can this be added to the
ceremony census checks". Four lexical patterns: `List.new()` (an empty list
is `[]`, D93), `: List[T] = []` / `= List.new()`, `for i in 0..xs.len():`,
and runs of consecutively numbered `const KIND: i32 = n`. Each starts at a
bar of 0, so build/ceremony-allowances.tsv grants the tree's counts at the
pattern's birth until the next reseed records them; the Sema-driven
rewriter that burns them down is #3061. The tool's own `var x: List[str]
= List.new()` are `let x = []`.
…ock's slot and releases, the pointer-case expectation reads the D194 hint, three pubs the package alone uses dropped
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