AI Updates #8: document cargo cgp expand, and restate error coalescing as cause-keyed - #261
Merged
Conversation
cargo-cgp no longer groups the failures it coalesces by a whole-failure cause signature, which required two failures to carry identical cause sets. It keys on each root cause separately and groups the failures that share one, so the class this document describes now also collapses when a single omission is reached at several instantiations: each check entry stops at the first unmet leaf on its own branch while a use-site call reaches them all, so the cause sets overlap without ever being equal and the exact key grouped none of them. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`cargo-cgp` has a second reading command: `expand` prints a target after
macro expansion with CGP's type-level constructs resugared, so a field tag
reads `Symbol!("width")` rather than a raw `Chars` spine. That is the
answer to "what did this macro actually generate?", which a CGP error
cannot give, so it belongs wherever the knowledge base discusses reading
generated code or debugging a wiring failure.
The cargo-cgp reference gains a full section on it: when to reach for it,
what the resugaring buys over plain `cargo expand`, the one-target
requirement and cargo's refusal without `--lib`/`--bin NAME`, and the
three `--item` rules — a module gives its contents, a type its declaration
and the impls for it, a trait its definition and the impls of it. The
worked sample expands the area-calculation example's own `rectangle_area`,
so it shows what `#[cgp_fn]` emits and what `#[implicit]` arguments become
in one snippet.
The skill gains the agent-facing version in its tooling section: the four
situations where the answer is in the generated code rather than the
message, the commands, and the caveat that `expand` stops after expansion
— it reports nothing about wiring, but it also succeeds on a crate that
does not type-check, which is what makes it useful mid-debugging. The
error-extraction sub-skill now leads its "read the expansion" step with
it, since a spine the error mangled is legible there, and it tells the
agent to redirect long output to a file rather than flood its context.
Two more views followed from the same change: the debugging guide's
"inspect what the macro actually emitted" step leads with `cargo cgp
expand` and keeps plain `cargo expand` and the `snapshot_*!` helpers as
fallbacks, and the type-level-primitives decoder notes that a raw spine in
a `cargo cgp expand` dump means the resugaring declined.
Every command and snippet here was run against the tool rather than
recalled — which corrected one claim: naming a component's provider trait
selects the provider trait, the delegation blanket, the `UseContext` and
`RedirectLookup` impls, and each provider's impl, but *not* the consumer
blanket, which `--item CanCalculateArea` selects instead.
`expand` postdates cargo-cgp v0.1.0-alpha, so both documents say a
crates.io install does not carry it yet and name the two ways to get it.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
AI overview
This PR is documentation only: seven Markdown files under docs/, +151/−16 lines, and no change to any crate, macro, test, or snapshot. Both commits bring the knowledge base back in line with
cargo-cgp, which has gained a second command and changed how it groups the diagnostics it rewrites. Nothing here alters CGP's behavior, so nothing here can break a build; what it changes is what a reader — and an agent — is told to do when a CGP error stops making sense.The high-level concepts
The first and larger change makes
cargo cgp expanda documented part of the CGP workflow. Until now the toolchain was presented as one command,check, whose job is to reshape a CGP compile error into a root-cause-first form.expandanswers a different question thatcheckstructurally cannot: what did that macro actually generate? Every CGP wiring failure is "the emitted impls do not resolve," and the impls are generated, so reading them is often faster than reasoning about the diagnostic that describes them. The PR threads that idea through the knowledge base wherever reading generated code or debugging a wiring failure already came up.What makes the command worth documenting rather than deferring to plain
cargo expandis resugaring.cargo cgp expandprints the post-expansion crate with CGP's type-level constructs folded back into their source vocabulary — a field tag readsSymbol!("width")instead of the rawSymbol<5, Chars<'w', …>>spine, a pipeline readsProduct![StepOne, StepTwo], a namespace key readsPath!(@app.GreeterComponent). That turns the expansion into something legible in the same terms as the source, which is precisely what the compiler's own rendering of those types is not.The second concept the PR adds is the
--itemselection model, because a whole crate's expansion is unusable in practice. The docs now spell out that--itembehaves by three rules according to what the path names: a module yields its contents, a type yields its declaration and every impl written for it, and a trait yields its definition and every impl of it. The trait rule is called out as the one to reach for on CGP code, since a component's generated items are almost all impls and an impl has no name to select by. Naming a component's provider trait therefore gathers the provider trait, the delegation blanket impl, theUseContextandRedirectLookupimpls, and each wired provider's own impl — the whole set of things that can answer "which provider serves this component, and under what bounds?" — while the consumer trait is the smaller companion selection.The second commit restates a claim about how
cargo-cgpcoalesces a verbose cascade, because the tool's grouping rule changed underneath it. The error catalog previously said the tool groups failures by a consumer-independent cause signature, which demanded that two failures carry identical cause sets. It now keys on each root cause separately and groups the failures that share one, transitively. The distinction matters for a shape the old rule missed: because CGP wiring is lazy, one omission surfaces at several depths, and each depth sees a different subset of the causes — acheck_components!entry stops at the first unmet leaf on its own branch, while a use-site call walks every wired component and reaches them all — so those subsets overlap without ever being equal, and an exact-match key grouped none of them, leaving a single mistake reported as several blocks.The structural changes
The reference gains a new top-level section and the skill gains its agent-facing twin. docs/reference/cargo-cgp.md grows an "Expanding the generated code" section — roughly sixty lines covering when to reach for the command, what resugaring buys over plain
cargo expand, the one-target requirement and cargo's exact refusal without--lib/--bin NAME, the three--itemrules, and the two limits (it is not a check, and its output is for reading rather than compiling). Its worked sample expands the area-calculation example's ownrectangle_area, so one snippet shows both what#[cgp_fn]emits and what#[implicit]arguments become — aHasFieldbound per argument plus a cloningget_fieldcall. The document's framing lines and its opening paragraph were widened from "the error toolchain" to cover both commands, and docs/reference/README.md extends the same document's catalog entry.The skill's tooling section gains the parallel treatment, and it ships in the same edit. docs/skills/cgp/SKILL.md gets a "Reading what a macro generated:
cargo cgp expand" subsection written for an agent rather than a reader: the four situations where the answer lives in the generated code rather than the message, the commands, the--itemrules in compressed form, and an instruction to redirect long output to a file rather than flood its own context. Because .claude/skills/cgp is a symlink todocs/skills/cgp, the deployed skill and the documented skill are one file — there is no second copy left to drift.Three smaller edits re-point existing "read the expansion" advice at the new command. The debugging guide now leads its "inspect what the macro actually emitted" step with
cargo cgp expandand demotes plaincargo expandand thesnapshot_*!helpers to fallbacks; the error-extraction sub-skill does the same for its expansion step; and the type-level-primitives decoder notes that a raw spine appearing in acargo cgp expanddump means the resugaring declined, whereas an error message or a plaincargo expandshows the spines as they are. The coalescing restatement touches docs/errors/checks/verbose-cascade.md in two places: the "How cargo-cgp presents it" mechanism paragraph and the "Notes for tooling" summary.Impacts
The impacts are a set of independent consequences rather than one argument, so they are listed. Each is something a reviewer or a downstream reader should expect to be different after this merges.
expandpostdates the v0.1.0-alpha release, so acargo install cargo-cgpfrom crates.io does not carry it yet, and the two ways to get it in the meantime (an untagged Nix reference trackingmain, or a source checkout) are named.cargo expandor the snapshot helpers; it now sends it tocargo cgp expandfirst, with an explicit context-hygiene instruction to narrow with--itemor redirect to a file. Agents following the skill will therefore issue different commands when diagnosing wiring failures.check" now reads "checkandexpand" in the skill, and the reference's corresponding paragraph was rewritten the same way. The load-bearing part is unchanged and still stated in both: there is nocargo cgp build/run/test, CGP compiles on any stable Rust ≥ 1.89, and you build, run, and test with ordinary cargo.--item <provider trait>does not include the consumer blanket impl —--item <consumer trait>selects that. The reference and the skill both state the split correctly.cargo-cgp'sgroup_by_shared_causegroups failures sharing at least one root cause, transitively, keyed structurally on context plus leaf rather than on rendered wording. The two edited paragraphs say exactly that, including that overlapping-but-unequal cause sets group.../cargo-cgpalready carries both theexpandcommand and the shared-cause grouping, and its owndocs/reference/usage.mdalready documentsexpand, so this PR is thecgpside catching up rather than a change that obliges an update there. The one cross-repo link added — the source-install anchor in the installation doc — is written as a GitHub URL per the repository's convention.docs/,AGENTS.md,README.md, andCHANGELOG.mdforcargo expandandcargo cgp expandfinds no mention outside the five files this PR edits, so no other document is left recommending the un-resugared fallback as the primary route.crates/is touched, so no macro behavior, expansion snapshot,trybuildfixture, or wiring check is affected, and thecargo nextestsuite is unaffected by construction. Nothing here changes the published surface or requires a version edit — the tree remains the0.8.0-alphapre-release documented as v0.8.0.--itemrules, the one-target refusal message, and the two limits describe an unreleasedexpand, tracked frommainin the sibling repository. If that behavior shifts before the next cargo-cgp release, these five documents are what needs re-verifying, and the anchors added here (#expanding-the-generated-code, referenced from three other documents) are what would need to survive any restructure.