Repository navigation
D194 (#3010): retained pointer cases of a variadic contract; census patterns for list-new, list-annotation, index-loop, numbered-kind-const - #3063
Merged
Conversation
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
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.
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.
Compiler.
Parser.w: the case line takeslength param CONST as Tanduntil A, Bafterretains by param N; theuntilnames are the case node's trailing extras (its count is the node's).Sema.w/SemaFacade.w: the slot records its form (FacadeRetainedForm.Textfor&CString/&CStr,.Sizedfor&[u8]/&str), its length option and itsuntilnames. Refused with the fix named:strin the slot; a sized case withoutlength param; a text case with one; the length option listed as a case of its own (D51 §9); a sized case on an operation withoutok; anuntilname 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; eachuntiltarget'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'sok.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 byuntilops on their success edge only (a failedCOPYPOSTFIELDSleaves the old pointer in the library), cleared by the abandonment path and by destruction, kept across helper calls.retains_any/retains_originread it, so the existing escape, expire and move checks cover it: the handle is ephemeral throughperform, and aCStringthat 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 aList[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_listnow asks the place's own type, aslower_sequence_placedoes (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, soForeignPairState.borrowkeeps a seed-bound&until a post-fix seed.libcurl facade.
CURLOPT_POSTFIELDSis the sized&strcase overCURLOPT_POSTFIELDSIZE_LARGE, quoted from the manual;COPYPOSTFIELDSis 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 anuntilcase then returned; reset then returned; a sizedstrwith 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.wexpects 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 enumFacadeVariadicKind;ForeignPairState.witerates its lists and uses[], comprehensions andletthroughout; thepairs_list_*helpers are comprehensions; inferable return types and widening casts removed from the new code. Ceremony census:len-castinsrcfalls 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 numberedconst KIND: i32 = n). A new pattern has no bar, sobuild/ceremony-allowances.tsvgrants 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 ownvar x: List[str] = List.new()arelet x = [].Filed: #3060 (
[]in anifbranch is not typed from the other branch), #3061 (with fix-ceremony), #3062 (a bare variant shorthand under anOptiondemand in an assignment orifbranch; threeSome(.Kind)inSemaFacade.ware granted against it).Flagged for Eric (rules that forced an explicit spelling): a shift count must be unsigned, so
1 << iover ani32index needsas u32(foreign_slot_bit); under the pre-D183 seed ani32loop index overlen()needsas i32(removed from the new code here, legacy in the neighbours).