diff --git a/docs/CONFORMANCE-COVERAGE.md b/docs/CONFORMANCE-COVERAGE.md index 404885bac..f592738c9 100644 --- a/docs/CONFORMANCE-COVERAGE.md +++ b/docs/CONFORMANCE-COVERAGE.md @@ -13,11 +13,8 @@ The suite reaches Metal through `objc2-metal`, whose Rust name for a binding is Its limits, measured rather than asserted: - **1469 of 1635 call sites** in the Metal leg resolve to an item of the SDK. 53 of those resolve because only one type in `objc2-metal` binds the name at all, so no typing was needed. -- **127 call sites resolve to no item**: an instance send whose receiver this could not type, or a message to a Metal class whose name `objc2-metal` declares on no Metal type. They cost the count 3 selectors, which the suite calls and which this attributes to no item: - - `alloc`, which `objc2-metal` declares on no Metal type, so it is an item of no Metal container - - `class`, which `objc2-metal` declares on no Metal type, so it is an item of no Metal container - - `count`, bound by `MTL4CounterHeap`, `MTL4CounterHeapDescriptor` - So every per-item count below is a **floor**, by at least these. That list is what this derivation recognises as a call to Metal and cannot attribute; it is not a proof that nothing else is unmeasured. +- **2 call sites send a selector `objc2-metal` binds on no Metal type at all**, so they are an item of no Metal container and there is no count for them to cost: `alloc`, `class`, which are `NSObject`'s. +- **125 call sites resolve to no item although some Metal type binds the selector**: an instance send whose receiver this could not type, or a message to a class that does not bind the name sent to it. Each sent its selector to exactly one receiver, so each exercised one item; which one is what the typing could not say. **Every one of their selectors is bound by at least one item some other call site credits**, so none of these sites proves an item is missing from the count. That is not a proof that the count is complete: such a site may have sent its selector to a type other than the credited one, and this cannot tell. To rule it out, spell the receiver's type at the call site — a `let` with a type, rather than a pattern binding or an inferred one — and this re-derives with the item credited to the case that calls it. - **0 call sites typed to a receiver that does not bind the selector sent to it.** The generator fails rather than writing this document if any does, which is what keeps the typing from quietly counting the wrong item. - **96 of the map's implemented rows are a container's own**: the `class`, `protocol` and `category` rows, whose name is the container's and not a selector's. No call site can resolve to one, because `objc2-metal` binds no selector by that name, so these are credited by the suite **messaging** the type instead — a call whose receiver is the container or a subtype of it — under the same gate and the same family attribution as the selector it sends. - **12 are the header's free functions**, which no container declares. `objc2-metal` binds these as Rust functions, so the receiver typing never sees one; the leg calls such a function by its own C name and the walk reads it as an edge of the call graph. diff --git a/scripts/conformance-coverage/coverage.py b/scripts/conformance-coverage/coverage.py index 66c33d255..6b52103fe 100644 --- a/scripts/conformance-coverage/coverage.py +++ b/scripts/conformance-coverage/coverage.py @@ -881,26 +881,65 @@ def write(data) -> str: f"{len(leg.by_uniqueness)} of those resolve because only one type in `objc2-metal` binds " "the name at all, so no typing was needed." ) - only = sorted({r for _, _, r, _ in leg.unresolved} - {c.rust for c in leg.calls if c.item}) w( - f"- **{len(leg.unresolved)} call sites resolve to no item**: an instance send whose " - "receiver this could not type, or a message to a Metal class whose name `objc2-metal` " - f"declares on no Metal type. They cost the count {len(only)} selectors, which the suite " - "calls and which this attributes to no item:" + f"- **{len(leg.foreign)} call sites send a selector `objc2-metal` binds on no Metal type " + "at all**, so they are an item of no Metal container and there is no count for them to " + "cost: " + ", ".join(f"`{rust}`" for rust in sorted({r for _, _, r, _ in leg.foreign})) + + ", which are `NSObject`'s." ) - for rust in only: - owners = sorted(api.receivers(rust)) - if owners: - spelled = api.selector[next((t, n) for t, n in api.selector if n == rust)] - w(f" - `{spelled}`, bound by " + ", ".join(f"`{ty}`" for ty in owners)) - else: - w(f" - `{rust}`, which `objc2-metal` declares on no Metal type, so it is an item of " - "no Metal container") - w( - " So every per-item count below is a **floor**, by at least these. That list is what " - "this derivation recognises as a call to Metal and cannot attribute; it is not a proof " - "that nothing else is unmeasured." + # The sites that DO cost something, stated in items rather than selector names. Listing the + # selector names alone -- which this did until 2026-10-24 -- hides exactly what a reader wants: + # eight items of one family read as uncalled while the leg demonstrably called them, and the + # document said only that some selectors were ambiguous. + # + # The careful part is the bound. An untyped site sent its selector to ONE receiver, so one of + # the items binding that name is exercised -- but where another call site already credits one + # of them, that may be the one, and the site proves nothing. What proves something is a + # selector NONE of whose candidates anything else credits: then whichever type received it, + # an item that reads here as uncalled was called. Candidates of different selectors are + # disjoint, so each such selector contributes at least one. + credited = set(data["called"]) + candidates: dict[str, set[tuple[str, str]]] = {} + for _, _, rust, _ in leg.unresolved: + if rust not in candidates: + candidates[rust] = { + item + for ty in api.receivers(rust) + if (item := api.binds(ty, rust)) and item in keys + } + blind = {rust: items for rust, items in candidates.items() if items and not items & credited} + hidden = sorted({item for items in blind.values() for item in items}) + head = ( + f"- **{len(leg.unresolved)} call sites resolve to no item although some Metal type binds " + "the selector**: an instance send whose receiver this could not type, or a message to a " + "class that does not bind the name sent to it. Each sent its selector to exactly one " + "receiver, so each exercised one item; which one is what the typing could not say." ) + if blind: + w( + head + f" {len(blind)} of the selectors they send are bound only by items **nothing " + "else credits**, so whichever type received those calls, an item that reads below as " + f"not exercised was exercised: at least {len(blind)} of the {len(hidden)} candidates " + "listed here, and at most all of them." + ) + for item in hidden: + w(f" - `{item[0]}`'s `{item[1]}`") + w( + " So every per-item count below is a **floor**, by at least these. To close one, " + "spell the receiver's type at the call site — a `let` with a type, rather than a " + "pattern binding or an inferred one — and this re-derives with the item credited to " + "the case that calls it." + ) + else: + w( + head + " **Every one of their selectors is bound by at least one item some other call " + "site credits**, so none of these sites proves an item is missing from the count. That " + "is not a proof that the count is complete: such a site may have sent its selector to " + "a type other than the credited one, and this cannot tell. To rule it out, spell the " + "receiver's type at the call site — a `let` with a type, rather than a pattern binding " + "or an inferred one — and this re-derives with the item credited to the case that " + "calls it." + ) w( "- **0 call sites typed to a receiver that does not bind the selector sent to it.** The " "generator fails rather than writing this document if any does, which is what keeps the " diff --git a/scripts/conformance-coverage/metal_leg.py b/scripts/conformance-coverage/metal_leg.py index 668dad380..133d2e3a6 100644 --- a/scripts/conformance-coverage/metal_leg.py +++ b/scripts/conformance-coverage/metal_leg.py @@ -15,9 +15,14 @@ is `MTLResource`'s item). The resolution checks itself: a receiver typed `T` sent a selector that `objc2-metal` does not bind on `T` or any of its supertypes is a **typing error**, not a Metal call, and [`Leg.mistyped`][Leg] carries it so the caller can fail rather than quietly count the wrong item. -The honest limit is the other direction: a receiver this cannot type is reported in -[`Leg.unresolved`][Leg] and attributed to no item, and so is a message to a Metal class whose name -`objc2-metal` declares on no Metal type. Neither is dropped. +The honest limit is the other direction, and it is kept in two piles rather than one, because they +cost different things. A site whose selector `objc2-metal` binds on no Metal type at all +(`alloc`, `class`) is in [`Leg.foreign`][Leg]: no item exists, so nothing is hidden. A site whose +selector some Metal type DOES bind, but whose receiver this could not type, is in +[`Leg.unresolved`][Leg], and that one hides items: the call is real, one of the types binding the +name received it, and the caller can enumerate which. Pooled together they read as one harmless +limit, which is how eight items of one family read as uncalled while the leg demonstrably called +them. Neither pile is dropped. A message to a class — `MTLRenderPassDescriptor::renderPassDescriptor()` — needs no typing at all: the path names its receiver. It is resolved against that class the same way an instance send is @@ -233,10 +238,15 @@ class Leg: """Every Metal call the leg makes, and what the typing could not reach.""" calls: list[Call] = field(default_factory=list) - #: Call sites this attributes to no item, as `(file, function, rust name, receiver text)`: - #: an instance send whose receiver did not type, or a message to a Metal class whose name - #: `objc2-metal` declares on no Metal type. + #: Call sites this attributes to no item although some Metal type binds the selector, as + #: `(file, function, rust name, receiver text)`. The call is real and one of those types + #: received it; which one is what the typing could not say, so these are the sites that hide + #: items, and the candidates are enumerable from `receivers`. unresolved: list[tuple[str, str, str, str]] = field(default_factory=list) + #: Call sites whose selector `objc2-metal` binds on no Metal type at all, as + #: `(file, function, rust name, receiver text)`: `alloc` and `class`, which are `NSObject`'s. + #: There is no item to hide, so these are counted apart from `unresolved`. + foreign: list[tuple[str, str, str, str]] = field(default_factory=list) #: Call sites whose receiver typed to something that does not bind the selector: a bug in this #: typing, never a Metal call. mistyped: list[tuple[str, str, str, str]] = field(default_factory=list) @@ -741,12 +751,13 @@ def read_leg(api: Api, src: Path, files: list[str], enums: set[str]) -> Leg: here = tuple(v for lo, hi, v in arms if lo <= at < hi) item = api.binds(ty, rust) if item is None: - # A message to a Metal class that `objc2-metal` declares on no Metal type, so - # it is an item of no Metal container: `alloc`, which is `NSObject`'s. Counted - # as a call site, attributed to no item, and named in `unresolved` rather than - # dropped. Not `mistyped`: nothing was typed wrongly, the SDK simply has no - # item here. - leg.unresolved.append((name, fn.name, rust, ty)) + # The class named here does not bind this selector. Not `mistyped`: nothing was + # typed wrongly, the path says its own receiver. Which pile it belongs in is + # whether ANY Metal type binds the name: `alloc` and `class` are `NSObject`'s + # and so are an item of no Metal container, while a name some other Metal type + # binds means a real item received this call and the table cannot say which. + pile = leg.unresolved if api.receivers(rust) else leg.foreign + pile.append((name, fn.name, rust, ty)) leg.calls.append(Call(name, fn.name, here, rust, "", None)) continue leg.calls.append(Call(name, fn.name, here, rust, ty, item))