diff --git a/.github/workflows/test-deploy.yaml b/.github/workflows/test-deploy.yaml index 71dc1347..d6fe4d06 100644 --- a/.github/workflows/test-deploy.yaml +++ b/.github/workflows/test-deploy.yaml @@ -23,7 +23,7 @@ permissions: # To minimize supply-chain exposure this workflow uses only GitHub's own # first-party actions. Each job runs a check the repository's documentation # lists: the site build from README.md, and the snippet tests from -# example-code/README.md. +# example-code/README.md and example-code-nightly/README.md. jobs: build: name: Build the site @@ -72,3 +72,25 @@ jobs: - name: Run the snippet tests working-directory: contextgeneric.dev/example-code run: cargo test -- --skip rejected_snippets_do_not_compile + + example-code-nightly: + name: Nightly snippet tests + runs-on: ubuntu-latest + timeout-minutes: 30 + env: + CARGO_TERM_COLOR: always + steps: + - name: Check out the website + uses: actions/checkout@v4 + with: + path: contextgeneric.dev + # `example-code-nightly/rust-toolchain.toml` pins the nightly whose + # unstable features the snippets need; rustup installs it from there. + - name: Install the pinned nightly toolchain + working-directory: contextgeneric.dev/example-code-nightly + run: rustup toolchain install + # The snippets that need a nightly feature are compiled here. The + # compile-fail snapshots are skipped, as in the stable job. + - name: Run the nightly snippet tests + working-directory: contextgeneric.dev/example-code-nightly + run: cargo test -- --skip rejected_snippets_do_not_compile diff --git a/AGENTS.md b/AGENTS.md index 63917364..a3a6e5dd 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -33,8 +33,9 @@ Each kind of task has a guide in the knowledge base's `website/` section. Read i - **Adding or moving a page, or writing a blog post:** `writing-guides/README.md` and `information-architecture.md`. - **Changing the theme or a page's styles:** `visual-design.md`. -- **Changing the build, the navigation, or the `example-code` crate:** `site.md` and - [example-code/README.md](example-code/README.md). +- **Changing the build, the navigation, or the `example-code` crates:** `site.md`, + [example-code/README.md](example-code/README.md), and + [example-code-nightly/README.md](example-code-nightly/README.md). ## Public prose @@ -79,8 +80,12 @@ Every snippet on a page is verified against current CGP: - Put a page's code in the `example-code/` crate, one module per heading, except a Projects page, whose code is checked against the project's repository; do not mirror the knowledge base's own snippets there. +- Put a snippet that shows an unstable feature it needs in the `example-code-nightly/` crate + instead, on the nightly it pins, as + [example-code-nightly/README.md](example-code-nightly/README.md) describes. - Run the `example-code` tests after changing a page's code, as - [example-code/README.md](example-code/README.md) describes. + [example-code/README.md](example-code/README.md) describes, and the `example-code-nightly` tests + when the page has nightly snippets. - Fill an elided body with a comment saying so, write a rejected snippet as a compile-fail fixture, and prefer duplication between files over a shared helper neither page shows. - Treat a page without an `example-code` file as unvisited, not unverified, and check generated code diff --git a/blog/2026-11-29-incoherent-rust-today.md b/blog/2026-11-29-incoherent-rust-today.md new file mode 100644 index 00000000..35363eee --- /dev/null +++ b/blog/2026-11-29-incoherent-rust-today.md @@ -0,0 +1,1172 @@ +--- +slug: 'incoherent-rust-today' +authors: [soares] +tags: [deepdive] +description: 'How CGP lets parts of Incoherent Rust, from the 2026 Rust discussion of incoherent traits, be tried on stable Rust today, and where it falls short.' +--- + +# Trying Incoherent Rust today with Context-Generic Programming + +In March, three blog posts started a discussion about traits and coherence in Rust. Nadrieril's [**Elaborating Rust Traits to Explicit Trait Proofs**](https://nadrieril.github.io/blog/2026/03/20/dictionary-passing-style.html) and [**What If Traits Carried Values**](https://nadrieril.github.io/blog/2026/03/22/what-if-traits-carried-values.html) read trait impls as values passed through a program, and Boxy's [**An Incoherent Rust**](https://www.boxyuwu.blog/posts/an-incoherent-rust/) used that reading to ask what Rust would look like if traits could opt out of coherence. The discussion has since become a [Rust project goal](https://github.com/rust-lang/goals/issues/630), and Nadrieril and Niko Matsakis have turned to the question of [when trait impls may depend on themselves](https://nadrieril.github.io/blog/2026/05/14/when-can-traits-depend-on-themselves.html). + +[**Context-Generic Programming**](/docs/) (CGP) extends Rust with pluggable trait implementations, chosen per context at compile time, and it runs on stable Rust today. In this post, I explain how CGP relates to the discussion: which parts of [Incoherent Rust](https://www.boxyuwu.blog/posts/an-incoherent-rust/) it can express now, where its context type works like the dictionaries of [dictionary-passing style](https://nadrieril.github.io/blog/2026/03/20/dictionary-passing-style.html), and where it falls short. + + + +:::note[Author's note] +This post was first drafted in April, after Boxy's and Nadrieril's posts from March, and was put on hold for lack of time and because the work on [CGP v0.8.0](/blog/v0.8.0-release) came first. It was revised before publication to follow the discussion since then. +::: + +## Outline + +This post first sets out the background and a short introduction to CGP. It then [desugars several features of Incoherent Rust into CGP code](#expressing-incoherence-with-cgp), [compares CGP's context type with the dictionaries](#context-as-dictionary) of dictionary-passing style, and states the [limitations](#limitations-and-open-challenges) of expressing Incoherent Rust this way. The later sections cover what CGP's providers and contexts [can do beyond the current designs](#where-cgp-diverges-from-incoherent-rust), the [ideas CGP suggests](#ideas-from-cgp-for-incoherent-rust) for Incoherent Rust, and how [other languages](#related-work) handle the same trade-offs. + +In summary, CGP: + +- Lets a significant subset of Incoherent Rust be [tried on stable Rust today](#a-testing-ground-for-incoherent-rust). +- Lets [contexts and capabilities be tried](#trying-contexts-and-capabilities-today) through context fields. +- Does not solve the [formalization goal](#formalization-of-rust), and only partly addresses [ecosystem evolution](#ecosystem-evolution) for existing traits. +- Reveals [specific challenges](#limitations-and-open-challenges) that full dictionary-passing style in Rust would need to address. + +--- + +## Background + +This section summarizes the discussion as I read it from public writing, so it may miss context that the participants have. The website's [Rust's own proposals](/docs/comparisons/rust-language-proposals) page summarizes each proposal on its own terms. + +Nadrieril's first post reads trait solving as building explicit proofs. A trait is like a struct of methods, an impl is like a value of that struct, and a trait bound is how such values are passed along. This way of passing impls is called dictionary-passing style in the Haskell literature, where [type classes pass their implementations this way](/docs/comparisons/implicit-parameters#type-classes-as-implicit-dictionary-passing). Making the proofs explicit turns each trait choice into a value that can be checked. A footnote in the post connects the idea to his [**Rust via Desugarings**](https://nadrieril.github.io/rust-via-desugarings/) book, which explains Rust by translating it into a simpler subset of the language. His later post on [**a formal specification**](https://nadrieril.github.io/blog/2026/06/16/formal-spec-vision.html) builds on that approach. The language that post translates Rust into, **PolyMiniRust**, makes every trait proof explicit: it is Ralf Jung's [MiniRust](https://github.com/minirust/minirust), an interpreter for Rust's runtime semantics, extended with generics and trait proofs. + +His second post, [What If Traits Carried Values](https://nadrieril.github.io/blog/2026/03/22/what-if-traits-carried-values.html), lets those dictionaries carry runtime values. It credits Tyler Mandry, the author of the 2021 [**contexts and capabilities**](https://tmandry.gitlab.io/blog/posts/2021-12-21-context-capabilities/) proposal, with pointing out that the idea resembles that proposal. [Boxy's post](https://www.boxyuwu.blog/posts/an-incoherent-rust/) then explores how the same model could enable [**incoherent traits**](https://www.boxyuwu.blog/posts/an-incoherent-rust/#incoherent-traits), which opt out of Rust's coherence rules. That post starts from the problem of [ecosystem evolution](https://www.boxyuwu.blog/posts/an-incoherent-rust/#stunted-ecosystem-development), with `serde` as its example, and works through what such traits would mean for [`HashMap`](https://www.boxyuwu.blog/posts/an-incoherent-rust/#the-hashmap-problem-revisited) and associated types. I use **Incoherent Rust** for this envisioned version of Rust, broadly covering the features that Nadrieril, Boxy, and Tyler Mandry explore, none of which are settled yet. + +Since March, the work has become the types team's [**Dictionary Passing Style Experiment**](https://github.com/rust-lang/goals/issues/630), with a [project repository](https://github.com/rust-lang/project-dictionary-passing) whose reading list gives Boxy's post as its entry on incoherence. Nadrieril's [**When can Traits Depend on Themselves?**](https://nadrieril.github.io/blog/2026/05/14/when-can-traits-depend-on-themselves.html) and Niko Matsakis's [**series on cyclic trait impls**](https://smallcultfollowing.com/babysteps/series/cyclic-trait-impls/) study which cycles between trait impls are sound. Niko Matsakis's series takes perfect derive as its motivating case, and the section on [cyclic providers](#cyclic-providers) takes the question up again. Nadrieril's other recent post, [**Capabilities using Plain Traits**](https://nadrieril.github.io/blog/2026/06/07/capabilities-with-plain-traits.html), expresses `cfg` and target features as traits, including *selfless* traits without a `Self` type, which [a later section](#selfless-traits) comes back to. + +These discussions now run along three lines. The [types team's experiment](https://github.com/rust-lang/goals/issues/630) asks whether rustc can compute each trait proof once, during type checking, instead of solving the same bounds again during borrow checking and code generation. Nadrieril's [vision for a formal specification](https://nadrieril.github.io/blog/2026/06/16/formal-spec-vision.html) translates Rust into PolyMiniRust, where every trait proof is explicit, and the project has since accepted a related goal for an [**executable specification**](https://goals.rust-lang.org/2026/executable-spec.html), built on [a-mir-formality](https://github.com/rust-lang/a-mir-formality) and MiniRust. And the feature posts show what explicit proofs would enable, such as [incoherent traits](https://www.boxyuwu.blog/posts/an-incoherent-rust/#incoherent-traits) and [traits that carry values](https://nadrieril.github.io/blog/2026/03/22/what-if-traits-carried-values.html). + +The three need not go together. The compiler might compute proofs once without ever exposing incoherent traits, and a feature like Incoherent Rust could be designed before the compiler supports it. This post therefore treats them separately, so that the feasibility of one does not decide how we judge another. + +--- + +## A brief introduction to CGP + +This section introduces CGP for readers who already know Rust's traits, generics, and coherence rules in depth, such as members of the Rust compiler and types teams. + +CGP extends Rust with pluggable trait implementations: code is written generically over a context type, which takes the place of `Self` in trait definitions, and each context chooses which implementation it uses. CGP does this with design patterns that work within Rust's [coherence rules](/docs/concepts/coherence#the-coherence-guarantee), so multiple overlapping implementations can coexist on stable Rust. A [consumer trait](/docs/concepts/consumer-and-provider-traits) remains an ordinary trait, which can still be implemented directly. + +This section covers only what the rest of the post needs. My RustLab 2025 talk, [**How to stop fighting with coherence and start writing context-generic trait impls**](/blog/rustlab-2025-coherence), explains the motivation in more depth. The website's [coherence](/docs/concepts/coherence), [consumer and provider traits](/docs/concepts/consumer-and-provider-traits), and [modularity hierarchy](/docs/concepts/modularity-hierarchy) pages explain the mechanism, and [`cargo cgp expand`](/docs/tooling/cargo-cgp/expand) shows the code each macro generates. + +### Bypassing coherence + +CGP bypasses coherence restrictions at two levels. + +The first level lets a trait have multiple overlapping implementations through a layer of indirection called a [provider trait](/docs/concepts/consumer-and-provider-traits#splitting-one-trait-in-two). For example, serde's `Serialize` trait could be redefined with CGP as follows: + +```rust +#[cgp_component(SerializeImpl)] +pub trait Serialize { + fn serialize(&self, serializer: S) -> Result; +} +``` + +The main difference from serde's definition is the [`#[cgp_component]`](/docs/reference/macros/cgp_component) macro. It generates a provider trait called `SerializeImpl`, along with the constructs that let overlapping implementations coexist. With the provider trait, we can define an implementation that serializes a value as its `Display` string: + +```rust +#[cgp_impl(new SerializeWithDisplay)] +#[uses(Display)] +impl SerializeImpl { + fn serialize(&self, serializer: S) -> Result { + // serde's own `Serialize`, implemented by `String` + serde::Serialize::serialize(&self.to_string(), serializer) + } +} +``` + +The [`#[cgp_impl]`](/docs/reference/macros/cgp_impl) macro implements the `SerializeImpl` provider trait on a new named provider, `SerializeWithDisplay`, for any context that implements `Display`. In the generated code, `SerializeWithDisplay` is the `Self` type of that impl, so the impl cannot conflict with other implementations of `SerializeImpl`, each of which has its own provider as `Self`. + +A concrete context then needs one more step: wiring, written with [`delegate_components!`](/docs/reference/macros/delegate_components). Here the context is `Person`, which is also the value being serialized: + +```rust +pub struct Person { + pub first_name: String, + pub last_name: String, +} + +impl Display for Person { + fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { + write!(f, "{} {}", self.first_name, self.last_name) + } +} + +delegate_components! { + Person { + SerializeImplComponent: SerializeWithDisplay, + } +} +``` + +The `delegate_components!` macro turns this wiring into a type-level lookup table, written as impls of the [`DelegateComponent`](/docs/reference/traits/wiring/delegate_component) trait. The blanket implementations that `#[cgp_component]` generated then look up that table at compile time and implement `Serialize` for `Person` through `SerializeWithDisplay`. Any number of overlapping providers can be defined this way, and each context selects the ones it reuses, one line per trait. The [Bypassing coherence](/docs/concepts/coherence) page walks through this level in more depth, and [Type-level tables](/docs/concepts/type-level-tables) explains how the compiler looks the table up. + +This first level bypasses the overlap rule, but not the [orphan rule](https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules). To implement `Serialize` for `Person`, the `delegate_components!` call must still live in a crate that owns either `Person` or the trait. So this level alone does not solve the [ecosystem evolution problem](https://www.boxyuwu.blog/posts/an-incoherent-rust/#stunted-ecosystem-development) that [**Incoherent Rust**](https://www.boxyuwu.blog/posts/an-incoherent-rust/) addresses. As my [**RustLab presentation**](/blog/rustlab-2025-coherence) explains, though, CGP has a more advanced pattern that handles overlapping and orphan implementations together: a new type parameter becomes the context, in the `Self` position, and the original `Self` type moves into a generic parameter of the consumer trait. + +For example, a fully incoherent version of `Serialize` would be defined as follows: + +```rust +#[cgp_component(SerializeImpl)] +pub trait Serialize { + fn serialize( + &self, + value: &T, + serializer: S, + ) -> Result; +} +``` + +Unlike the first version, this one takes the value type as the generic parameter `T`, and its `Self` becomes a separate context type. `Person` is then no longer the context but the value being serialized. The `Display`-based provider now takes the value as an argument instead of reading it from `self`: + +```rust +#[cgp_impl(new SerializeWithDisplay)] +impl SerializeImpl { + fn serialize( + &self, + value: &T, + serializer: S, + ) -> Result { + serde::Serialize::serialize(&value.to_string(), serializer) + } +} +``` + +Implementations of this `Serialize` are wired on a central context type, which does not need to live in the same crate as `Person` or the trait: + +```rust +// inside a third party crate +pub struct MyApp; + +delegate_components! { + MyApp { + // Choose a provider per value of the component's generic parameter + open SerializeImplComponent; + + // Path notation that names the generic parameter as part of the + // component path. + @SerializeImplComponent.Person: SerializeWithDisplay, + } +} +``` + +The [`open` statement](/docs/reference/macros/delegate_components#choosing-a-provider-per-type-the-open-statement) lets the context choose a provider for each value of the component's generic parameter, and each `@`-path key names one such value. + +With this approach, third-party crates can define their own contexts like `MyApp` and locally rewire the `Serialize` implementation for a value type without affecting global coherence. The [modularity hierarchy](/docs/concepts/modularity-hierarchy#tier-4-one-provider-per-target-type) page explains this pattern in more depth, as one tier among the ways CGP can arrange contexts and providers. + +The added context type only partly solves the [orphan rules problem](https://www.boxyuwu.blog/posts/an-incoherent-rust/#why-orphan-rules), though. Every trait involved must adopt CGP and include the context parameter in its definition, so the approach cannot be applied to existing traits like `serde::Serialize` without breaking changes across the entire Rust ecosystem. It suits new traits well, since they can take the context parameter from the start without breaking anything. + +### CGP as a library or as language sugar + +CGP is currently a library on stable Rust. Behind it is a small set of design patterns, which the website's [Concepts pages](/docs/concepts/) explain. The patterns are deliberately minimal, and they work within the existing rules of Rust's type system rather than requiring changes to it. + +The [sections below](#expressing-incoherence-with-cgp) desugar Incoherent Rust into CGP, but I am not suggesting that the compiler should implement Incoherent Rust this way. If rustc computes [explicit trait proofs](https://nadrieril.github.io/blog/2026/03/20/dictionary-passing-style.html), a named impl is already a value the compiler can pass around. Translating it first into CGP's provider traits and wiring, and then elaborating those traits into proofs, would only add a detour through the coherence rules that incoherent traits set out to relax. + +What CGP offers instead is a place to try these ideas now. The desugarings below are ordinary CGP code that compiles today, so Rust programmers can write code in the style Incoherent Rust envisions without waiting for incoherent traits to reach the language. The experience from real CGP projects can then feed into the design questions that [Boxy's post](https://www.boxyuwu.blog/posts/an-incoherent-rust/#closing-thoughts) leaves open, such as syntax, ergonomics, and whether the complexity is worth it. + +Trying the ideas through CGP has its costs, though. CGP's wiring adds compile-time work, readers have to learn the context and provider model, and errors that pass through generated providers are long in their raw form. For those errors, the project ships an error toolchain, cargo-cgp: [`cargo cgp check`](/docs/tooling/cargo-cgp/check) leads with the root cause for the classes it recognizes, and the tool does not yet reshape every class. A compiler that understood incoherent traits natively could report such errors in its own terms. + +--- + +## Expressing incoherence with CGP + +With these concepts in place, we can look at how CGP expresses the features that [Boxy](https://www.boxyuwu.blog/posts/an-incoherent-rust/), [Nadrieril](https://nadrieril.github.io/blog/2026/03/20/dictionary-passing-style.html), and [Tyler Mandry](https://tmandry.gitlab.io/blog/posts/2021-12-21-context-capabilities/) propose. + +### Incoherent traits + +In [An Incoherent Rust](https://www.boxyuwu.blog/posts/an-incoherent-rust/#incoherent-traits), Boxy proposes introducing an `incoherent` keyword on traits to allow overlapping implementations. For example: + +```rust title="Incoherent Rust" +// crate a +pub incoherent trait Serialize { + fn serialize(&self) -> String; +} +``` + +With CGP, an incoherent trait like this desugars into a [component](/docs/reference/macros/cgp_component) whose `Self` type is a generic context: + +```rust title="CGP" +// crate a +// A revised `Serialize`, following the simpler signature of Boxy's example +#[cgp_component(SerializeImpl)] +pub trait Serialize { + fn serialize(&self, value: &T) -> String; +} +``` + +The original `Self` type, which represents the value being serialized, becomes the explicit generic parameter `T`. The `Self` position now holds the context type, which carries the implementation choices and lets multiple overlapping implementations coexist without violating coherence. + +### Named impls + +In the [proposed Incoherent Rust syntax](https://www.boxyuwu.blog/posts/an-incoherent-rust/#named-impls-and-trait-bound-parameters), each implementation gets a name. For example: + +```rust title="Incoherent Rust" +// crate b +pub struct Matrix(...) + +// crate c +impl CSerialize = a::Serialize for b::Matrix { ... } + +// crate d +impl DSerialize = a::Serialize for b::Matrix { ... } +``` + +With CGP, each named impl becomes a [provider struct](/docs/concepts/consumer-and-provider-traits#providers-as-type-level-names) with an implementation of the corresponding provider trait. The two named implementations above would desugar to: + +```rust title="CGP" +// crate c +#[cgp_impl(new CSerialize)] +impl a::SerializeImpl { + ... +} + +// crate d +#[cgp_impl(new DSerialize)] +impl a::SerializeImpl { + ... +} +``` + +Because the `Self` type of each provider trait implementation is the provider struct itself, which is defined in the local crate, the two implementations do not conflict under [coherence](/docs/concepts/coherence) even when both target the same value type `b::Matrix`. + +### Using incoherent trait bounds + +Uses of incoherent trait bounds desugar too. [Boxy's post](https://www.boxyuwu.blog/posts/an-incoherent-rust/#incoherent-traits) gives this example, which calls the same function with two implementations of the same trait: + +```rust title="Incoherent Rust" +incoherent trait Name { + const NAME: &'static str; +} + +impl DummyName = Name for T { + const NAME: &'static str = "dummy"; +} +impl RealName = Name for T { + const NAME: &'static str = core::any::type_name::(); +} + +#[derive(Copy, Clone)] +struct Foo(T); +impl MyImpl = Foo { + pub fn do_stuff(self) { + println!("{}", ::NAME); + } +} + +fn main() { + let foo = Foo(1); + + // prints "dummy" + MyImpl<_ + DummyName<_>>::do_stuff(foo); + // prints "i32" + MyImpl<_ + RealName<_>>::do_stuff(foo); +} +``` + +In CGP, the same code becomes: + +```rust title="CGP" +// Needed for `core::any::type_name` in a constant; see below. +#![feature(const_type_name)] + +#[cgp_component(NameImpl)] +pub trait Name { + const NAME: &'static str; +} + +#[cgp_impl(new DummyName)] +impl NameImpl { + const NAME: &'static str = "dummy"; +} + +#[cgp_impl(new RealName)] +impl NameImpl { + const NAME: &'static str = core::any::type_name::(); +} + +pub struct Foo(pub T); + +#[cgp_fn] +#[uses(Name)] +pub fn do_stuff(&self, foo: &Foo) { + println!("{}", Self::NAME); +} + +fn main() { + let foo = Foo(1); + + { + struct Context; + + delegate_components! { + Context { + NameImplComponent: DummyName, + } + } + + // prints "dummy" + Context.do_stuff(&foo); + } + + { + struct Context; + + delegate_components! { + Context { + NameImplComponent: RealName, + } + } + + // prints "i32" + Context.do_stuff(&foo); + } +} +``` + +In the desugared code, the incoherent `Name` trait becomes a CGP component `Name`, with the provider trait `NameImpl`. The generic function `do_stuff` becomes a context-generic CGP function, written with [`#[cgp_fn]`](/docs/reference/macros/cgp_fn), that uses `Name` through the [`#[uses]`](/docs/reference/attributes/uses) attribute and accepts `&self` as the implicit context parameter. Each anonymous call site in the original code, such as `MyImpl<_ + DummyName<_>>`, desugars into a locally scoped `Context` struct with a [`delegate_components!`](/docs/reference/macros/delegate_components) block that wires the chosen provider. + +The constant stays an associated constant, since a CGP component can declare one just as an ordinary trait does. Only `RealName`'s constant needs care: it calls `core::any::type_name`, which is not yet stable as a `const fn`. That is why the snippet opens with `#![feature(const_type_name)]` and needs a nightly compiler, as do the [later examples](#binding-an-implementation-to-a-struct) that reuse `Name`. The requirement comes from the standard library, not from CGP. + +`do_stuff` takes `&self` because the context type, `Self`, carries the implementation choice at the type level. As we will see later, the same `&self` can also carry runtime values, which makes context-generic functions suitable for expressing [contexts and capabilities](#contexts-and-capabilities). + +### Binding an implementation to a struct + +[Boxy's blog post](https://www.boxyuwu.blog/posts/an-incoherent-rust/#incoherent-traits) also discusses binding an incoherent trait implementation directly to a struct, so that the same implementation is always used whenever that struct is passed around: + +```rust title="Incoherent Rust" +#[derive(Copy, Clone)] +struct Foo(T); +impl MyImpl = Foo { + ... +} + +fn main() { + let foo = Foo::<_ + DummyName<_>>(1) + + // prints "dummy" + MyImpl<_ + DummyName<_>>::do_stuff(foo); + + // errors as `foo` has type `Foo>` but + // the impl requires the self type to be `Foo>` + MyImpl<_ + RealName<_>>::do_stuff(foo); +} +``` + +With CGP, this pattern desugars by adding the `Context` type as a parameter on the struct itself, so that the struct carries the implementation choice in its type: + +```rust title="CGP" +pub struct Foo { + pub value: T, + pub phantom: PhantomData, +} + +#[cgp_fn] +#[uses(Name)] +pub fn do_stuff(&self, foo: &Foo) { + println!("{}", Self::NAME); +} + +struct ContextA; + +delegate_components! { + ContextA { + NameImplComponent: DummyName, + } +} + +struct ContextB; + +delegate_components! { + ContextB { + NameImplComponent: RealName, + } +} + +fn main() { + let foo: Foo = Foo { + value: 1, + phantom: PhantomData, + }; + + ContextA.do_stuff(&foo); + + // type error: foo has type Foo but ContextB expects Foo + ContextB.do_stuff(&foo); +} +``` + +Because the `Context` type is part of the struct's type signature, a value of type `Foo` and a value of type `Foo` are distinct types. This distinction is the property [Boxy describes](https://www.boxyuwu.blog/posts/an-incoherent-rust/#incoherent-traits): once a struct is created with a particular incoherent implementation bound to it, that binding cannot be silently swapped out at another call site. + +This property is especially useful for the [hash table problem](https://www.boxyuwu.blog/posts/an-incoherent-rust/#the-hashmap-problem-revisited) that Boxy's post raises. A hash map can include the `Context` type in its definition, becoming `HashMap`, to ensure that the same `Hash` implementation is always used when inserting or looking up entries. + +One downside of binding the full `Context` type to a struct is that two contexts with identical provider wirings are still different types. The difference gets in the way when you want to share a struct value across modules or functions that use different contexts. + +An alternative is to bind a specific provider type to the struct rather than a full context. The provider type becomes a generic parameter of the struct, and a CGP function binds it the way a [higher-order provider](/docs/concepts/higher-order-providers#a-provider-carried-by-a-value) binds its inner provider: + +```rust title="CGP" +pub struct Foo { + pub value: T, + pub phantom: PhantomData, +} + +#[cgp_fn] +#[use_provider(NameProvider: NameImpl)] +pub fn do_stuff(&self, foo: &Foo) { + println!("{}", NameProvider::NAME); +} + +fn main() { + pub struct ContextA; + pub struct ContextB; + + let foo: Foo = Foo { + value: 1, + phantom: PhantomData, + }; + + // Both contexts can call do_stuff on the same foo value, + // because the Name implementation is fixed by RealName, not by the context. + ContextA.do_stuff(&foo); + ContextB.do_stuff(&foo); +} +``` + +In this version, the struct carries the provider type directly, so the choice of `Name` implementation is locked to `RealName` regardless of which context is used to call `do_stuff`. This provider binding is more flexible than the full-context binding, because any context can interact with the struct without needing to match the exact context type that created it. + +The trade-off is that this approach only fixes the binding for one specific trait. If multiple incoherent traits are involved and you want each one to be bound independently, the struct would need a separate provider parameter for each trait. Depending on how many traits are involved, those parameters can become verbose. The [full-context approach](#binding-an-implementation-to-a-struct) described earlier handles several traits more uniformly, at the cost of tying the struct to a single concrete context type. + +### Contexts and capabilities + +Nadrieril's second post, [**What If Traits Carried Values**](https://nadrieril.github.io/blog/2026/03/22/what-if-traits-carried-values.html), explores how Tyler Mandry's [**contexts and capabilities**](https://tmandry.gitlab.io/blog/posts/2021-12-21-context-capabilities/) proposal could be implemented using dictionary-passing style. Its motivating example passes a `BasicArena` value into an implementation of `Deserialize`: + +```rust title="Incoherent Rust" +capability arena; + +impl<'a> Deserialize for &'a Foo +where + arena: &'a BasicArena, +{ + ... +} + +fn main() -> Result<(), Error> { + let bytes = read_some_bytes()?; + with arena = &arena::BasicArena::new() { + let foos: Vec<&Foo> = deserialize(bytes)?; + println!("foos: {:?}", foos); + } + Ok(()) +} +``` + +As my [`cgp-serde` blog post](/blog/cgp-serde-release) explains, CGP's [incoherent traits](#incoherent-traits) already pass runtime values alongside trait implementations through the `Context` type. CGP's [**implicit arguments**](/docs/concepts/implicit-arguments) make the values in the context's fields easier to read. + +With them, the example above desugars into this CGP code: + +```rust title="CGP" +// cgp-serde's deserialization component, with the target `Value` in place of `Self`: +// +// #[cgp_component(ValueDeserializer)] +// pub trait CanDeserializeValue<'de, Value> { +// fn deserialize(&self, deserializer: D) -> Result +// where +// D: serde::Deserializer<'de>; +// } + +#[cgp_impl(new DeserializeFooRef)] +#[uses(CanDeserializeValue<'de, Foo>)] +impl<'de, 'a> ValueDeserializer<'de, &'a Foo> { + fn deserialize( + &self, + // The arena is "passed" as an implicit argument through the context. + // Its field already holds a reference, which the argument borrows as `&&`. + #[implicit] arena: &&'a Arena, + deserializer: D, + ) -> Result<&'a Foo, D::Error> + where + D: serde::Deserializer<'de>, + { + let foo = self.deserialize(deserializer)?; + Ok(arena.alloc(foo)) + } +} + +// The `Context` type now contains fields instead of being an empty struct. +#[derive(HasField)] +pub struct Context<'a> { + pub arena: &'a Arena, +} + +delegate_components! { + <'a> Context<'a> { + open ValueDeserializerComponent; + + ErrorTypeProviderComponent: + UseAnyhowError, + ErrorRaiserComponent: + RaiseAnyhowError, + @ValueDeserializerComponent.u64: + UseSerde, + @ValueDeserializerComponent.Foo: + DeserializeRecordFields, + @ValueDeserializerComponent.<'b> &'b Foo: + DeserializeFooRef, + // A context-generic provider from cgp-serde that implements + // deserialization using the `Extend` method of the container. + @ValueDeserializerComponent.<'b> Vec<&'b Foo>: + DeserializeExtend, + } +} + +fn main() -> Result<(), anyhow::Error> { + let json = read_some_json()?; + let arena = Arena::new(); + + // The `with` binding becomes a field assignment to a local `context` value. + let context = Context { arena: &arena }; + + // `deserialize_json_string` is a method from cgp-serde-json that wraps + // `serde_json` deserialization in a context-generic way. + let foos: Vec<&Foo> = context.deserialize_json_string(&json)?; + println!("foos: {:?}", foos); + + Ok(()) +} +``` + +Passing the context through `&self` pays off here: the same value that selects the implementations also carries the arena they need. [cgp-serde](/docs/projects/cgp-serde/)'s [context services](/docs/projects/cgp-serde/architecture/context-services) page explains how a deserializer takes a service such as an arena from its context. + +--- + +## Context as dictionary + +In the desugared CGP code of the [previous sections](#expressing-incoherence-with-cgp), the additional generic `Context` type works much like the dictionaries described in Nadrieril's post on [**Elaborating Rust Traits to Explicit Trait Proofs**](https://nadrieril.github.io/blog/2026/03/20/dictionary-passing-style.html). + +That post rewrites Rust code in dictionary-passing style: a trait becomes a struct of function pointers, each impl becomes a constant of that struct, and a trait bound becomes a const generic argument that passes one of those constants along. + +### Context-aware dictionaries + +Suppose that we want to combine Nadrieril's dictionaries with Boxy's incoherence, and make `Clone` an [incoherent trait](#incoherent-traits). [Nadrieril's post](https://nadrieril.github.io/blog/2026/03/20/dictionary-passing-style.html#trait-solving-is-elaboration) writes a `Clone` example in made-up notation for explicit trait proofs, which names each impl and passes it explicitly: + +```rust title="Explicit trait proofs" +trait Clone { + fn clone(&self) -> Self; +} + +// This syntax gives a name to the impl. +impl "clone_u32" Clone for u32 { ... } + +// This takes two arguments: the explicit `T`, and the implicit `T: Clone`. +impl "clone_vec" Clone for Vec +where + clone_t: (T: Clone) // weird syntax don't @ me +{ + fn clone(&self) -> Self { + vec + .iter() + // We use the trait bound explicitly here + .map(|x: &T| clone_t::clone(x)) + .collect() + } +} + +let my_vec: Vec = vec![0, 1, 2]; +// square brackets is my syntax for passing implicit params: +clone_vec::[clone_u32]::clone(&my_vec); +``` + +Following the [earlier sections](#expressing-incoherence-with-cgp), the CGP translation is: + +```rust title="CGP" +#[cgp_component(CloneImpl)] +trait Clone { + fn clone(&self, value: &T) -> T; +} + +#[cgp_impl(new CloneU32)] +impl CloneImpl { ... } + +#[cgp_impl(new CloneVec)] +#[uses(Clone)] +impl CloneImpl> { + fn clone(&self, values: &Vec) -> Vec { + values + .iter() + .map(|value| self.clone(value)) + .collect() + } +} + +fn main() { + struct Context; + + delegate_components! { + Context { + open CloneImplComponent; + + @CloneImplComponent.u32: CloneU32, + @CloneImplComponent.Vec: CloneVec, + } + } + + let my_vec: Vec = vec![0, 1, 2]; + let cloned_vec = Context.clone(&my_vec); +} +``` + +Set beside Nadrieril's version, the CGP code shows its `Context` type acting as a [type-level dictionary](/docs/concepts/type-level-tables). Each [`delegate_components!`](/docs/reference/macros/delegate_components) entry plays the part of one of Nadrieril's dictionaries, and the context holds them all, so CGP already follows the programming model of dictionary-passing style closely. + +Because of that closeness, CGP code could be desugared naturally into [dictionary-passing style](https://nadrieril.github.io/blog/2026/03/20/dictionary-passing-style.html), as in Nadrieril's [PolyMiniRust](https://nadrieril.github.io/blog/2026/06/16/formal-spec-vision.html), where every trait proof is explicit. The context would become a dictionary that holds the other dictionaries as fields, almost one per `delegate_components!` entry. Each of those dictionaries would take the context as an extra parameter and look up the others through it. The dictionaries would then need no fixed order of instantiation, because the context would be a single root from which every dependency can be reached. + +### Cyclic providers + +The context stops serving as a single root for every dependency when a provider depends on itself. CGP's lookups are trait obligations, so a provider that needs the very instance it is defining overflows the trait solver with `E0275`. A serializer for a linked list that serializes its tail through the context is one such provider. [Rust's own proposals](/docs/comparisons/rust-language-proposals#the-context-as-a-dictionary) explains this limit and its usual workaround: a provider written for the concrete context. Recursive providers like this are a concrete use case for the cyclic impls that [Nadrieril](https://nadrieril.github.io/blog/2026/05/14/when-can-traits-depend-on-themselves.html) and [Niko Matsakis](https://smallcultfollowing.com/babysteps/series/cyclic-trait-impls/) study. The linked list has the shape of [perfect derive](https://nadrieril.github.io/blog/2026/05/14/when-can-traits-depend-on-themselves.html#perfect-derive), the motivating example in Niko Matsakis's series, and sound cyclic impls of that kind could remove the workaround. + +--- + +## Limitations and open challenges + +Passing every dependency through one generic `Context` type has several advantages. It keeps the desugaring simple, and it makes the semantics of Incoherent Rust code easy to reason about: the context maintains a locally scoped coherence, so all code that uses the same `Context` type receives the same trait implementation. + +Because the context serves as a top-level dictionary for the other trait dictionaries, it also simplifies how they are instantiated with their dependencies, though not when those dependencies form cycles, as the section on [cyclic providers](#cyclic-providers) explains. + +That said, several limitations may prevent the single-context approach from working in the general case. + +### Mutable or owned value access + +The biggest limitation is that a single context cannot easily supply mutable or owned values to trait implementations. The desugared trait methods always take `&self`, and mutable or owned values cannot be taken out of a borrowed context. + +Changing the parameter to `&mut self` or `self` does not help either. The change would spread to every caller, forcing all methods to take `&mut self` or `self`, and it would significantly limit the order in which methods can be called, especially methods that return references borrowed from other parameters. + +[Nadrieril's post](https://nadrieril.github.io/blog/2026/03/22/what-if-traits-carried-values.html#linearity) also notes that bounds whose dictionaries carry such values would need ownership semantics: a dictionary that carries a `&mut` must not be passed to two functions at once, and its methods would implement `FnMut` or `FnOnce` rather than plain function pointers. + +A simple way around the problem, which Nadrieril also proposes, is to limit capabilities to `Copy` values and use [interior mutability](https://doc.rust-lang.org/book/ch15-05-interior-mutability.html). After all, `RefCell`, `Arc`, and `Clone` already let code mutate or copy values from a borrowed context. + +But if Rust chooses to support `&mut` or owned values as capabilities too, it may need to pass each of them as a separate parameter, rather than grouping them in a single context. + +### Nested dynamically scoped bindings + +Another key limitation is that CGP binds every runtime value and trait implementation in one place, where the concrete context type is defined. Binding everything in one place can severely limit where an incoherent trait implementation can be called. + +In [**What If Traits Carried Values**](https://nadrieril.github.io/blog/2026/03/22/what-if-traits-carried-values.html), Nadrieril presents [**scoped impls**](https://nadrieril.github.io/blog/2026/03/22/what-if-traits-carried-values.html#scoped-impls): a trait impl may be defined anywhere, and uses of the trait within its scope take that local impl, overriding any global or outer one. + +For example, a user may want to introduce new bindings freely in different functions, rather than in one place: + +```rust title="Incoherent Rust" +fn deserialize_and_print_foo(json_string: &str) { + let foo: Vec<&Foo> = + with arena = &arena::BasicArena::new() { + serde_json::deserialize(json_string).unwrap() + }; + + println!("foos: {:?}", foo); +} + +fn deserialize_and_print_upper_foo(json_string: &str) { + local impl<'de> Deserialize<'de> for String { + // Deserialize string as uppercase + ... + } + + // Expect the string fields to become uppercase + deserialize_and_print_foo(json_string); +} +``` + +With a single context, varying its bindings from one call site to another would be very hard. The compiler would have to choose one place to define the context, such as inside `deserialize_and_print_foo`. That anonymous context would then be out of reach of `deserialize_and_print_upper_foo`, which could not override the implementation of `Deserialize` for `String`. + +Supporting such scoped bindings through a single context type might lead to something that resembles **inheritance** in OOP: to modify the trait bindings at different scopes, the context would need some kind of inheritance relationship with a parent context. + +I point out the resemblance not to advocate OOP-style inheritance in Rust, but to show that supporting this kind of binding may bring inheritance-like behavior into Rust code. + +CGP already has a static form of this inheritance for wiring: a [namespace](/docs/concepts/namespaces) lets a context inherit a shared table, but a context [cannot replace a binding it inherits](/docs/concepts/namespaces#overriding-a-bound-entry), and scoped impls need exactly that override. + +Readers who know Scala may notice that the scoped bindings above strongly resemble Scala's [implicit parameters](/docs/comparisons/implicit-parameters), which Rust might not want to support. CGP's [implicit arguments](/docs/concepts/implicit-arguments) differ from them: every implicit argument must come from one flattened context type. + +These limitations raise the question of whether Rust should let users bind [capabilities](#contexts-and-capabilities) or [incoherent trait implementations](#named-impls) anywhere in the code. Such code might desugar into dictionary-passing style in other ways, but those ways may make Incoherent Rust code much harder to reason about. + +On the other hand, the restricted Incoherent Rust that CGP provides may encourage more disciplined code. Because every binding is made where a context type is defined, a reader can usually find the implementations a context uses in one place, its [`delegate_components!`](/docs/reference/macros/delegate_components) block, which keeps the semantics of context-generic code within a specific context relatively simple. + +--- + +## Where CGP diverges from Incoherent Rust + +So far, this post has covered [how CGP can express Incoherent Rust](#expressing-incoherence-with-cgp). This section turns to the other direction: what CGP's providers and contexts can do that the current designs of Incoherent Rust do not support directly. The [dictionary model](https://nadrieril.github.io/blog/2026/03/20/dictionary-passing-style.html) behind those designs can express several of these ideas, since its dictionaries can take other dictionaries and hold types. I offer the ideas in the hope that Incoherent Rust will support what CGP users already rely on. The Incoherent Rust snippets in this section are my own sketches of how the current designs might extend, not syntax from the proposals. + +### Named impls as provider types + +The most notable difference is that [Boxy's](https://www.boxyuwu.blog/posts/an-incoherent-rust/#named-impls-and-trait-bound-parameters) and [Nadrieril's](https://nadrieril.github.io/blog/2026/03/20/dictionary-passing-style.html) posts treat [named implementations](#named-impls) as a different kind of entity from ordinary Rust types. Given named impls like: + +```rust title="Incoherent Rust" +impl Impl1 = Clone for MyType { ... } +impl Impl2 = Clone for MyType { ... } +``` + +the implementations `Impl1` and `Impl2` are not Rust types. They can be passed where a trait bound is expected, but they cannot stand where a type does, such as in a type alias or a type-level list. + +In contrast, CGP's named implementations, called [providers](/docs/concepts/consumer-and-provider-traits#providers-as-type-level-names), are ordinary Rust types that compose with other Rust types. + +#### Multiple implementations on the same name + +Among other things, a CGP provider can implement several provider traits. In Incoherent Rust, the equivalent might look like: + +```rust title="Incoherent Rust" +impl MyMatrixSerde = Serialize for Matrix { ... } + +// How to disambiguate intentional name sharing vs accidental naming? +impl MyMatrixSerde = Deserialize for Matrix { ... } +``` + +Here `MyMatrixSerde` is one named implementation of both `Serialize` and `Deserialize` for `Matrix`. In CGP, it becomes: + +```rust title="CGP" +// A provider is just a struct +pub struct MyMatrixSerde; + +#[cgp_impl(MyMatrixSerde)] +impl SerializeImpl { ... } + +#[cgp_impl(MyMatrixSerde)] +impl DeserializeImpl { ... } +``` + +#### Grouping named impls + +Because CGP's named impls are types, related implementations can be grouped under a single name, which CGP calls an [aggregate provider](/docs/concepts/aggregate-providers). For example, we might want to group the `Serialize` and `Deserialize` implementations of all domain types defined across different modules. + +With Incoherent Rust, we might need additional syntax to support aliasing, such as: + +```rust title="Incoherent Rust" +impl MyAppSerde = Serialize for Matrix = MyMatrixSerialize; +impl MyAppSerde = Deserialize for Matrix = MyMatrixDeserialize; +impl MyAppSerde = Serialize for Scalar = MyScalarSerialize; +impl MyAppSerde = Deserialize for Scalar = MyScalarDeserialize; +``` + +CGP has dedicated notation for such grouping: [`delegate_components!` with the `new` keyword](/docs/reference/macros/delegate_components#defining-the-target-at-the-same-time) declares the aggregate provider and its table in one block, and an [`open` statement](/docs/reference/macros/delegate_components#choosing-a-provider-per-type-the-open-statement) inside it keys each entry by component and value type, as in `@SerializeImplComponent.Matrix: MyMatrixSerialize`. + +#### Higher-order providers + +CGP also supports [higher-order providers](/docs/concepts/higher-order-providers), where a provider explicitly accepts other providers as generic parameters. A higher-order provider binds its inner providers directly, rather than through the context as other providers do. + +For example, a `SerializeIterator` named impl in Incoherent Rust might look like: + +```rust title="Incoherent Rust" +impl SerializeIterator = + Serialize for T +where + T: IntoIterator, + ItemSerializer: Serialize for T::Item, +{ ... } +``` + +Here the named impl `SerializeIterator` takes an inner named impl, `ItemSerializer`, which serializes the `::Item` type. + +In CGP, `SerializeIterator` is a plain struct with the inner provider as a phantom type parameter, and its implementation binds that parameter with [`#[use_provider]`](/docs/reference/attributes/use_provider), as the [higher-order providers](/docs/concepts/higher-order-providers#wrapping-a-provider) page shows with a scaling wrapper. + +#### Type-level DSLs + +Since CGP's named implementations are just types, higher-order providers also enable design patterns that go beyond what the current sketches of Incoherent Rust describe. [Hypershell](/docs/projects/hypershell/), for example, uses higher-order providers to build a type-level DSL for shell scripting in Rust, a pattern the [type-level DSLs](/docs/concepts/type-level-dsls) page explains. + +After desugaring, a [Hypershell program is a plain Rust type](/docs/projects/hypershell/#a-program-that-is-a-type): the shell command `echo hello world!` becomes a `Pipe` of higher-order providers that names the command, its arguments as type-level strings, and where its output goes. The [Hypershell announcement](/blog/hypershell-release) explains this design in depth. If Incoherent Rust treats named implementations differently from Rust types, such type-level DSLs would be much more difficult to build from named impls. + +### Contexts as explicit types + +Another key distinction is that CGP contexts are explicit Rust types, so a context can be used like any other Rust type, even inside a larger context. The capability designs, such as [contexts and capabilities](https://tmandry.gitlab.io/blog/posts/2021-12-21-context-capabilities/), instead assume an implicit ambient context that carries impls and values from callers to callees, which makes them more restrictive when implementing traits for concrete types. + +For example, in CGP it is common to define an [application context](/docs/concepts/modularity-hierarchy#value-contexts-and-application-contexts) that contains both provider wirings and runtime fields, read through [`HasField`](/docs/reference/traits/field-access/has_field), together with additional constructors for building that context: + +```rust title="CGP" +#[derive(HasField)] +pub struct App { + // Runtime values accessible by providers + pub database: Database, + pub s3_client: S3Client, + pub redis_cache: redis::Client, + ... +} + +delegate_components! { + App { + // Use higher-order provider to provide caching middlewares + UserQuerierComponent: + CachedQueryUser, + ... + } +} + +// App is used in the return type +pub async fn build_app_from_config( + config: &Config, +) -> Result { + ... +} +``` + +With Incoherent Rust, it might be possible to implement something like `query_user` through [named impls](#named-impls) and [capabilities](#contexts-and-capabilities), but each binding would be explicit, so developers may need more code to bridge into concrete contexts: + +```rust title="Incoherent Rust" +impl App { + pub async fn query_user( + &self, + user_id: &UserId, + ) -> Result { + // convert field values into capabilities using `with` + with + database = &self.database, + redis_cache = &self.redis_cache, + { + // Explicitly call named impls + + as UserQuerier + >::query_user().await + } + } +} +``` + +Because CGP works with concrete Rust types, an explicit context type avoids the manual bridging that ambient capabilities would require. The [capabilities comparison](/docs/comparisons/capabilities) sets CGP beside these and other capability designs. + +--- + +## Ideas from CGP for Incoherent Rust + +The rest of CGP's divergences are ideas the current designs could take up: [functions that defer their implementation choices](#incoherent-functions), [traits without a `Self` type whose implementation the context chooses](#selfless-traits), and [types chosen by the context](#abstract-types). + +### Incoherent functions + +The CGP functions annotated with [`#[cgp_fn]`](/docs/reference/macros/cgp_fn), [seen earlier](#using-incoherent-trait-bounds), suggest a new concept that I call **incoherent functions**: functions that use an incoherent trait without knowing which implementation is chosen, leaving that choice to a coherent caller. + +Take the `do_stuff` CGP function [from earlier](#using-incoherent-trait-bounds): + +```rust title="CGP" +#[cgp_fn] +#[uses(Name)] +pub fn do_stuff(&self, foo: &Foo) { + println!("{}", Self::NAME); +} +``` + +It can be read as equivalent to this Incoherent Rust function: + +```rust title="Incoherent Rust" +pub incoherent fn do_stuff(foo: &Foo) +where + impl NameImpl: Name, +{ + println!("{}", NameImpl::NAME); +} +``` + +Other incoherent functions can then call `do_stuff` without restating its `where` bound: + +```rust title="Incoherent Rust" +pub incoherent fn do_more_stuff(foo: &Foo) { + // no need to specify `where impl NameImpl: Name` + do_stuff(foo); +} +``` + +which is equivalent to the CGP function: + +```rust title="CGP" +#[cgp_fn] +#[uses(DoStuff)] +pub fn do_more_stuff(&self, foo: &Foo) { + self.do_stuff(foo); +} +``` + +So incoherent functions can call each other without spelling out every transitive incoherent trait bound of the functions they call. All those bounds are gathered and resolved at once, when a coherent function calls into the incoherent world. + +Together, incoherent functions set up an incoherent world, isolated from the coherent world where all existing Rust code lives. As with async functions, the split [colors functions](https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/): incoherent traits and functions can freely call coherent or incoherent ones, but coherent code cannot call incoherent code without explicitly binding every incoherent trait implementation it requires. + +This separation between the incoherent and coherent worlds is essential, because it simplifies the semantics and creates a clear boundary for where the bindings for incoherent implementations can be specified. + +In CGP, the incoherent world is any code that works with a generic context. Each `#[cgp_fn]` function desugars into a trait with a blanket implementation over the context, as [Impl-side dependencies](/docs/concepts/impl-side-dependencies) explains, and those impl-side dependencies hide each function's use of other CGP functions behind its trait's interface. The boundary between the two worlds lies where a top-level context type is defined. Once that type is defined, every incoherent binding is final, and we are back in the coherent world, which needs no generic context. + +As [noted earlier](#nested-dynamically-scoped-bindings), this clean separation holds only without dynamically scoped impls and capabilities. A full version of Incoherent Rust may not keep such a clear boundary, and its semantics would then differ considerably from CGP's. + +For readers familiar with monads and algebraic effects, the incoherent world of a generic context can be understood as a form of effect, or more precisely as a coeffect, which describes what a computation requires from its environment. The [algebraic effects comparison](/docs/comparisons/algebraic-effects#coeffects) develops that reading. + +### Selfless traits + +As the section on [incoherent traits](#incoherent-traits) showed, CGP desugars an incoherent trait into a CGP trait whose `Self` is the context, and moves the original `Self` type into a generic parameter, as `Serialize` does. CGP code also commonly defines traits with no generic parameter besides the context, such as: + +```rust title="CGP" +#[cgp_component(GreetImpl)] +pub trait Greet { + fn greet(&self); +} +``` + +Nadrieril's [**Capabilities using Plain Traits**](https://nadrieril.github.io/blog/2026/06/07/capabilities-with-plain-traits.html) arrives at traits of a similar shape from another direction. His post uses *capability* in a narrower sense than this one: a permission that carries no value, such as being allowed to call Unix-only APIs or to unwind. He expresses each capability as an ordinary trait bound on a zero-sized `Env` type. A function that calls Unix-only APIs declares `where Env: Unix`, and in his sketch, the standard library implements `Unix` for `Env` only when compiling for Unix. In his terms, a capability is a zero-sized context. He also observes that a standard set of such capability traits, covering I/O, allocation, unwinding, and the like, amounts to a small effect system. + +Because `Env` serves only as a placeholder, he goes on to imagine dropping it. *Selfless traits* are traits without a `Self` type, marked with a `#[selfless]` attribute, and with them the bound `Env: Unix` becomes just `Unix`. + +His capability traits have no methods. Each one only states whether something is allowed, and the target platform, or a runtime check such as CPU feature detection, decides whether it holds. An incoherent selfless trait would instead carry methods, with an implementation that the context chooses. In Incoherent Rust, the `Greet` trait above would be such a trait, with neither a `Self` type nor a generic parameter. The Incoherent Rust snippets in this section are my own sketches, combining Boxy's [named impls](https://www.boxyuwu.blog/posts/an-incoherent-rust/#named-impls-and-trait-bound-parameters) with Nadrieril's [`#[selfless]`](https://nadrieril.github.io/blog/2026/06/07/capabilities-with-plain-traits.html#selfless-traits) attribute: + +```rust title="Incoherent Rust" +#[selfless] +pub incoherent trait Greet { + fn greet(); // no use of `self` or `Self` +} +``` + +Incoherence and [value-carrying capabilities](#contexts-and-capabilities) together suggest a useful pattern: incoherent selfless traits whose implementations work only with the ambient context. For example, the `Greet` trait could be implemented with: + +```rust title="Incoherent Rust" +impl GreetHello = Greet +with + name: &String, +{ + fn greet() { + println!("Hello, {}!", name); + } +} +``` + +In CGP, the context type is explicit, so an incoherent selfless trait becomes a CGP trait whose only type is the context, and that trait needs no new syntax. The provider reads the name from the context through an [implicit argument](/docs/concepts/implicit-arguments), written with [`#[implicit]`](/docs/reference/attributes/implicit): + +```rust title="CGP" +#[cgp_impl(new GreetHello)] +impl GreetImpl { + fn greet( + &self, + #[implicit] name: &String, + ) { + println!("Hello, {}!", name); + } +} +``` + +### Abstract types + +Associated types within [selfless traits](#selfless-traits) give CGP's [abstract types](/docs/concepts/abstract-types). For example, we can introduce an abstract type called `Name` with the following trait, written with [`#[cgp_type]`](/docs/reference/macros/cgp_type): + +```rust title="CGP" +#[cgp_type] +pub trait HasNameType { + type Name: Display; +} +``` + +An abstract type is not tied to any particular value type. The context chooses its concrete form. The [earlier `GreetHello` implementation](#selfless-traits) can use the abstract `Name` type instead, imported with [`#[use_type]`](/docs/reference/attributes/use_type): + +```rust title="CGP" +#[cgp_impl(new GreetHello)] +#[use_type(HasNameType.Name)] +impl GreetImpl { + fn greet( + &self, + #[implicit] name: &Name, + ) { + println!("Hello, {}!", name); + } +} +``` + +The `name` parameter now has the abstract type `HasNameType::Name` instead of a hardcoded `String`, so the same provider works with whichever name type the context wires in. + +A context then chooses the concrete type in its wiring through [`UseType`](/docs/reference/providers/use_type), such as a `FullName` struct with first and last name fields, as the [abstract types](/docs/concepts/abstract-types#choosing-the-type-by-wiring) page shows. + +#### Abstract types in Incoherent Rust + +In Incoherent Rust, abstract types would start from `HasNameType` as a selfless trait: + +```rust title="Incoherent Rust" +#[selfless] +pub incoherent trait HasNameType { + type Name: Display; +} +``` + +Since abstract types are built on top of [selfless traits](#selfless-traits), using them requires new syntax to bind and reference the abstract type: + +```rust title="Incoherent Rust" +impl GreetHello = Greet +where + impl NameType: HasNameType, +with + name: &NameType::Name, +{ + fn greet() { + println!("Hello, {}!", name); + } +} +``` + +Here, `GreetHello` requires the context to provide an implementation of `HasNameType` and binds it to the local identifier `NameType`. The abstract type is then referenced as `NameType::Name` when specifying the type of the `name` capability. + +With the implementation in place, we can set up the wiring and call `GreetHello::greet()` as follows: + +```rust title="Incoherent Rust" +impl UseFullNameType = HasNameType { + type Name = FullName; +} + +fn main() { + with + UseFullNameType, + name = FullName { + first_name: "John".to_owned(), + last_name: "Smith".to_owned(), + } + { + // Prints "Hello, John Smith!" + GreetHello::greet(); + } +} +``` + +Here, the `with` block chooses `UseFullNameType` as the incoherent implementation for `HasNameType` and binds the capability `name` to a `FullName` value. When `GreetHello::greet()` runs, the trait system supplies both the type implementation and the name value, and the greeting prints. + +#### Using abstract types across incoherent traits + +The [`Name` example](#abstract-types) leaves open why an associated type on a [selfless trait](#selfless-traits) is better than one on an ordinary trait. Consider a `touch` function that sets the `last_modified` field of any type that supports it. With plain Rust traits, the time type either becomes an extra generic parameter, which still ties `touch` to `SystemTime::now()`, or becomes an associated type of `UpdateLastModified`. That associated type gives every value type its own time type and clock, so swapping in a mock clock for a test means changing each of them. + +With selfless traits and Incoherent Rust, we can write the following instead: + +```rust title="Incoherent Rust" +// An abstract type trait is a selfless trait with an associated type +#[selfless] +pub incoherent trait HasTimeType { + type Time; +} + +// The current time is provided by the ambient context using a selfless trait +#[selfless] +pub incoherent trait CurrentTime +where + impl TimeImpl: HasTimeType, +{ + fn current_time() -> TimeImpl::Time; +} + +// The `Time` type does not depend on `Self` +pub trait UpdateLastModified +where + impl TimeImpl: HasTimeType, +{ + fn update_last_modified( + &mut self, + time: TimeImpl::Time, + ); +} + +// The time type and current time implementations are not bound to `T` +pub incoherent fn touch( + value: &mut T, +) +where + impl TimeImpl: HasTimeType + CurrentTime, +{ + let time = TimeImpl::current_time(); + value.update_last_modified(time); +} +``` + +With selfless traits, implementations need not be bound to any particular `Self` type or generic parameter. When two value types, such as `Folder` and `File`, both need `touch`, they can share one time implementation through the ambient context instead of each carrying its own. + +The same example can be expressed in CGP today as: + +```rust title="CGP" +#[cgp_type] +pub trait HasTimeType { + type Time; +} + +#[cgp_component(CurrentTimeImpl)] +#[use_type(HasTimeType.Time)] +pub trait CurrentTime { + fn current_time(&self) -> Time; +} + +#[cgp_component(UpdateLastModifiedImpl)] +#[use_type(HasTimeType.Time)] +pub trait UpdateLastModified { + fn update_last_modified(value: &mut T, time: Time); +} + +#[cgp_fn] +#[uses(CurrentTime, UpdateLastModified)] +pub fn touch(&self, value: &mut T) { + let time = self.current_time(); + Self::update_last_modified(value, time); +} +``` + +CGP converts [selfless traits](#selfless-traits) into traits that are bound to the generic context, while the original `Self` type from the Incoherent Rust version becomes an explicit generic parameter `T`. With this structure, traits like `HasTimeType` and `CurrentTime` are bound to the context rather than to any particular value type. The example shows the benefit of anchoring abstract types to the context: several value types share one interchangeable choice, and none of them carries its own copy. + +--- + +## Related work + +Other languages have already given up global coherence, each in its own way. [Cairo](/docs/comparisons/traits-without-coherence#cairo) infers named impls from those in scope at each call site, [Scala](/docs/comparisons/traits-without-coherence#scala) resolves `given` instances by scope and priority, [OCaml's modular implicits](/docs/comparisons/traits-without-coherence#ocaml-modular-implicits) choose module arguments from scope and reject ambiguity, and [Haskell](/docs/comparisons/traits-without-coherence#haskell) offers overlapping and incoherent instances as exceptions to global uniqueness. The website's [traits without coherence](/docs/comparisons/traits-without-coherence) page compares these designs with CGP, and its [ML modules](/docs/comparisons/ml-modules) and [implicit parameters](/docs/comparisons/implicit-parameters) pages cover OCaml and Scala in more depth. + +### Lessons for Rust + +The designs that give up global coherence share three problems. Call sites can resolve the same type differently, a choice can change with what a module imports, and a data structure such as a hash map needs one implementation used consistently. They answer these problems in different ways. Haskell keeps one answer for the whole program and relaxes it only by exception. Cairo, Scala, and modular implicits infer the choice from what is in scope. [Boxy's sketch](https://www.boxyuwu.blog/posts/an-incoherent-rust/#named-impls-and-trait-bound-parameters) names it explicitly at each call, and CGP centralizes it on a [context type](#contexts-as-explicit-types) that is defined once. + +A single global answer needs no wiring at all, but where Haskell's [overlap extensions](/docs/comparisons/type-classes#overlapping-instances) apply, GHC's manual warns that different parts of a program can choose different instances. Inference from scope is convenient in small programs, but it ties the choice to imports. Scala, for one, has reworked its mechanism: Scala 3 separates `given` definitions from `using` parameters, where Scala 2 wrote `implicit` for both. Explicit naming is precise, but it repeats the choice at every call. CGP's centralized context is more verbose up front, yet every call through a context uses the same choice, and a reader finds that choice in one [`delegate_components!`](/docs/reference/macros/delegate_components) block. If Incoherent Rust adopts [scoped](#nested-dynamically-scoped-bindings) or inferred impls, a context-like mechanism that fixes the choices for a whole program, alongside the lower-level machinery, is worth considering too. + +--- + +## Conclusion + +This post has explored how CGP relates to the discussion of [dictionary-passing style](https://nadrieril.github.io/blog/2026/03/20/dictionary-passing-style.html) and [Incoherent Rust](https://www.boxyuwu.blog/posts/an-incoherent-rust/). The sections below sum up where CGP helps, where it helps only partly, and where it does not help. + +### What CGP helps solve + +#### A testing ground for Incoherent Rust + +The most direct takeaway is that CGP already lets programmers try, on stable Rust, many of the ideas in [Boxy's blog post](https://www.boxyuwu.blog/posts/an-incoherent-rust/): overlapping implementations become [named providers](#named-impls), and a [concrete context chooses among them](#using-incoherent-trait-bounds) through [`delegate_components!`](/docs/reference/macros/delegate_components). CGP's design has been refined across several releases and used in projects such as [cgp-serde](/docs/projects/cgp-serde/) and [Hypershell](/docs/projects/hypershell/), so its patterns have already met real code. CGP does not show how the compiler should implement these features: with [explicit trait proofs](https://nadrieril.github.io/blog/2026/03/20/dictionary-passing-style.html), the compiler could desugar named impls into proofs directly, without going through CGP's traits. What CGP can show is how code written in this style feels in practice, and which features real programs come to need. + +#### Trying contexts and capabilities today + +CGP's implicit arguments and field-carrying contexts also provide a way to try Tyler Mandry's [contexts and capabilities](https://tmandry.gitlab.io/blog/posts/2021-12-21-context-capabilities/) proposal today. Rather than threading runtime values through an ambient implicit scope, CGP passes them as fields of a concrete context, which providers read through [`HasField`](/docs/reference/traits/field-access/has_field) and [implicit arguments](/docs/concepts/implicit-arguments). As the [arena-backed `Deserialize` example](#contexts-and-capabilities) shows, this covers the core use case of capabilities. + +### What CGP partially solves + +#### Ecosystem evolution + +[Boxy's blog post](https://www.boxyuwu.blog/posts/an-incoherent-rust/#stunted-ecosystem-development) shows how the orphan rules hold back ecosystem evolution around foundational traits, with serde's `Serialize` as the example. CGP partially addresses this problem by allowing incoherent traits to be defined from scratch with an [explicit context parameter](#bypassing-coherence). What CGP cannot do is retroactively fix existing traits in the ecosystem that were designed without one. + +For traits that are already widely used, such as `Serialize` or `Hash`, adopting CGP's approach would require breaking changes to those trait definitions. Such breaking changes are not a realistic path in the short term. CGP offers a model for designing new incoherent traits, but it does not address the ecosystem fragmentation that already exists. + +A language feature would do better here. Programmers would not need to add a context parameter to their traits, because the compiler would handle incoherent traits itself. A trait like `Hash` or `Serialize` would still need to opt into incoherence somehow, such as with an [`incoherent` keyword](https://www.boxyuwu.blog/posts/an-incoherent-rust/#incoherent-traits), and whether that opt-in could avoid a breaking change remains an open question. + +That question stands however the compiler implements incoherent traits. Before committing to a design, the Rust community would need to decide how existing traits can evolve toward incoherence without fracturing the code that depends on them. + +### What CGP doesn't solve + +#### Formalization of Rust + +The [dictionary-passing work](https://github.com/rust-lang/goals/issues/630) began with soundness: computing each trait proof once, checking it, and giving Rust's trait system a formal footing that can help avoid compiler bugs. CGP does not contribute to that goal. It is a library-level pattern built on the existing trait system, it relies on coherence to function correctly, and it cannot replace or formalize the trait solver itself. + +[Explicit trait proofs](https://nadrieril.github.io/blog/2026/03/20/dictionary-passing-style.html), in the compiler and in a specification language such as Nadrieril's [PolyMiniRust](https://nadrieril.github.io/blog/2026/06/16/formal-spec-vision.html), remain the right direction for that work, and CGP code would benefit from them like any other Rust code. + +#### Dynamic scoping and mutable values + +The two [limitations](#limitations-and-open-challenges) described earlier also remain unsolved. CGP binds every implementation and value where the concrete context is defined, so it cannot express the [nested, dynamically scoped bindings](#nested-dynamically-scoped-bindings) that [scoped impls](https://nadrieril.github.io/blog/2026/03/22/what-if-traits-carried-values.html#scoped-impls) envision, and its shared `&self` context cannot hand providers [mutable or owned values](#mutable-or-owned-value-access) without interior mutability. + +### The future of CGP with an Incoherent Rust + +If features like [Incoherent Rust](https://www.boxyuwu.blog/posts/an-incoherent-rust/) and [contexts and capabilities](https://tmandry.gitlab.io/blog/posts/2021-12-21-context-capabilities/) are eventually implemented in Rust, they would likely make parts of the CGP library unnecessary. The boilerplate of defining [provider traits](/docs/concepts/consumer-and-provider-traits), implementing [`DelegateComponent`](/docs/reference/traits/wiring/delegate_component), and wiring components through [`delegate_components!`](/docs/reference/macros/delegate_components) exists precisely because today's Rust does not support incoherent traits natively. + +However, the underlying design patterns that CGP promotes, such as writing generic code against a context type, [deferring implementation choices to a top-level context](#incoherent-functions), and separating the definition of an interface from its wiring, would remain valuable regardless of how the language evolves. CGP's goal has never been to create a framework that developers depend on indefinitely. The goal is to enable [context-generic programming patterns](/docs/concepts/) in Rust, and ideally those patterns should eventually become idiomatic Rust that requires no special library support. + +Several of CGP's features go beyond the current sketches of Incoherent Rust, such as [providers that can be named and composed as types](#named-impls-as-provider-types), [incoherent functions](#incoherent-functions), and [abstract types chosen by a context](#abstract-types). If there is an opportunity for collaboration, I would be interested in working with the Rust compiler team to design and refine these features, so that Incoherent Rust can support what CGP users rely on today. Should Incoherent Rust's final design leave them out, CGP risks being unable to take full advantage of the new language and being forced to keep its own library encoding within the existing coherent trait system. + +If [explicit trait proofs](https://nadrieril.github.io/blog/2026/03/20/dictionary-passing-style.html) are implemented in nightly Rust, I would like to try desugaring CGP code into them in an experimental fork of Rust. The fork would not be a rival to Incoherent Rust: it would allow faster experimentation with that desugaring, without waiting for the design of Incoherent Rust to be finalized. It would implement CGP's features directly in the compiler, which would desugar them into the dictionary-passing intermediate representation. + +The current discussions of Incoherent Rust and dictionary-passing style point the same way CGP is headed, and I hope the two efforts keep learning from each other. + +I am grateful to Nadrieril, Boxy, Tyler Mandry, and Niko Matsakis for writing these ideas down in public, and to the [types team](https://www.rust-lang.org/governance/teams/compiler#team-types) for turning them into [project work](https://github.com/rust-lang/goals/issues/630). This post reads their designs from the outside, so I may have misread some of them. If I have, I would like to hear about it. + +--- + +*This post was drafted by the human author and then revised by an AI agent. The agent also checked the post's code and claims against the CGP knowledge base. See [How AI is used in this project](/docs/ai/disclaimer#blog-posts-and-tutorials).* diff --git a/docs/ai/disclaimer.md b/docs/ai/disclaimer.md index c44098b2..6139defe 100644 --- a/docs/ai/disclaimer.md +++ b/docs/ai/disclaimer.md @@ -136,15 +136,8 @@ it. Report a problem in the knowledge base on its [GitHub Discussions](https://github.com/orgs/contextgeneric/discussions) or on the repository it concerns. -## How pages are marked - -A new or substantially rewritten page carries a short note at the bottom, linking to the section -of this page that describes how it was made. The front page is the one exception and carries no -note. An older page gets a note only once its provenance has been established, so a page without -one may still have been written with AI assistance. - --- -*An AI agent wrote and revised this page using the +*This page was written and revised by an AI agent from the [CGP knowledge base](https://github.com/contextgeneric/cgp-knowledge-base). See [Documentation and reference pages](#documentation-and-reference-pages).* diff --git a/docs/ai/index.md b/docs/ai/index.md index 0715100a..52c3f186 100644 --- a/docs/ai/index.md +++ b/docs/ai/index.md @@ -55,5 +55,5 @@ it is checked: --- -*An AI agent wrote this page using the CGP knowledge base. See +*This page was written by an AI agent from the CGP knowledge base. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/ai/knowledge-base/contributing-with-an-agent.md b/docs/ai/knowledge-base/contributing-with-an-agent.md index 325a7069..28d2ee2b 100644 --- a/docs/ai/knowledge-base/contributing-with-an-agent.md +++ b/docs/ai/knowledge-base/contributing-with-an-agent.md @@ -148,5 +148,5 @@ page lists other ways to help CGP. --- -*An AI agent wrote this page using the CGP knowledge base. See +*This page was written by an AI agent from the CGP knowledge base. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/ai/knowledge-base/how-cgp-is-documented.md b/docs/ai/knowledge-base/how-cgp-is-documented.md index ed5429bb..0c158376 100644 --- a/docs/ai/knowledge-base/how-cgp-is-documented.md +++ b/docs/ai/knowledge-base/how-cgp-is-documented.md @@ -147,5 +147,5 @@ error in a page on this site or in the code, report it on the repository it conc --- -*An AI agent wrote this page using the CGP knowledge base. See +*This page was written by an AI agent from the CGP knowledge base. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/ai/knowledge-base/index.md b/docs/ai/knowledge-base/index.md index 4991c4da..b7799b5d 100644 --- a/docs/ai/knowledge-base/index.md +++ b/docs/ai/knowledge-base/index.md @@ -103,5 +103,5 @@ Choose the page that answers your question: --- -*An AI agent wrote this page using the CGP knowledge base. See +*This page was written by an AI agent from the CGP knowledge base. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/ai/knowledge-base/using-it-with-your-agent.md b/docs/ai/knowledge-base/using-it-with-your-agent.md index d60a6d91..a756dc73 100644 --- a/docs/ai/knowledge-base/using-it-with-your-agent.md +++ b/docs/ai/knowledge-base/using-it-with-your-agent.md @@ -97,5 +97,5 @@ prompt that surfaced it, so the document can be corrected. --- -*An AI agent wrote this page using the CGP knowledge base. See +*This page was written by an AI agent from the CGP knowledge base. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/ai/skills/index.md b/docs/ai/skills/index.md index 58096fa0..ec91bd72 100644 --- a/docs/ai/skills/index.md +++ b/docs/ai/skills/index.md @@ -56,5 +56,5 @@ has its own directory in this section, so more skills can be added alongside `/c --- -*An AI agent wrote and revised this page using the CGP knowledge base. See +*This page was written and revised by an AI agent from the CGP knowledge base. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/ai/skills/installation.md b/docs/ai/skills/installation.md index fa6572fd..6e45a676 100644 --- a/docs/ai/skills/installation.md +++ b/docs/ai/skills/installation.md @@ -206,5 +206,5 @@ files as they stood when this site was last built. --- -*An AI agent wrote and revised this page using the CGP knowledge base. See +*This page was written and revised by an AI agent from the CGP knowledge base. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/comparisons/algebraic-effects.md b/docs/comparisons/algebraic-effects.md index 2bd036c4..0e572213 100644 --- a/docs/comparisons/algebraic-effects.md +++ b/docs/comparisons/algebraic-effects.md @@ -312,6 +312,17 @@ what a computation does; a coeffect describes what it requires from its environm [Petricek's coeffects work](https://tomasp.net/coeffects/) develops that distinction. CGP's field and trait requirements suggest such a comparison, but CGP does not implement a coeffect calculus. +CGP's requirements point toward the coeffect side. A provider's trait and field requirements state +what it needs from its context, rather than operations it performs for an enclosing handler to +interpret, and the context carries both the implementation choices and the values that satisfy them. +Those requirements are resolved all at once, when a concrete context is defined: once its wiring is +complete, the code runs with fixed implementations, much as a computation returns a pure value once +all its effects are handled. The same wiring also chooses types, as +[Configuring abstract types through the same wiring](#configuring-abstract-types-through-the-same-wiring) +shows, while the effect handlers compared on this page pass operations and values rather than types. +This describes how requirements flow into CGP code, not a formal correspondence with a coeffect +calculus. + ## What each approach costs Effect handlers separate operation use from interpretation and support reusable control-flow @@ -395,6 +406,7 @@ assertion per wired context. --- -*An AI agent wrote this page using the CGP knowledge base. Its CGP code was verified against the -library's source and its other snippets against the toolchains named in Sources. See +*This page was written by an AI agent from the CGP knowledge base. Its CGP code was verified against +the library's source, and its other snippets were verified against the toolchains named in its +Sources section. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/comparisons/capabilities.md b/docs/comparisons/capabilities.md index a35b4782..02d7f4bc 100644 --- a/docs/comparisons/capabilities.md +++ b/docs/comparisons/capabilities.md @@ -374,6 +374,7 @@ with a `check_components!` assertion per wired context; the Scala snippet was co --- -*An AI agent wrote this page using the CGP knowledge base. Its CGP code was verified against the -library's source and its other snippets against the toolchains named in Sources. See +*This page was written by an AI agent from the CGP knowledge base. Its CGP code was verified against +the library's source, and its other snippets were verified against the toolchains named in its +Sources section. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/comparisons/dependency-injection.md b/docs/comparisons/dependency-injection.md index da44e202..8315420a 100644 --- a/docs/comparisons/dependency-injection.md +++ b/docs/comparisons/dependency-injection.md @@ -285,6 +285,7 @@ wired context. The Java snippets follow the framework documentation cited below. --- -*An AI agent wrote this page using the CGP knowledge base. Its CGP code was verified against the -library's source and its other snippets against the toolchains named in Sources. See +*This page was written by an AI agent from the CGP knowledge base. Its CGP code was verified against +the library's source, and its other snippets were verified against the toolchains named in its +Sources section. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/comparisons/dynamic-dispatch.md b/docs/comparisons/dynamic-dispatch.md index af003b9f..400fef68 100644 --- a/docs/comparisons/dynamic-dispatch.md +++ b/docs/comparisons/dynamic-dispatch.md @@ -1,323 +1,537 @@ --- sidebar_label: 'Dynamic dispatch' sidebar_position: 9 -description: 'Compare Context-Generic Programming static wiring with dynamic dispatch, duck typing, and prototype delegation, including how trait objects can coexist with CGP.' +description: 'How vtables, prototype chains, and dictionary lookup choose a method at runtime, and how Context-Generic Programming makes the same choice at compile time with static dispatch, beside dyn Trait.' --- -# Dynamic dispatch, dynamic typing, and prototypal inheritance +# Dynamic dispatch -[Context-Generic Programming](/docs/) supports interchangeable implementations and delegation while -resolving provider selection at compile time. CGP extends Rust with pluggable trait implementations, -chosen per context and resolved at compile time, as a library on stable Rust whose consumer traits -are ordinary Rust traits. For readers familiar with objects, messages, vtables, or prototypes, this -page explains the shared structure, the limits of static selection, and where runtime dispatch -remains useful. +How does a method call find the code it runs? [Context-Generic Programming](/docs/) (CGP) extends Rust with +pluggable trait implementations, chosen at compile time: each context names its implementations in a table, and the +compiler resolves a call through that table to a direct call, with static dispatch in place of a vtable lookup. +Dynamic dispatch answers the same question at runtime. This page is for readers who know vtables in Java, +Go's interfaces, or Rust's `dyn Trait`, or prototypes and classes in JavaScript and Python. It explains each answer, +then shows where CGP's lookup matches and differs. CGP is a library on stable Rust, its consumer traits are ordinary +traits, and it works beside runtime dispatch rather than replacing it. ## In your terms -A **context** is the type a CGP method runs on, supplying data through fields and implementations -through wiring. It plays the receiver's role: a provider operates on that context even when several -layers of delegation lead to the provider. +A **[context](/docs/reference/glossary#context)** is the type a CGP method runs on, supplying data through its fields +and implementations through its wiring. It plays the receiver's role. The page follows one greeting through the +languages it compares, and this table maps each runtime piece of it onto CGP and the Concepts page that explains it: -| In object-oriented code | In CGP | -| --- | --- | -| An object receiving a method call | A context value | -| An interface declaring methods | A consumer trait within a **component** | -| An implementation of that interface | A **provider** | -| A method table or vtable | A **wiring table**, resolved by the compiler | -| Shared behavior reached through delegation | An [aggregate provider](/docs/reference/glossary#aggregate-provider) or namespace | -| Checking that a receiver supports an operation | Trait bounds and `check_components!` | +| At runtime | In CGP | Explained in | +| --- | --- | --- | +| `context.greet()` | The [consumer trait](/docs/reference/glossary#consumer-trait) `CanGreet` | [Consumer and provider traits](/docs/concepts/consumer-and-provider-traits) | +| `greet_hello(context)`, a function given the context | The [provider](/docs/reference/glossary#provider) `GreetHello` | [Consumer and provider traits](/docs/concepts/consumer-and-provider-traits) | +| `context["name"]`, a field read by a string | `#[implicit] name: &str`, a field read by a type-level name | [Implicit arguments](/docs/concepts/implicit-arguments) | +| `context.name` in `greet_hello`, trusted to exist | The same field, a requirement of `GreetHello` that the compiler checks | [Impl-side dependencies](/docs/concepts/impl-side-dependencies) | +| `greet = greet_hello`, a class choosing its function | A [wiring](/docs/reference/glossary#wiring) entry in `delegate_components!`, keyed by `GreeterComponent` | [Type-level tables](/docs/concepts/type-level-tables) | +| `personPrototype`, an object that others ask | An [aggregate provider](/docs/reference/glossary#aggregate-provider) such as `PersonPrototype` | [Aggregate providers](/docs/concepts/aggregate-providers) | +| `undefined`, `AttributeError`, `TypeError` | `check_components!`, failing when the program is built | [Checking your wiring](/docs/concepts/check-traits) | ## The idea -Dynamic dispatch lets a call site invoke an implementation selected at runtime. Dynamic typing and -prototypal inheritance address related but separate questions: when operations are type-checked, -and how objects share behavior. Keeping these distinctions clear makes it possible to compare -CGP with each mechanism without treating them as one feature. +Dynamic dispatch chooses the code a call runs from a value known only at runtime. Dynamic typing is a separate +question, about when the call's validity is checked: Rust's `dyn Trait` dispatches at runtime but is checked at +compile time, while Python both checks and dispatches at runtime. -### Dynamic typing and duck typing +Ordinary Rust generics dispatch statically: a call through a `T: CanGreet` bound is compiled once for each concrete +type and calls the implementation directly. CGP does not add +[static dispatch](/docs/reference/glossary#static-dispatch), which Rust already has. Instead, it adds a choice that +each context records in a table. -Duck typing accepts an object according to the operations it supports. In a dynamically typed -language, a call such as `x.quack()` can work without a declared interface as long as the receiver -responds appropriately at runtime. This makes generic behavior convenient, but an unsupported -operation may fail only when the call executes. Python's -[glossary](https://docs.python.org/3/glossary.html#term-duck-typing) describes this style. +The examples share one case. Two greeters serve several contexts: one reads a `name`, and the other reads a +`salutation` and a `last_name`. Each context uses the greeter its fields suit, whatever other fields it carries. +The examples also make one mistake on purpose, giving a context the wrong greeter, to show when each approach +reports it. -### Dynamic dispatch and late binding +### Names looked up at runtime -Dynamic dispatch selects an implementation using runtime information about the receiver. -Smalltalk expresses calls as message sends; statically typed languages also support late binding -through virtual methods or trait objects. Multiple-dispatch systems extend the selection to more -than one argument. The timing of implementation selection is distinct from whether the language -checks the call's interface statically. +A dynamically typed language looks a method up by name while the call runs, first in the object and then along a +chain. -### Vtables and method dictionaries +A JavaScript object can be read as a dictionary, as +[MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors) puts it: its +property names are the keys, and a method is one of its entries. `context.greet()` finds the function under the name +`greet` in the receiver and calls it with the receiver as `this`. The function reads the fields it names from whatever +object that is, so objects of different shapes share it. Giving an object the wrong greeter is not an error here: the +missing fields read as `undefined`. An object without `greet` throws, but only when the call runs: -A vtable stores the method implementations used for dynamic calls. Rust's trait-object pointers -pair a pointer to the value with a pointer to a vtable containing the relevant method pointers. -The call therefore follows an indirect route, as described in the -[Rust Reference](https://doc.rust-lang.org/reference/types/trait-object.html). +```js +function greetHello() { return `Hello, ${this.name}!`; } +function greetFormally() { return `Good day, ${this.salutation} ${this.lastName}.`; } -Indirect dispatch can limit optimization, but its cost depends on the call and compiler. -Devirtualization can recover a direct call when the target is known. Dynamic-language runtimes -also optimize property and method lookup; V8's hidden classes help it identify object layouts. -The [V8 documentation](https://v8.dev/docs/hidden-classes) describes that mechanism. A comparison -of dispatch mechanisms alone does not establish a performance ranking for whole programs. +const person = { name: "Ada", greet: greetHello }; +const personWithAge = { name: "Bob", age: 30, greet: greetHello }; +const formalPerson = { salutation: "Dr.", lastName: "Lovelace", greet: greetFormally }; +const formalPersonWithEmail = { salutation: "Mr.", lastName: "Babbage", email: "cb@example.com", greet: greetFormally }; -### Prototypal inheritance and delegation +console.log(person.greet()); // Hello, Ada! +console.log(personWithAge.greet()); // Hello, Bob! +console.log(formalPerson.greet()); // Good day, Dr. Lovelace. +console.log(formalPersonWithEmail.greet()); // Good day, Mr. Babbage. -Prototypal inheritance shares behavior by linking objects. JavaScript property lookup follows an -object's prototype chain when the property is absent from the object itself, and an own property -shadows an inherited one. The -[MDN guide](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain) -explains these rules. +console.log(person["name"]); // Ada: a field is an entry under a string key +console.log(person["greet"] === greetHello); // true: so is a method -Delegation preserves the original receiver while obtaining behavior elsewhere. An inherited method -can therefore read the receiving object's state. This is the property of -[Lieberman's delegation model](https://web.media.mit.edu/~lieber/Lieberary/OOP/Delegation/Delegation.html) -that matters for CGP: selecting another implementation does not replace the context it operates on. -JavaScript's actual `this` binding also depends on how the function is called. +const wrong = { name: "Eve", greet: greetFormally }; +console.log(wrong.greet()); // Good day, undefined undefined. +({ name: "Eve" }).greet(); // TypeError, raised only when this line runs +``` -## How CGP expresses it +Python looks attributes up by name as well. A function stored on a class becomes a method when an instance looks it +up, with the instance as its first argument, as the +[data model](https://docs.python.org/3/reference/datamodel.html#instance-methods) describes. `greet_hello` names no +class: it works on any context that has a `name`, so unrelated classes can share it. That is duck typing, and `Wrong` +shows its cost: + +```python +def greet_hello(context): + return f"Hello, {context.name}!" # trusts the context to have a name + +def greet_formally(context): + return f"Good day, {context.salutation} {context.last_name}." + +class Person: + greet = greet_hello + def __init__(self, name): + self.name = name + +class FormalPerson: + greet = greet_formally + def __init__(self, salutation, last_name): + self.salutation, self.last_name = salutation, last_name + +class Wrong: + greet = greet_formally # has no salutation + def __init__(self, name): + self.name = name + +print(Person("Ada").greet()) # Hello, Ada! +print(FormalPerson("Dr.", "Lovelace").greet()) # Good day, Dr. Lovelace. +print(getattr(Person("Ada"), "name")) # Ada: a field is looked up by a string +Wrong("Eve").greet() # AttributeError, raised only when this line runs +``` -CGP combines generic provider code with statically selected implementations. Its wiring resembles -a method table in purpose, but the table consists of trait impls and is resolved during compilation. -The examples below omit supporting declarations where the surrounding prose identifies their roles. +Python's full lookup searches the instance's own dictionary and its class's method resolution order, where a data +descriptor on the class comes first, and falls back to `__getattr__`, as its +[descriptor guide](https://docs.python.org/3/howto/descriptor.html) describes. -### Calls on a generic receiver +When a JavaScript object lacks a property, the lookup asks its prototype, an ordinary object that `Object.create` links +to it, and passes the original receiver down unchanged, as the +[ECMAScript specification](https://tc39.es/ecma262/multipage/ordinary-and-exotic-objects-behaviours.html) defines +`OrdinaryGet`: -A CGP provider can call a method on a context without naming that context's concrete type. -The trait dependency makes the required operation explicit: +```js +const personPrototype = { + greet() { return `Hello, ${this.name}!`; }, +}; -```rust -#[cgp_auto_getter] -pub trait HasName { - fn name(&self) -> &str; +const person = Object.create(personPrototype); // person asks personPrototype for what it lacks +person.name = "Ada"; + +console.log(person.greet()); // Hello, Ada!: greet is found on personPrototype, with `this` as person +``` + +The chain is data, so `Object.setPrototypeOf` can rewire it while the program runs. The receiver comes from the call: +"the value of `this` depends on how the function is called", as +[MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this) puts it, so a method taken +off its object loses its receiver. + +Smalltalk sends a message by consulting the receiver's class method dictionary, and Self delegates to prototype +objects, the model [Lieberman described in 1986](https://web.media.mit.edu/~lieber/Lieberary/OOP/Delegation/Delegation.html), +with `self` bound to the original receiver. Runtimes such as Self's and V8 speed these lookups up by caching them: +inline caches record the receiver's shape at a call site ([Hölzle, Chambers, and Ungar](https://bibliography.selflanguage.org/pics.html)), +and V8's [hidden classes](https://v8.dev/docs/hidden-classes) give objects of one layout a shared shape. + +### Method tables + +A slot table gives each method a fixed position, and each implementation supplies a table of function pointers. The +call site knows the slot when it is compiled and reads the pointer when it runs. + +Java dispatches every instance method that is neither private nor static on its receiver. The JVM selects the +method from the receiver's class, then its superclasses, then a maximally specific default method of an interface, as +the [JVM specification](https://docs.oracle.com/javase/specs/) sets out in §5.4.6; the table layout is left to the +implementation. + +Java checks at compile time that every `CanGreet` has a `greet`, and chooses the code at runtime from the receiver's +class. Each value below is held as a `CanGreet`, so its call goes through the interface. Each class writes its own +body, because it reads its own fields. The example is a compact source file, final since Java +25 under [JEP 512](https://openjdk.org/jeps/512), so it needs neither imports nor a wrapping class: + +```java +interface CanGreet { + String greet(); } -#[cgp_impl(new GreetHello)] -#[uses(HasName)] -impl Greeter { - fn greet(&self) -> String { - format!("Hello, {}!", self.name()) - } +record Person(String name) implements CanGreet { + public String greet() { return "Hello, " + name + "!"; } +} + +record FormalPerson(String salutation, String lastName) implements CanGreet { + public String greet() { return "Good day, " + salutation + " " + lastName + "."; } +} + +void main() { + CanGreet person = new Person("Ada"); + CanGreet formalPerson = new FormalPerson("Dr.", "Lovelace"); + + IO.println(person.greet()); // Hello, Ada! + IO.println(formalPerson.greet()); // Good day, Dr. Lovelace. } ``` -`self.name()` calls the context's `HasName` method. An implicit argument provides a shorter form -when the implementation simply needs a field value: +Rust's `&dyn Trait` is a pointer to the value and a pointer to a [vtable](/docs/reference/glossary#vtable) that holds, +in the [Reference](https://doc.rust-lang.org/reference/types/trait-object.html)'s words, "for each method of +SomeTrait and its supertraits that T implements, a pointer to T's implementation". A call on a concrete type would be +a direct call, so each value here is a `&dyn CanGreet`: ```rust -#[cgp_fn] -pub fn greet_implicitly(&self, #[implicit] name: &str) -> String { - format!("Hello, {name}!") +pub trait CanGreet { + fn greet(&self) -> String; } -``` -Both forms declare a dependency that Rust checks statically. The first requires `HasName`; the -second requires access to a field named `name`. The method body may resemble duck-typed code, -but it relies on declared traits and generated bounds. Ordinary generic Rust can express these -bounds too; CGP's macros supply the context parameter and supporting impls. +pub struct Person { pub name: String } +pub struct FormalPerson { pub salutation: String, pub last_name: String } -A `Person` type with the required field and wiring is a [value context](/docs/reference/glossary#value-context) in this example. -It is the value being greeted, rather than an application environment selecting behavior for a -separate target. [Implicit arguments](/docs/concepts/implicit-arguments) explains the field-based form. +impl CanGreet for Person { + fn greet(&self) -> String { format!("Hello, {}!", self.name) } +} -### Deferring the choice to wiring +impl CanGreet for FormalPerson { + fn greet(&self) -> String { format!("Good day, {} {}.", self.salutation, self.last_name) } +} -A generic caller can invoke `context.area()` through `CanCalculateArea` without choosing an -implementation. The context's wiring supplies that choice, and [monomorphization](/docs/reference/glossary#monomorphization) resolves the route -to a static call. This allows provider selection after the generic caller has been written, -while keeping that selection fixed for each concrete context type. +fn main() { + let person: &dyn CanGreet = &Person { name: "Ada".into() }; + let formal_person: &dyn CanGreet = + &FormalPerson { salutation: "Dr.".into(), last_name: "Lovelace".into() }; -Generic components can also select providers by their type parameters. The -[`open` statement](/docs/reference/macros/delegate_components) supports entries for different -parameter types, giving a form of type-directed selection across several inputs. This is a -compile-time comparison with multiple dispatch; it does not inspect the runtime types of objects. + println!("{}", person.greet()); // Hello, Ada! + println!("{}", formal_person.greet()); // Good day, Dr. Lovelace. +} +``` -### Wiring as a vtable +A Go interface value pairs the data with an itab, the method pointers for that interface and the value's concrete +type, as [Russ Cox explains](https://research.swtch.com/interfaces). A type satisfies an interface by having its +methods. Each variable here is a `CanGreet`: -A wiring entry maps a component key to a provider. This resembles the mapping from a vtable slot -to an implementation, except that both the key and selected provider are Rust types: +```go +type CanGreet interface{ Greet() string } -```rust -delegate_components! { - Rectangle { - AreaCalculatorComponent: RectangleArea, - } -} +type Person struct{ Name string } +type FormalPerson struct{ Salutation, LastName string } + +func (p Person) Greet() string { return "Hello, " + p.Name + "!" } +func (p FormalPerson) Greet() string { return "Good day, " + p.Salutation + " " + p.LastName + "." } -// expands to the type-level table entry: -// impl DelegateComponent for Rectangle { -// type Delegate = RectangleArea; -// } +func main() { + var person CanGreet = Person{"Ada"} + var formalPerson CanGreet = FormalPerson{"Dr.", "Lovelace"} + + fmt.Println(person.Greet()) // Hello, Ada! + fmt.Println(formalPerson.Greet()) // Good day, Dr. Lovelace. +} ``` -`Rectangle` is a value context, and the [self-targeted](/docs/reference/glossary#self-targeted-component) area component operates on that rectangle. -The compiler resolves `AreaCalculatorComponent` to `RectangleArea` through the shown trait impl. -The program does not store or consult this wiring table at runtime. Components can group several -methods, associated types, and consts, so an entry is not necessarily equivalent to one method slot. +### Reusing methods across fields -Runtime heterogeneity remains available through ordinary Rust trait objects. If the consumer trait -is dyn-compatible, a collection such as `Vec>` can contain different -context types and dispatch to their consumer methods dynamically. Each concrete context can still -use CGP wiring internally. The [consumer/provider explanation](/docs/concepts/consumer-and-provider-traits) -traces that internal route. +Java, Rust, and Go reuse a method across types only through what the types share. Each class and type above writes its +own `greet`, because a method reads only the fields its type declares, and an interface value or a +[trait object](/docs/reference/glossary#trait-object) exposes methods but no fields. Sharing a method between types +with different fields, when it is chosen at runtime, takes another language feature: a shared base type that holds +the fields, a dynamic cast to an interface the object did not declare, or [reflection](./reflection.md), which reads a +field by its name. A cast or a reflective read that meets the wrong type fails when it runs. Languages with structural +record types or rows, such as TypeScript and PureScript, check a function's field requirements without those +declarations, which [Row polymorphism](./row-polymorphism.md) compares with CGP. -### Delegation and the original context +## How CGP expresses it -An [aggregate provider](/docs/concepts/aggregate-providers) groups wiring entries for reuse. -A context can delegate several components to the aggregate: +Both families above are lookups keyed by the receiver, and so is CGP's wiring. They differ in what chooses the code, +when a missing method shows up, and whether the choice can change: + +| Family | Code chosen by | A missing method | Can change | +| --- | --- | --- | --- | +| Name lookup (JavaScript, Python) | A name looked up in the receiver | Found when the line runs | Yes | +| Method table (Java, Rust `dyn`, Go) | The receiver's class or vtable | A compile error | No | +| CGP wiring | The context's table, read by the compiler | A compile error once used or checked | No, fixed at build | + +Every context below is a [value context](/docs/reference/glossary#value-context), the value being greeted. + +### Calls on a generic receiver + +`CanGreet` is the interface callers use, as in Java, Rust, and Go above. The +[component](/docs/reference/glossary#component) adds providers: each names an implementation written against a +context it does not name, like the Python functions. `GreetHello` reads `name` as `greet_hello` does, but its +`#[implicit]` argument turns that trust into a requirement the compiler checks. Each provider reads its fields by +names that are types rather than strings: ```rust -delegate_components! { - new GeometryComponents { - AreaCalculatorComponent: RectangleArea, - PerimeterCalculatorComponent: RectanglePerimeter, +#[cgp_component(Greeter)] +pub trait CanGreet { + fn greet(&self) -> String; +} + +#[cgp_impl(new GreetHello)] +impl Greeter { + fn greet(&self, #[implicit] name: &str) -> String { + format!("Hello, {name}!") } } -delegate_components! { - Rectangle { - [AreaCalculatorComponent, PerimeterCalculatorComponent]: GeometryComponents, +#[cgp_impl(new GreetFormally)] +impl Greeter { + fn greet(&self, #[implicit] salutation: &str, #[implicit] last_name: &str) -> String { + format!("Good day, {salutation} {last_name}.") } } ``` -An area call follows `Rectangle` to `GeometryComponents` and then `RectangleArea`, with `Rectangle` -as the context at every step. The area provider reads the rectangle's `width` and `height`; -`GeometryComponents` holds neither value. This preserves the receiver in the same sense as -prototypal delegation, with the route resolved statically. [`UseContext`](/docs/reference/providers/use_context) -allows a provider to call back through the context's consumer-trait implementation. +[Consumer and provider traits](/docs/concepts/consumer-and-provider-traits#splitting-one-trait-in-two) explains the +split into a consumer and a provider trait, [Implicit arguments](/docs/concepts/implicit-arguments) the field reads, and +[Impl-side dependencies](/docs/concepts/impl-side-dependencies) why the fields stay out of `CanGreet`. -### Namespaces and inheritance +### A table on the context -A CGP [namespace](/docs/concepts/namespaces) shares wiring across contexts. Its inheritance differs -from JavaScript property shadowing: a bound key cannot be redefined by a conflicting impl. -A context can instead fill a path the namespace leaves unbound: +Each context names its provider in a table, as a Python class names its function with `greet = greet_hello`. The key +is the type `GreeterComponent`, and the compiler reads the table, so `person.greet()` compiles to a direct call. A +context derives its field access once and picks any provider its fields satisfy, without an interface per greeter. The +extra `age` and `email` do not matter, and `Member` has the fields for both providers, so its table decides: ```rust -// The shared prototype: it binds the farewell and leaves the greeting path open. -cgp_namespace! { - new AppDefaults: AppNamespace { - @app.FarewellComponent: SayGoodbye, - } -} +#[derive(HasField)] +pub struct Person { pub name: String } -delegate_components! { - AppA { - namespace AppDefaults; // inherit every wiring the namespace binds +#[derive(HasField)] +pub struct PersonWithAge { pub name: String, pub age: u8 } - @app.GreeterComponent: GreetHello, // fill a slot the namespace leaves open - } +#[derive(HasField)] +pub struct FormalPerson { pub salutation: String, pub last_name: String } + +#[derive(HasField)] +pub struct FormalPersonWithEmail { pub salutation: String, pub last_name: String, pub email: String } + +#[derive(HasField)] +pub struct Member { pub name: String, pub salutation: String, pub last_name: String } + +delegate_components! { Person { GreeterComponent: GreetHello } } +delegate_components! { PersonWithAge { GreeterComponent: GreetHello } } +delegate_components! { FormalPerson { GreeterComponent: GreetFormally } } +delegate_components! { FormalPersonWithEmail { GreeterComponent: GreetFormally } } +delegate_components! { Member { GreeterComponent: GreetFormally } } // either would do + +check_components! { Person { GreeterComponent } } +check_components! { PersonWithAge { GreeterComponent } } +check_components! { FormalPerson { GreeterComponent } } +check_components! { FormalPersonWithEmail { GreeterComponent } } +check_components! { Member { GreeterComponent } } +``` + +```rust +let person = Person { name: "Ada".to_owned() }; +let formal = FormalPerson { salutation: "Dr.".to_owned(), last_name: "Lovelace".to_owned() }; + +println!("{}", person.greet()); // Hello, Ada! +println!("{}", formal.greet()); // Good day, Dr. Lovelace. +``` + +[Type-level tables](/docs/concepts/type-level-tables#a-table-and-its-entries) builds the same kind of table in plain +Rust, [Consumer and provider traits](/docs/concepts/consumer-and-provider-traits#how-a-call-finds-its-provider) traces +the call through it, and +[Impl-side dependencies](/docs/concepts/impl-side-dependencies#providers-with-different-requirements) shows providers +with different requirements serving one interface. + +Wiring `Person` to `GreetFormally` is the mistake that printed `undefined` in JavaScript and threw in Python. The check +rejects it when the program is built: + +```rust +#[derive(HasField)] +pub struct Person { pub name: String } + +delegate_components! { Person { GreeterComponent: GreetFormally } } + +// error[E0277]: the trait bound `Person: CanUseComponent` is not satisfied +check_components! { Person { GreeterComponent } } +``` + +[`cargo cgp check`](/docs/tooling/cargo-cgp/check) reports it as "`[CGP-E001]` missing fields `salutation` and +`last_name` on `Person`", with the chain from `CanGreet` through `GreetFormally` to both fields. A wiring entry alone +checks nothing: the check, or a call to `greet`, makes the compiler verify the provider's requirements, as +[Checking your wiring](/docs/concepts/check-traits#writing-a-check-trait) explains. + +Side by side, the three approaches read a field and report the wrong greeter like this: + +| Approach | A greeter reads a field by | Each context declares | The wrong greeter | +| --- | --- | --- | --- | +| JavaScript | Its name, at runtime | Nothing | Prints `undefined` | +| Python | Its name, at runtime | Nothing | `AttributeError` when it runs | +| CGP | Its name, as a type | `#[derive(HasField)]` | A compile error once used or checked | + +A context without an entry fails the same check. JavaScript found an object without `greet` only when the call ran: + +```rust +#[derive(HasField)] +pub struct Stranger { + pub name: String, } + +// error[E0277]: the trait bound `Stranger: CanUseComponent` is not satisfied +check_components! { Stranger { GreeterComponent } } ``` -`AppDefaults` supplies the farewell provider, while `AppA` supplies the greeting provider at the -open path. A child namespace can fill that path for contexts that join it: +`cargo cgp check` reports "`[CGP-E001]` missing wiring for `GreeterComponent` on `Stranger`". +[Reading the errors with cargo-cgp](/docs/concepts/check-traits#reading-the-errors-with-cargo-cgp) walks through such +reports. + +### A chain walked by the compiler + +An aggregate provider is a wiring table that other tables can name, so it can play a prototype's part. Here `Person` +delegates its greeter to `PersonPrototype` in place of its direct entry above, as `person` asks `personPrototype`: ```rust -cgp_namespace! { - new QuietDefaults: AppDefaults { - @app.GreeterComponent: GreetQuietly, +delegate_components! { + new PersonPrototype { + GreeterComponent: GreetHello, } } +#[derive(HasField)] +pub struct Person { + pub name: String, +} + delegate_components! { - AppB { - namespace QuietDefaults; + Person { + GreeterComponent: PersonPrototype, } } + +check_components! { Person { GreeterComponent } } ``` -`AppA` and `AppB` are [environmental contexts](/docs/reference/glossary#environmental-context) representing applications. Their providers are found -through [`RedirectLookup`](/docs/reference/providers/redirect_lookup), which follows type-level -paths. This resembles sharing defaults through a prototype, but customization fills unbound paths -rather than shadowing already-bound entries. An attempt to bind the same key again conflicts under -Rust's [coherence](/docs/reference/glossary#coherence) rules. +```rust +let person = Person { name: "Ada".to_owned() }; +println!("{}", person.greet()); // Hello, Ada!: GreetHello reads Person's name +``` -## What each approach costs +The two lookups line up piece by piece: -Dynamic dispatch supports runtime choice, including mixed collections of implementations. -Dynamically typed languages also allow programs to accept objects without an explicit interface -declaration, and mutable object systems can change behavior while running. Those freedoms are -useful for interactive work and runtime extensibility. - -Dynamic typing can defer unsupported-operation errors until execution. That cost does not apply -to every form of dynamic dispatch: Rust checks a trait object's interface at compile time. -Runtime lookup and indirect calls also have costs, though optimizations can reduce them. -Prototype mutation and call-dependent `this` binding add separate reasoning demands, as the -[MDN guide](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain) -explains. - -CGP moves implementation selection into compilation and requires declarations and wiring to express -it. The learning cost includes tracing consumer traits through provider tables; the compile-time -cost includes trait resolution and monomorphization. Static wiring itself cannot discover plugins, -replace a provider on a live value, or handle an undeclared operation. Those features need other -runtime mechanisms, which CGP code can use alongside its wiring. - -CGP's raw diagnostics expose generated traits and types. -[`cargo cgp check`](/docs/tooling/cargo-cgp/check) leads with the root cause for the classes it recognizes, -and the tool does not yet reshape every class. The -[Modularity Hierarchy](/docs/concepts/modularity-hierarchy) compares these costs with ordinary -traits, generics, and trait objects. +| In JavaScript | In CGP | +| --- | --- | +| `personPrototype = { greet() { ... } }` | `new PersonPrototype { GreeterComponent: GreetHello }` | +| `person = Object.create(personPrototype)` | `Person { GreeterComponent: PersonPrototype }` | +| `this` | The context, `Person` at every step | -## Where runtime dispatch is the better choice +CGP's lookup has the shape of a [prototype chain](/docs/reference/glossary#prototype-chain), walked by the compiler. The +two lookups differ in reach and in time. A JavaScript prototype answers every property the object lacks, while a CGP +table delegates each component it names. And a JavaScript prototype can change while the program runs, while a CGP +table is fixed when the program is built. `PersonPrototype` is not a context itself, so the check runs on `Person`, as +[Aggregate providers](/docs/concepts/aggregate-providers#checking-a-bundle-as-a-context) explains. +[Delegating through a bundle](/docs/concepts/aggregate-providers#delegating-through-a-bundle) follows the call through +the bundle, and [Type-level tables](/docs/concepts/type-level-tables#prototype-chains) builds the chain in plain Rust. -Runtime dispatch fits implementations chosen while the program runs, such as mixed collections or -runtime-selected services. Dynamic object systems additionally support changing object behavior -and intercepting otherwise unknown messages. Plugin loading requires an appropriate loading and -interface mechanism as well as dispatch; a vtable alone does not provide it. +### Runtime values inside a context -Rust's `dyn Trait` is useful for runtime polymorphism and can coexist with CGP. A context may hold a -trait object, or a dyn-compatible consumer trait may be used as a trait object. CGP wiring fits -implementation choices known at build time, where reusable providers justify the additional tables. +Static wiring and runtime dispatch work together. A dyn-compatible consumer trait can be a `dyn Trait` over +different CGP contexts, each using its own wiring inside the call. A context can also hold trait objects or enums for +choices made at runtime. -## What to expect that differs +## What each approach costs -CGP resolves wiring during compilation, while provider bodies execute at runtime. -Static selection removes the wiring lookup from execution; it does not guarantee that every call -is inlined or that the provider's work is free. +Dynamic dispatch buys runtime choice, and its costs come from choosing late. A missing method fails only when the +call runs, as a `TypeError` in JavaScript or an `AttributeError` in Python, and a missing JavaScript field reads as +`undefined` without an error at all. JavaScript's `this` depends on the call, so a detached method loses its receiver. +Dictionary lookup needs caches and hidden classes to run fast, and an indirect call through a vtable can limit +optimization, though a compiler may devirtualize a call whose target it knows. Developers who add types to dynamic +code report the other side: respondents to the +[2024 Typed Python survey](https://engineering.fb.com/2024/12/09/developer-tools/typed-python-2024-survey-meta/), +over 1,000 people asked about type hints, said they "value the ability to catch potential bugs early and the ease of +refactoring code". Rust's trait objects dispatch at runtime but keep compile-time checks, under the +[dyn-compatibility rules](https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility). + +CGP moves the choice into compilation and pays for it in declarations, wiring, and compile-time work. Static wiring +cannot discover plugins, replace a provider on a live value, or handle an undeclared operation. A lookup that needs +its own answer overflows the trait solver, as the cycle on +[Type-level tables](/docs/concepts/type-level-tables#what-it-costs) shows. Reading fields by name has costs +of its own, as [Implicit arguments](/docs/concepts/implicit-arguments#what-it-costs) states: renaming a field breaks +the providers that read it, the struct does not list those providers, and Rust cannot tell whether two fields with the +same name and type mean the same thing. CGP's raw diagnostics expose generated traits and types; +[`cargo cgp check`](/docs/tooling/cargo-cgp/check) leads with the root cause for the classes it recognizes, and the +tool does not yet reshape every class. The [Modularity Hierarchy](/docs/concepts/modularity-hierarchy) compares these +costs with ordinary traits, generics, and trait objects. -The context type fixes its provider choices. Two values of that type can contain different state, -but changing their fields does not rewrite the type's wiring. Runtime variation must be expressed -through the selected implementation or another Rust dispatch mechanism. +## Where runtime dispatch is the better choice + +Runtime dispatch fits implementations chosen while the program runs: a collection of values of different types, +services selected from configuration, plugins, and behavior changed on a live object. An enum fits a small closed set +of cases. Plugin loading also needs a way to load code and agree on an interface, which a vtable alone does not +provide. Runtime field access reaches further as well. Java's reflection and dynamic languages read the fields of +objects whose classes the program does not own, while CGP reads a field only where the context derives `HasField`. +The orphan rule rejects that implementation for a type from another crate, so such a type needs a local wrapper that +holds its fields. CGP's wiring fits choices known when the program is built, where reusable +providers justify the tables, and a CGP context can hold `dyn Trait` values for the rest. -A dependency check catches missing declared operations before execution. -`check_components!` forces validation at the check site; a wiring declaration alone is lazy. -This is a guarantee about declared dependencies, not about every possible runtime failure. +## What to expect that differs -Namespaces preserve bindings that are already defined. Contexts and child namespaces customize -paths left unbound rather than shadowing inherited entries. This restriction follows from the -ordinary trait impls used to represent wiring. +These follow from CGP resolving its lookup at compile time: + +- **A direct call:** the running program needs neither a wiring table nor a lookup; the provider's own work still + runs, and a static call is not guaranteed to inline. +- **Answer or delegate:** a context either delegates a component or implements it, never both, because two + implementations that could both apply break [coherence](/docs/reference/glossary#coherence). +- **One key per component:** each component's marker type, such as `GreeterComponent`, is the key its blanket + implementation reads, which lets that implementation coexist with every provider. +- **The original context:** the chain passes the context through every step, so the provider receives the value the + method was called on. +- **Compile-time failures:** once the component is used or checked, a missing method or field is a compile error. ## Where to go next -These pages explain the static mechanisms and related comparisons: +These pages go further: -- [Consumer and provider traits](/docs/concepts/consumer-and-provider-traits): how a call reaches - its provider. -- [Aggregate providers](/docs/concepts/aggregate-providers) and [Namespaces](/docs/concepts/namespaces): - sharing and following wiring tables. -- [Row polymorphism](./row-polymorphism.md): structural interfaces and field requirements. -- [Reflection](./reflection.md): inspecting data and types at compile time or runtime. +- [Type-level tables](/docs/concepts/type-level-tables): Tables and the prototype chain in plain Rust. +- [Consumer and provider traits](/docs/concepts/consumer-and-provider-traits): How a call reaches its provider. +- [Implicit arguments](/docs/concepts/implicit-arguments): Fields read by type-level names. +- [Impl-side dependencies](/docs/concepts/impl-side-dependencies): Requirements that stay with the provider. +- [Checking your wiring](/docs/concepts/check-traits): Where a missing field or entry is reported. +- [Aggregate providers](/docs/concepts/aggregate-providers): A shared table in the chain. +- [Row polymorphism](./row-polymorphism.md): Structural interfaces and field requirements. +- [Reflection](./reflection.md): Inspecting data and types at compile time or runtime. ## Sources -The CGP snippets were compiled against `cgp` `0.8.0` with a `check_components!` assertion per -wired context. This page contains only Rust snippets. - -- [The Rust Reference, *Trait object types*](https://doc.rust-lang.org/reference/types/trait-object.html): trait-object pointers and dynamic dispatch. -- [Python glossary, *Duck typing*](https://docs.python.org/3/glossary.html#term-duck-typing): using an object through the operations it supports. -- [Wikipedia, *Dynamic dispatch*](https://en.wikipedia.org/wiki/Dynamic_dispatch), [*Virtual method table*](https://en.wikipedia.org/wiki/Virtual_method_table), and [*Duck typing*](https://en.wikipedia.org/wiki/Duck_typing): late binding, the vtable, and usability decided by the methods an object has. -- [The Rust Programming Language, *Trait objects*](https://doc.rust-lang.org/book/ch18-02-trait-objects.html) and [geo-ant, *Rust Dyn Trait Objects and Fat Pointers*](https://geo-ant.github.io/blog/2023/rust-dyn-trait-objects-fat-pointers/): Rust's own dynamic dispatch as a fat pointer and a vtable. -- [Lieberman, *Using Prototypical Objects to Implement Shared Behavior in Object-Oriented Systems* (OOPSLA 1986)](https://web.media.mit.edu/~lieber/Lieberary/OOP/Delegation/Delegation.html): delegation, and the rule that `self` stays bound to the original receiver. -- [MDN, *Inheritance and the prototype chain*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain): JavaScript's prototype chain and own-property shadowing. -- [V8, *Maps (Hidden Classes)*](https://v8.dev/docs/hidden-classes): the engineering that dynamic dispatch's runtime cost demands. -- [SitePoint, *Making Ruby Quack*](https://www.sitepoint.com/making-ruby-quack-why-we-love-duck-typing/), [GeeksforGeeks, *Type Systems*](https://www.geeksforgeeks.org/python/type-systemsdynamic-typing-static-typing-duck-typing/), and [DevGex, *Duck Typing*](https://devgex.com/en/article/00035033): community sentiment on what duck typing buys and costs. +The CGP and Rust snippets were compiled against `cgp` 0.8.0 and rustc 1.100.0 in the site's verification crate, with +a `check_components!` assertion per wired context. The other snippets ran as shown, with the Go snippet's `package` and +`import` lines restored, on Node 25.4.0, Python 3.14.10, OpenJDK 25.0.5, and Go 1.27.4. + +- [*Dynamic dispatch* (Wikipedia)](https://en.wikipedia.org/wiki/Dynamic_dispatch): late binding and message sends. +- [MDN, *Property accessors*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors), + [MDN, `Object.create`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create), + and [MDN, `this`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this): objects as + dictionaries, prototypes, and the receiver. +- [ECMAScript, *Ordinary and exotic objects*](https://tc39.es/ecma262/multipage/ordinary-and-exotic-objects-behaviours.html): + prototype lookup. +- [Python, *Data model*](https://docs.python.org/3/reference/datamodel.html#instance-methods), + [*Descriptor guide*](https://docs.python.org/3/howto/descriptor.html), + [`getattr`](https://docs.python.org/3/library/functions.html#getattr), and the + [glossary](https://docs.python.org/3/glossary.html#term-duck-typing): methods, attribute lookup, and duck typing. +- [Lieberman, *Using Prototypical Objects to Implement Shared Behavior in Object-Oriented Systems* (OOPSLA 1986)](https://web.media.mit.edu/~lieber/Lieberary/OOP/Delegation/Delegation.html): + delegation. +- [Hölzle, Chambers, and Ungar, ECOOP '91](https://bibliography.selflanguage.org/pics.html) and + [V8, *Maps (Hidden Classes)*](https://v8.dev/docs/hidden-classes): inline caches. +- [The Java Virtual Machine Specification](https://docs.oracle.com/javase/specs/) and + [JEP 512](https://openjdk.org/jeps/512): method selection and compact source files. +- [The Rust Reference, *Trait object types*](https://doc.rust-lang.org/reference/types/trait-object.html): trait + objects and their vtables. +- [Russ Cox, *Go Data Structures: Interfaces*](https://research.swtch.com/interfaces) and the + [Go specification](https://go.dev/ref/spec): itabs and interface satisfaction. +- [2024 Typed Python survey](https://engineering.fb.com/2024/12/09/developer-tools/typed-python-2024-survey-meta/): + why developers add type hints. --- -*An AI agent wrote this page using the CGP knowledge base. Its CGP code was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its CGP code was verified against +the library's source, and its other snippets were verified against the toolchains named in its +Sources section. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/comparisons/implicit-parameters.md b/docs/comparisons/implicit-parameters.md index 66544997..583ee2f4 100644 --- a/docs/comparisons/implicit-parameters.md +++ b/docs/comparisons/implicit-parameters.md @@ -320,6 +320,7 @@ context. --- -*An AI agent wrote this page using the CGP knowledge base. Its CGP code was verified against the -library's source and its other snippets against the toolchains named in Sources. See +*This page was written by an AI agent from the CGP knowledge base. Its CGP code was verified against +the library's source, and its other snippets were verified against the toolchains named in its +Sources section. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/comparisons/index.md b/docs/comparisons/index.md index 7eb720f4..9c54647e 100644 --- a/docs/comparisons/index.md +++ b/docs/comparisons/index.md @@ -18,22 +18,24 @@ other tool. ## Which page to read -Choose the page that matches your background. Rust's proposals and C++ policy-based design come -first, followed by type-system concepts, dependency injection, and runtime or security mechanisms. +Choose the page that matches your background. Rust's own proposals come first, followed by +type-system concepts, dependency injection, and runtime or security mechanisms, and then C++ +policy-based design and the comparison of trait systems without coherence. | If you know | Read | | --- | --- | | Rust's coherence debates: specialization, named impls, contexts and capabilities | [Rust's own proposals](./rust-language-proposals.md) | -| C++ templates, policy classes, CRTP, and concepts | [Policy-based design](./policy-based-design.md) | | Haskell, Agda, or Lean type classes | [Type classes](./type-classes.md) | | OCaml or Standard ML signatures, structures, and functors | [ML modules](./ml-modules.md) | | Scala `given`/`using`, Haskell `ImplicitParams`, or the `Reader` monad | [Implicit parameters](./implicit-parameters.md) | | Koka, OCaml 5, Flix, or Eff effect handlers | [Algebraic effects](./algebraic-effects.md) | | PureScript rows, OCaml polymorphic variants, or structural typing | [Row polymorphism](./row-polymorphism.md) | | Spring, Guice, Dagger, or constructor injection | [Dependency injection](./dependency-injection.md) | -| Python, Ruby, JavaScript, Smalltalk, vtables, or prototypes | [Dynamic dispatch](./dynamic-dispatch.md) | +| JavaScript, Python, Smalltalk, Java virtual methods, Go interfaces, Rust `dyn Trait`, vtables, or prototypes | [Dynamic dispatch](./dynamic-dispatch.md) | | Bevy reflection, Zig `comptime`, or Rust's reflection work | [Reflection](./reflection.md) | | Object capabilities, `cap-std`, WASI, Effekt, or Scala capture checking | [Capabilities](./capabilities.md) | +| C++ templates, policy classes, CRTP, and concepts | [Policy-based design](./policy-based-design.md) | +| Cairo's named impls, or how Scala, OCaml, and Haskell choose among overlapping impls | [Traits without coherence](./traits-without-coherence.md) | ## What every page shares @@ -56,5 +58,5 @@ borrowed ones alike. --- -*An AI agent wrote this page using the CGP knowledge base. See +*This page was written by an AI agent from the CGP knowledge base. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/comparisons/ml-modules.md b/docs/comparisons/ml-modules.md index 4c8b358e..20188eb2 100644 --- a/docs/comparisons/ml-modules.md +++ b/docs/comparisons/ml-modules.md @@ -346,6 +346,7 @@ These references support the module semantics and comparison: --- -*An AI agent wrote this page using the CGP knowledge base. Its CGP code was verified against the -library's source and its other snippets against the toolchains named in Sources. See +*This page was written by an AI agent from the CGP knowledge base. Its CGP code was verified against +the library's source, and its other snippets were verified against the toolchains named in its +Sources section. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/comparisons/policy-based-design.md b/docs/comparisons/policy-based-design.md index 6d79ebfa..0088f3fe 100644 --- a/docs/comparisons/policy-based-design.md +++ b/docs/comparisons/policy-based-design.md @@ -1,6 +1,6 @@ --- sidebar_label: 'Policy-based design' -sidebar_position: 2 +sidebar_position: 12 description: 'Compare Context-Generic Programming providers and wiring with C++ policy classes, host templates, CRTP, and concepts.' --- @@ -421,6 +421,7 @@ These references support the C++ mechanisms and example origins: --- -*An AI agent wrote this page using the CGP knowledge base. Its CGP code was verified against the -library's source and its other snippets against the toolchains named in Sources. See +*This page was written by an AI agent from the CGP knowledge base. Its CGP code was verified against +the library's source, and its other snippets were verified against the toolchains named in its +Sources section. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/comparisons/reflection.md b/docs/comparisons/reflection.md index 20adb8d1..d0d605fa 100644 --- a/docs/comparisons/reflection.md +++ b/docs/comparisons/reflection.md @@ -354,6 +354,7 @@ and is unstable. The CGP snippets were compiled against `cgp` `0.8.0` with a --- -*An AI agent wrote this page using the CGP knowledge base. Its CGP code was verified against the -library's source and its other snippets against the toolchains named in Sources. See +*This page was written by an AI agent from the CGP knowledge base. Its CGP code was verified against +the library's source, and its other snippets were verified against the toolchains named in its +Sources section. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/comparisons/row-polymorphism.md b/docs/comparisons/row-polymorphism.md index b67e42d8..59da659d 100644 --- a/docs/comparisons/row-polymorphism.md +++ b/docs/comparisons/row-polymorphism.md @@ -340,6 +340,7 @@ snippet with OCaml 5.5.0. The CGP snippets were compiled against `cgp` `0.8.0`. --- -*An AI agent wrote this page using the CGP knowledge base. Its CGP code was verified against the -library's source and its other snippets against the toolchains named in Sources. See +*This page was written by an AI agent from the CGP knowledge base. Its CGP code was verified against +the library's source, and its other snippets were verified against the toolchains named in its +Sources section. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/comparisons/rust-language-proposals.md b/docs/comparisons/rust-language-proposals.md index e4d4045f..aa723807 100644 --- a/docs/comparisons/rust-language-proposals.md +++ b/docs/comparisons/rust-language-proposals.md @@ -23,7 +23,7 @@ The proposals' constructs map onto CGP as follows: | --- | --- | | A named impl (`impl Name = Trait for T`) | A **provider**: a zero-sized type that implements a component's provider trait | | An `incoherent trait` bound passed at a call | A consumer-trait bound on the context, resolved by the context's **wiring** | -| An impl passed as a parameter (`impl TDrop: Drop` in Cairo) | A **[higher-order provider](/docs/reference/glossary#higher-order-provider)**, bound with `#[use_provider]` | +| A generic impl that takes another impl as a parameter | A **[higher-order provider](/docs/reference/glossary#higher-order-provider)**, bound with `#[use_provider]` | | A capability in a `with` clause | An `#[implicit]` argument read from a context field | | The `with` block that binds everything | The definition of a context type and its `delegate_components!` table | | The root dictionary of a dictionary-passing elaboration | The context itself | @@ -87,8 +87,16 @@ const CLONE_U32: Clone = Clone { clone: |x: &u32| *x }; Trait resolution supplies the dictionary in this model. Passing dictionaries explicitly would let callers choose different implementations, while coherence restricts that choice. Nadrieril uses the translation to examine which restrictions belong to Rust's design and which follow from the -underlying mechanism ([*Dictionary-passing -style*](https://nadrieril.github.io/blog/2026/03/20/dictionary-passing-style.html)). +underlying mechanism ([*Elaborating Rust Traits to Explicit Trait +Proofs*](https://nadrieril.github.io/blog/2026/03/20/dictionary-passing-style.html)). + +The model has since become project work. The types team's 2026 goal, the *Dictionary Passing Style +Experiment*, has Nadrieril as its contact and a project repository whose reading list includes Boxy's +post, described below ([goal #630](https://github.com/rust-lang/goals/issues/630)). Later writing +asks which cycles between impls are sound. Nadrieril's *When can Traits Depend on Themselves?* looks +for a rule that rejects cycles that prove false facts, and Niko Matsakis's posts on cyclic trait impls +make the case for such impls through perfect derive ([Nadrieril](https://nadrieril.github.io/blog/2026/05/14/when-can-traits-depend-on-themselves.html); +[Matsakis](https://smallcultfollowing.com/babysteps/series/cyclic-trait-impls/)). ### Named and incoherent impls @@ -142,29 +150,13 @@ names the difficulties that follow: ownership modes for the carried value, the s a trait differently in different scopes, and methods that become closures ([*What If Traits Carried Values*](https://nadrieril.github.io/blog/2026/03/22/what-if-traits-carried-values.html)). -### Named impls in Cairo - -Cairo provides a working example of named impls in a language with Rust-like syntax. A generic -function can take an impl as an explicit parameter, named or anonymous: - -```rust -// Cairo -fn largest_list>(l1: Array, l2: Array) -> Array { /* ... */ } - -fn smallest_element, +Copy, +Drop>(list: @Array) -> T { /* ... */ } -``` - -A caller can let the compiler infer the impl from those visible at the call site ([Cairo Book, -*Traits*](https://www.starknet.io/cairo-book/ch08-02-traits-in-cairo.html); -[*Generic Data Types*](https://www.starknet.io/cairo-book/ch08-01-generic-data-types.html)). This -inference matters for the comparison: because resolution uses what is in scope, a call site's -imports decide which implementation it uses. - ## How CGP expresses it CGP records provider choices on a context. Named-impl designs can instead select an impl at a call site, and capability designs can bind a value within a scope. The examples below show the practical -effect of that difference. +effect of that difference. The blog post [Trying Incoherent Rust +today](/blog/incoherent-rust-today#expressing-incoherence-with-cgp) translates Boxy's, Nadrieril's, +and Mandry's own examples into CGP at greater length. ### Naming implementations with providers {#a-named-impl-is-a-provider} @@ -232,16 +224,17 @@ delegate_components! { ``` Every call through `ApiServer` uses its selected provider for `String`; `Firmware` has its own -choice. This gives consistency per context, component, and dispatch key. Boxy's sketch permits -explicit choices at calls, while Cairo can infer them from scope. The +choice. This gives consistency per context, component, and dispatch key. Boxy's sketch makes +the choice explicitly at each call, and languages that infer impls from scope make it from a call +site's imports, as [Traits without coherence](./traits-without-coherence.md) shows. The [type classes](./type-classes.md) page compares these choices with Haskell's instance resolution. ### Passing providers as type parameters {#passing-an-impl-explicitly-is-a-higher-order-provider} -Where the proposals and Cairo let a caller pass an impl as a parameter, CGP uses +Where the proposals let a caller pass an impl as a parameter, CGP uses [higher-order providers](/docs/concepts/higher-order-providers). A provider takes another provider -as a type parameter and binds it with `#[use_provider]`, which corresponds to Cairo's -`impl TDrop: Drop` written as a Rust generic: +as a type parameter and binds it with `#[use_provider]`, which writes the impl it is given as a +Rust generic parameter: ```rust #[cgp_impl(new ScaledArea)] @@ -309,24 +302,35 @@ the wiring. `App` is an environmental context; the greeter is A CGP context serves a role similar to a root dictionary: it connects generic code to its dependencies. Each provider receives the context, whose wiring selects other providers. The analogy describes how dependencies are organized; CGP resolves the selections statically and does not store -a runtime record of function pointers. +a runtime record of function pointers. The blog post [Trying Incoherent Rust +today](/blog/incoherent-rust-today#context-as-dictionary) sets the CGP translation of Nadrieril's +`Clone` example beside his notation for explicit trait proofs. Providers can refer to each other's operations through the shared context. This avoids a manual order for constructing separate dictionaries. Rust still checks the resulting trait dependencies. The [ML modules](./ml-modules.md) page compares this with explicit functor application. +That freedom stops at cycles, because each lookup is a trait obligation that the compiler proves. A +provider that depends on another instance resolves: an encoder for `Vec` that needs the encoder for +`T` stops when it reaches the element type. But a provider that needs the instance it is defining, +such as a serializer for a linked list or an evaluator for a recursive expression type, overflows the +trait solver with `E0275`. The usual workaround is a provider written for the concrete context, without +the bound that leads back to itself, as the expression interpreter's +[dispatch layers](/docs/projects/cgp-examples/expression/architecture/dispatch-layers) explain. These +providers are one use case for the sound cyclic impls that the posts above study. + ## What each approach costs These proposals have different levels of maturity and different open questions. Specialization has an accepted RFC but remains unstable because of a soundness problem ([tracking issue -#31844](https://github.com/rust-lang/rust/issues/31844)). Named impls and dictionary passing remain -design sketches whose authors discuss syntax, ergonomics, migration, and coherence -([Boxy](https://www.boxyuwu.blog/posts/an-incoherent-rust/); +#31844](https://github.com/rust-lang/rust/issues/31844)). Named impls remain a design +sketch whose author discusses syntax, ergonomics, migration, and complexity +([Boxy](https://www.boxyuwu.blog/posts/an-incoherent-rust/)), and dictionary passing is a types-team +experiment whose questions include which cycles are sound +([goal #630](https://github.com/rust-lang/goals/issues/630); [Nadrieril](https://nadrieril.github.io/blog/2026/03/20/dictionary-passing-style.html)). Contexts and capabilities has open questions about thread boundaries and scope -([Mandry](https://tmandry.gitlab.io/blog/posts/2021-12-21-context-capabilities/)). Cairo's -scope-based resolution requires the caller to import the needed impls; two call sites can then -resolve the same type differently. +([Mandry](https://tmandry.gitlab.io/blog/posts/2021-12-21-context-capabilities/)). CGP requires a component definition and explicit wiring. A provider trait created by [`#[cgp_component]`](/docs/reference/macros/cgp_component) cannot retrofit a foreign trait such as @@ -372,12 +376,16 @@ These pages develop the constructs and the neighbouring comparisons: passed impls and `with` clauses. - [Type classes](./type-classes.md): the same trade seen from Haskell's side, including the `INCOHERENT` and overlapping-instance extensions. +- [Traits without coherence](./traits-without-coherence.md): how Cairo, Scala, OCaml, and Haskell + choose among several impls of one trait, compared with CGP. - [RustLab 2025 talk](/blog/rustlab-2025-coherence): why coherence exists and why specialization does not remove the overlap problem, argued on a hash-table example. +- [Blog post: Trying Incoherent Rust today](/blog/incoherent-rust-today): the proposals' examples + written in CGP, the context read as a dictionary, and where CGP diverges from the proposals. ## Sources -The Rust snippets from the proposals are quoted from their authors' posts and the Cairo book. The +The Rust snippets from the proposals are quoted from their authors' posts. The specialization snippet was compiled against a stable toolchain to confirm it is rejected with `E0658`; the CGP snippets were compiled against `cgp` `0.8.0` with a `check_components!` assertion per wired context. @@ -385,14 +393,16 @@ assertion per wired context. - [Rust Reference, *Implementations*](https://doc.rust-lang.org/reference/items/implementations.html) and [RFC 2451](https://rust-lang.github.io/rfcs/2451-re-rebalancing-coherence.html): the orphan and overlap rules. - [RFC 1210, *impl specialization*](https://rust-lang.github.io/rfcs/1210-impl-specialization.html) and [tracking issue #31844](https://github.com/rust-lang/rust/issues/31844): the strictly-more-specific rule, the `default` keyword, the lifetime soundness hole, and the `min_specialization` subset. - [Boxy, *An Incoherent Rust*](https://www.boxyuwu.blog/posts/an-incoherent-rust/): named impls, `incoherent trait`, the ecosystem-evolution motivation, and the `HashMap` and associated-type answers. -- [Nadrieril, *Elaborating Rust Traits to Dictionary-Passing Style*](https://nadrieril.github.io/blog/2026/03/20/dictionary-passing-style.html) and [*What If Traits Carried Values*](https://nadrieril.github.io/blog/2026/03/22/what-if-traits-carried-values.html): traits as structs and impls as values, and the extension that carries values. +- [Nadrieril, *Elaborating Rust Traits to Explicit Trait Proofs*](https://nadrieril.github.io/blog/2026/03/20/dictionary-passing-style.html) and [*What If Traits Carried Values*](https://nadrieril.github.io/blog/2026/03/22/what-if-traits-carried-values.html): traits as structs and impls as values, and the extension that carries values. +- [Dictionary Passing Style Experiment, goal #630](https://github.com/rust-lang/goals/issues/630): the types-team goal, its contact, and its reading list. +- [Nadrieril, *When can Traits Depend on Themselves?*](https://nadrieril.github.io/blog/2026/05/14/when-can-traits-depend-on-themselves.html) and [Niko Matsakis, *Cyclic Trait Impls*](https://smallcultfollowing.com/babysteps/series/cyclic-trait-impls/): the search for a rule that rejects unsound cycles, and perfect derive as the motivating case. - [Mandry, *Contexts and capabilities in Rust*](https://tmandry.gitlab.io/blog/posts/2021-12-21-context-capabilities/): the `with` clause and block, context-dependent trait impls, and the open questions. -- [Cairo Book, *Traits in Cairo*](https://www.starknet.io/cairo-book/ch08-02-traits-in-cairo.html) and [*Generic Data Types*](https://www.starknet.io/cairo-book/ch08-01-generic-data-types.html): named and anonymous impl parameters and compiler inference of the impl. - [Ixrec, *rust-orphan-rules*](https://github.com/Ixrec/rust-orphan-rules) and [Greyblake, *Alternative blanket implementations for a single Rust trait*](https://www.greyblake.com/blog/alternative-blanket-implementations-for-single-rust-trait/): the orphan rule as a durable frustration and the hand-rolled marker-struct workaround for overlap. - [RustLab 2025, *How to stop fighting with coherence*](/blog/rustlab-2025-coherence): why specialization does not solve overlap, and the connection to the contexts-and-capabilities proposal. --- -*An AI agent wrote this page using the CGP knowledge base. Its CGP code was verified against the -library's source and its other snippets against the toolchains named in Sources. See +*This page was written by an AI agent from the CGP knowledge base. Its CGP code was verified against +the library's source, and its other snippets were verified against the toolchains named in its +Sources section. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/comparisons/traits-without-coherence.md b/docs/comparisons/traits-without-coherence.md new file mode 100644 index 00000000..54d1bd4f --- /dev/null +++ b/docs/comparisons/traits-without-coherence.md @@ -0,0 +1,382 @@ +--- +sidebar_label: 'Without coherence' +sidebar_position: 13 +description: 'How Cairo, Scala, OCaml modular implicits, and Haskell choose among several impls of one trait, compared with Context-Generic Programming.' +--- + +# Traits without coherence + +Some trait systems let one type have several implementations of a trait, and each then has to +decide which implementation a given use gets. [Context-Generic Programming](/docs/) is one answer: +CGP enables pluggable trait implementations in Rust, as a library on the stable toolchain whose +consumer traits are ordinary traits. Each context chooses among the implementations, while every impl +that Rust checks still obeys its coherence rules. This page compares that answer with Cairo's named +impls, Scala's `given` instances, OCaml's modular implicits, and Haskell's +overlapping and incoherent instances. It covers one +question only, how each system makes the choice, and links each system's own comparison for the +rest. + +## In your terms + +A **context** is the type a CGP method runs on. It chooses implementations through its wiring and can +supply values through its fields. Often it is a type defined to stand for one application. + +Each system resolves the choice in its own place, and CGP has a construct that plays the same part: + +| System | How it chooses an implementation | Where the choice lives | In CGP | +| --- | --- | --- | --- | +| Haskell | One instance per type, with opt-in overlap | The whole program | A provider, one of several, chosen per context | +| Cairo | Inferred from the named impls a call site imports | The caller's imports | A provider named in a `delegate_components!` table | +| Scala 3 | Ranked among the `given` instances in scope | The enclosing scopes | The context's wiring, with no ranking | +| Modular implicits | Found among the implicit modules in scope, ambiguity rejected | The enclosing scopes | The context's wiring | + +## The idea + +Once a type can have several implementations, three problems follow. Two call sites can resolve the +same type differently. Changing an import can change which implementation a call uses. And a +structure such as a hash table, which needs every operation on one value to agree on one hashing +implementation, loses that agreement unless something restores it. The systems below answer in two +ways. Haskell keeps one answer for the whole program and relaxes it only by exception, while Cairo, +Scala, and modular implicits search what is in scope at the call. CGP takes a third way, fixing the +choice on a type, as the section after them shows. + +### Haskell + +Haskell resolves instances across the whole program and expects one instance per class and type, so +its departures from coherence are extensions that a programmer opts into for each instance. An +instance marked `OVERLAPPABLE` or `OVERLAPPING` may sit beside a more or less specific one, and +resolution commits only to a match that is strictly more specific than every other: + +```haskell +{-# LANGUAGE FlexibleInstances #-} +import Prelude hiding (Show, show) +import Data.List (intercalate) + +class Show a where + show :: a -> String + +instance {-# OVERLAPPABLE #-} Show a => Show [a] where -- lists in general + show xs = "[" ++ intercalate "," (map show xs) ++ "]" + +instance {-# OVERLAPPING #-} Show [Char] where -- but strings specially + show s = s +``` + +An instance marked `INCOHERENT` goes further, because resolution may commit to it even where a more +specific instance could later apply. GHC's manual warns that overlap alone "can give rise to +incoherence (different instance choices are made in different parts of the program)", and that its +optimiser "assumes that type-classes are coherent" +([GHC User's Guide](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/instances.html)). The +[type classes](./type-classes.md#overlapping-instances) page covers both extensions in full. + +### Cairo + +Cairo, the smart-contract language of Starknet, borrows Rust's syntax but gives every impl a name and +drops the requirement that an impl be unique. In the words of its design discussion, it has "no +orphan rules nor uniqueness demand" ([discussion #2744](https://github.com/starkware-libs/cairo/discussions/2744)). A +trait takes every type as an explicit parameter, an impl is written `impl Name of Trait<…>`, and a +generic impl takes the impls it depends on as parameters, named as `impl Inner: Describe` or +anonymous as `+Drop` ([Cairo Book](https://www.starknet.io/cairo-book/ch08-02-traits-in-cairo.html)). +Here two impls of one trait for `u8` coexist in separate modules: + +```rust +// Cairo +trait Describe { + fn describe(self: @T) -> felt252; +} + +mod decimal { + pub impl U8Decimal of super::Describe { + fn describe(self: @u8) -> felt252 { 10 } + } +} + +mod hex { + pub impl U8Hex of super::Describe { + fn describe(self: @u8) -> felt252 { 16 } + } +} + +impl ArrayDescribe, +Drop> of Describe> { + fn describe(self: @Array) -> felt252 { + let mut total = 0; + for x in self.span() { + total += Inner::describe(x); + }; + total + } +} + +mod uses_decimal { + use super::Describe; + use super::decimal::U8Decimal; + pub fn run() -> felt252 { + let xs: Array = array![1, 2]; + xs.describe() // ArrayDescribe with U8Decimal: 20 + } +} + +mod uses_hex { + use super::Describe; + use super::hex::U8Hex; + pub fn run() -> felt252 { + let x: u8 = 1; + x.describe() // U8Hex: 16 + } +} +``` + +The caller never passes an impl. Instead, the compiler infers each one from the impls the call site +imports, including the `Inner` impl that `ArrayDescribe` needs. That is why the two modules resolve +`Describe` differently: each imports a different impl. A call that can see both fails with +`E2313`, "Trait `Describe::` has multiple implementations", and one that can see neither fails +with "Trait has no implementation in context". A caller must also import each impl in the chain that +a generic impl needs, such as `U8Decimal` for `ArrayDescribe`. A glob import shortens that list, but +it brings in every impl in the module, so a module that holds both of them leads to the same +`E2313`. + +### Scala + +Scala 3 fills a `using` parameter from the `given` instances in scope: + +```scala +trait Comparator[A]: + def compare(x: A, y: A): Int + +given Comparator[Int]: + def compare(x: Int, y: Int): Int = x - y + +def max[A](x: A, y: A)(using c: Comparator[A]): A = + if c.compare(x, y) > 0 then x else y + +max(1, 2) // Comparator[Int] resolved and passed implicitly +``` + +Where several givens fit, Scala ranks them instead of requiring one. A given nested more deeply +wins, a case Scala 2 reported as ambiguous. An ambiguity found partway through the search is still an +error, and it is reported to the caller +([*Changes in Implicit Resolution*](https://docs.scala-lang.org/scala3/reference/changed-features/implicit-resolution.html)). +Scala 3 also keeps givens out of ordinary wildcard imports. `import A.*` brings in everything except +givens, and `import A.given` brings in the givens, so that "it is made clearer where givens in scope +are coming from" ([*Importing Givens*](https://docs.scala-lang.org/scala3/reference/contextual/given-imports.html)). +The [implicit parameters](./implicit-parameters.md#context-parameters-in-scala) page covers `given` and +`using` in full. + +### OCaml modular implicits + +The modular-implicits proposal lets an OCaml function take a module parameter that the compiler +fills from the modules declared `implicit` in scope. An implicit functor builds an instance for lists +from one for their elements: + +```ocaml +module type Show = sig + type t + val show : t -> string +end + +let show {S : Show} x = S.show x + +implicit module Show_int = struct + type t = int + let show x = string_of_int x +end + +implicit module Show_list {S : Show} = struct + type t = S.t list + let show x = "[" ^ String.concat ", " (List.map S.show x) ^ "]" +end + +let () = + print_endline (show 5); (* resolves Show_int *) + print_endline (show [1; 2; 3]) (* resolves Show_list(Show_int) *) +``` + +Different scopes can hold different implicit modules for one type. Where two would fit, resolution +rejects the call rather than ranking them, and the programmer passes the module explicitly +([White, Bour & Yallop](https://arxiv.org/abs/1512.01895)). The snippet follows the proposal paper, +because the extension exists only as an +[experimental fork](https://github.com/ocamllabs/ocaml-modular-implicits) and does not run on released +OCaml. The [ML modules](./ml-modules.md#modular-implicits) page covers it with the module system it +extends. + +## How CGP expresses it + +CGP fixes the choice on a type, and the type it uses is the context. A +**provider** is a named impl, implemented for a marker type its own crate owns, so two providers of +one component for one type coexist and Rust's overlap check accepts both. The context's +`delegate_components!` table then picks one provider for each component and value type, and every use +through that context gets the same one. The examples wire an +**[environmental context](/docs/reference/glossary#environmental-context)**, `App`, for a +[parameter-targeted](/docs/reference/glossary#parameter-targeted-component) serializer component. +The blog post [Trying Incoherent Rust today](/blog/incoherent-rust-today#named-impls) turns the +named impls proposed for Rust into providers in the same way. + +### Assembling the chain at the call + +Cairo's `ArrayDescribe`, a generic impl that takes its element's impl as a parameter, can be written +almost directly in CGP. Here the same shape serializes a list: the element's provider becomes a type +parameter of a [higher-order provider](/docs/concepts/higher-order-providers), bound with +`#[use_provider]`, and the caller assembles the chain that Cairo would infer: + +```rust +#[cgp_component(ValueSerializer)] +pub trait CanSerializeValue { + fn serialize(&self, value: &T, output: &mut Vec); +} + +#[cgp_impl(new VecSerdeWith)] +#[use_provider(Inner: ValueSerializer)] +impl ValueSerializer> { + fn serialize(&self, value: &Vec, output: &mut Vec) { + output.push(value.len() as u64); + for item in value { + Inner::serialize(self, item, output); + } + } +} + +// The caller names every provider in the chain. +> as ValueSerializer>>::serialize( + &App, &value, &mut output, +); +``` + +The example omits the `PairSerdeWith`, `U8Serde`, and `BoolSerde` providers, which follow the same +pattern. Written this way, every caller repeats the assembly that Cairo's compiler infers from imports. + +### Fixing the choice on the context + +Idiomatic CGP moves the choice to the context. The provider asks the context for the element's +serializer through `#[uses]`, and the context's table answers once, for every caller: + +```rust +#[cgp_impl(new VecSerde)] +#[uses(CanSerializeValue)] +impl ValueSerializer> { + fn serialize(&self, value: &Vec, output: &mut Vec) { + output.push(value.len() as u64); + for item in value { + self.serialize(item, output); + } + } +} + +pub struct App; + +delegate_components! { + App { + open ValueSerializerComponent; + + @ValueSerializerComponent. Vec: VecSerde, + @ValueSerializerComponent. (A, B): PairSerde, + @ValueSerializerComponent.u8: U8Serde, + @ValueSerializerComponent.bool: BoolSerde, + } +} + +check_components! { + App { + ValueSerializerComponent: Vec<(u8, bool)>, + } +} +``` + +Code that serializes through `App` imports only the consumer trait, `CanSerializeValue`, and calls +`app.serialize(&value, &mut output)`. The `open` statement dispatches the component by value type, +and the table is the one place a reader looks to learn which provider each type gets. This answers +all three problems. Every call through `App` agrees, and no import can change a choice. The +agreement a hash table needs also follows from the context, for every component the context wires. A +second context with a different provider for `u8` makes a different choice from the same providers. + +CGP does not relax Rust's coherence to do this. Each provider implements the provider trait for its +own type, and each table entry is an ordinary impl on the context, so a second entry for the same +context and value type fails with `E0119`, like any overlapping impl. +[Bypassing coherence](/docs/concepts/coherence) explains the arrangement in full. + +## What each approach costs + +Each system's costs are the ones its own documentation and authors name: + +- **Haskell:** the overlap extensions trade away determinism, and GHC's manual warns that they can + make different parts of a program choose different instances. +- **Cairo:** a caller imports every impl in the chain, and imports decide the choice, so two call + sites in one project can use different impls for one type. +- **Scala 3:** the ranking rules decide among givens in scope, and they changed between Scala 2 and + Scala 3; the redesign also renamed Scala 2's overloaded `implicit` keyword to `given` and `using`. +- **Modular implicits:** the proposal has not shipped in OCaml, so it has no users to report on. + +CGP's costs are its ordinary ones. The component and its providers need declarations, and the wiring +is code someone writes and reads. Wiring also adds compile-time work, and its raw errors are trait-solver +output over generated types. [`cargo cgp check`](/docs/tooling/cargo-cgp/check) leads with the root +cause for the classes it recognizes, and the tool does not yet reshape every class. CGP reaches only +the traits defined as components, so it cannot give `serde::Serialize` a second impl without a +parallel component. And it cannot nest choices: a block inside a program cannot override the +context's wiring for the code it encloses, as Scala's nesting rule allows. The +[Modularity Hierarchy](/docs/concepts/modularity-hierarchy) page weighs these costs against simpler +approaches. + +## Where another system is the better choice + +Each of the other systems fits a setting better than CGP does: + +- **Haskell's global instances** give the same answer everywhere with no table, which suits code + that needs one meaning per type, as Rust's own coherence does for ordinary Rust code. +- **Cairo's and Scala's inference** keeps a small program free of wiring when it needs only one + choice per type and its imports are easy to follow. +- **A language feature,** such as an incoherent Rust, would reach existing traits like + `serde::Serialize`, which a library cannot. The blog post [Trying Incoherent Rust + today](/blog/incoherent-rust-today#ideas-from-cgp-for-incoherent-rust) suggests which of CGP's + features such a language could adopt. + +CGP fits a program that needs several valid implementations of a trait and wants each application +to make its choice once, in a table it can read, on stable Rust today. + +## What to expect that differs + +A reader coming from these systems may expect behavior that CGP does not have: + +- **CGP does not search scope.** A context names every provider it uses, so importing a provider + never changes a choice. The cost is that the choice must be written down. +- **CGP keeps Rust's coherence rules.** The provider traits allow several implementations, but every + impl Rust checks is coherent, so the compiler never picks between two candidates on its own, as it + may with Haskell's `INCOHERENT` instances. +- **Choices belong to types, not blocks.** A different choice needs another context type rather than + an inner scope. +- **Generic code names only the consumer trait.** It never names a provider, so the same function + works with any context that wires the component. + +## Where to go next + +These pages develop the ideas this comparison rests on: + +- [Bypassing coherence](/docs/concepts/coherence): the coherence rules and how separate provider types + work within them. +- [Higher-order providers](/docs/concepts/higher-order-providers): providers that take other providers + as parameters, as the Cairo-style chain does. +- [Rust's own proposals](./rust-language-proposals.md): specialization, dictionary passing, named + impls, and contexts and capabilities. +- [Type classes](./type-classes.md), [Implicit parameters](./implicit-parameters.md), and + [ML modules](./ml-modules.md): the full comparisons with Haskell, Scala, and OCaml. +- [Blog post: Trying Incoherent Rust today](/blog/incoherent-rust-today): CGP set against the named + impls and incoherent traits proposed for Rust. + +## Sources + +The Cairo snippet was compiled and run with Cairo 2.21.0 (`cairo-run`), and the errors it quotes come +from that release. The Haskell snippet was compiled with GHC 9.10 and the Scala snippet with Scala +3.8.4, as on their own comparison pages. The modular-implicits snippet follows the proposal paper and +cannot run on released OCaml. The CGP snippets +were compiled against `cgp` `0.8.0` with a `check_components!` assertion on `App`. + +- [Cairo Book, *Traits in Cairo*](https://www.starknet.io/cairo-book/ch08-02-traits-in-cairo.html) and [*Generic Data Types*](https://www.starknet.io/cairo-book/ch08-01-generic-data-types.html): the `impl Name of Trait` form, named and anonymous impl parameters, and inferred impls. +- [Cairo design discussion #2744](https://github.com/starkware-libs/cairo/discussions/2744): Cairo's lack of orphan rules and of a uniqueness requirement. +- [GHC User's Guide, *Instance declarations and resolution*](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/instances.html): the overlap and incoherence pragmas and the manual's warnings. +- [Scala 3 Reference, *Changes in Implicit Resolution*](https://docs.scala-lang.org/scala3/reference/changed-features/implicit-resolution.html) and [*Importing Givens*](https://docs.scala-lang.org/scala3/reference/contextual/given-imports.html): the nesting rule, propagated ambiguity, and given imports. +- [White, Bour & Yallop, *Modular implicits*](https://arxiv.org/abs/1512.01895) and the [experimental fork](https://github.com/ocamllabs/ocaml-modular-implicits): implicit module parameters, implicit functors, and rejected ambiguity. + +--- + +*This page was written by an AI agent from the CGP knowledge base. Its CGP code was verified against +the library's source, and its other snippets were verified against the toolchains named in its +Sources section. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/comparisons/type-classes.md b/docs/comparisons/type-classes.md index 4257ff3c..e9946354 100644 --- a/docs/comparisons/type-classes.md +++ b/docs/comparisons/type-classes.md @@ -380,6 +380,7 @@ the Lean snippet evaluated with Lean 4.34.0. The CGP snippets were compiled agai --- -*An AI agent wrote this page using the CGP knowledge base. Its CGP code was verified against the -library's source and its other snippets against the toolchains named in Sources. See +*This page was written by an AI agent from the CGP knowledge base. Its CGP code was verified against +the library's source, and its other snippets were verified against the toolchains named in its +Sources section. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/concepts/abstract-types.md b/docs/concepts/abstract-types.md index 90c06ee4..771d1327 100644 --- a/docs/concepts/abstract-types.md +++ b/docs/concepts/abstract-types.md @@ -1,7 +1,7 @@ --- title: 'Let each context choose a shared type' sidebar_label: 'Abstract types' -sidebar_position: 5 +sidebar_position: 6 description: 'How a context chooses an associated type through wiring, so providers share one scalar, error type, or runtime without adding a parameter at every call.' --- @@ -203,6 +203,6 @@ These pages explain related dependencies and the constructs used here: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/concepts/aggregate-providers.md b/docs/concepts/aggregate-providers.md index 1e0bfbe4..613f53e7 100644 --- a/docs/concepts/aggregate-providers.md +++ b/docs/concepts/aggregate-providers.md @@ -1,7 +1,7 @@ --- title: 'Reuse a group of wiring choices as one provider' sidebar_label: 'Aggregate providers' -sidebar_position: 8 +sidebar_position: 9 description: 'How a provider bundle records a group of wiring choices once, why a context delegates to it, and why a bundle must be checked through a real context.' --- @@ -68,6 +68,8 @@ the provider's requirements. The same delegation can continue through another bundle. At each step, the compiler follows the next table while keeping the original context argument, until it reaches the provider that performs the work. It resolves that chain at compile time, so adding a bundle does not add a runtime lookup. +[Type-level tables](./type-level-tables.md#prototype-chains) shows, in plain Rust, how a table asks +the table its entry names, as a bundle does here. ## Checking a bundle as a context @@ -157,6 +159,7 @@ still need to use the intended context. These pages explain related wiring choices and checks: - [Namespaces](./namespaces.md): Sharing tables through paths and inheritance. +- [Type-level tables](./type-level-tables.md): The lookups a bundle chains together. - [Consumer and provider traits](./consumer-and-provider-traits.md): How delegation preserves the context. - [Checking your wiring](./check-traits.md): Context checks and checks on individual providers. - [`delegate_components!`](/docs/reference/macros/delegate_components): The `new` and grouped-key forms. @@ -165,6 +168,6 @@ These pages explain related wiring choices and checks: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/concepts/check-traits.md b/docs/concepts/check-traits.md index 0b63110e..03e2f199 100644 --- a/docs/concepts/check-traits.md +++ b/docs/concepts/check-traits.md @@ -1,7 +1,7 @@ --- title: 'Check wiring where the choice is written' sidebar_label: 'Checking your wiring' -sidebar_position: 6 +sidebar_position: 7 description: 'How check traits and check_components! verify a context wiring beside the table, what the raw and rewritten diagnostics show, and what a check does not prove.' --- @@ -135,6 +135,40 @@ implementation. The cause is closer to the surface, but the field tags still app character types, leaving `local_dir` and `bucket_id` difficult to recognize. The headline also refers to the generated `CanUseComponent` bound rather than the public trait. +## The `IsProviderFor` marker + +The note at the end of that error names +[`IsProviderFor`](/docs/reference/traits/wiring/is_provider_for), the trait that lets a check reach +the missing field. It is an empty marker trait whose job is to carry each provider's requirements. +The provider macros implement it for every provider with the same bounds as the provider's own +implementation. `FetchLocalObject` reads a `local_dir` field through an implicit argument, so it +implements `IsProviderFor` only if `BrokenApp` has that +field. + +Every provider trait requires the marker as a [supertrait](/docs/reference/glossary#supertrait). It is +the checking bound that the trait signatures on +[Consumer and provider traits](./consumer-and-provider-traits.md) leave out: + +```rust +pub trait StorageObjectFetcher: + IsProviderFor +{ + fn fetch_storage_object( + context: &Context, + object_id: &str, + ) -> anyhow::Result>; +} +``` + +The wiring passes the marker along as well. `delegate_components!` writes an `IsProviderFor` +implementation beside each table entry, which holds for the context exactly when it holds for the +chosen provider, and the generated implementation that reads the table requires it, as the call +trace on [Consumer and provider traits](./consumer-and-provider-traits.md#how-a-call-finds-its-provider) +shows. So when the check asks whether `BrokenApp` can use the component, the compiler follows the +entry to `FetchLocalObject` and evaluates that provider's requirements, which the marker states +explicitly, and it can report the `HasField` bound that failed. The macros generate every +`IsProviderFor` implementation, so code never writes one by hand. + ## Reading the errors with cargo-cgp [`cargo cgp check`](/docs/tooling/cargo-cgp/check) rewrites recognized CGP diagnostics @@ -230,6 +264,8 @@ These pages explain the dependencies being checked and the available check forms - [Impl-side dependencies](./impl-side-dependencies.md): Why provider requirements can be absent from the caller's interface. +- [Consumer and provider traits](./consumer-and-provider-traits.md): The wiring table a check follows + to the chosen provider. - [Higher-order providers](./higher-order-providers.md): Composing providers and checking their layers. - [Aggregate providers](./aggregate-providers.md): Verifying shared wiring against a real context. - [`check_components!`](/docs/reference/macros/check_components): Component parameters and @@ -240,6 +276,6 @@ These pages explain the dependencies being checked and the available check forms --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/concepts/coherence.md b/docs/concepts/coherence.md index 46e3b47f..5a8e7429 100644 --- a/docs/concepts/coherence.md +++ b/docs/concepts/coherence.md @@ -185,7 +185,9 @@ assert_eq!(>::encode(&value), b"6869"); The provider struct also gives its crate a local implementing type, so the crate can supply a provider even when both the trait and the context type are defined elsewhere. Distinct provider types avoid overlap, and local ownership satisfies the orphan rule, so the generated code follows -both coherence rules. +both coherence rules. The same split also lets CGP express the *incoherent traits* proposed for Rust +in 2026, whose implementations may overlap. The blog post [Trying Incoherent Rust +today](/blog/incoherent-rust-today#incoherent-traits) shows the translation. ## Selecting one provider for each type {#coherence-comes-back-one-type-at-a-time} @@ -198,7 +200,8 @@ delegate_components! { Vec { EncoderComponent: EncodeAsHex } } ``` Rust's rule still holds, but the choice now lives in the wiring: coherence is scoped to each -provider type, and each value type names one of them. +provider type, and each value type names one of them. The table itself is a set of trait +implementations the compiler looks up, which [Type-level tables](./type-level-tables.md) explains. ![Diagram: both blanket impls match String, so Rust rejects the second with E0119. CGP gives each encoder its own provider type, so String is wired to EncodeAsText and Vec of bytes to EncodeAsHex, and both impls coexist while each value type names one provider.](/img/coherence-scoped.svg) @@ -252,17 +255,21 @@ with related approaches: - [Modularity Hierarchy](./modularity-hierarchy.md): When a plain trait is enough and when further provider choices are useful. - [Consumer and provider traits](./consumer-and-provider-traits.md): How a method call reaches its provider. +- [Type-level tables](./type-level-tables.md): How the wiring table works as a compile-time map. - [Hello World tutorial](/docs/tutorials/hello) and [Area calculation series](/docs/tutorials/area-calculation/): Working examples of the component model. - [`#[cgp_component]`](/docs/reference/macros/cgp_component), [`#[cgp_impl]`](/docs/reference/macros/cgp_impl), and [`delegate_components!`](/docs/reference/macros/delegate_components): The constructs used here. - [RustLab 2025 talk](/blog/rustlab-2025-coherence): A longer account of coherence and CGP's approach. +- [Blog post: Trying Incoherent Rust today](/blog/incoherent-rust-today): Which parts of the Rust + discussion of incoherent traits CGP can express on stable Rust, and where it falls short. - [Comparison: Type classes](/docs/comparisons/type-classes): How Haskell, Agda, and Lean handle coherence. - [Comparison: Rust's own proposals](/docs/comparisons/rust-language-proposals): Changes Rust has considered for its coherence rules. +- [Comparison: Traits without coherence](/docs/comparisons/traits-without-coherence): How Cairo, Scala, OCaml, and Haskell choose among several impls of one trait. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/concepts/consumer-and-provider-traits.md b/docs/concepts/consumer-and-provider-traits.md index 76600fe7..0512be51 100644 --- a/docs/concepts/consumer-and-provider-traits.md +++ b/docs/concepts/consumer-and-provider-traits.md @@ -82,7 +82,7 @@ The provider trait moves the consumer's `Self` into a `Context` parameter. Its m the context as an explicit argument, leaving the implementing type free to name the behavior. The signatures below show the split. They omit a generated checking bound on the provider trait, -which the call trace explains later: +which the call trace below names: ```rust // what callers use @@ -217,18 +217,23 @@ gives `App` its own `StorageObjectFetcher` implementation, which in turn su throughout, so the final provider receives the same application value on which the caller invoked the method. -The other bound, [`IsProviderFor`](/docs/reference/traits/wiring/is_provider_for), helps check -that the provider's dependencies hold. Provider macros generate an implementation of this trait -with the provider's bounds, and the provider trait requires it as a -[supertrait](/docs/reference/glossary#supertrait). This is the checking bound omitted from the -earlier `StorageObjectFetcher` declaration. Explicit component checks use it to expose missing -requirements that a consumer-trait error can hide. +The other bound, [`IsProviderFor`](/docs/reference/traits/wiring/is_provider_for), is the checking +bound omitted from the earlier `StorageObjectFetcher` declaration. Provider macros generate it with +each provider's bounds, and +[Checking your wiring](./check-traits.md#the-isproviderfor-marker) explains how a check uses it to +name a missing requirement. The listings use shorter names to keep this connection readable. In an actual expansion, the parameters are `__Context__` and `__Provider__`, and the delegate is spelled as `<__Provider__ as DelegateComponent>::Delegate`. You can inspect the full expansion of a concrete component with [`cargo cgp expand`](/docs/tooling/cargo-cgp/expand). +The table these implementations read is an ordinary use of Rust's trait system: a trait whose +associated type names a value for each key. [Type-level tables](./type-level-tables.md) shows that +mechanism in plain Rust, beside the value-level map it mirrors. The second implementation has the shape of a +[prototype chain](/docs/reference/glossary#prototype-chain): a type without a provider of its own asks the one its entry names, and that one may delegate in +turn, as [Prototype chains](./type-level-tables.md#prototype-chains) shows. + ## Writing a component The macros generate these connections while letting you write methods from the context's point @@ -344,6 +349,10 @@ and the choices each context must make. These pages develop those ideas and show model in practice: - [Bypassing coherence](./coherence.md): Why distinct provider types permit reusable alternatives. +- [Type-level tables](./type-level-tables.md): How a trait works as a compile-time table, in plain + Rust. +- [Checking your wiring](./check-traits.md): The checking bound on the provider trait, and how a check + uses it. - [Impl-side dependencies](./impl-side-dependencies.md): How a provider states requirements without adding them to the caller's interface. - [Area calculation tutorial](/docs/tutorials/area-calculation/): Building the same split from plain @@ -351,11 +360,11 @@ model in practice: - [`#[cgp_component]`](/docs/reference/macros/cgp_component), [`#[cgp_impl]`](/docs/reference/macros/cgp_impl), and [`delegate_components!`](/docs/reference/macros/delegate_components): Exact syntax and generated code. -- [Comparison: Dynamic dispatch](/docs/comparisons/dynamic-dispatch): How compile-time wiring compares with a runtime vtable. +- [Comparison: Dynamic dispatch](/docs/comparisons/dynamic-dispatch): How compile-time wiring compares with vtables and prototype chains. - [Comparison: Policy-based design](/docs/comparisons/policy-based-design): The corresponding split in C++ policy classes and host templates. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/concepts/dispatching.md b/docs/concepts/dispatching.md index cdbd8749..45677e7f 100644 --- a/docs/concepts/dispatching.md +++ b/docs/concepts/dispatching.md @@ -1,7 +1,7 @@ --- title: 'Route fields and variants to their handlers' sidebar_label: 'Dispatching' -sidebar_position: 15 +sidebar_position: 16 description: 'How a dispatcher routes record fields and enum variants to the providers that process them, and how the compiler checks coverage and completeness.' --- @@ -157,6 +157,6 @@ These pages explain the data operations and computation interfaces behind dispat --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/concepts/extensible-records.md b/docs/concepts/extensible-records.md index 0788c108..6defb094 100644 --- a/docs/concepts/extensible-records.md +++ b/docs/concepts/extensible-records.md @@ -1,7 +1,7 @@ --- title: 'Build a struct field by field, checked at compile time' sidebar_label: 'Extensible records' -sidebar_position: 13 +sidebar_position: 14 description: 'How a struct field list becomes a type, how a builder records which fields are present, and how independent providers assemble a record the compiler checks.' --- @@ -173,6 +173,6 @@ These pages explain related data operations and the traits used here: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/concepts/extensible-variants.md b/docs/concepts/extensible-variants.md index 049625da..c293a149 100644 --- a/docs/concepts/extensible-variants.md +++ b/docs/concepts/extensible-variants.md @@ -1,7 +1,7 @@ --- title: 'Handle every enum variant without a wildcard' sidebar_label: 'Extensible variants' -sidebar_position: 14 +sidebar_position: 15 description: 'How an enum variant list becomes a sum type, how extraction proves every variant is handled without a wildcard, and how one handler serves several enums.' --- @@ -187,6 +187,6 @@ These pages explain the related representations and operations: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/concepts/handlers.md b/docs/concepts/handlers.md index 694233f4..284209d9 100644 --- a/docs/concepts/handlers.md +++ b/docs/concepts/handlers.md @@ -1,7 +1,7 @@ --- title: 'Represent a computation as a selectable component' sidebar_label: 'Handlers' -sidebar_position: 11 +sidebar_position: 12 description: 'How CGP represents computations as components, the synchronous, async, fallible, and borrowed forms, and how a wiring entry composes them into a pipeline.' --- @@ -208,6 +208,6 @@ These pages explain composition and specify the handler interfaces: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/concepts/higher-order-providers.md b/docs/concepts/higher-order-providers.md index 2352f497..eb33b797 100644 --- a/docs/concepts/higher-order-providers.md +++ b/docs/concepts/higher-order-providers.md @@ -1,7 +1,7 @@ --- title: 'Compose providers that take other providers' sidebar_label: 'Higher-order providers' -sidebar_position: 7 +sidebar_position: 8 description: 'How a provider takes another provider as a parameter, so a wrapper such as scaling reuses one body with different inner calculations.' --- @@ -14,8 +14,8 @@ the inner implementation that produces the result. Wiring can then combine the s different inner providers, while both operate on the same context. This page builds a scaling wrapper, shows the bound that names its inner provider, and covers -compositions named before any context uses them, the `UseContext` default, and what deeper -compositions cost. +compositions named before any context uses them, the `UseContext` default, a provider carried by a +value, and what deeper compositions cost. ## Wrapping a provider @@ -152,6 +152,35 @@ To give the parameter its `UseContext` default, declare the provider struct expl The `#[cgp_impl(SumAreas)]` block then implements that existing struct, because the `new` form would declare a provider without the default. +## A provider carried by a value + +A provider can also be a type parameter of something other than a provider. A value type can carry +its calculator in its type, so the value fixes how it is measured wherever it goes: + +```rust +pub struct Measured { + pub shape: Shape, + pub calculator: PhantomData, +} + +#[cgp_fn] +#[use_provider(Calculator: ShapeAreaCalculator)] +pub fn measured_area(&self, measured: &Measured) -> f64 { + Calculator::shape_area(self, &measured.shape) +} +``` + +A [`#[cgp_fn]`](/docs/reference/macros/cgp_fn) function binds and calls the provider the same way a +higher-order provider does, though the trait it generates is not itself a provider. +`#[use_provider]` completes the bound to `Calculator: ShapeAreaCalculator`, and the body +calls the provider explicitly with the context. A `Measured` therefore uses +`RectangleArea` whichever context calls `measured_area` on it, regardless of that context's own +wiring, while the context must still meet the provider's requirements. + +Carrying the choice in a value's type suits data that must keep one implementation across contexts. +Each choice the value fixes adds a type parameter, though, so a value that fixes several becomes +harder to write than one that leaves them to its context. + ## Other generic providers A generic provider is higher-order when its parameter represents a provider used to perform work. @@ -212,6 +241,6 @@ These pages explain related forms of composition and their checks: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/concepts/impl-side-dependencies.md b/docs/concepts/impl-side-dependencies.md index 8136e2ed..e9d5f849 100644 --- a/docs/concepts/impl-side-dependencies.md +++ b/docs/concepts/impl-side-dependencies.md @@ -1,7 +1,7 @@ --- title: 'Keep provider dependencies out of the caller interface' sidebar_label: 'Impl-side dependencies' -sidebar_position: 3 +sidebar_position: 4 description: 'How a provider keeps its trait, value, and type requirements out of the caller interface, and how CGP checks them when a context selects the provider.' --- @@ -309,6 +309,6 @@ check them: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/concepts/implicit-arguments.md b/docs/concepts/implicit-arguments.md index 537fa8d3..0551d77b 100644 --- a/docs/concepts/implicit-arguments.md +++ b/docs/concepts/implicit-arguments.md @@ -1,7 +1,7 @@ --- title: 'Read context values without extra parameters' sidebar_label: 'Implicit arguments' -sidebar_position: 4 +sidebar_position: 5 description: 'How implicit arguments read context fields through function parameters, how the declared type controls borrowing and cloning, and when a getter trait is the better fit.' --- @@ -105,7 +105,8 @@ pub fn describe( An owned argument calls `.clone()` on the field, leaving the stored value in the context. A `&str` argument reads any field implementing `AsRef` with `.as_ref()`, and `&Vec` borrows the -vector directly. Prefer a borrow when the body only needs to read the value, especially when cloning +vector directly. The same rule applies to a field whose type is itself a reference: a field of type +`&'a Config` is read by an argument of type `&&'a Config`, a borrow of the stored reference. Prefer a borrow when the body only needs to read the value, especially when cloning would allocate or copy substantial data. The macro supports specific access forms rather than arbitrary conversions between types. The @@ -177,6 +178,6 @@ These pages connect implicit arguments to the rest of CGP: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/concepts/index.md b/docs/concepts/index.md index 16321b3f..11acedf8 100644 --- a/docs/concepts/index.md +++ b/docs/concepts/index.md @@ -47,6 +47,8 @@ on them and where that additional structure is useful: separate provider types let alternative implementations coexist. - [Consumer and provider traits](./consumer-and-provider-traits.md): How the trait split and wiring connect a method call to a provider. +- [Type-level tables](./type-level-tables.md): How a trait with an associated type works as a + compile-time map, in plain Rust. - [Modularity Hierarchy](./modularity-hierarchy.md): How to choose how much of CGP a program needs. ### Dependencies @@ -92,6 +94,6 @@ at the page that explains each term. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/concepts/modular-error-handling.md b/docs/concepts/modular-error-handling.md index 24fd3209..d21fa5f3 100644 --- a/docs/concepts/modular-error-handling.md +++ b/docs/concepts/modular-error-handling.md @@ -1,7 +1,7 @@ --- title: 'Choose one error type for the whole context' sidebar_label: 'Modular error handling' -sidebar_position: 10 +sidebar_position: 11 description: 'How a context chooses one error type and the providers that raise and wrap it, so reusable code reports failures without fixing their representation.' --- @@ -261,6 +261,6 @@ it needs. These pages explain the supporting mechanisms and available providers: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/concepts/modularity-hierarchy.md b/docs/concepts/modularity-hierarchy.md index c85f704a..c1c41cef 100644 --- a/docs/concepts/modularity-hierarchy.md +++ b/docs/concepts/modularity-hierarchy.md @@ -1,7 +1,7 @@ --- title: 'When to use CGP, and when a plain trait is enough' sidebar_label: 'Modularity Hierarchy' -sidebar_position: 18 +sidebar_position: 19 description: 'How implementation choice grows from a shared blanket impl to providers selected per context and target, and how to pick the least complex tier your program needs.' --- @@ -214,12 +214,18 @@ delegate_components! { `ApiServer` encodes a `String` as text, while `Firmware` encodes its bytes as hexadecimal. A crate owning either context can supply that wiring even when it owns neither the component nor `String`. -Ownership of the context satisfies Rust's rules for the wiring implementation. - -Making the value a parameter enables these independent application choices. A self-targeted -trait cannot gain that separation through wiring alone, because its interface still treats the -context as the value. With the parameter-targeted interface, each context must cover the target -types it uses, although generic entries can supply providers for whole families of targets. +Ownership of the context satisfies Rust's rules for the wiring implementation. The `open` statement +turns the value type into part of the lookup key, as +[Namespaces](./namespaces.md#presets-and-per-type-dispatch) explains. + +Making the value a parameter enables these independent application choices. A self-targeted trait +cannot gain that separation through wiring alone, because its interface still treats the context as +the value. With the parameter-targeted interface, each context must cover the target types it uses, +although generic entries can supply providers for whole families of targets. The parameter also has +to be in the trait from the start: it cannot be retrofitted onto an existing trait such as +`serde::Serialize` without a breaking change. `Serialize` is redefined both ways in the blog post +[Trying Incoherent Rust today](/blog/incoherent-rust-today#bypassing-coherence): first as a +self-targeted component, then as a parameter-targeted one. ## Tier 5: an inner provider chosen locally @@ -388,11 +394,13 @@ These pages explain the mechanisms and develop working examples: - [Area calculation](/docs/tutorials/area-calculation/): A tutorial progressing from functions to components and composition. - [`#[cgp_component]`](/docs/reference/macros/cgp_component): Component definitions and generated traits. +- [Blog post: Trying Incoherent Rust today](/blog/incoherent-rust-today#bypassing-coherence): Two + levels of bypassing coherence, worked through serde's `Serialize`. - [Comparison: Type classes](/docs/comparisons/type-classes): How context-based selection changes the scope of implementation choices. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/concepts/monadic-handlers.md b/docs/concepts/monadic-handlers.md index a7ac79cc..119515d1 100644 --- a/docs/concepts/monadic-handlers.md +++ b/docs/concepts/monadic-handlers.md @@ -1,7 +1,7 @@ --- title: 'Choose how a pipeline continues on a result' sidebar_label: 'Monadic handlers' -sidebar_position: 12 +sidebar_position: 13 description: 'How monadic handlers put a pipeline continuation rule in a type, the err, ok, and identity monads, and how a monad transformer stacks two result layers.' --- @@ -136,6 +136,6 @@ These pages cover the computations, applications, and traits behind the pipeline --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/concepts/namespaces.md b/docs/concepts/namespaces.md index 9adbba4f..6d5f4bb3 100644 --- a/docs/concepts/namespaces.md +++ b/docs/concepts/namespaces.md @@ -1,7 +1,7 @@ --- title: 'Share and inherit wiring with namespaces' sidebar_label: 'Namespaces' -sidebar_position: 9 +sidebar_position: 10 description: 'How a namespace names and routes shared wiring, how contexts inherit it while filling unbound paths, and why an inherited binding cannot be overridden.' --- @@ -13,8 +13,8 @@ contexts can inherit. It organizes component lookups under paths, allowing a sha the choices its contexts have in common and leave other destinations for each context to fill. The distinction matters: a context can fill an unbound path, but it cannot replace an inherited binding. -This page starts from repeated wiring, follows a lookup along its path, shows why a bound entry -cannot be overridden, and ends with presets and per-type dispatch. +This page starts from repeated wiring, follows a lookup along its path and the registration behind +it, shows why a bound entry cannot be overridden, and ends with presets and per-type dispatch. ## Repeated wiring @@ -54,14 +54,15 @@ visible: cgp_namespace! { new AppNamespace {} } #[cgp_component(Greeter)] -#[prefix(@app.GreeterComponent in AppNamespace)] +#[prefix(@app in AppNamespace)] pub trait CanGreet { fn greet(&self) -> String; } ``` -`AppNamespace` routes requests for the greeter through `@app.GreeterComponent`. A context joins the -namespace and supplies the provider at that path: +`AppNamespace` routes requests for the greeter through `@app.GreeterComponent`: the attribute names +the prefix, and the macro appends the component's marker to it. A context joins the namespace and +supplies the provider at that path: ```rust delegate_components! { @@ -81,12 +82,40 @@ entries no priority. The route can also cover a group of components. Redirecting a shared prefix sends the subsystem's lookups to another prefix, while the rest of each path still identifies the component and its parameters. The [`cgp_namespace!` reference](/docs/reference/macros/cgp_namespace) gives the syntax -for these grouped redirections. +for these grouped redirections, and [Presets and per-type dispatch](#presets-and-per-type-dispatch) +shows how a path is looked up as a single key. + +## Registering from the component's side + +A namespace is a table written from the key's side rather than the table's. In a context's own +wiring table, the context is the implementing type, so only the crate that owns the context can add +an entry for a key it does not own. A namespace entry instead implements the namespace trait for the +key, with the table left as a parameter. The greeter's `#[prefix(@app in AppNamespace)]` produces +an implementation like this one, shown with a readable name for the table parameter: + +```rust +impl AppNamespace
for GreeterComponent { + type Delegate = RedirectLookup; +} +``` + +Because this implementation is for the component marker, the crate that defines the component can +register its route in a namespace that it does not own, for every context that later joins. +Registered defaults follow the same [orphan rule](/docs/reference/glossary#orphan-rule) more +narrowly: [`#[default_impl]`](/docs/reference/attributes/default_impl) needs the crate to own the +namespace, or a local type before the table parameter, such as the key or a component named in the +namespace path. + +Joining works from the context's side again. `namespace AppNamespace;` adds one blanket entry to the +context's table that forwards every key the namespace answers. A direct entry for a key the namespace +binds therefore overlaps that blanket entry, as [Overriding a bound entry](#overriding-a-bound-entry) +shows. A `for … in` loop in `delegate_components!` copies registered defaults into a context's table. ## Binding shared choices -A child namespace can inherit routes and bind the choices its contexts share. Assume `Farewell` -is registered in `AppNamespace` at `@app.FarewellComponent`, just as the greeter is registered above: +A child namespace can inherit routes and bind the choices its contexts share. Assume `Farewell` is +registered with `#[prefix(@app in AppNamespace)]`, as the greeter is above, so its route is +`@app.FarewellComponent`: ```rust cgp_namespace! { @@ -133,7 +162,9 @@ delegate_components! { Joining this namespace already generates a forwarding implementation for `GreeterComponent`. The local entry tries to implement the same lookup again, so Rust rejects the overlap. A child -namespace that redefines an inherited key runs into the same conflict. +namespace that redefines an inherited key runs into the same conflict. The same rule holds for a single +table, where a type cannot both answer a component and delegate it, as +[Prototype chains](./type-level-tables.md#prototype-chains) shows. Keep configurable paths unbound in the shared base. Returning to the path-based example, each configuration can bind the open greeter path in its own child namespace: @@ -173,6 +204,32 @@ provider for `String`. This uses path routing without requiring a shared namespa component has a namespace prefix, however, its lookups already follow that prefixed route. Entries must use the full path, because opening its bare name does not reach them. +Each `@` key in such a table is a path. The `open` statement routes the component to +[`RedirectLookup`](/docs/reference/providers/redirect_lookup), a provider that every component +already has. It appends each of the component's type parameters to the path and looks the whole path +up in the context's table, in one query. A path entry ends in a generic tail, so a key matches every +longer path beneath it, and a shorter key beside a longer one gives two answers for the same lookup. +With a converter component that takes a source and a target type, this table is rejected: + +```rust +delegate_components! { + App { + open ConverterComponent; + + // The shorter key matches every path beneath it, `@ConverterComponent.u8.u64` included. + @ConverterComponent.u8: ConvertFromU8, + @ConverterComponent.u8.u64: ConvertU8ToU64, + } +} +// error[E0119]: conflicting implementations of trait +// `DelegateComponent>>>` +// for type `App` +``` + +The table has no rule that the most specific entry wins, so each lookup must have exactly one key +that matches it. A generic segment, such as ` Target` in a key's last position, likewise +matches every type there. + ## What it costs Binding a shared key commits every joining context to that choice. If a later context needs a @@ -198,6 +255,8 @@ structure. An [aggregate provider](/docs/reference/glossary#aggregate-provider) These pages cover simpler grouping and the namespace constructs: - [Aggregate providers](./aggregate-providers.md): Reusing selected groups of providers. +- [Type-level tables](./type-level-tables.md): How a trait works as a compile-time table, in plain + Rust. - [Bypassing coherence](./coherence.md) and [Dispatching](./dispatching.md): Provider selection and per-type dispatch. - [`cgp_namespace!`](/docs/reference/macros/cgp_namespace): Namespace definitions and inheritance. @@ -206,11 +265,9 @@ These pages cover simpler grouping and the namespace constructs: using `open`. - [`RedirectLookup`](/docs/reference/providers/redirect_lookup) and [`Path!`](/docs/reference/macros/path): The routing provider and path types. -- [Comparison: Dynamic dispatch](/docs/comparisons/dynamic-dispatch): Shared defaults and the - differences between namespace inheritance and runtime prototype lookup. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/concepts/send-bounds.md b/docs/concepts/send-bounds.md index f17202ae..2a94dd68 100644 --- a/docs/concepts/send-bounds.md +++ b/docs/concepts/send-bounds.md @@ -1,7 +1,7 @@ --- title: 'Recover a Send bound from an async trait method' sidebar_label: 'Recovering Send bounds' -sidebar_position: 17 +sidebar_position: 18 description: 'How a companion trait exposes a sendable future when an async CGP method leaves Send open, and why the forwarding implementation needs a concrete context.' --- @@ -152,6 +152,6 @@ These pages explain the async components and the wiring checked by a concrete fo --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/concepts/type-level-dsls.md b/docs/concepts/type-level-dsls.md index d037b9c9..6c411d34 100644 --- a/docs/concepts/type-level-dsls.md +++ b/docs/concepts/type-level-dsls.md @@ -1,7 +1,7 @@ --- title: 'Represent a program as Rust types' sidebar_label: 'Type-level DSLs' -sidebar_position: 16 +sidebar_position: 17 description: 'How Rust types can represent a program, how providers give each syntax form meaning, and how the compiler resolves a whole expression through wiring.' --- @@ -166,6 +166,6 @@ These pages explain the constructs used to build and package the language: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/concepts/type-level-tables.md b/docs/concepts/type-level-tables.md new file mode 100644 index 00000000..1ab10c9f --- /dev/null +++ b/docs/concepts/type-level-tables.md @@ -0,0 +1,562 @@ +--- +title: 'Look up a type in a type-level table' +sidebar_label: 'Type-level tables' +sidebar_position: 3 +description: 'How a trait with an associated type works as a compile-time map, shown in plain Rust beside the value-level code it mirrors.' +--- + +# Type-level tables + +[Context-Generic Programming](/docs/) (CGP) extends Rust with pluggable trait implementations, and a +context's wiring records which implementation it selects for each component. That record is a +table, but not one the running program holds. It is a set of trait implementations that the +compiler looks up while it checks types. + +This page shows how a trait can hold such a table, in plain Rust and without any CGP. Its tables +are plain types rather than contexts, and each lookup returns a `&'static str`, so you can set each one +beside the ordinary value-level code it mirrors, written with a global `HashMap`. Each section then +ends by naming the CGP construct built on its operation, with a link to the page that shows it at +work. + +## A table and its entries + +A trait whose only item is an associated type already works as a map. Each implementation is one +entry: the implementing type is the table, the trait's type parameter is the key, and the associated +type is the value. This table has two entries, which map `FooKey` to `Bar` and `BarKey` to `Baz`: + +```rust +use core::any::type_name; + +pub trait HasEntry { + type Value; +} + +pub struct MyTable; + +pub struct FooKey; +pub struct BarKey; + +pub struct Bar; +pub struct Baz; + +impl HasEntry for MyTable { + type Value = Bar; +} + +impl HasEntry for MyTable { + type Value = Baz; +} + +pub fn get_foo_value>() -> &'static str { + type_name::() +} + +pub fn my_table_foo_value() -> &'static str { + get_foo_value::() +} + +#[test] +fn the_foo_entry_is_bar() { + assert_eq!(my_table_foo_value(), type_name::()); +} +``` + +Reading an entry takes two steps. The bound `Table: HasEntry` asks whether the table has an +entry for `FooKey`, and `Table::Value` names the value stored there. That short form stands for +`
>::Value`, and Rust accepts it because only one bound in scope supplies a +`Value`. The function then turns the type into a string with +[`type_name`](https://doc.rust-lang.org/std/any/fn.type_name.html), which returns the type's full path +rather than the bare name `Bar`. That is why the test compares the result with `type_name::()`. + +At the value level, the same table is an ordinary map from strings to strings. A type-level table +is global: the program has one set of its entries, and any function can read them. Its value-level +counterpart is therefore a `static`: + +```rust +use std::collections::HashMap; +use std::sync::LazyLock; + +static MY_TABLE: LazyLock> = + LazyLock::new(|| HashMap::from([("FooKey", "Bar"), ("BarKey", "Baz")])); + +fn get_foo_value(table: &HashMap<&'static str, &'static str>) -> &'static str { + table["FooKey"] +} + +fn my_table_foo_value() -> &'static str { + get_foo_value(&MY_TABLE) +} + +assert_eq!(my_table_foo_value(), "Bar"); +``` + +[`LazyLock`](https://doc.rust-lang.org/std/sync/struct.LazyLock.html) builds the map the first time it +is read, because a `static` needs a constant initializer and inserting into a `HashMap` is not +constant. + +The two versions pass their table the same way. The value-level `get_foo_value` receives it as an +argument, while the type-level one receives it as the type parameter `Table`, and in both, +`my_table_foo_value` passes the global table in. + +The key can be a parameter too: `get_value, Key>()` reads whichever entry its +caller names, as a value-level function would take the key as a second argument. + +In CGP, this trait is [`DelegateComponent`](/docs/reference/traits/wiring/delegate_component), +with a context as the table and a component as the key. Its associated type is named `Delegate`, and +[`delegate_components!`](/docs/reference/macros/delegate_components) writes one implementation per +entry. + +## Duplicate and missing keys + +[Coherence](/docs/reference/glossary#coherence), Rust's rule that a trait has at most one +implementation for a given type and set of parameters, makes this trait a map rather than a list of +pairs. A second entry for the same key would be a second implementation of +`HasEntry` for `MyTable`, and the compiler rejects it: + +```rust +impl HasEntry for MyTable { + type Value = Bar; +} + +// error[E0119]: conflicting implementations of trait `HasEntry` for type `MyTable` +impl HasEntry for MyTable { + type Value = Baz; +} +``` + +A missing key fails at compile time as well. Asking for `FooKey` in a table without that entry does +not compile: + +```rust +pub struct OtherTable; + +// error[E0277]: the trait bound `OtherTable: HasEntry` is not satisfied +get_foo_value::(); +``` + +The `HashMap` version finds the same mistake only when the program runs: indexing a map that lacks +the key panics, and `get` returns `None`. + +Keys can be generic, and a generic key covers every type it matches. An entry for every `Vec` +therefore overlaps an entry for `Vec`, and the compiler rejects the pair rather than choosing the +more specific one: + +```rust +impl HasEntry> for MyTable { + type Value = Bar; +} + +// error[E0119]: conflicting implementations of trait `HasEntry>` for type `MyTable` +impl HasEntry> for MyTable { + type Value = Baz; +} +``` + +The compiler resolves every lookup while it checks types, so the compiled program contains no table +and never consults one. + +CGP's wiring tables follow the same rules. The +[common mistakes on `DelegateComponent`](/docs/reference/traits/wiring/delegate_component#common-mistakes) +show the errors that a missing entry and a duplicate entry produce there. + +## A lookup as a type + +A type can also answer a question by reading a table it is given. The trait `HasStaticStringFor` +works as a function from a key to a string, and `Lookup
` implements it by reading `Table`: + +```rust +use core::marker::PhantomData; + +pub trait HasStaticStringFor { + fn static_string() -> &'static str; +} + +pub struct Lookup
(pub PhantomData
); + +impl HasStaticStringFor for Lookup
+where + Table: HasEntry, +{ + fn static_string() -> &'static str { + type_name::() + } +} + +#[test] +fn lookup_reads_the_table() { + assert_eq!( + as HasStaticStringFor>::static_string(), + type_name::(), + ); +} +``` + +The `where` clause is a precondition that the compiler checks at each use: `Lookup` answers +`FooKey` because `MyTable` has an entry for it, and it would not compile for a key the table lacks. +[`PhantomData`](https://doc.rust-lang.org/std/marker/struct.PhantomData.html) lets the struct name +`Table` without storing a value of it, since the table exists only as a type. + +At the value level, the table and the key are both arguments: + +```rust +fn lookup(table: &HashMap<&'static str, &'static str>, key: &str) -> &'static str { + table[key] +} + +assert_eq!(lookup(&MY_TABLE, "BarKey"), "Baz"); +``` + +In CGP, the legacy [`UseDelegate`](/docs/reference/providers/use_delegate) is such a type: a provider +that reads the table it is given, keyed by the component's type parameter that `#[derive_delegate]` +names. New code uses the `open` statement instead, which the *Composite keys* section returns +to. + +## Nested tables + +An entry's value can itself answer a question, which gives a lookup in two steps. +`Forward` reads `Table`'s entry for `KeyB`, then asks the type it finds there about `KeyA`: + +```rust +pub struct Forward(pub PhantomData<(Table, KeyB)>); + +impl HasStaticStringFor for Forward +where + Table: HasEntry, + Table::Value: HasStaticStringFor, +{ + fn static_string() -> &'static str { + >::static_string() + } +} + +pub struct OuterTable; +pub struct InnerKey; + +impl HasEntry for OuterTable { + type Value = Lookup; +} + +#[test] +fn forward_reads_both_tables() { + assert_eq!( + as HasStaticStringFor>::static_string(), + type_name::(), + ); +} +``` + +The outer table's entry for `InnerKey` is `Lookup`, so `Forward` +answers `FooKey` by reading `MyTable`. Each step is its own bound in the `where` clause, and the +compiler proves both. + +At the value level, the same shape is a global map whose values refer to other global maps, just as +the entry `Lookup` names `MyTable` rather than copying it: + +```rust +static OUTER_TABLE: LazyLock>> = + LazyLock::new(|| HashMap::from([("InnerKey", &*MY_TABLE)])); + +fn forward( + outer: &HashMap<&'static str, &'static HashMap<&'static str, &'static str>>, + key_b: &str, + key_a: &str, +) -> &'static str { + outer[key_b][key_a] +} + +assert_eq!(forward(&OUTER_TABLE, "InnerKey", "FooKey"), "Bar"); +``` + +In CGP, an entry whose value is a [`UseDelegate`](/docs/reference/providers/use_delegate) has this +nested shape: the context's entry for a component names a `UseDelegate` table, which is then asked +about the component's type parameter, just as `OuterTable`'s `Lookup` entry is asked about `FooKey`. + +## Prototype chains + +The tables so far answer questions through a separate reader type, such as `Lookup` or `Forward`. A +table can also answer a question itself, by asking the value in one of its own entries. Prototype-based +languages such as JavaScript look up a method the same way: an object that lacks the method asks its +prototype, which may ask its own prototype in turn. + +```rust +impl
HasStaticStringFor for Table +where + Table: HasEntry, + Table::Value: HasStaticStringFor, +{ + fn static_string() -> &'static str { + >::static_string() + } +} + +impl HasStaticStringFor for Bar { + fn static_string() -> &'static str { + type_name::() + } +} + +pub struct Parent; +pub struct Child; + +impl HasEntry for Parent { + type Value = Bar; +} + +impl HasEntry for Child { + type Value = Parent; +} + +#[test] +fn the_chain_reaches_bar() { + assert_eq!(>::static_string(), type_name::()); +} +``` + +`Bar` answers `FooKey` with an implementation of its own. `Parent` has none, so the blanket +implementation answers for it by asking `Bar`, the value of its entry for `FooKey`. `Child` asks `Parent` +in the same way, and the lookup walks the chain from `Child` to `Bar`. `MyTable` answers too, since its +entry for `FooKey` is `Bar`. + +The blanket implementation covers one fixed key, `FooKey`, which the crate that defines the tables owns. +Because the key is fixed, the implementation can coexist with leaves such as `Bar` and with the reader +`Lookup`. Over every key at once, it would overlap `Lookup`, because another crate could give the reader +an entry under a key of its own: + +```rust +impl HasStaticStringFor for Table +where + Table: HasEntry, + Table::Value: HasStaticStringFor, +{ + fn static_string() -> &'static str { + >::static_string() + } +} + +// error[E0119]: conflicting implementations of trait `HasStaticStringFor<_>` for type `Lookup<_>` +// note: downstream crates may implement trait `HasEntry<_>` for type `Lookup<_>` +``` + +That overlap is also why `Lookup`, `Forward`, and `Redirect` are reader types rather than tables. + +A JavaScript object can also define a property of its own that hides the one its prototype supplies. +A table cannot do that. An implementation of its own beside an entry for the same key is a second +implementation that could apply, and coherence rejects it: + +```rust +pub struct Shadow; + +impl HasEntry for Shadow { + type Value = Bar; +} + +// error[E0119]: conflicting implementations of trait `HasStaticStringFor` for type `Shadow` +impl HasStaticStringFor for Shadow { + fn static_string() -> &'static str { + "Shadow" + } +} +``` + +Each table therefore either answers the question itself or delegates it through its entry. + +At the value level, the same chain is a set of global objects, each with entries of its own and an +optional link to the next object: + +```rust +pub struct Object { + pub own: HashMap<&'static str, &'static str>, + pub proto: Option<&'static Object>, +} + +fn get(object: &Object, key: &str) -> Option<&'static str> { + match object.own.get(key) { + Some(value) => Some(*value), + None => object.proto.and_then(|proto| get(proto, key)), + } +} + +static BAR: LazyLock = LazyLock::new(|| Object { + own: HashMap::from([("FooKey", "Bar")]), + proto: None, +}); + +static PARENT: LazyLock = + LazyLock::new(|| Object { own: HashMap::new(), proto: Some(&*BAR) }); + +static CHILD: LazyLock = + LazyLock::new(|| Object { own: HashMap::new(), proto: Some(&*PARENT) }); + +assert_eq!(get(&CHILD, "FooKey"), Some("Bar")); +``` + +The value-level `get` checks an object's own entries first, so it would let an object override what it +inherits. The type-level chain refuses that override. + +In CGP, every component's provider trait has this blanket implementation, with the component's +marker type as the key, so a context answers through its wiring entry as `Child` answers through its +own. An [aggregate provider](./aggregate-providers.md) is a table in the middle of such a chain, and the +call trace on [Consumer and provider traits](./consumer-and-provider-traits.md#how-a-call-finds-its-provider) +follows one. + +## Composite keys + +A key can also be made of several types. A tuple of two keys is one key, so a single entry can +answer a pair: + +```rust +impl HasEntry<(FooKey, BarKey)> for MyTable { + type Value = Baz; +} + +pub struct Redirect(pub PhantomData<(Table, Prefix)>); + +impl HasStaticStringFor for Redirect +where + Table: HasEntry<(Prefix, Key)>, +{ + fn static_string() -> &'static str { + type_name::<
>::Value>() + } +} + +#[test] +fn redirect_reads_the_pair() { + assert_eq!( + as HasStaticStringFor>::static_string(), + type_name::(), + ); +} +``` + +`Redirect` fixes the first half of the key and takes the second half as its +question, so asking it about `BarKey` reads the entry for `(FooKey, BarKey)`. The listing writes the +projection in full to show which key the bound names, although `Table::Value` would also compile here, +since one bound supplies it. + +At the value level, the key is a tuple of strings. A `HashMap` has a single key type, so the pairs +live in a second global map, while the type-level `MyTable` holds both kinds of key: + +```rust +static MY_PAIR_TABLE: LazyLock> = + LazyLock::new(|| HashMap::from([(("FooKey", "BarKey"), "Baz")])); + +fn redirect( + table: &HashMap<(&'static str, &'static str), &'static str>, + prefix: &'static str, + key: &'static str, +) -> &'static str { + table[&(prefix, key)] +} + +assert_eq!(redirect(&MY_PAIR_TABLE, "FooKey", "BarKey"), "Baz"); +``` + +A generic position in a composite key matches every type there, as a generic key did. An entry for +every pair that starts with `FooKey` therefore overlaps the entry for `(FooKey, BarKey)`: + +```rust +// error[E0119]: conflicting implementations of trait `HasEntry<(FooKey, BarKey)>` for type `MyTable` +impl HasEntry<(FooKey, Key)> for MyTable { + type Value = Bar; +} +``` + +In CGP, [`RedirectLookup`](/docs/reference/providers/redirect_lookup) works as a `Redirect` whose keys +are type-level paths, and the `open` statement routes a component to it. +[Namespaces](./namespaces.md#presets-and-per-type-dispatch) shows the path entries it reads, which end +in a generic tail, so a shorter path covers every longer one beneath it. + +## Entry ownership + +Rust's [orphan rules](https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules) +decide which crate may write an entry, because an entry is an implementation. A crate that owns a key +type can add an entry for it to a table it does not own: + +```rust +// In a crate that depends on the crate defining `HasEntry` and `TheirTable`. +pub struct MyKey; +pub struct MyValue; + +impl HasEntry for TheirTable { + type Value = MyValue; +} +``` + +That crate cannot, however, add one entry for every table at once. In a crate other than the one +that defines `HasEntry`, `impl
HasEntry for Table` fails with `E0210`: "type parameter +`Table` must be covered by another type when it appears before the first local type (`MyKey`)". + +Turning the trait around removes that limit. When the key implements the trait and the table is its +parameter, the key's crate can write one entry that every table reads, even though the trait comes +from the other crate: + +```rust +// In the crate that defines `HasEntry`: +pub trait InTable
{ + type Value; +} + +// In the crate that owns `MyKey`: +impl
InTable
for MyKey { + type Value = MyValue; +} +``` + +`MyKey` is local and comes first in this implementation, so the orphan rules accept it for every +`Table`. In other words, the table is now written from the key's side. + +In CGP, a [namespace](./namespaces.md#registering-from-the-components-side) entry has the shape of +`InTable`, which lets a component's crate register its route in a namespace that it does not own. + +## What it costs + +A table cannot express a preference. Every overlap is an error, whether between two entries or +between a generic entry and a specific one, so a table cannot hold a default beside the cases that +override it. For the same reason, a table in a [prototype chain](/docs/reference/glossary#prototype-chain) cannot override what it inherits. + +Each lookup is a trait obligation, which the compiler proves rather than evaluates. A lookup that +needs its own answer overflows the trait solver, as when a table's entry is a `Forward` back to the +same table and key: + +```rust +pub struct Loop; + +impl HasEntry for Loop { + type Value = Forward; +} + +// error[E0275]: overflow evaluating the requirement `Forward: HasStaticStringFor` + as HasStaticStringFor>::static_string(); +``` + +CGP meets the same limit with recursive types. +[Rust's own proposals](/docs/comparisons/rust-language-proposals#the-context-as-a-dictionary) +describes the workaround. + +The table is also fixed when the program compiles. Unlike its `HashMap` counterpart, it cannot be +listed, iterated, or changed while the program runs, and each lookup adds work for the compiler. + +## Where to go next + +These pages show the same tables in CGP's wiring: + +- [Consumer and provider traits](./consumer-and-provider-traits.md): How a call reaches its provider + through a context's table. +- [Aggregate providers](./aggregate-providers.md): A table used as a provider and shared between + contexts. +- [Namespaces](./namespaces.md): Tables written from the key's side, and path keys. +- [`DelegateComponent`](/docs/reference/traits/wiring/delegate_component) and + [`delegate_components!`](/docs/reference/macros/delegate_components): The table trait and the macro + that writes it. +- [`RedirectLookup`](/docs/reference/providers/redirect_lookup), + [`UseDelegate`](/docs/reference/providers/use_delegate), [`Path!`](/docs/reference/macros/path), and + [`PathCons`](/docs/reference/types/path_cons): Path keys and nested tables. +- [Comparison: Rust's own proposals](/docs/comparisons/rust-language-proposals): The context as a + dictionary of providers, and the cycles it cannot yet express. + +--- + +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/contribute.md b/docs/contribute.md index db11d0d7..8eeeca75 100644 --- a/docs/contribute.md +++ b/docs/contribute.md @@ -63,9 +63,3 @@ If you appreciate my work and want to see CGP gain wider adoption, the best way CGP is created by [Soares Chen](https://maybevoid.com/), with inspiration drawn from various programming languages and paradigms, particularly Haskell typeclasses. The development of CGP would not have been possible without the strong support of my employer, [Informal Systems](https://informal.systems/). CGP was initially introduced and refined as part of the Hermes SDK project, which leverages CGP to build a highly modular relayer for inter-blockchain communication. - ---- - -*An AI agent rewrote this page, apart from the sponsorship section and the acknowledgement, which are -the author's own. See -[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/index.md b/docs/index.md index 4cfad932..bbef5f8d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -66,5 +66,5 @@ library as it was when they were published, so for CGP as it is today, rely on t --- -*An AI agent revised this page using the CGP knowledge base. See +*This page was revised by an AI agent from the CGP knowledge base. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/overview.md b/docs/overview.md index 027aea16..ad215918 100644 --- a/docs/overview.md +++ b/docs/overview.md @@ -316,6 +316,6 @@ To try these patterns in your own code or learn how they work, continue with the --- -*An AI agent wrote this page using the CGP knowledge base, and its examples were verified by +*This page was written by an AI agent from the CGP knowledge base. Its examples were verified by compiling them. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-examples/expression/architecture/dispatch-layers.md b/docs/projects/cgp-examples/expression/architecture/dispatch-layers.md index 7ea52e08..3d725687 100644 --- a/docs/projects/cgp-examples/expression/architecture/dispatch-layers.md +++ b/docs/projects/cgp-examples/expression/architecture/dispatch-layers.md @@ -116,6 +116,6 @@ example](../examples/add-mult.md#try-a-change) shows. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-examples/expression/architecture/index.md b/docs/projects/cgp-examples/expression/architecture/index.md index d750f545..e4a56794 100644 --- a/docs/projects/cgp-examples/expression/architecture/index.md +++ b/docs/projects/cgp-examples/expression/architecture/index.md @@ -94,6 +94,6 @@ edit the original, such as a second crate adding an operator. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-examples/expression/examples/add-mult-binary-op.md b/docs/projects/cgp-examples/expression/examples/add-mult-binary-op.md index d7a979d3..ec17b3c6 100644 --- a/docs/projects/cgp-examples/expression/examples/add-mult-binary-op.md +++ b/docs/projects/cgp-examples/expression/examples/add-mult-binary-op.md @@ -192,6 +192,6 @@ multiply. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-examples/expression/examples/add-mult-code.md b/docs/projects/cgp-examples/expression/examples/add-mult-code.md index dca0b1e5..17d82225 100644 --- a/docs/projects/cgp-examples/expression/examples/add-mult-code.md +++ b/docs/projects/cgp-examples/expression/examples/add-mult-code.md @@ -196,6 +196,6 @@ method is called, as `add_mult` does, keeps the table shorter when there are onl --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-examples/expression/examples/add-mult-neg.md b/docs/projects/cgp-examples/expression/examples/add-mult-neg.md index a89afa85..253ca409 100644 --- a/docs/projects/cgp-examples/expression/examples/add-mult-neg.md +++ b/docs/projects/cgp-examples/expression/examples/add-mult-neg.md @@ -193,6 +193,6 @@ reused, rather than in the enums, which stay ordinary closed Rust enums. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-examples/expression/examples/add-mult.md b/docs/projects/cgp-examples/expression/examples/add-mult.md index c46570bb..00c7a399 100644 --- a/docs/projects/cgp-examples/expression/examples/add-mult.md +++ b/docs/projects/cgp-examples/expression/examples/add-mult.md @@ -335,6 +335,6 @@ the `match` is simpler and better. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-examples/expression/examples/index.md b/docs/projects/cgp-examples/expression/examples/index.md index 5e67c465..bbc6d28b 100644 --- a/docs/projects/cgp-examples/expression/examples/index.md +++ b/docs/projects/cgp-examples/expression/examples/index.md @@ -53,6 +53,6 @@ prints. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-examples/expression/index.md b/docs/projects/cgp-examples/expression/index.md index 827ee723..3eb9c771 100644 --- a/docs/projects/cgp-examples/expression/index.md +++ b/docs/projects/cgp-examples/expression/index.md @@ -113,6 +113,6 @@ test contexts::add_mult::test::test_add_mult ... ok --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-examples/index.md b/docs/projects/cgp-examples/index.md index a15f3160..28d371b4 100644 --- a/docs/projects/cgp-examples/index.md +++ b/docs/projects/cgp-examples/index.md @@ -57,6 +57,6 @@ crate's tests. Each crate's pages give the command for its programs. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-examples/web-app/examples/coarse-grained.md b/docs/projects/cgp-examples/web-app/examples/coarse-grained.md index db0563c5..8b54e5d5 100644 --- a/docs/projects/cgp-examples/web-app/examples/coarse-grained.md +++ b/docs/projects/cgp-examples/web-app/examples/coarse-grained.md @@ -195,6 +195,6 @@ requirement to a provider. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-examples/web-app/examples/default-impls.md b/docs/projects/cgp-examples/web-app/examples/default-impls.md index c33541db..5dc55847 100644 --- a/docs/projects/cgp-examples/web-app/examples/default-impls.md +++ b/docs/projects/cgp-examples/web-app/examples/default-impls.md @@ -192,6 +192,6 @@ every context that joins; where it is wrong, the fix is a different namespace, n --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-examples/web-app/examples/fine-grained.md b/docs/projects/cgp-examples/web-app/examples/fine-grained.md index 1fd827f3..88abc977 100644 --- a/docs/projects/cgp-examples/web-app/examples/fine-grained.md +++ b/docs/projects/cgp-examples/web-app/examples/fine-grained.md @@ -207,6 +207,6 @@ every context. The [next stage](./namespaces.md) removes that. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-examples/web-app/examples/namespaces.md b/docs/projects/cgp-examples/web-app/examples/namespaces.md index a82d05de..c5b88989 100644 --- a/docs/projects/cgp-examples/web-app/examples/namespaces.md +++ b/docs/projects/cgp-examples/web-app/examples/namespaces.md @@ -193,6 +193,6 @@ stage](./default-impls.md) moves that into the namespace too. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-examples/web-app/index.md b/docs/projects/cgp-examples/web-app/index.md index 337e71f9..4e05bfaa 100644 --- a/docs/projects/cgp-examples/web-app/index.md +++ b/docs/projects/cgp-examples/web-app/index.md @@ -78,6 +78,6 @@ satisfies every component it wires. The stage pages make one change each and sho --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/architecture/component-design.md b/docs/projects/cgp-serde/architecture/component-design.md index ea1144d5..54b6a2ed 100644 --- a/docs/projects/cgp-serde/architecture/component-design.md +++ b/docs/projects/cgp-serde/architecture/component-design.md @@ -157,6 +157,6 @@ same choice everywhere, it is a cost with no return. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/architecture/context-services.md b/docs/projects/cgp-serde/architecture/context-services.md index 9e1c5784..8adf7f3a 100644 --- a/docs/projects/cgp-serde/architecture/context-services.md +++ b/docs/projects/cgp-serde/architecture/context-services.md @@ -149,6 +149,6 @@ it there. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/architecture/crate-layout.md b/docs/projects/cgp-serde/architecture/crate-layout.md index 212310dc..12a4a8fe 100644 --- a/docs/projects/cgp-serde/architecture/crate-layout.md +++ b/docs/projects/cgp-serde/architecture/crate-layout.md @@ -82,6 +82,6 @@ The examples use two to four of them. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/architecture/derive-free-records.md b/docs/projects/cgp-serde/architecture/derive-free-records.md index cecb6a8c..a4a0d795 100644 --- a/docs/projects/cgp-serde/architecture/derive-free-records.md +++ b/docs/projects/cgp-serde/architecture/derive-free-records.md @@ -109,6 +109,6 @@ writing the code rather than compiling it. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/architecture/index.md b/docs/projects/cgp-serde/architecture/index.md index f9e9d3e6..2e217189 100644 --- a/docs/projects/cgp-serde/architecture/index.md +++ b/docs/projects/cgp-serde/architecture/index.md @@ -108,6 +108,6 @@ side. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/architecture/reentrant-providers.md b/docs/projects/cgp-serde/architecture/reentrant-providers.md index 6b510d58..abb27656 100644 --- a/docs/projects/cgp-serde/architecture/reentrant-providers.md +++ b/docs/projects/cgp-serde/architecture/reentrant-providers.md @@ -164,6 +164,6 @@ giving one of them a distinct type. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/architecture/serde-bridge.md b/docs/projects/cgp-serde/architecture/serde-bridge.md index 4b99ac25..8cbfac1e 100644 --- a/docs/projects/cgp-serde/architecture/serde-bridge.md +++ b/docs/projects/cgp-serde/architecture/serde-bridge.md @@ -125,6 +125,6 @@ encoding it wants to choose, and Serde's derive for the rest, in the same value --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/examples/basic.md b/docs/projects/cgp-serde/examples/basic.md index a6ec45d4..49db24e8 100644 --- a/docs/projects/cgp-serde/examples/basic.md +++ b/docs/projects/cgp-serde/examples/basic.md @@ -282,6 +282,6 @@ that encodes each type one way, Serde's derive is shorter. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/examples/events.md b/docs/projects/cgp-serde/examples/events.md index 7deed23e..c868b6a2 100644 --- a/docs/projects/cgp-serde/examples/events.md +++ b/docs/projects/cgp-serde/examples/events.md @@ -212,6 +212,6 @@ wiring. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/examples/index.md b/docs/projects/cgp-serde/examples/index.md index 2c00aadb..f2f6b7e1 100644 --- a/docs/projects/cgp-serde/examples/index.md +++ b/docs/projects/cgp-serde/examples/index.md @@ -55,6 +55,6 @@ services](../architecture/context-services.md) explains the design they show. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/examples/messages.md b/docs/projects/cgp-serde/examples/messages.md index fe34acd4..1e54aa8a 100644 --- a/docs/projects/cgp-serde/examples/messages.md +++ b/docs/projects/cgp-serde/examples/messages.md @@ -312,6 +312,6 @@ from Serde's derive with none of this. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/guides/debugging-wiring.md b/docs/projects/cgp-serde/guides/debugging-wiring.md index afac35bb..dcc31837 100644 --- a/docs/projects/cgp-serde/guides/debugging-wiring.md +++ b/docs/projects/cgp-serde/guides/debugging-wiring.md @@ -265,6 +265,6 @@ context](./wiring-a-context.md#3-write-keys-for-references-lifetimes-and-arrays) --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/guides/formats.md b/docs/projects/cgp-serde/guides/formats.md index 0c6e659c..6600385e 100644 --- a/docs/projects/cgp-serde/guides/formats.md +++ b/docs/projects/cgp-serde/guides/formats.md @@ -96,6 +96,6 @@ array of numbers in JSON. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/guides/wiring-a-context.md b/docs/projects/cgp-serde/guides/wiring-a-context.md index f00f4263..ebd5c3a7 100644 --- a/docs/projects/cgp-serde/guides/wiring-a-context.md +++ b/docs/projects/cgp-serde/guides/wiring-a-context.md @@ -227,6 +227,6 @@ syntax. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/guides/writing-a-provider.md b/docs/projects/cgp-serde/guides/writing-a-provider.md index 0a1980a3..fc29d649 100644 --- a/docs/projects/cgp-serde/guides/writing-a-provider.md +++ b/docs/projects/cgp-serde/guides/writing-a-provider.md @@ -156,6 +156,6 @@ Wire the provider on a test context, assert the wiring with --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/index.md b/docs/projects/cgp-serde/index.md index 513cb498..745c2677 100644 --- a/docs/projects/cgp-serde/index.md +++ b/docs/projects/cgp-serde/index.md @@ -174,6 +174,6 @@ serde_json = "1" --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/limitations.md b/docs/projects/cgp-serde/limitations.md index 3d6daf61..04a14510 100644 --- a/docs/projects/cgp-serde/limitations.md +++ b/docs/projects/cgp-serde/limitations.md @@ -96,6 +96,6 @@ full. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/components/can_alloc.md b/docs/projects/cgp-serde/reference/components/can_alloc.md index 416e105d..ea5ecab0 100644 --- a/docs/projects/cgp-serde/reference/components/can_alloc.md +++ b/docs/projects/cgp-serde/reference/components/can_alloc.md @@ -81,6 +81,6 @@ on the component, rather than on an arena, keeps the provider usable with any al --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/index.md b/docs/projects/cgp-serde/reference/index.md index b103a236..d9c608ad 100644 --- a/docs/projects/cgp-serde/reference/index.md +++ b/docs/projects/cgp-serde/reference/index.md @@ -103,6 +103,6 @@ Some names belong to a construct documented under another name: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/allocate_with_arena.md b/docs/projects/cgp-serde/reference/providers/allocate_with_arena.md index ffdc709d..f5918b15 100644 --- a/docs/projects/cgp-serde/reference/providers/allocate_with_arena.md +++ b/docs/projects/cgp-serde/reference/providers/allocate_with_arena.md @@ -94,6 +94,6 @@ deserializer is unchanged. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/deserialize_and_allocate.md b/docs/projects/cgp-serde/reference/providers/deserialize_and_allocate.md index ed3cd2c5..adbb0f03 100644 --- a/docs/projects/cgp-serde/reference/providers/deserialize_and_allocate.md +++ b/docs/projects/cgp-serde/reference/providers/deserialize_and_allocate.md @@ -83,6 +83,6 @@ small values in one arena rather than a `Box` each. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/deserialize_default.md b/docs/projects/cgp-serde/reference/providers/deserialize_default.md index 3652a90e..00837d66 100644 --- a/docs/projects/cgp-serde/reference/providers/deserialize_default.md +++ b/docs/projects/cgp-serde/reference/providers/deserialize_default.md @@ -87,6 +87,6 @@ type is an `Option`. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/deserialize_extend.md b/docs/projects/cgp-serde/reference/providers/deserialize_extend.md index dec23498..bee60936 100644 --- a/docs/projects/cgp-serde/reference/providers/deserialize_extend.md +++ b/docs/projects/cgp-serde/reference/providers/deserialize_extend.md @@ -83,6 +83,6 @@ per item type. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/deserialize_from_json_reader.md b/docs/projects/cgp-serde/reference/providers/deserialize_from_json_reader.md index eb7bf28a..c4993cd1 100644 --- a/docs/projects/cgp-serde/reference/providers/deserialize_from_json_reader.md +++ b/docs/projects/cgp-serde/reference/providers/deserialize_from_json_reader.md @@ -111,6 +111,6 @@ it in a reader itself. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/deserialize_from_json_string.md b/docs/projects/cgp-serde/reference/providers/deserialize_from_json_string.md index 4a855569..379e95b6 100644 --- a/docs/projects/cgp-serde/reference/providers/deserialize_from_json_string.md +++ b/docs/projects/cgp-serde/reference/providers/deserialize_from_json_string.md @@ -98,6 +98,6 @@ pass it a string reader directly. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/deserialize_record_fields.md b/docs/projects/cgp-serde/reference/providers/deserialize_record_fields.md index 9150f8ac..27b3e4a8 100644 --- a/docs/projects/cgp-serde/reference/providers/deserialize_record_fields.md +++ b/docs/projects/cgp-serde/reference/providers/deserialize_record_fields.md @@ -112,6 +112,6 @@ provider replaces a null value, not a missing one. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/deserialize_variant_fields.md b/docs/projects/cgp-serde/reference/providers/deserialize_variant_fields.md index 91a17add..88bc7139 100644 --- a/docs/projects/cgp-serde/reference/providers/deserialize_variant_fields.md +++ b/docs/projects/cgp-serde/reference/providers/deserialize_variant_fields.md @@ -117,6 +117,6 @@ wired to [`UseSerde`](./use_serde.md). --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/deserialize_with_from_str.md b/docs/projects/cgp-serde/reference/providers/deserialize_with_from_str.md index 88f4911a..f0b0e6f5 100644 --- a/docs/projects/cgp-serde/reference/providers/deserialize_with_from_str.md +++ b/docs/projects/cgp-serde/reference/providers/deserialize_with_from_str.md @@ -82,6 +82,6 @@ and parses that; [writing a provider](../../guides/writing-a-provider.md) shows --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/serialize_base64.md b/docs/projects/cgp-serde/reference/providers/serialize_base64.md index 212586aa..ff5da3f2 100644 --- a/docs/projects/cgp-serde/reference/providers/serialize_base64.md +++ b/docs/projects/cgp-serde/reference/providers/serialize_base64.md @@ -82,6 +82,6 @@ write. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/serialize_bytes.md b/docs/projects/cgp-serde/reference/providers/serialize_bytes.md index f8d43817..1056b954 100644 --- a/docs/projects/cgp-serde/reference/providers/serialize_bytes.md +++ b/docs/projects/cgp-serde/reference/providers/serialize_bytes.md @@ -93,6 +93,6 @@ string back. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/serialize_deref.md b/docs/projects/cgp-serde/reference/providers/serialize_deref.md index 69e26d07..166b439e 100644 --- a/docs/projects/cgp-serde/reference/providers/serialize_deref.md +++ b/docs/projects/cgp-serde/reference/providers/serialize_deref.md @@ -79,6 +79,6 @@ It writes only. Reading into a reference needs somewhere for the value to live, --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/serialize_from.md b/docs/projects/cgp-serde/reference/providers/serialize_from.md index 8dd9e6df..529aebb2 100644 --- a/docs/projects/cgp-serde/reference/providers/serialize_from.md +++ b/docs/projects/cgp-serde/reference/providers/serialize_from.md @@ -93,6 +93,6 @@ integer, reach for [`TrySerializeFrom`](./try_serialize_from.md). --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/serialize_hex.md b/docs/projects/cgp-serde/reference/providers/serialize_hex.md index 3fc80e48..fe7a7cab 100644 --- a/docs/projects/cgp-serde/reference/providers/serialize_hex.md +++ b/docs/projects/cgp-serde/reference/providers/serialize_hex.md @@ -93,6 +93,6 @@ as keys and digests. [`SerializeBase64`](./serialize_base64.md) is the more comp --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/serialize_iterator.md b/docs/projects/cgp-serde/reference/providers/serialize_iterator.md index ef122c0d..cb9f8ec5 100644 --- a/docs/projects/cgp-serde/reference/providers/serialize_iterator.md +++ b/docs/projects/cgp-serde/reference/providers/serialize_iterator.md @@ -90,6 +90,6 @@ choices.** For a collection of types the application does not customize, such as --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/serialize_record_fields.md b/docs/projects/cgp-serde/reference/providers/serialize_record_fields.md index 4904e568..963a4c04 100644 --- a/docs/projects/cgp-serde/reference/providers/serialize_record_fields.md +++ b/docs/projects/cgp-serde/reference/providers/serialize_record_fields.md @@ -103,6 +103,6 @@ derive. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/serialize_rfc3339_date.md b/docs/projects/cgp-serde/reference/providers/serialize_rfc3339_date.md index 69ce6a76..3f6aead7 100644 --- a/docs/projects/cgp-serde/reference/providers/serialize_rfc3339_date.md +++ b/docs/projects/cgp-serde/reference/providers/serialize_rfc3339_date.md @@ -76,6 +76,6 @@ The same provider reads what it writes, with any offset normalized to UTC. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/serialize_string.md b/docs/projects/cgp-serde/reference/providers/serialize_string.md index 1be7f408..61f4ce58 100644 --- a/docs/projects/cgp-serde/reference/providers/serialize_string.md +++ b/docs/projects/cgp-serde/reference/providers/serialize_string.md @@ -88,6 +88,6 @@ itself**, or to write several string-like types the same way. For `String` alone --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/serialize_timestamp.md b/docs/projects/cgp-serde/reference/providers/serialize_timestamp.md index a5d4ec81..950963b5 100644 --- a/docs/projects/cgp-serde/reference/providers/serialize_timestamp.md +++ b/docs/projects/cgp-serde/reference/providers/serialize_timestamp.md @@ -87,6 +87,6 @@ enough.** For sub-second precision, or dates a person should read, --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/serialize_to_json_string.md b/docs/projects/cgp-serde/reference/providers/serialize_to_json_string.md index 7b072287..b7349c21 100644 --- a/docs/projects/cgp-serde/reference/providers/serialize_to_json_string.md +++ b/docs/projects/cgp-serde/reference/providers/serialize_to_json_string.md @@ -109,6 +109,6 @@ directly, which returns `serde_json`'s error; see [using a format](../../guides/ --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/serialize_unit.md b/docs/projects/cgp-serde/reference/providers/serialize_unit.md index c64de6df..2a87d62e 100644 --- a/docs/projects/cgp-serde/reference/providers/serialize_unit.md +++ b/docs/projects/cgp-serde/reference/providers/serialize_unit.md @@ -100,6 +100,6 @@ payload. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/serialize_variant_fields.md b/docs/projects/cgp-serde/reference/providers/serialize_variant_fields.md index d2523f29..6c624031 100644 --- a/docs/projects/cgp-serde/reference/providers/serialize_variant_fields.md +++ b/docs/projects/cgp-serde/reference/providers/serialize_variant_fields.md @@ -137,6 +137,6 @@ An enum outside these limits keeps its own Serde impl and is wired to --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/serialize_with_display.md b/docs/projects/cgp-serde/reference/providers/serialize_with_display.md index 38692f51..0e191c0e 100644 --- a/docs/projects/cgp-serde/reference/providers/serialize_with_display.md +++ b/docs/projects/cgp-serde/reference/providers/serialize_with_display.md @@ -78,6 +78,6 @@ provider ask for itself, and the context fails to compile; wire `String` to a le --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/try_deserialize_bytes.md b/docs/projects/cgp-serde/reference/providers/try_deserialize_bytes.md index 46678e7d..5e8eb3c5 100644 --- a/docs/projects/cgp-serde/reference/providers/try_deserialize_bytes.md +++ b/docs/projects/cgp-serde/reference/providers/try_deserialize_bytes.md @@ -78,6 +78,6 @@ it without the conversion. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/try_serialize_from.md b/docs/projects/cgp-serde/reference/providers/try_serialize_from.md index 73345e79..40f17943 100644 --- a/docs/projects/cgp-serde/reference/providers/try_serialize_from.md +++ b/docs/projects/cgp-serde/reference/providers/try_serialize_from.md @@ -87,6 +87,6 @@ rather than a panic or a silent truncation. When the conversion always succeeds, --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/providers/use_serde.md b/docs/projects/cgp-serde/reference/providers/use_serde.md index 7256d569..287c238b 100644 --- a/docs/projects/cgp-serde/reference/providers/use_serde.md +++ b/docs/projects/cgp-serde/reference/providers/use_serde.md @@ -98,6 +98,6 @@ follow the context's choices, since `UseSerde` hands the whole struct to its own --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/types/can_deserialize_json_string.md b/docs/projects/cgp-serde/reference/types/can_deserialize_json_string.md index 555f21f7..ad8ad9bf 100644 --- a/docs/projects/cgp-serde/reference/types/can_deserialize_json_string.md +++ b/docs/projects/cgp-serde/reference/types/can_deserialize_json_string.md @@ -87,6 +87,6 @@ To read from bytes or a stream, or to produce a value that borrows from the inpu --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/types/deserialize_with_context.md b/docs/projects/cgp-serde/reference/types/deserialize_with_context.md index 066356de..a075cebf 100644 --- a/docs/projects/cgp-serde/reference/types/deserialize_with_context.md +++ b/docs/projects/cgp-serde/reference/types/deserialize_with_context.md @@ -90,6 +90,6 @@ checks for trailing input itself. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/reference/types/serialize_with_context.md b/docs/projects/cgp-serde/reference/types/serialize_with_context.md index 2d3c38e3..e24415a6 100644 --- a/docs/projects/cgp-serde/reference/types/serialize_with_context.md +++ b/docs/projects/cgp-serde/reference/types/serialize_with_context.md @@ -90,6 +90,6 @@ type, [`SerializeToJsonString`](../providers/serialize_to_json_string.md) wraps --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/cgp-serde/serde-comparison.md b/docs/projects/cgp-serde/serde-comparison.md index 9f3b2dae..ff745cff 100644 --- a/docs/projects/cgp-serde/serde-comparison.md +++ b/docs/projects/cgp-serde/serde-comparison.md @@ -119,6 +119,6 @@ work together through `UseSerde` and the adapters, a program can use each for th --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/architecture/abstract-syntax.md b/docs/projects/hypershell/architecture/abstract-syntax.md index f63f087d..d984c1f3 100644 --- a/docs/projects/hypershell/architecture/abstract-syntax.md +++ b/docs/projects/hypershell/architecture/abstract-syntax.md @@ -109,6 +109,6 @@ scope, which every example imports. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/architecture/assembly.md b/docs/projects/hypershell/architecture/assembly.md index dca8e8f2..c9667d0e 100644 --- a/docs/projects/hypershell/architecture/assembly.md +++ b/docs/projects/hypershell/architecture/assembly.md @@ -163,6 +163,6 @@ explains the rule. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/architecture/crate-layout.md b/docs/projects/hypershell/architecture/crate-layout.md index a9b8b49c..3d20d4e5 100644 --- a/docs/projects/hypershell/architecture/crate-layout.md +++ b/docs/projects/hypershell/architecture/crate-layout.md @@ -72,6 +72,6 @@ every crate that builds Hypershell programs that large, not only to Hypershell i --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/architecture/index.md b/docs/projects/hypershell/architecture/index.md index 87e2fb1e..6e616233 100644 --- a/docs/projects/hypershell/architecture/index.md +++ b/docs/projects/hypershell/architecture/index.md @@ -114,6 +114,6 @@ be reusable, checked by the compiler, and replaceable without editing the progra --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/architecture/streams-and-input-dispatch.md b/docs/projects/hypershell/architecture/streams-and-input-dispatch.md index 856d4b98..c6187320 100644 --- a/docs/projects/hypershell/architecture/streams-and-input-dispatch.md +++ b/docs/projects/hypershell/architecture/streams-and-input-dispatch.md @@ -160,6 +160,6 @@ to the program. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/examples/bluesky-websocket.md b/docs/projects/hypershell/examples/bluesky-websocket.md index 35f1c454..46fa4f9a 100644 --- a/docs/projects/hypershell/examples/bluesky-websocket.md +++ b/docs/projects/hypershell/examples/bluesky-websocket.md @@ -188,6 +188,6 @@ above. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/examples/bluesky.md b/docs/projects/hypershell/examples/bluesky.md index b206878f..a12e2527 100644 --- a/docs/projects/hypershell/examples/bluesky.md +++ b/docs/projects/hypershell/examples/bluesky.md @@ -119,6 +119,6 @@ reports; a stalled feed here looks the same as a quiet one. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/examples/github-issues.md b/docs/projects/hypershell/examples/github-issues.md index c7e95680..b93ca564 100644 --- a/docs/projects/hypershell/examples/github-issues.md +++ b/docs/projects/hypershell/examples/github-issues.md @@ -153,6 +153,6 @@ reported at the end of a long chain of lookups, which is why checking the progra --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/examples/hello-name.md b/docs/projects/hypershell/examples/hello-name.md index 55139965..6b39eb5f 100644 --- a/docs/projects/hypershell/examples/hello-name.md +++ b/docs/projects/hypershell/examples/hello-name.md @@ -183,6 +183,6 @@ against its context, as above, is worth doing. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/examples/hello.md b/docs/projects/hypershell/examples/hello.md index c290734d..9e7d9b70 100644 --- a/docs/projects/hypershell/examples/hello.md +++ b/docs/projects/hypershell/examples/hello.md @@ -179,6 +179,6 @@ replaceable. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/examples/http-checksum-cli.md b/docs/projects/hypershell/examples/http-checksum-cli.md index c619eed5..dd5f04bd 100644 --- a/docs/projects/hypershell/examples/http-checksum-cli.md +++ b/docs/projects/hypershell/examples/http-checksum-cli.md @@ -165,6 +165,6 @@ stage between them. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/examples/http-checksum-client.md b/docs/projects/hypershell/examples/http-checksum-client.md index 24f688cc..bf756c02 100644 --- a/docs/projects/hypershell/examples/http-checksum-client.md +++ b/docs/projects/hypershell/examples/http-checksum-client.md @@ -186,6 +186,6 @@ once the converters have an entry for it, which is a change to the language, not --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/examples/http-checksum-native.md b/docs/projects/hypershell/examples/http-checksum-native.md index db30d968..ea35ff21 100644 --- a/docs/projects/hypershell/examples/http-checksum-native.md +++ b/docs/projects/hypershell/examples/http-checksum-native.md @@ -200,6 +200,6 @@ more about what this means. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/examples/index.md b/docs/projects/hypershell/examples/index.md index dabbbab3..52f6b063 100644 --- a/docs/projects/hypershell/examples/index.md +++ b/docs/projects/hypershell/examples/index.md @@ -74,6 +74,6 @@ that runs whole programs as operands. Their pages are still being written. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/examples/nix-manual.md b/docs/projects/hypershell/examples/nix-manual.md index 0827cd0d..61a6cb24 100644 --- a/docs/projects/hypershell/examples/nix-manual.md +++ b/docs/projects/hypershell/examples/nix-manual.md @@ -139,6 +139,6 @@ in a URL, a reader looks at how URLs are produced, rather than at one definition --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/examples/rust-playground.md b/docs/projects/hypershell/examples/rust-playground.md index 638a433d..f76d9b9e 100644 --- a/docs/projects/hypershell/examples/rust-playground.md +++ b/docs/projects/hypershell/examples/rust-playground.md @@ -153,6 +153,6 @@ by following that wiring rather than by reading a declaration. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/examples/save-webpage.md b/docs/projects/hypershell/examples/save-webpage.md index 7e082f17..285564e9 100644 --- a/docs/projects/hypershell/examples/save-webpage.md +++ b/docs/projects/hypershell/examples/save-webpage.md @@ -119,6 +119,6 @@ a compile error at the call rather than from a declaration. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/guides/debugging.md b/docs/projects/hypershell/guides/debugging.md index e90ac823..92a9952f 100644 --- a/docs/projects/hypershell/guides/debugging.md +++ b/docs/projects/hypershell/guides/debugging.md @@ -280,6 +280,6 @@ wiring, and does not mention CGP. It means the prelude is not imported: the macr --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/guides/writing-a-program.md b/docs/projects/hypershell/guides/writing-a-program.md index 2133290c..950153d5 100644 --- a/docs/projects/hypershell/guides/writing-a-program.md +++ b/docs/projects/hypershell/guides/writing-a-program.md @@ -158,6 +158,6 @@ largest examples exhausted memory while type-checking; see --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/index.md b/docs/projects/hypershell/index.md index 327342b8..4ef6baa3 100644 --- a/docs/projects/hypershell/index.md +++ b/docs/projects/hypershell/index.md @@ -184,6 +184,6 @@ nightly and solver. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/hypershell/limitations.md b/docs/projects/hypershell/limitations.md index 8aea6d73..f641c77e 100644 --- a/docs/projects/hypershell/limitations.md +++ b/docs/projects/hypershell/limitations.md @@ -83,6 +83,6 @@ CGP, even for a reader who never writes a Hypershell program. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/projects/index.md b/docs/projects/index.md index 9d5d88ab..209c131a 100644 --- a/docs/projects/index.md +++ b/docs/projects/index.md @@ -73,6 +73,6 @@ the Concepts page that explains the idea: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -project's source. See [How AI is used in this -project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the project's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/quickstart.md b/docs/quickstart.md index 5d8f1515..22847fef 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -82,6 +82,6 @@ the same `greet` function runs unchanged on a different context. --- -*An AI agent wrote this page using the CGP knowledge base, and its program was verified by compiling -and running it. See +*This page was written by an AI agent from the CGP knowledge base. Its program was verified by +compiling and running it. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/attributes/default_impl.md b/docs/reference/attributes/default_impl.md index f0f4647f..98d227be 100644 --- a/docs/reference/attributes/default_impl.md +++ b/docs/reference/attributes/default_impl.md @@ -371,6 +371,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/attributes/derive_delegate.md b/docs/reference/attributes/derive_delegate.md index 41507953..5a8ec6e7 100644 --- a/docs/reference/attributes/derive_delegate.md +++ b/docs/reference/attributes/derive_delegate.md @@ -328,6 +328,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/attributes/extend.md b/docs/reference/attributes/extend.md index cd92814c..4a52d151 100644 --- a/docs/reference/attributes/extend.md +++ b/docs/reference/attributes/extend.md @@ -299,6 +299,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/attributes/extend_where.md b/docs/reference/attributes/extend_where.md index 3208ed82..4276652a 100644 --- a/docs/reference/attributes/extend_where.md +++ b/docs/reference/attributes/extend_where.md @@ -256,6 +256,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/attributes/impl_generics.md b/docs/reference/attributes/impl_generics.md index f6c376f2..512d33db 100644 --- a/docs/reference/attributes/impl_generics.md +++ b/docs/reference/attributes/impl_generics.md @@ -327,6 +327,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/attributes/implicit.md b/docs/reference/attributes/implicit.md index 8afb4324..90df891f 100644 --- a/docs/reference/attributes/implicit.md +++ b/docs/reference/attributes/implicit.md @@ -363,6 +363,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/attributes/index.md b/docs/reference/attributes/index.md index d477ff0b..e045ce46 100644 --- a/docs/reference/attributes/index.md +++ b/docs/reference/attributes/index.md @@ -72,6 +72,6 @@ because you will meet the form in existing wiring and in CGP's own error and han --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/attributes/prefix.md b/docs/reference/attributes/prefix.md index 0ec7db1d..96c21730 100644 --- a/docs/reference/attributes/prefix.md +++ b/docs/reference/attributes/prefix.md @@ -419,6 +419,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/attributes/use_provider.md b/docs/reference/attributes/use_provider.md index e7cb8ac1..57f2106f 100644 --- a/docs/reference/attributes/use_provider.md +++ b/docs/reference/attributes/use_provider.md @@ -329,6 +329,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/attributes/use_type.md b/docs/reference/attributes/use_type.md index a7f3bbc2..bfc295a9 100644 --- a/docs/reference/attributes/use_type.md +++ b/docs/reference/attributes/use_type.md @@ -461,6 +461,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/attributes/uses.md b/docs/reference/attributes/uses.md index 1c99083e..7d3c0e31 100644 --- a/docs/reference/attributes/uses.md +++ b/docs/reference/attributes/uses.md @@ -286,6 +286,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/components/can_raise_error.md b/docs/reference/components/can_raise_error.md index c278d38a..1477976b 100644 --- a/docs/reference/components/can_raise_error.md +++ b/docs/reference/components/can_raise_error.md @@ -175,6 +175,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/components/can_wrap_error.md b/docs/reference/components/can_wrap_error.md index 68217a75..716d0038 100644 --- a/docs/reference/components/can_wrap_error.md +++ b/docs/reference/components/can_wrap_error.md @@ -206,6 +206,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/components/handler/async_computer.md b/docs/reference/components/handler/async_computer.md index 074af326..c1600deb 100644 --- a/docs/reference/components/handler/async_computer.md +++ b/docs/reference/components/handler/async_computer.md @@ -158,6 +158,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/components/handler/async_computer_ref.md b/docs/reference/components/handler/async_computer_ref.md index 6af52b30..9e6347f5 100644 --- a/docs/reference/components/handler/async_computer_ref.md +++ b/docs/reference/components/handler/async_computer_ref.md @@ -145,6 +145,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/components/handler/computer.md b/docs/reference/components/handler/computer.md index fc94721f..c55583bc 100644 --- a/docs/reference/components/handler/computer.md +++ b/docs/reference/components/handler/computer.md @@ -225,6 +225,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/components/handler/computer_ref.md b/docs/reference/components/handler/computer_ref.md index 042813a4..306a81aa 100644 --- a/docs/reference/components/handler/computer_ref.md +++ b/docs/reference/components/handler/computer_ref.md @@ -171,6 +171,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/components/handler/handler.md b/docs/reference/components/handler/handler.md index fa08c8a3..724dc68f 100644 --- a/docs/reference/components/handler/handler.md +++ b/docs/reference/components/handler/handler.md @@ -207,6 +207,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/components/handler/handler_ref.md b/docs/reference/components/handler/handler_ref.md index c61002c6..c8dcc7f6 100644 --- a/docs/reference/components/handler/handler_ref.md +++ b/docs/reference/components/handler/handler_ref.md @@ -173,6 +173,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/components/handler/index.md b/docs/reference/components/handler/index.md index 03e8b510..ac3cf711 100644 --- a/docs/reference/components/handler/index.md +++ b/docs/reference/components/handler/index.md @@ -71,6 +71,6 @@ an effectful one reaches the runtime through [`HasRuntime`](../has_runtime.md). --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/components/handler/producer.md b/docs/reference/components/handler/producer.md index 374bd37e..d753ea61 100644 --- a/docs/reference/components/handler/producer.md +++ b/docs/reference/components/handler/producer.md @@ -187,6 +187,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/components/handler/try_computer.md b/docs/reference/components/handler/try_computer.md index 5534bec1..dd48348b 100644 --- a/docs/reference/components/handler/try_computer.md +++ b/docs/reference/components/handler/try_computer.md @@ -195,6 +195,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/components/handler/try_computer_ref.md b/docs/reference/components/handler/try_computer_ref.md index 42e4e081..68d3241e 100644 --- a/docs/reference/components/handler/try_computer_ref.md +++ b/docs/reference/components/handler/try_computer_ref.md @@ -174,6 +174,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/components/has_error_type.md b/docs/reference/components/has_error_type.md index 21651e3d..a431e687 100644 --- a/docs/reference/components/has_error_type.md +++ b/docs/reference/components/has_error_type.md @@ -191,6 +191,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/components/has_runtime.md b/docs/reference/components/has_runtime.md index 52230f70..d8bdbd7c 100644 --- a/docs/reference/components/has_runtime.md +++ b/docs/reference/components/has_runtime.md @@ -166,6 +166,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/components/has_runtime_type.md b/docs/reference/components/has_runtime_type.md index 9bfe9ef2..3fd15be9 100644 --- a/docs/reference/components/has_runtime_type.md +++ b/docs/reference/components/has_runtime_type.md @@ -138,6 +138,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/components/has_type.md b/docs/reference/components/has_type.md index 9cefac48..f6250be4 100644 --- a/docs/reference/components/has_type.md +++ b/docs/reference/components/has_type.md @@ -171,6 +171,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/components/index.md b/docs/reference/components/index.md index a73f3d0f..67bc09ad 100644 --- a/docs/reference/components/index.md +++ b/docs/reference/components/index.md @@ -71,6 +71,6 @@ a thread boundary. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/components/runner.md b/docs/reference/components/runner.md index deba31df..8ec2f117 100644 --- a/docs/reference/components/runner.md +++ b/docs/reference/components/runner.md @@ -152,6 +152,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/components/send_runner.md b/docs/reference/components/send_runner.md index 34945c00..f20de254 100644 --- a/docs/reference/components/send_runner.md +++ b/docs/reference/components/send_runner.md @@ -154,6 +154,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/derives/derive_build_field.md b/docs/reference/derives/derive_build_field.md index 6acdc20b..b38b899e 100644 --- a/docs/reference/derives/derive_build_field.md +++ b/docs/reference/derives/derive_build_field.md @@ -355,6 +355,6 @@ The implementation is defined in these source files: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/derives/derive_cgp_data.md b/docs/reference/derives/derive_cgp_data.md index a183c0fb..92f77068 100644 --- a/docs/reference/derives/derive_cgp_data.md +++ b/docs/reference/derives/derive_cgp_data.md @@ -208,6 +208,6 @@ The implementation is defined in these source files: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/derives/derive_cgp_record.md b/docs/reference/derives/derive_cgp_record.md index 004c4eb3..b2e8e0ea 100644 --- a/docs/reference/derives/derive_cgp_record.md +++ b/docs/reference/derives/derive_cgp_record.md @@ -221,6 +221,6 @@ The implementation is defined in these source files: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/derives/derive_cgp_variant.md b/docs/reference/derives/derive_cgp_variant.md index 65ddce30..19defe2e 100644 --- a/docs/reference/derives/derive_cgp_variant.md +++ b/docs/reference/derives/derive_cgp_variant.md @@ -266,6 +266,6 @@ The implementation is defined in these source files: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/derives/derive_extract_field.md b/docs/reference/derives/derive_extract_field.md index c55d3b04..d6148e88 100644 --- a/docs/reference/derives/derive_extract_field.md +++ b/docs/reference/derives/derive_extract_field.md @@ -379,6 +379,6 @@ The implementation is defined in these source files: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/derives/derive_from_variant.md b/docs/reference/derives/derive_from_variant.md index 1dcb8a0d..87495110 100644 --- a/docs/reference/derives/derive_from_variant.md +++ b/docs/reference/derives/derive_from_variant.md @@ -261,6 +261,6 @@ The implementation is defined in these source files: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/derives/derive_has_field.md b/docs/reference/derives/derive_has_field.md index 23a05745..d170b71b 100644 --- a/docs/reference/derives/derive_has_field.md +++ b/docs/reference/derives/derive_has_field.md @@ -351,6 +351,6 @@ The implementation is defined in these source files: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/derives/derive_has_fields.md b/docs/reference/derives/derive_has_fields.md index 62f2ab4d..2711fdec 100644 --- a/docs/reference/derives/derive_has_fields.md +++ b/docs/reference/derives/derive_has_fields.md @@ -341,6 +341,6 @@ The implementation is defined in these source files: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/derives/index.md b/docs/reference/derives/index.md index 50db2e72..600f1421 100644 --- a/docs/reference/derives/index.md +++ b/docs/reference/derives/index.md @@ -71,6 +71,6 @@ keeps only its documentation, so a helper attribute that belongs to another deri --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/errors.md b/docs/reference/errors.md index d20aaca9..5673ac3f 100644 --- a/docs/reference/errors.md +++ b/docs/reference/errors.md @@ -781,6 +781,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/glossary.md b/docs/reference/glossary.md index 94c2cdf1..cd2cf54d 100644 --- a/docs/reference/glossary.md +++ b/docs/reference/glossary.md @@ -104,6 +104,7 @@ a concrete type, so a context selects among them at compile time. An entry in a wiring table, mapping one component to the provider that supplies it. Delegating a component does not by itself check that the provider's dependencies hold; a check trait does that. +[Type-level tables](/docs/concepts/type-level-tables) · [Consumer and provider traits](/docs/concepts/consumer-and-provider-traits) · [`DelegateComponent`](./traits/wiring/delegate_component.md) @@ -287,6 +288,7 @@ The type-level table on a context recording which provider supplies each compone resolves it during type checking, so a wired call compiles to a direct call without a runtime lookup. +[Type-level tables](/docs/concepts/type-level-tables) · [Consumer and provider traits](/docs/concepts/consumer-and-provider-traits) · [`delegate_components!`](./macros/delegate_components.md) @@ -321,7 +323,8 @@ resolves the same way anywhere in a program. The overlap and orphan rules are wh ### dynamic dispatch -Choosing an implementation at run time through a pointer to a method table, as `dyn Trait` does. +Choosing the implementation a call runs at run time, from the receiver: through a table of function +pointers, as `dyn Trait` does, or by name along a chain of dictionaries, as in JavaScript and Python. [Rust Book: Trait objects](https://doc.rust-lang.org/book/ch18-02-trait-objects.html) @@ -523,6 +526,16 @@ arguments, so behavior is composed at compile time. [Comparison: Policy-based design](/docs/comparisons/policy-based-design) · [Policy-based design](https://en.wikipedia.org/wiki/Policy-based_design) +### prototype chain + +The sequence of objects a property lookup follows in a prototype-based language such as JavaScript: an +object that lacks the property asks its prototype, which may ask its own. CGP's wiring has the same shape, +walked by the compiler instead of at run time. + +[Comparison: Dynamic dispatch](/docs/comparisons/dynamic-dispatch) · +[Type-level tables](/docs/concepts/type-level-tables#prototype-chains) · +[MDN: Inheritance and the prototype chain](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain) + ### reflection Inspecting a type's structure (its fields, variants, and names) from within the program. CGP's @@ -591,6 +604,6 @@ the implementation. CGP wiring does not use one, because it resolves every call --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/index.md b/docs/reference/index.md index 5315440c..a585344c 100644 --- a/docs/reference/index.md +++ b/docs/reference/index.md @@ -278,6 +278,6 @@ If you arrived knowing one of these names, this is where it lives. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/async_trait.md b/docs/reference/macros/async_trait.md index 8187bd73..0f3cf9a5 100644 --- a/docs/reference/macros/async_trait.md +++ b/docs/reference/macros/async_trait.md @@ -290,6 +290,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/blanket_trait.md b/docs/reference/macros/blanket_trait.md index 890cb2aa..62d07f34 100644 --- a/docs/reference/macros/blanket_trait.md +++ b/docs/reference/macros/blanket_trait.md @@ -325,6 +325,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/cgp_auto_dispatch.md b/docs/reference/macros/cgp_auto_dispatch.md index 6301a2dc..fc073c87 100644 --- a/docs/reference/macros/cgp_auto_dispatch.md +++ b/docs/reference/macros/cgp_auto_dispatch.md @@ -371,6 +371,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/cgp_auto_getter.md b/docs/reference/macros/cgp_auto_getter.md index 5531636b..bc906b1e 100644 --- a/docs/reference/macros/cgp_auto_getter.md +++ b/docs/reference/macros/cgp_auto_getter.md @@ -428,6 +428,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/cgp_component.md b/docs/reference/macros/cgp_component.md index 92aad52b..fc03c674 100644 --- a/docs/reference/macros/cgp_component.md +++ b/docs/reference/macros/cgp_component.md @@ -619,6 +619,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/cgp_computer.md b/docs/reference/macros/cgp_computer.md index 5edcac65..5268b2f3 100644 --- a/docs/reference/macros/cgp_computer.md +++ b/docs/reference/macros/cgp_computer.md @@ -364,6 +364,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/cgp_fn.md b/docs/reference/macros/cgp_fn.md index 548210f7..5dea9472 100644 --- a/docs/reference/macros/cgp_fn.md +++ b/docs/reference/macros/cgp_fn.md @@ -384,6 +384,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/cgp_getter.md b/docs/reference/macros/cgp_getter.md index fd33df34..d9ca25c8 100644 --- a/docs/reference/macros/cgp_getter.md +++ b/docs/reference/macros/cgp_getter.md @@ -355,6 +355,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/cgp_impl.md b/docs/reference/macros/cgp_impl.md index e7586cdd..fe80c87c 100644 --- a/docs/reference/macros/cgp_impl.md +++ b/docs/reference/macros/cgp_impl.md @@ -579,6 +579,6 @@ and `#[cgp_impl]` up from the same coherence failure that --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/cgp_namespace.md b/docs/reference/macros/cgp_namespace.md index dad38364..b519c53c 100644 --- a/docs/reference/macros/cgp_namespace.md +++ b/docs/reference/macros/cgp_namespace.md @@ -470,6 +470,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/cgp_producer.md b/docs/reference/macros/cgp_producer.md index 03750e71..e9b73a5d 100644 --- a/docs/reference/macros/cgp_producer.md +++ b/docs/reference/macros/cgp_producer.md @@ -286,6 +286,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/cgp_provider.md b/docs/reference/macros/cgp_provider.md index d1921988..79a5fb35 100644 --- a/docs/reference/macros/cgp_provider.md +++ b/docs/reference/macros/cgp_provider.md @@ -439,6 +439,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/cgp_type.md b/docs/reference/macros/cgp_type.md index ad06299e..a86976cb 100644 --- a/docs/reference/macros/cgp_type.md +++ b/docs/reference/macros/cgp_type.md @@ -365,6 +365,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/check_components.md b/docs/reference/macros/check_components.md index 205777cf..ff24b3a7 100644 --- a/docs/reference/macros/check_components.md +++ b/docs/reference/macros/check_components.md @@ -430,6 +430,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/delegate_and_check_components.md b/docs/reference/macros/delegate_and_check_components.md index a476e4c2..e894809d 100644 --- a/docs/reference/macros/delegate_and_check_components.md +++ b/docs/reference/macros/delegate_and_check_components.md @@ -448,6 +448,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/delegate_components.md b/docs/reference/macros/delegate_components.md index 91cb57e5..dec60d84 100644 --- a/docs/reference/macros/delegate_components.md +++ b/docs/reference/macros/delegate_components.md @@ -820,6 +820,7 @@ namespace itself binds: see [`cgp_namespace!`](./cgp_namespace.md#common-mistake The ideas behind it: +- [Type-level tables](/docs/concepts/type-level-tables) — the plain-Rust table each entry becomes. - [Bypassing coherence](/docs/concepts/coherence) — why a context chooses its providers through a table rather than through impls. - [Aggregate providers](/docs/concepts/aggregate-providers) — the `new`-keyword bundle, and why it @@ -834,6 +835,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/enum.md b/docs/reference/macros/enum.md index 4361af3f..b3ff87dd 100644 --- a/docs/reference/macros/enum.md +++ b/docs/reference/macros/enum.md @@ -203,6 +203,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/index.md b/docs/reference/macros/index.md index 7e0f5a46..6d5fa15e 100644 --- a/docs/reference/macros/index.md +++ b/docs/reference/macros/index.md @@ -72,6 +72,6 @@ back out of a compiler error, since a diagnostic prints the raw list each expand --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/path.md b/docs/reference/macros/path.md index b3278c5c..64fb393f 100644 --- a/docs/reference/macros/path.md +++ b/docs/reference/macros/path.md @@ -252,6 +252,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/product.md b/docs/reference/macros/product.md index d28f3e06..42264a28 100644 --- a/docs/reference/macros/product.md +++ b/docs/reference/macros/product.md @@ -233,6 +233,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/struct.md b/docs/reference/macros/struct.md index 14cb6158..2913ec09 100644 --- a/docs/reference/macros/struct.md +++ b/docs/reference/macros/struct.md @@ -259,6 +259,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/sum.md b/docs/reference/macros/sum.md index 415f6427..8edf6ffb 100644 --- a/docs/reference/macros/sum.md +++ b/docs/reference/macros/sum.md @@ -218,6 +218,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/macros/symbol.md b/docs/reference/macros/symbol.md index 9ae61523..aea22274 100644 --- a/docs/reference/macros/symbol.md +++ b/docs/reference/macros/symbol.md @@ -261,6 +261,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/chain_getters.md b/docs/reference/providers/chain_getters.md index d596a366..ab0716bb 100644 --- a/docs/reference/providers/chain_getters.md +++ b/docs/reference/providers/chain_getters.md @@ -201,6 +201,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/dispatch/build_and_merge.md b/docs/reference/providers/dispatch/build_and_merge.md index 254257d7..9e7c2b7e 100644 --- a/docs/reference/providers/dispatch/build_and_merge.md +++ b/docs/reference/providers/dispatch/build_and_merge.md @@ -207,6 +207,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/dispatch/build_and_merge_outputs.md b/docs/reference/providers/dispatch/build_and_merge_outputs.md index dc8d97a0..28234b52 100644 --- a/docs/reference/providers/dispatch/build_and_merge_outputs.md +++ b/docs/reference/providers/dispatch/build_and_merge_outputs.md @@ -219,6 +219,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/dispatch/build_and_set_field.md b/docs/reference/providers/dispatch/build_and_set_field.md index 66d05022..ca7c0ca4 100644 --- a/docs/reference/providers/dispatch/build_and_set_field.md +++ b/docs/reference/providers/dispatch/build_and_set_field.md @@ -182,6 +182,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/dispatch/build_with_handlers.md b/docs/reference/providers/dispatch/build_with_handlers.md index 78095182..3270729f 100644 --- a/docs/reference/providers/dispatch/build_with_handlers.md +++ b/docs/reference/providers/dispatch/build_with_handlers.md @@ -223,6 +223,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/dispatch/downcast_and_handle.md b/docs/reference/providers/dispatch/downcast_and_handle.md index 198dd786..374feedb 100644 --- a/docs/reference/providers/dispatch/downcast_and_handle.md +++ b/docs/reference/providers/dispatch/downcast_and_handle.md @@ -192,6 +192,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/dispatch/extract_field_and_handle.md b/docs/reference/providers/dispatch/extract_field_and_handle.md index 44da7323..2ebc6153 100644 --- a/docs/reference/providers/dispatch/extract_field_and_handle.md +++ b/docs/reference/providers/dispatch/extract_field_and_handle.md @@ -189,6 +189,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/dispatch/handle_field_value.md b/docs/reference/providers/dispatch/handle_field_value.md index 18174a70..1ea938b5 100644 --- a/docs/reference/providers/dispatch/handle_field_value.md +++ b/docs/reference/providers/dispatch/handle_field_value.md @@ -167,6 +167,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/dispatch/index.md b/docs/reference/providers/dispatch/index.md index 12c679d9..11a8b4dc 100644 --- a/docs/reference/providers/dispatch/index.md +++ b/docs/reference/providers/dispatch/index.md @@ -99,6 +99,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/dispatch/match_first_with_handlers.md b/docs/reference/providers/dispatch/match_first_with_handlers.md index b12cea99..cae51f4d 100644 --- a/docs/reference/providers/dispatch/match_first_with_handlers.md +++ b/docs/reference/providers/dispatch/match_first_with_handlers.md @@ -219,6 +219,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/dispatch/match_with_field_handlers.md b/docs/reference/providers/dispatch/match_with_field_handlers.md index b4a8297a..0ae7fe18 100644 --- a/docs/reference/providers/dispatch/match_with_field_handlers.md +++ b/docs/reference/providers/dispatch/match_with_field_handlers.md @@ -201,6 +201,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/dispatch/match_with_handlers.md b/docs/reference/providers/dispatch/match_with_handlers.md index 69e8759d..b28144bf 100644 --- a/docs/reference/providers/dispatch/match_with_handlers.md +++ b/docs/reference/providers/dispatch/match_with_handlers.md @@ -257,6 +257,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/dispatch/match_with_value_handlers.md b/docs/reference/providers/dispatch/match_with_value_handlers.md index d01f0c9f..6b5e7ef1 100644 --- a/docs/reference/providers/dispatch/match_with_value_handlers.md +++ b/docs/reference/providers/dispatch/match_with_value_handlers.md @@ -273,6 +273,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/error/debug_error.md b/docs/reference/providers/error/debug_error.md index dffd61f9..13615f93 100644 --- a/docs/reference/providers/error/debug_error.md +++ b/docs/reference/providers/error/debug_error.md @@ -192,6 +192,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/error/discard_detail.md b/docs/reference/providers/error/discard_detail.md index b563c0af..056a8684 100644 --- a/docs/reference/providers/error/discard_detail.md +++ b/docs/reference/providers/error/discard_detail.md @@ -141,6 +141,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/error/display_error.md b/docs/reference/providers/error/display_error.md index 1c29387a..d4f38831 100644 --- a/docs/reference/providers/error/display_error.md +++ b/docs/reference/providers/error/display_error.md @@ -191,6 +191,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/error/index.md b/docs/reference/providers/error/index.md index c4674abf..b10835bb 100644 --- a/docs/reference/providers/error/index.md +++ b/docs/reference/providers/error/index.md @@ -101,6 +101,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/error/panic_on_error.md b/docs/reference/providers/error/panic_on_error.md index a82c99f4..5e63eddb 100644 --- a/docs/reference/providers/error/panic_on_error.md +++ b/docs/reference/providers/error/panic_on_error.md @@ -140,6 +140,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/error/raise_from.md b/docs/reference/providers/error/raise_from.md index 93724207..e8aa3649 100644 --- a/docs/reference/providers/error/raise_from.md +++ b/docs/reference/providers/error/raise_from.md @@ -194,6 +194,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/error/raise_infallible.md b/docs/reference/providers/error/raise_infallible.md index 769d060c..0f8fb4f4 100644 --- a/docs/reference/providers/error/raise_infallible.md +++ b/docs/reference/providers/error/raise_infallible.md @@ -151,6 +151,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/error/return_error.md b/docs/reference/providers/error/return_error.md index b3ed1fef..2b1fa246 100644 --- a/docs/reference/providers/error/return_error.md +++ b/docs/reference/providers/error/return_error.md @@ -165,6 +165,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/handler/compose_handlers.md b/docs/reference/providers/handler/compose_handlers.md index 328ce3d1..f5534a3a 100644 --- a/docs/reference/providers/handler/compose_handlers.md +++ b/docs/reference/providers/handler/compose_handlers.md @@ -143,6 +143,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/handler/index.md b/docs/reference/providers/handler/index.md index e3bae62f..c2cfdd6f 100644 --- a/docs/reference/providers/handler/index.md +++ b/docs/reference/providers/handler/index.md @@ -112,6 +112,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/handler/pipe_handlers.md b/docs/reference/providers/handler/pipe_handlers.md index 1e548aeb..618a4f3f 100644 --- a/docs/reference/providers/handler/pipe_handlers.md +++ b/docs/reference/providers/handler/pipe_handlers.md @@ -169,6 +169,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/handler/promote.md b/docs/reference/providers/handler/promote.md index 88bfff03..d05ffeb2 100644 --- a/docs/reference/providers/handler/promote.md +++ b/docs/reference/providers/handler/promote.md @@ -155,6 +155,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/handler/promote_async.md b/docs/reference/providers/handler/promote_async.md index f03df2cb..d0f6b165 100644 --- a/docs/reference/providers/handler/promote_async.md +++ b/docs/reference/providers/handler/promote_async.md @@ -150,6 +150,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/handler/promote_async_computer.md b/docs/reference/providers/handler/promote_async_computer.md index b4c9807a..364400ba 100644 --- a/docs/reference/providers/handler/promote_async_computer.md +++ b/docs/reference/providers/handler/promote_async_computer.md @@ -138,6 +138,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/handler/promote_computer.md b/docs/reference/providers/handler/promote_computer.md index 524e2742..79f1dc9f 100644 --- a/docs/reference/providers/handler/promote_computer.md +++ b/docs/reference/providers/handler/promote_computer.md @@ -190,6 +190,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/handler/promote_handler.md b/docs/reference/providers/handler/promote_handler.md index b6ef71b4..7ad85afb 100644 --- a/docs/reference/providers/handler/promote_handler.md +++ b/docs/reference/providers/handler/promote_handler.md @@ -143,6 +143,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/handler/promote_producer.md b/docs/reference/providers/handler/promote_producer.md index 303c937e..d67b1e2c 100644 --- a/docs/reference/providers/handler/promote_producer.md +++ b/docs/reference/providers/handler/promote_producer.md @@ -163,6 +163,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/handler/promote_ref.md b/docs/reference/providers/handler/promote_ref.md index ac1bf8a8..ee81a4ad 100644 --- a/docs/reference/providers/handler/promote_ref.md +++ b/docs/reference/providers/handler/promote_ref.md @@ -161,6 +161,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/handler/promote_try_computer.md b/docs/reference/providers/handler/promote_try_computer.md index 3d667588..2157afe4 100644 --- a/docs/reference/providers/handler/promote_try_computer.md +++ b/docs/reference/providers/handler/promote_try_computer.md @@ -164,6 +164,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/handler/return_input.md b/docs/reference/providers/handler/return_input.md index f070f3c8..a0867a4a 100644 --- a/docs/reference/providers/handler/return_input.md +++ b/docs/reference/providers/handler/return_input.md @@ -109,6 +109,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/handler/try_promote.md b/docs/reference/providers/handler/try_promote.md index 652decb0..93f46c72 100644 --- a/docs/reference/providers/handler/try_promote.md +++ b/docs/reference/providers/handler/try_promote.md @@ -162,6 +162,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/handler/use_input_delegate.md b/docs/reference/providers/handler/use_input_delegate.md index 0947744e..742b6b9d 100644 --- a/docs/reference/providers/handler/use_input_delegate.md +++ b/docs/reference/providers/handler/use_input_delegate.md @@ -220,6 +220,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/index.md b/docs/reference/providers/index.md index 46cf57e6..bdff6aa8 100644 --- a/docs/reference/providers/index.md +++ b/docs/reference/providers/index.md @@ -66,6 +66,6 @@ subsection here with one page per provider and its own overview. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/monad/bind_err.md b/docs/reference/providers/monad/bind_err.md index 76927d60..13449f18 100644 --- a/docs/reference/providers/monad/bind_err.md +++ b/docs/reference/providers/monad/bind_err.md @@ -131,6 +131,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/monad/bind_ok.md b/docs/reference/providers/monad/bind_ok.md index 312ae426..89378cda 100644 --- a/docs/reference/providers/monad/bind_ok.md +++ b/docs/reference/providers/monad/bind_ok.md @@ -138,6 +138,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/monad/index.md b/docs/reference/providers/monad/index.md index 90bb82c7..8f1acdde 100644 --- a/docs/reference/providers/monad/index.md +++ b/docs/reference/providers/monad/index.md @@ -82,6 +82,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/monad/pipe_monadic.md b/docs/reference/providers/monad/pipe_monadic.md index 3edeff34..8b00cbad 100644 --- a/docs/reference/providers/monad/pipe_monadic.md +++ b/docs/reference/providers/monad/pipe_monadic.md @@ -215,6 +215,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/redirect_lookup.md b/docs/reference/providers/redirect_lookup.md index 5bd0d83f..54bf020b 100644 --- a/docs/reference/providers/redirect_lookup.md +++ b/docs/reference/providers/redirect_lookup.md @@ -235,6 +235,8 @@ Bind the provider at the registered path, `@app.GreeterComponent: GreetHello`, a The ideas behind it: +- [Type-level tables](/docs/concepts/type-level-tables) — a lookup on a composite key, the plain-Rust form of this + provider. - [Namespaces](/docs/concepts/namespaces) — reusable, inheritable wiring tables, which this provider implements. @@ -249,6 +251,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/use_context.md b/docs/reference/providers/use_context.md index 848a2de1..db39bb02 100644 --- a/docs/reference/providers/use_context.md +++ b/docs/reference/providers/use_context.md @@ -236,6 +236,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/use_default.md b/docs/reference/providers/use_default.md index 7f704821..b70d4d36 100644 --- a/docs/reference/providers/use_default.md +++ b/docs/reference/providers/use_default.md @@ -191,6 +191,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/use_delegate.md b/docs/reference/providers/use_delegate.md index a167b8e6..1776c9ee 100644 --- a/docs/reference/providers/use_delegate.md +++ b/docs/reference/providers/use_delegate.md @@ -209,6 +209,7 @@ differently. The ideas behind it: +- [Type-level tables](/docs/concepts/type-level-tables) — a nested table read in two steps, in plain Rust. - [Consumer and provider traits](/docs/concepts/consumer-and-provider-traits) — the delegation table this reuses, keyed on a type parameter rather than a component name. @@ -224,6 +225,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/use_delegated_type.md b/docs/reference/providers/use_delegated_type.md index ad7098cc..03431b3f 100644 --- a/docs/reference/providers/use_delegated_type.md +++ b/docs/reference/providers/use_delegated_type.md @@ -137,6 +137,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/use_field.md b/docs/reference/providers/use_field.md index 64e38748..efb517a1 100644 --- a/docs/reference/providers/use_field.md +++ b/docs/reference/providers/use_field.md @@ -236,6 +236,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/use_field_ref.md b/docs/reference/providers/use_field_ref.md index b9856f99..4b18a6eb 100644 --- a/docs/reference/providers/use_field_ref.md +++ b/docs/reference/providers/use_field_ref.md @@ -110,6 +110,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/use_fields.md b/docs/reference/providers/use_fields.md index b1d10256..bf27fd5e 100644 --- a/docs/reference/providers/use_fields.md +++ b/docs/reference/providers/use_fields.md @@ -180,6 +180,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/use_type.md b/docs/reference/providers/use_type.md index fbf6b53d..d36a91ab 100644 --- a/docs/reference/providers/use_type.md +++ b/docs/reference/providers/use_type.md @@ -209,6 +209,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/with_context.md b/docs/reference/providers/with_context.md index 51ed2273..1008810d 100644 --- a/docs/reference/providers/with_context.md +++ b/docs/reference/providers/with_context.md @@ -166,6 +166,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/with_delegated_type.md b/docs/reference/providers/with_delegated_type.md index 889cf211..a7fa63cf 100644 --- a/docs/reference/providers/with_delegated_type.md +++ b/docs/reference/providers/with_delegated_type.md @@ -144,6 +144,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/with_field.md b/docs/reference/providers/with_field.md index d01218ee..2a73dbaa 100644 --- a/docs/reference/providers/with_field.md +++ b/docs/reference/providers/with_field.md @@ -149,6 +149,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/with_field_ref.md b/docs/reference/providers/with_field_ref.md index 95c262a5..e1118c9c 100644 --- a/docs/reference/providers/with_field_ref.md +++ b/docs/reference/providers/with_field_ref.md @@ -159,6 +159,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/with_provider.md b/docs/reference/providers/with_provider.md index aa446538..e04f82fb 100644 --- a/docs/reference/providers/with_provider.md +++ b/docs/reference/providers/with_provider.md @@ -214,6 +214,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/providers/with_type.md b/docs/reference/providers/with_type.md index 5f1735d7..5c5d1712 100644 --- a/docs/reference/providers/with_type.md +++ b/docs/reference/providers/with_type.md @@ -115,6 +115,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/builder/build_field.md b/docs/reference/traits/builder/build_field.md index 70607873..ec03d9b1 100644 --- a/docs/reference/traits/builder/build_field.md +++ b/docs/reference/traits/builder/build_field.md @@ -212,6 +212,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/builder/finalize_build.md b/docs/reference/traits/builder/finalize_build.md index 9432a16c..13c2513c 100644 --- a/docs/reference/traits/builder/finalize_build.md +++ b/docs/reference/traits/builder/finalize_build.md @@ -208,6 +208,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/builder/has_builder.md b/docs/reference/traits/builder/has_builder.md index 7fab2bc5..76dc9e1d 100644 --- a/docs/reference/traits/builder/has_builder.md +++ b/docs/reference/traits/builder/has_builder.md @@ -287,6 +287,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/builder/index.md b/docs/reference/traits/builder/index.md index 473c17b0..37fb3387 100644 --- a/docs/reference/traits/builder/index.md +++ b/docs/reference/traits/builder/index.md @@ -41,6 +41,6 @@ generic builder code knows what it is building before the build is complete. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/builder/into_builder.md b/docs/reference/traits/builder/into_builder.md index 8f55c064..de31fff3 100644 --- a/docs/reference/traits/builder/into_builder.md +++ b/docs/reference/traits/builder/into_builder.md @@ -185,6 +185,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/builder/partial_data.md b/docs/reference/traits/builder/partial_data.md index a0aa6a99..08d851f4 100644 --- a/docs/reference/traits/builder/partial_data.md +++ b/docs/reference/traits/builder/partial_data.md @@ -170,6 +170,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/builder/take_field.md b/docs/reference/traits/builder/take_field.md index 571b0d99..383868a3 100644 --- a/docs/reference/traits/builder/take_field.md +++ b/docs/reference/traits/builder/take_field.md @@ -200,6 +200,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/builder/update_field.md b/docs/reference/traits/builder/update_field.md index c506decb..28165345 100644 --- a/docs/reference/traits/builder/update_field.md +++ b/docs/reference/traits/builder/update_field.md @@ -242,6 +242,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/casting/can_build_from.md b/docs/reference/traits/casting/can_build_from.md index fbc77c6e..9dbf0d52 100644 --- a/docs/reference/traits/casting/can_build_from.md +++ b/docs/reference/traits/casting/can_build_from.md @@ -284,6 +284,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/casting/can_downcast.md b/docs/reference/traits/casting/can_downcast.md index 2c7b5c70..d22807d9 100644 --- a/docs/reference/traits/casting/can_downcast.md +++ b/docs/reference/traits/casting/can_downcast.md @@ -199,6 +199,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/casting/can_downcast_fields.md b/docs/reference/traits/casting/can_downcast_fields.md index 96331d35..5829c725 100644 --- a/docs/reference/traits/casting/can_downcast_fields.md +++ b/docs/reference/traits/casting/can_downcast_fields.md @@ -201,6 +201,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/casting/can_upcast.md b/docs/reference/traits/casting/can_upcast.md index 0a7482a3..d90d9f15 100644 --- a/docs/reference/traits/casting/can_upcast.md +++ b/docs/reference/traits/casting/can_upcast.md @@ -227,6 +227,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/casting/index.md b/docs/reference/traits/casting/index.md index fcf86259..4fcf6b44 100644 --- a/docs/reference/traits/casting/index.md +++ b/docs/reference/traits/casting/index.md @@ -36,6 +36,6 @@ builder, so several sources can be merged into one target before it is finalized --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/field-access/field_getter.md b/docs/reference/traits/field-access/field_getter.md index 6ca4d0cd..a3adac6c 100644 --- a/docs/reference/traits/field-access/field_getter.md +++ b/docs/reference/traits/field-access/field_getter.md @@ -269,6 +269,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/field-access/field_mapper.md b/docs/reference/traits/field-access/field_mapper.md index 1cca7d95..db19a1b1 100644 --- a/docs/reference/traits/field-access/field_mapper.md +++ b/docs/reference/traits/field-access/field_mapper.md @@ -212,6 +212,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/field-access/has_field.md b/docs/reference/traits/field-access/has_field.md index 659b488e..f0ffcb95 100644 --- a/docs/reference/traits/field-access/has_field.md +++ b/docs/reference/traits/field-access/has_field.md @@ -272,6 +272,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/field-access/has_field_mut.md b/docs/reference/traits/field-access/has_field_mut.md index c09af727..6b95b1a7 100644 --- a/docs/reference/traits/field-access/has_field_mut.md +++ b/docs/reference/traits/field-access/has_field_mut.md @@ -185,6 +185,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/field-access/index.md b/docs/reference/traits/field-access/index.md index c97b395b..277dbbfb 100644 --- a/docs/reference/traits/field-access/index.md +++ b/docs/reference/traits/field-access/index.md @@ -45,6 +45,6 @@ lifetime bound on the intermediate type. [`MapField`](map_field.md) is the consu --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/field-access/map_field.md b/docs/reference/traits/field-access/map_field.md index d72d6534..6655af62 100644 --- a/docs/reference/traits/field-access/map_field.md +++ b/docs/reference/traits/field-access/map_field.md @@ -205,6 +205,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/field-access/mut_field_getter.md b/docs/reference/traits/field-access/mut_field_getter.md index 056d182a..b476455d 100644 --- a/docs/reference/traits/field-access/mut_field_getter.md +++ b/docs/reference/traits/field-access/mut_field_getter.md @@ -179,6 +179,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/field-access/option_as_ref.md b/docs/reference/traits/field-access/option_as_ref.md index da4566a3..e8282280 100644 --- a/docs/reference/traits/field-access/option_as_ref.md +++ b/docs/reference/traits/field-access/option_as_ref.md @@ -98,6 +98,6 @@ the --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/formatting/concat_path.md b/docs/reference/traits/formatting/concat_path.md index 4de682b0..6472426c 100644 --- a/docs/reference/traits/formatting/concat_path.md +++ b/docs/reference/traits/formatting/concat_path.md @@ -196,6 +196,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/formatting/index.md b/docs/reference/traits/formatting/index.md index 045858c5..21fb8270 100644 --- a/docs/reference/traits/formatting/index.md +++ b/docs/reference/traits/formatting/index.md @@ -34,6 +34,6 @@ prelude, and they sit in two different modules, which is the group's sharpest ed --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/formatting/static_format.md b/docs/reference/traits/formatting/static_format.md index 25e06dfc..b5193abe 100644 --- a/docs/reference/traits/formatting/static_format.md +++ b/docs/reference/traits/formatting/static_format.md @@ -209,6 +209,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/formatting/static_string.md b/docs/reference/traits/formatting/static_string.md index 46c89e9b..52940c1b 100644 --- a/docs/reference/traits/formatting/static_string.md +++ b/docs/reference/traits/formatting/static_string.md @@ -182,6 +182,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/index.md b/docs/reference/traits/index.md index aaf5c37e..ed6fa30c 100644 --- a/docs/reference/traits/index.md +++ b/docs/reference/traits/index.md @@ -58,6 +58,6 @@ Three smaller groups each serve one area: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/monad/contains_value.md b/docs/reference/traits/monad/contains_value.md index 0f60c389..6498bf83 100644 --- a/docs/reference/traits/monad/contains_value.md +++ b/docs/reference/traits/monad/contains_value.md @@ -192,6 +192,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/monad/index.md b/docs/reference/traits/monad/index.md index 29267c9d..80c4775a 100644 --- a/docs/reference/traits/monad/index.md +++ b/docs/reference/traits/monad/index.md @@ -38,6 +38,6 @@ the output type on either branch. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/monad/lift_value.md b/docs/reference/traits/monad/lift_value.md index f34bd49b..6bc4b5c2 100644 --- a/docs/reference/traits/monad/lift_value.md +++ b/docs/reference/traits/monad/lift_value.md @@ -195,6 +195,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/monad/monadic_bind.md b/docs/reference/traits/monad/monadic_bind.md index 446b25cd..86ead277 100644 --- a/docs/reference/traits/monad/monadic_bind.md +++ b/docs/reference/traits/monad/monadic_bind.md @@ -213,6 +213,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/monad/monadic_trans.md b/docs/reference/traits/monad/monadic_trans.md index 3e7d21e6..41574046 100644 --- a/docs/reference/traits/monad/monadic_trans.md +++ b/docs/reference/traits/monad/monadic_trans.md @@ -200,6 +200,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/namespace/default_impls1.md b/docs/reference/traits/namespace/default_impls1.md index caa82869..d4cf014b 100644 --- a/docs/reference/traits/namespace/default_impls1.md +++ b/docs/reference/traits/namespace/default_impls1.md @@ -301,6 +301,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/namespace/default_impls2.md b/docs/reference/traits/namespace/default_impls2.md index 7ae8376a..96eac265 100644 --- a/docs/reference/traits/namespace/default_impls2.md +++ b/docs/reference/traits/namespace/default_impls2.md @@ -221,6 +221,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/namespace/default_namespace.md b/docs/reference/traits/namespace/default_namespace.md index 0409d290..d861dc2c 100644 --- a/docs/reference/traits/namespace/default_namespace.md +++ b/docs/reference/traits/namespace/default_namespace.md @@ -245,6 +245,7 @@ type takes the `Self` position instead. The inconsistency is the family's sharpe The ideas behind it: +- [Type-level tables](/docs/concepts/type-level-tables): a namespace as a table written from the key's side. - [Namespaces](/docs/concepts/namespaces): reusable, inheritable wiring tables and preset-style configuration. @@ -256,6 +257,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/namespace/index.md b/docs/reference/traits/namespace/index.md index 0f2692f8..4f90ee88 100644 --- a/docs/reference/traits/namespace/index.md +++ b/docs/reference/traits/namespace/index.md @@ -39,6 +39,6 @@ works it out. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/optional/can_build_with_default.md b/docs/reference/traits/optional/can_build_with_default.md index 67e70034..cd3aff36 100644 --- a/docs/reference/traits/optional/can_build_with_default.md +++ b/docs/reference/traits/optional/can_build_with_default.md @@ -225,6 +225,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/optional/can_finalize_with_default.md b/docs/reference/traits/optional/can_finalize_with_default.md index 8f973ab3..210834cf 100644 --- a/docs/reference/traits/optional/can_finalize_with_default.md +++ b/docs/reference/traits/optional/can_finalize_with_default.md @@ -227,6 +227,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/optional/finalize_optional.md b/docs/reference/traits/optional/finalize_optional.md index 9a20d65e..dad1a2f9 100644 --- a/docs/reference/traits/optional/finalize_optional.md +++ b/docs/reference/traits/optional/finalize_optional.md @@ -225,6 +225,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/optional/has_optional_builder.md b/docs/reference/traits/optional/has_optional_builder.md index 032ddf86..5701b178 100644 --- a/docs/reference/traits/optional/has_optional_builder.md +++ b/docs/reference/traits/optional/has_optional_builder.md @@ -201,6 +201,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/optional/index.md b/docs/reference/traits/optional/index.md index deb890b9..d554be0a 100644 --- a/docs/reference/traits/optional/index.md +++ b/docs/reference/traits/optional/index.md @@ -44,6 +44,6 @@ The **transform markers** carry the per-field conversions the endings run. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/optional/set_optional.md b/docs/reference/traits/optional/set_optional.md index 687c8d25..6230543e 100644 --- a/docs/reference/traits/optional/set_optional.md +++ b/docs/reference/traits/optional/set_optional.md @@ -199,6 +199,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/optional/to_optional.md b/docs/reference/traits/optional/to_optional.md index 966c0b17..cd2b1d1f 100644 --- a/docs/reference/traits/optional/to_optional.md +++ b/docs/reference/traits/optional/to_optional.md @@ -197,6 +197,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/optional/transform_map_default.md b/docs/reference/traits/optional/transform_map_default.md index 9fea8ece..be153d2f 100644 --- a/docs/reference/traits/optional/transform_map_default.md +++ b/docs/reference/traits/optional/transform_map_default.md @@ -202,6 +202,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/optional/transform_optional.md b/docs/reference/traits/optional/transform_optional.md index c9974b6d..dc17a81c 100644 --- a/docs/reference/traits/optional/transform_optional.md +++ b/docs/reference/traits/optional/transform_optional.md @@ -210,6 +210,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/shape/from_fields.md b/docs/reference/traits/shape/from_fields.md index d60e7d39..12991aba 100644 --- a/docs/reference/traits/shape/from_fields.md +++ b/docs/reference/traits/shape/from_fields.md @@ -190,6 +190,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/shape/has_fields.md b/docs/reference/traits/shape/has_fields.md index 0f521724..2f15f0d4 100644 --- a/docs/reference/traits/shape/has_fields.md +++ b/docs/reference/traits/shape/has_fields.md @@ -250,6 +250,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/shape/has_fields_ref.md b/docs/reference/traits/shape/has_fields_ref.md index e48c896b..ddfb0490 100644 --- a/docs/reference/traits/shape/has_fields_ref.md +++ b/docs/reference/traits/shape/has_fields_ref.md @@ -183,6 +183,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/shape/index.md b/docs/reference/traits/shape/index.md index 9cc94465..e752ca0e 100644 --- a/docs/reference/traits/shape/index.md +++ b/docs/reference/traits/shape/index.md @@ -34,6 +34,6 @@ that reads a shape without consuming the value. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/shape/to_fields.md b/docs/reference/traits/shape/to_fields.md index 914232e3..0e175e2d 100644 --- a/docs/reference/traits/shape/to_fields.md +++ b/docs/reference/traits/shape/to_fields.md @@ -172,6 +172,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/shape/to_fields_ref.md b/docs/reference/traits/shape/to_fields_ref.md index e16a5146..c7ffb28b 100644 --- a/docs/reference/traits/shape/to_fields_ref.md +++ b/docs/reference/traits/shape/to_fields_ref.md @@ -162,6 +162,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/type-level/append_product.md b/docs/reference/traits/type-level/append_product.md index 845a9635..bf651682 100644 --- a/docs/reference/traits/type-level/append_product.md +++ b/docs/reference/traits/type-level/append_product.md @@ -170,6 +170,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/type-level/concat_product.md b/docs/reference/traits/type-level/concat_product.md index af40fe10..e64ea907 100644 --- a/docs/reference/traits/type-level/concat_product.md +++ b/docs/reference/traits/type-level/concat_product.md @@ -169,6 +169,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/type-level/index.md b/docs/reference/traits/type-level/index.md index baad91fa..6bcd8f58 100644 --- a/docs/reference/traits/type-level/index.md +++ b/docs/reference/traits/type-level/index.md @@ -38,6 +38,6 @@ one entry to a product and [`ConcatProduct`](concat_product.md) splices two toge --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/type-level/map_fields.md b/docs/reference/traits/type-level/map_fields.md index ca933389..bf2d4529 100644 --- a/docs/reference/traits/type-level/map_fields.md +++ b/docs/reference/traits/type-level/map_fields.md @@ -216,6 +216,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/type-level/map_type.md b/docs/reference/traits/type-level/map_type.md index 2db9a047..e26ac478 100644 --- a/docs/reference/traits/type-level/map_type.md +++ b/docs/reference/traits/type-level/map_type.md @@ -224,6 +224,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/type-level/map_type_ref.md b/docs/reference/traits/type-level/map_type_ref.md index 2faef94a..67f8fb3e 100644 --- a/docs/reference/traits/type-level/map_type_ref.md +++ b/docs/reference/traits/type-level/map_type_ref.md @@ -220,6 +220,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/type-level/transform_map.md b/docs/reference/traits/type-level/transform_map.md index 97c7e312..cca1ad80 100644 --- a/docs/reference/traits/type-level/transform_map.md +++ b/docs/reference/traits/type-level/transform_map.md @@ -218,6 +218,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/type-level/transform_map_fields.md b/docs/reference/traits/type-level/transform_map_fields.md index fc05b17e..f5f6db56 100644 --- a/docs/reference/traits/type-level/transform_map_fields.md +++ b/docs/reference/traits/type-level/transform_map_fields.md @@ -246,6 +246,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/variant/extract_field.md b/docs/reference/traits/variant/extract_field.md index 26e37019..e5d30e51 100644 --- a/docs/reference/traits/variant/extract_field.md +++ b/docs/reference/traits/variant/extract_field.md @@ -295,6 +295,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/variant/finalize_extract.md b/docs/reference/traits/variant/finalize_extract.md index a4cd19be..e03dfb14 100644 --- a/docs/reference/traits/variant/finalize_extract.md +++ b/docs/reference/traits/variant/finalize_extract.md @@ -210,6 +210,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/variant/finalize_extract_result.md b/docs/reference/traits/variant/finalize_extract_result.md index a5f9c791..fd928c02 100644 --- a/docs/reference/traits/variant/finalize_extract_result.md +++ b/docs/reference/traits/variant/finalize_extract_result.md @@ -217,6 +217,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/variant/from_variant.md b/docs/reference/traits/variant/from_variant.md index d53af175..1f32c5a5 100644 --- a/docs/reference/traits/variant/from_variant.md +++ b/docs/reference/traits/variant/from_variant.md @@ -257,6 +257,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/variant/has_extractor.md b/docs/reference/traits/variant/has_extractor.md index 1b42d3eb..eab41544 100644 --- a/docs/reference/traits/variant/has_extractor.md +++ b/docs/reference/traits/variant/has_extractor.md @@ -205,6 +205,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/variant/has_extractor_mut.md b/docs/reference/traits/variant/has_extractor_mut.md index dcc9877b..c3f0cc5e 100644 --- a/docs/reference/traits/variant/has_extractor_mut.md +++ b/docs/reference/traits/variant/has_extractor_mut.md @@ -195,6 +195,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/variant/has_extractor_ref.md b/docs/reference/traits/variant/has_extractor_ref.md index 0e04527f..fa13ec02 100644 --- a/docs/reference/traits/variant/has_extractor_ref.md +++ b/docs/reference/traits/variant/has_extractor_ref.md @@ -205,6 +205,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/variant/index.md b/docs/reference/traits/variant/index.md index 3e8fe362..6d9e7b59 100644 --- a/docs/reference/traits/variant/index.md +++ b/docs/reference/traits/variant/index.md @@ -40,6 +40,6 @@ result. --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/wiring/can_use_component.md b/docs/reference/traits/wiring/can_use_component.md index bb15bff5..c2aed7b4 100644 --- a/docs/reference/traits/wiring/can_use_component.md +++ b/docs/reference/traits/wiring/can_use_component.md @@ -274,6 +274,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/wiring/delegate_component.md b/docs/reference/traits/wiring/delegate_component.md index 2a34ce42..8b507f6e 100644 --- a/docs/reference/traits/wiring/delegate_component.md +++ b/docs/reference/traits/wiring/delegate_component.md @@ -323,6 +323,8 @@ not it. The ideas behind it: +- [Type-level tables](/docs/concepts/type-level-tables): the plain-Rust table this trait is, beside the + value-level map it mirrors. - [Consumer and provider traits](/docs/concepts/consumer-and-provider-traits): the split this table connects. - [Bypassing coherence](/docs/concepts/coherence): why the choice is recorded per context at all. @@ -339,6 +341,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/wiring/index.md b/docs/reference/traits/wiring/index.md index 56a42c70..af722594 100644 --- a/docs/reference/traits/wiring/index.md +++ b/docs/reference/traits/wiring/index.md @@ -40,6 +40,6 @@ provider's requirements hold? --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/traits/wiring/is_provider_for.md b/docs/reference/traits/wiring/is_provider_for.md index 2c3eafcd..85fd16b4 100644 --- a/docs/reference/traits/wiring/is_provider_for.md +++ b/docs/reference/traits/wiring/is_provider_for.md @@ -337,6 +337,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/types/chars.md b/docs/reference/types/chars.md index e750b272..a6dce64a 100644 --- a/docs/reference/types/chars.md +++ b/docs/reference/types/chars.md @@ -211,6 +211,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/types/cons.md b/docs/reference/types/cons.md index 2c3e4077..af0cf99a 100644 --- a/docs/reference/types/cons.md +++ b/docs/reference/types/cons.md @@ -179,6 +179,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/types/either.md b/docs/reference/types/either.md index 004637ae..155c8f25 100644 --- a/docs/reference/types/either.md +++ b/docs/reference/types/either.md @@ -189,6 +189,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/types/field.md b/docs/reference/types/field.md index 01a206df..36295a53 100644 --- a/docs/reference/types/field.md +++ b/docs/reference/types/field.md @@ -201,6 +201,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/types/index.md b/docs/reference/types/index.md index 6b430d14..d35e88b3 100644 --- a/docs/reference/types/index.md +++ b/docs/reference/types/index.md @@ -54,6 +54,6 @@ type rather than a trait or a provider, and you name it yourself as a getter's r --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/types/index_type.md b/docs/reference/types/index_type.md index 145c8c07..8b898137 100644 --- a/docs/reference/types/index_type.md +++ b/docs/reference/types/index_type.md @@ -174,6 +174,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/types/life.md b/docs/reference/types/life.md index 69c2a3ac..20017806 100644 --- a/docs/reference/types/life.md +++ b/docs/reference/types/life.md @@ -237,6 +237,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/types/mref.md b/docs/reference/types/mref.md index 964d2392..7ee45c0c 100644 --- a/docs/reference/types/mref.md +++ b/docs/reference/types/mref.md @@ -217,6 +217,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/types/nil.md b/docs/reference/types/nil.md index 6e71deea..0a05daaf 100644 --- a/docs/reference/types/nil.md +++ b/docs/reference/types/nil.md @@ -132,6 +132,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/types/path_cons.md b/docs/reference/types/path_cons.md index 5e1e27c8..98e41bc6 100644 --- a/docs/reference/types/path_cons.md +++ b/docs/reference/types/path_cons.md @@ -185,6 +185,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/types/phantom_data.md b/docs/reference/types/phantom_data.md index 36107f49..8f1fdd6b 100644 --- a/docs/reference/types/phantom_data.md +++ b/docs/reference/types/phantom_data.md @@ -267,6 +267,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/reference/types/void.md b/docs/reference/types/void.md index e9178642..29a70a70 100644 --- a/docs/reference/types/void.md +++ b/docs/reference/types/void.md @@ -196,6 +196,6 @@ The ideas behind it: --- -*An AI agent wrote this page using the CGP knowledge base. Its content was verified against the -library's source. See +*This page was written by an AI agent from the CGP knowledge base. Its content was verified against +the library's source. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/release-notes/cargo-cgp/v0-1-0.md b/docs/release-notes/cargo-cgp/v0-1-0.md index 29069659..fdfd4faa 100644 --- a/docs/release-notes/cargo-cgp/v0-1-0.md +++ b/docs/release-notes/cargo-cgp/v0-1-0.md @@ -101,6 +101,6 @@ The repository's flake builds both binaries against the pinned nightly without r --- -*An AI agent wrote this page from the release's source changes and the CGP knowledge base. Its -content was verified against the tool's source at the release's tag. See +*This page was written by an AI agent from the release's source changes and the CGP knowledge base. +Its content was verified against the tool's source at the release's tag. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/release-notes/cgp-serde/v0-1-0.md b/docs/release-notes/cgp-serde/v0-1-0.md index 08af7a5f..49dd6255 100644 --- a/docs/release-notes/cgp-serde/v0-1-0.md +++ b/docs/release-notes/cgp-serde/v0-1-0.md @@ -122,6 +122,6 @@ This is the library's first release, so there is nothing to upgrade from. Add `c --- -*An AI agent wrote this page from the release's source changes and the CGP knowledge base. Its -content was verified against the library's source at the release's tag. See +*This page was written by an AI agent from the release's source changes and the CGP knowledge base. +Its content was verified against the library's source at the release's tag. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/release-notes/cgp-serde/v0-2-0.md b/docs/release-notes/cgp-serde/v0-2-0.md index 88da4ebf..0d5a8592 100644 --- a/docs/release-notes/cgp-serde/v0-2-0.md +++ b/docs/release-notes/cgp-serde/v0-2-0.md @@ -55,6 +55,6 @@ compile beside `cgp` 0.6, and a project moves to `cgp` 0.7.0 with it. --- -*An AI agent wrote this page from the release's source changes and the CGP knowledge base. Its -content was verified against the library's source at the release's tag. See +*This page was written by an AI agent from the release's source changes and the CGP knowledge base. +Its content was verified against the library's source at the release's tag. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/release-notes/cgp-serde/v0-3-0.md b/docs/release-notes/cgp-serde/v0-3-0.md index 1bdabe90..18fd798c 100644 --- a/docs/release-notes/cgp-serde/v0-3-0.md +++ b/docs/release-notes/cgp-serde/v0-3-0.md @@ -89,6 +89,6 @@ in [#2](https://github.com/contextgeneric/cgp-serde/pull/2). --- -*An AI agent wrote this page from the release's source changes and the CGP knowledge base. Its -content was verified against the library's source at the release's tag. See +*This page was written by an AI agent from the release's source changes and the CGP knowledge base. +Its content was verified against the library's source at the release's tag. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/release-notes/cgp/v0-1-0.md b/docs/release-notes/cgp/v0-1-0.md index 7bcc6e2f..b35ad823 100644 --- a/docs/release-notes/cgp/v0-1-0.md +++ b/docs/release-notes/cgp/v0-1-0.md @@ -68,5 +68,6 @@ This is the first release, so there is nothing to upgrade from. A project adds ` --- -*An AI agent wrote this page from the release's source changes and the CGP knowledge base. Its content was verified against the library's source at the release's tag. See +*This page was written by an AI agent from the release's source changes and the CGP knowledge base. +Its content was verified against the library's source at the release's tag. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/release-notes/cgp/v0-2-0.md b/docs/release-notes/cgp/v0-2-0.md index 459b2d5a..27d2ed43 100644 --- a/docs/release-notes/cgp/v0-2-0.md +++ b/docs/release-notes/cgp/v0-2-0.md @@ -123,5 +123,6 @@ The associated type of `HasField` is `Value` ([#35](https://github.com/contextge --- -*An AI agent wrote this page from the release's source changes and the CGP knowledge base. Its content was verified against the library's source at the release's tag. See +*This page was written by an AI agent from the release's source changes and the CGP knowledge base. +Its content was verified against the library's source at the release's tag. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/release-notes/cgp/v0-3-0.md b/docs/release-notes/cgp/v0-3-0.md index 9995c4e2..675b697e 100644 --- a/docs/release-notes/cgp/v0-3-0.md +++ b/docs/release-notes/cgp/v0-3-0.md @@ -130,5 +130,6 @@ The providers of `cgp-error-eyre` and `cgp-error-std` have new names, and `cgp-e --- -*An AI agent wrote this page from the release's source changes and the CGP knowledge base. Its content was verified against the library's source at the release's tag. See +*This page was written by an AI agent from the release's source changes and the CGP knowledge base. +Its content was verified against the library's source at the release's tag. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/release-notes/cgp/v0-3-1.md b/docs/release-notes/cgp/v0-3-1.md index 7fe92f29..5d4cb578 100644 --- a/docs/release-notes/cgp/v0-3-1.md +++ b/docs/release-notes/cgp/v0-3-1.md @@ -38,5 +38,6 @@ A project on Rust 1.84 or newer takes one step: change the version to `cgp = "0. --- -*An AI agent wrote this page from the release's source changes and the CGP knowledge base. Its content was verified against the library's source at the release's tag. See +*This page was written by an AI agent from the release's source changes and the CGP knowledge base. +Its content was verified against the library's source at the release's tag. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/release-notes/cgp/v0-4-0.md b/docs/release-notes/cgp/v0-4-0.md index d7321d6a..60e68eb0 100644 --- a/docs/release-notes/cgp/v0-4-0.md +++ b/docs/release-notes/cgp/v0-4-0.md @@ -172,5 +172,6 @@ The macro writes the impl of the provider trait for `UseContext`, and its `IsPro --- -*An AI agent wrote this page from the release's source changes and the CGP knowledge base. Its content was verified against the library's source at the release's tag. See +*This page was written by an AI agent from the release's source changes and the CGP knowledge base. +Its content was verified against the library's source at the release's tag. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/release-notes/cgp/v0-4-1.md b/docs/release-notes/cgp/v0-4-1.md index 288c5324..b03883a0 100644 --- a/docs/release-notes/cgp/v0-4-1.md +++ b/docs/release-notes/cgp/v0-4-1.md @@ -63,5 +63,6 @@ The new trait `StaticFormat` formats a type without a value, and `Char` implemen --- -*An AI agent wrote this page from the release's source changes and the CGP knowledge base. Its content was verified against the library's source at the release's tag. See +*This page was written by an AI agent from the release's source changes and the CGP knowledge base. +Its content was verified against the library's source at the release's tag. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/release-notes/cgp/v0-4-2.md b/docs/release-notes/cgp/v0-4-2.md index 322c57ae..89a7a046 100644 --- a/docs/release-notes/cgp/v0-4-2.md +++ b/docs/release-notes/cgp/v0-4-2.md @@ -105,5 +105,6 @@ A project moving from v0.4.1 takes these steps, in this order: --- -*An AI agent wrote this page from the release's source changes and the CGP knowledge base. Its content was verified against the library's source at the release's tag. See +*This page was written by an AI agent from the release's source changes and the CGP knowledge base. +Its content was verified against the library's source at the release's tag. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/release-notes/cgp/v0-5-0.md b/docs/release-notes/cgp/v0-5-0.md index e984d800..ba24eb00 100644 --- a/docs/release-notes/cgp/v0-5-0.md +++ b/docs/release-notes/cgp/v0-5-0.md @@ -210,5 +210,6 @@ The types that `#[derive(BuildField)]` and `#[derive(ExtractField)]` generate ga --- -*An AI agent wrote this page from the release's source changes and the CGP knowledge base. Its content was verified against the library's source at the release's tag. See +*This page was written by an AI agent from the release's source changes and the CGP knowledge base. +Its content was verified against the library's source at the release's tag. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/release-notes/cgp/v0-6-0.md b/docs/release-notes/cgp/v0-6-0.md index b3028e13..e3a4faaa 100644 --- a/docs/release-notes/cgp/v0-6-0.md +++ b/docs/release-notes/cgp/v0-6-0.md @@ -59,5 +59,6 @@ The trait `HasCgpProvider` and its `CgpProvider` associated type are removed fro --- -*An AI agent wrote this page from the release's source changes and the CGP knowledge base. Its content was verified against the library's source at the release's tag. See +*This page was written by an AI agent from the release's source changes and the CGP knowledge base. +Its content was verified against the library's source at the release's tag. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/release-notes/cgp/v0-6-1.md b/docs/release-notes/cgp/v0-6-1.md index 3a1394df..53f67687 100644 --- a/docs/release-notes/cgp/v0-6-1.md +++ b/docs/release-notes/cgp/v0-6-1.md @@ -46,5 +46,6 @@ A project moving from v0.6.0 changes the version to `cgp = "0.6.1"`, and nothing --- -*An AI agent wrote this page from the release's source changes and the CGP knowledge base. Its content was verified against the library's source at the release's tag. See +*This page was written by an AI agent from the release's source changes and the CGP knowledge base. +Its content was verified against the library's source at the release's tag. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/release-notes/cgp/v0-7-0.md b/docs/release-notes/cgp/v0-7-0.md index d126194d..d64b50a8 100644 --- a/docs/release-notes/cgp/v0-7-0.md +++ b/docs/release-notes/cgp/v0-7-0.md @@ -113,5 +113,6 @@ The provider trait of `HasType` and its component key take the names that `#[cgp --- -*An AI agent wrote this page from the release's source changes and the CGP knowledge base. Its content was verified against the library's source at the release's tag. See +*This page was written by an AI agent from the release's source changes and the CGP knowledge base. +Its content was verified against the library's source at the release's tag. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/release-notes/cgp/v0-8-0.md b/docs/release-notes/cgp/v0-8-0.md index 7614e096..62918b01 100644 --- a/docs/release-notes/cgp/v0-8-0.md +++ b/docs/release-notes/cgp/v0-8-0.md @@ -441,6 +441,6 @@ turns on `DebugError` and `DisplayError`. The error backends keep their requirem --- -*An AI agent wrote this page from the release's source changes and the CGP knowledge base. Its -content was verified against the library's source at the release's tag. See +*This page was written by an AI agent from the release's source changes and the CGP knowledge base. +Its content was verified against the library's source at the release's tag. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/release-notes/hypershell/v0-1-0.md b/docs/release-notes/hypershell/v0-1-0.md index affd199e..494caf90 100644 --- a/docs/release-notes/hypershell/v0-1-0.md +++ b/docs/release-notes/hypershell/v0-1-0.md @@ -92,6 +92,6 @@ through, among them [`hello`](/docs/projects/hypershell/examples/hello), --- -*An AI agent wrote this page from the release's source changes and the CGP knowledge base. Its -content was verified against the project's source at the release's tag. See +*This page was written by an AI agent from the release's source changes and the CGP knowledge base. +Its content was verified against the project's source at the release's tag. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/release-notes/hypershell/v0-2-0.md b/docs/release-notes/hypershell/v0-2-0.md index 297748f3..6729a07d 100644 --- a/docs/release-notes/hypershell/v0-2-0.md +++ b/docs/release-notes/hypershell/v0-2-0.md @@ -123,6 +123,6 @@ Introduced in [#5](https://github.com/contextgeneric/hypershell/pull/5). --- -*An AI agent wrote this page from the release's source changes and the CGP knowledge base. Its -content was verified against the project's source at the release's tag. See +*This page was written by an AI agent from the release's source changes and the CGP knowledge base. +Its content was verified against the project's source at the release's tag. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/release-notes/index.md b/docs/release-notes/index.md index fb5905c1..5ff92504 100644 --- a/docs/release-notes/index.md +++ b/docs/release-notes/index.md @@ -56,5 +56,5 @@ every change. Each links the other. --- -*An AI agent wrote this page using the CGP knowledge base. See +*This page was written by an AI agent from the CGP knowledge base. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/resources/community.md b/docs/resources/community.md index 19bd7d0b..7626de9c 100644 --- a/docs/resources/community.md +++ b/docs/resources/community.md @@ -41,5 +41,5 @@ from reporting a problem to publishing components of your own. --- -*An AI agent wrote this page using the CGP knowledge base. See +*This page was written by an AI agent from the CGP knowledge base. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/resources/index.md b/docs/resources/index.md index eeebcae4..f7e04974 100644 --- a/docs/resources/index.md +++ b/docs/resources/index.md @@ -40,5 +40,5 @@ you find here keep working as the section grows. --- -*An AI agent wrote this page using the CGP knowledge base. See +*This page was written by an AI agent from the CGP knowledge base. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/resources/videos.md b/docs/resources/videos.md index d50e7bde..7c31284f 100644 --- a/docs/resources/videos.md +++ b/docs/resources/videos.md @@ -25,5 +25,5 @@ the blog. --- -*An AI agent wrote this page using the CGP knowledge base. See +*This page was written by an AI agent from the CGP knowledge base. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/tooling/cargo-cgp/check.md b/docs/tooling/cargo-cgp/check.md index 842feb6c..cdbdb683 100644 --- a/docs/tooling/cargo-cgp/check.md +++ b/docs/tooling/cargo-cgp/check.md @@ -225,5 +225,6 @@ If the command itself will not run, see [Troubleshooting](./troubleshooting.md). --- -*An AI agent wrote this page using the CGP knowledge base, and its outputs were produced by running the -commands. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. The outputs it shows were +produced by running its commands. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/tooling/cargo-cgp/command-reference.md b/docs/tooling/cargo-cgp/command-reference.md index 4d650090..9aadd216 100644 --- a/docs/tooling/cargo-cgp/command-reference.md +++ b/docs/tooling/cargo-cgp/command-reference.md @@ -157,5 +157,6 @@ shows how to supply it. --- -*An AI agent wrote this page using the CGP knowledge base, and checked it against the tool's source. -See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. The agent also checked the page +against the tool's source. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/tooling/cargo-cgp/editor-integration.md b/docs/tooling/cargo-cgp/editor-integration.md index f6f7169f..83b11119 100644 --- a/docs/tooling/cargo-cgp/editor-integration.md +++ b/docs/tooling/cargo-cgp/editor-integration.md @@ -188,6 +188,6 @@ configuration formats, but those editors, macOS, and Windows have not been tried --- -*An AI agent wrote this page using the CGP knowledge base, and checked its setup against the -rust-analyzer language server. See +*This page was written by an AI agent from the CGP knowledge base. The agent also checked the page's +setup against the rust-analyzer language server. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/tooling/cargo-cgp/error-codes.md b/docs/tooling/cargo-cgp/error-codes.md index a3f26b3b..a72cef0a 100644 --- a/docs/tooling/cargo-cgp/error-codes.md +++ b/docs/tooling/cargo-cgp/error-codes.md @@ -872,5 +872,5 @@ tool left as the compiler wrote it: --- -*An AI agent wrote this page using the CGP knowledge base. See +*This page was written by an AI agent from the CGP knowledge base. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/tooling/cargo-cgp/expand.md b/docs/tooling/cargo-cgp/expand.md index c35692da..c4af9e97 100644 --- a/docs/tooling/cargo-cgp/expand.md +++ b/docs/tooling/cargo-cgp/expand.md @@ -257,5 +257,6 @@ to choose the target directory. --- -*An AI agent wrote this page using the CGP knowledge base, and its outputs were produced by running the -commands. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. The outputs it shows were +produced by running its commands. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/tooling/cargo-cgp/index.md b/docs/tooling/cargo-cgp/index.md index b67bb9ae..c0fe02c1 100644 --- a/docs/tooling/cargo-cgp/index.md +++ b/docs/tooling/cargo-cgp/index.md @@ -210,5 +210,6 @@ step by step. --- -*An AI agent wrote this page using the CGP knowledge base, and its outputs were produced by running the -commands. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. The outputs it shows were +produced by running its commands. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/tooling/cargo-cgp/installation.md b/docs/tooling/cargo-cgp/installation.md index 7960903e..cb4ad5e3 100644 --- a/docs/tooling/cargo-cgp/installation.md +++ b/docs/tooling/cargo-cgp/installation.md @@ -224,5 +224,5 @@ compiler-linked binary, and to mention Nix only when you use it. --- -*An AI agent wrote this page using the CGP knowledge base. See +*This page was written by an AI agent from the CGP knowledge base. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/tooling/cargo-cgp/reading-output.md b/docs/tooling/cargo-cgp/reading-output.md index 9eb1ceeb..1a205fb1 100644 --- a/docs/tooling/cargo-cgp/reading-output.md +++ b/docs/tooling/cargo-cgp/reading-output.md @@ -376,5 +376,6 @@ compiler's own message and works back to the mistake. --- -*An AI agent wrote this page using the CGP knowledge base, and its outputs were produced by running the -commands. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. The outputs it shows were +produced by running its commands. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/tooling/cargo-cgp/troubleshooting.md b/docs/tooling/cargo-cgp/troubleshooting.md index 75f1dd47..e340da82 100644 --- a/docs/tooling/cargo-cgp/troubleshooting.md +++ b/docs/tooling/cargo-cgp/troubleshooting.md @@ -324,5 +324,6 @@ Failures not covered here are worth reporting on the --- -*An AI agent wrote this page using the CGP knowledge base, and its messages were produced by running the -tool. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* +*This page was written by an AI agent from the CGP knowledge base. The messages it shows were +produced by running the tool. See +[How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/tooling/index.md b/docs/tooling/index.md index de1ec5f3..3f9fde2b 100644 --- a/docs/tooling/index.md +++ b/docs/tooling/index.md @@ -34,5 +34,5 @@ in the future. --- -*An AI agent wrote this page using the CGP knowledge base. See +*This page was written by an AI agent from the CGP knowledge base. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/tutorials/area-calculation/checking.md b/docs/tutorials/area-calculation/checking.md index a7c0f583..7567950b 100644 --- a/docs/tutorials/area-calculation/checking.md +++ b/docs/tutorials/area-calculation/checking.md @@ -245,6 +245,6 @@ context, gives its tests their own storage backend, and checks both wirings. --- -*An AI agent wrote this page using the CGP knowledge base. Its code and every diagnostic it quotes -were produced by compiling and running the program. See +*This page was written by an AI agent from the CGP knowledge base. Its code and every diagnostic it +quotes were produced by compiling and running the program. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/docs/tutorials/storage-backend.md b/docs/tutorials/storage-backend.md index 0975258f..554a34cf 100644 --- a/docs/tutorials/storage-backend.md +++ b/docs/tutorials/storage-backend.md @@ -405,6 +405,6 @@ go further: --- -*An AI agent wrote this page using the CGP knowledge base, and its examples were verified by +*This page was written by an AI agent from the CGP knowledge base. Its examples were verified by compiling them. See [How AI is used in this project](/docs/ai/disclaimer#documentation-and-reference-pages).* diff --git a/example-code-nightly/.gitignore b/example-code-nightly/.gitignore new file mode 100644 index 00000000..4fffb2f8 --- /dev/null +++ b/example-code-nightly/.gitignore @@ -0,0 +1,2 @@ +/target +/Cargo.lock diff --git a/example-code-nightly/Cargo.toml b/example-code-nightly/Cargo.toml new file mode 100644 index 00000000..2df614bd --- /dev/null +++ b/example-code-nightly/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "cgp-website-example-code-nightly" +version = "0.0.0" +edition = "2024" +publish = false +description = "Compiled counterparts of the site's snippets that need a nightly feature. Not part of the site." + +[dependencies] +# The `cgp` release the site documents, the same pin as `example-code`. +cgp = { version = "0.8.0", features = ["alloc"] } + +[dev-dependencies] +trybuild = "1.0.125" diff --git a/example-code-nightly/README.md b/example-code-nightly/README.md new file mode 100644 index 00000000..b5d3011b --- /dev/null +++ b/example-code-nightly/README.md @@ -0,0 +1,43 @@ +# Website example code on nightly + +This crate compiles the site's snippets that need an unstable Rust feature, on the nightly that +[`rust-toolchain.toml`](rust-toolchain.toml) pins. **It is not part of the website**, and it follows +every convention of the stable [`example-code`](../example-code/README.md) crate: one test binary per +section, one file per page, one module per heading, and compile-fail fixtures under +`tests/compile_fail/` with `.stderr` snapshots. + +Run it from this directory: + +```sh +cargo test # the full check, compile-fail snapshots included +cargo test --no-run # the fast check: everything compiles, nothing runs +``` + +CI runs the same suite with the compile-fail snapshots skipped +(`cargo test -- --skip rejected_snippets_do_not_compile`), in a job of its own beside the stable one. + +## What belongs here + +A snippet belongs here only when the page shows an unstable feature that the snippet needs. Everything +else stays in `example-code`, so the site's code is checked on stable wherever it can be. + +A feature attribute such as `#![feature(const_type_name)]` must sit at a crate root, so each test +binary's root file carries the features its modules need, where the page shows the attribute at the top +of its snippet. That difference is expected and not a defect. + +The crate covers these pages: + +| Page | Coverage | +|---|---| +| `blog/2026-11-29-incoherent-rust-today.md` | the four sections that use the `Name` component, whose `RealName` provider calls `core::any::type_name` in a constant and so needs `const_type_name`; `tests/blog/incoherent_rust_today.rs`, with the struct-binding type error as a compile-fail fixture | + +## The toolchain + +The pin is `nightly-2026-11-16`, the nightly `cargo-cgp` pins. The `.stderr` snapshots quote that +compiler's wording, so bump the pin and re-bless them in one change: + +```sh +TRYBUILD=overwrite cargo test --test compile_fail_tests +``` + +The `cgp` pin matches `example-code`'s and moves with it at each release. diff --git a/example-code-nightly/rust-toolchain.toml b/example-code-nightly/rust-toolchain.toml new file mode 100644 index 00000000..9726c3b6 --- /dev/null +++ b/example-code-nightly/rust-toolchain.toml @@ -0,0 +1,6 @@ +# The nightly these snippets need for their unstable features, the same nightly +# `cargo-cgp` pins. The `.stderr` snapshots quote this compiler's wording, so +# bump this file and re-bless them in one change. +[toolchain] +channel = "nightly-2026-11-16" +profile = "minimal" diff --git a/example-code-nightly/tests/blog/incoherent_rust_today.rs b/example-code-nightly/tests/blog/incoherent_rust_today.rs new file mode 100644 index 00000000..23d70286 --- /dev/null +++ b/example-code-nightly/tests/blog/incoherent_rust_today.rs @@ -0,0 +1,211 @@ +//! Compiled counterparts of the `Name` sections of `blog/2026-11-29-incoherent-rust-today.md`. +//! Modules follow the post's headings. The post's other CGP snippets are in `example-code`'s +//! `tests/blog/incoherent_rust_today.rs`; the struct-binding type error is a compile-fail fixture +//! under `tests/compile_fail/blog/`. +#![allow(dead_code, unused_variables)] + +mod using_incoherent_trait_bounds { + use cgp::prelude::*; + + #[cgp_component(NameImpl)] + pub trait Name { + const NAME: &'static str; + } + + #[cgp_impl(new DummyName)] + impl NameImpl { + const NAME: &'static str = "dummy"; + } + + #[cgp_impl(new RealName)] + impl NameImpl { + const NAME: &'static str = core::any::type_name::(); + } + + pub struct Foo(pub T); + + #[cgp_fn] + #[uses(Name)] + pub fn do_stuff(&self, foo: &Foo) { + println!("{}", Self::NAME); + } + + #[test] + fn each_context_names_the_type_its_own_way() { + let foo = Foo(1); + + { + struct Context; + + delegate_components! { + Context { + NameImplComponent: DummyName, + } + } + + // prints "dummy" + Context.do_stuff(&foo); + assert_eq!(>::NAME, "dummy"); + } + + { + struct Context; + + delegate_components! { + Context { + NameImplComponent: RealName, + } + } + + // prints "i32" + Context.do_stuff(&foo); + assert_eq!(>::NAME, "i32"); + } + } +} + +mod binding_an_implementation_to_a_struct { + use cgp::prelude::*; + use core::marker::PhantomData; + + // `Name`, `DummyName`, and `RealName` as the previous section defines them. + #[cgp_component(NameImpl)] + pub trait Name { + const NAME: &'static str; + } + + #[cgp_impl(new DummyName)] + impl NameImpl { + const NAME: &'static str = "dummy"; + } + + #[cgp_impl(new RealName)] + impl NameImpl { + const NAME: &'static str = core::any::type_name::(); + } + + pub struct Foo { + pub value: T, + pub phantom: PhantomData, + } + + #[cgp_fn] + #[uses(Name)] + pub fn do_stuff(&self, foo: &Foo) { + println!("{}", Self::NAME); + } + + pub struct ContextA; + + delegate_components! { + ContextA { + NameImplComponent: DummyName, + } + } + + pub struct ContextB; + + delegate_components! { + ContextB { + NameImplComponent: RealName, + } + } + + #[test] + fn the_struct_keeps_its_context() { + let foo: Foo = Foo { + value: 1, + phantom: PhantomData, + }; + + ContextA.do_stuff(&foo); + // `ContextB.do_stuff(&foo)` is the compile-fail fixture + // `tests/compile_fail/blog/incoherent_rust_today_struct_context.rs`. + } +} + +/// The same section's provider binding, the alternative to binding the whole context. +mod binding_an_implementation_to_a_struct_by_provider { + use cgp::prelude::*; + use core::marker::PhantomData; + + // `Name` and `RealName` as the earlier sections define them. + #[cgp_component(NameImpl)] + pub trait Name { + const NAME: &'static str; + } + + #[cgp_impl(new RealName)] + impl NameImpl { + const NAME: &'static str = core::any::type_name::(); + } + + pub struct Foo { + pub value: T, + pub phantom: PhantomData, + } + + #[cgp_fn] + #[use_provider(NameProvider: NameImpl)] + pub fn do_stuff(&self, foo: &Foo) { + println!("{}", NameProvider::NAME); + } + + #[test] + fn any_context_uses_the_struct_s_provider() { + pub struct ContextA; + pub struct ContextB; + + let foo: Foo = Foo { + value: 1, + phantom: PhantomData, + }; + + // Both contexts can call do_stuff on the same foo value, + // because the Name implementation is fixed by RealName, not by the context. + ContextA.do_stuff(&foo); + ContextB.do_stuff(&foo); + } +} + +mod incoherent_functions { + use cgp::prelude::*; + + // `Name` and `Foo` as the earlier sections define them. + #[cgp_component(NameImpl)] + pub trait Name { + const NAME: &'static str; + } + + #[cgp_impl(new DummyName)] + impl NameImpl { + const NAME: &'static str = "dummy"; + } + + pub struct Foo(pub T); + + #[cgp_fn] + #[uses(Name)] + pub fn do_stuff(&self, foo: &Foo) { + println!("{}", Self::NAME); + } + + #[cgp_fn] + #[uses(DoStuff)] + pub fn do_more_stuff(&self, foo: &Foo) { + self.do_stuff(foo); + } + + #[test] + fn the_caller_never_names_the_inner_bound() { + struct Context; + + delegate_components! { + Context { + NameImplComponent: DummyName, + } + } + + Context.do_more_stuff(&Foo(1)); + } +} diff --git a/example-code-nightly/tests/blog_tests.rs b/example-code-nightly/tests/blog_tests.rs new file mode 100644 index 00000000..c975884e --- /dev/null +++ b/example-code-nightly/tests/blog_tests.rs @@ -0,0 +1,7 @@ +//! Compiled counterparts of blog-post examples that need a nightly feature. +// The post's `Name` snippets open with this attribute; a module cannot carry it, so the +// test binary's root does. +#![feature(const_type_name)] + +#[path = "blog/incoherent_rust_today.rs"] +mod incoherent_rust_today; diff --git a/example-code-nightly/tests/compile_fail/blog/incoherent_rust_today_struct_context.rs b/example-code-nightly/tests/compile_fail/blog/incoherent_rust_today_struct_context.rs new file mode 100644 index 00000000..6b53ec58 --- /dev/null +++ b/example-code-nightly/tests/compile_fail/blog/incoherent_rust_today_struct_context.rs @@ -0,0 +1,59 @@ +// `blog/2026-11-29-incoherent-rust-today.md`, "Binding an implementation to a struct": +// a `Foo` built for `ContextA` cannot be passed to `ContextB`'s `do_stuff`. +#![feature(const_type_name)] +use cgp::prelude::*; +use core::marker::PhantomData; + +#[cgp_component(NameImpl)] +pub trait Name { + const NAME: &'static str; +} + +#[cgp_impl(new DummyName)] +impl NameImpl { + const NAME: &'static str = "dummy"; +} + +#[cgp_impl(new RealName)] +impl NameImpl { + const NAME: &'static str = core::any::type_name::(); +} + +pub struct Foo { + pub value: T, + pub phantom: PhantomData, +} + +#[cgp_fn] +#[uses(Name)] +pub fn do_stuff(&self, foo: &Foo) { + println!("{}", Self::NAME); +} + +struct ContextA; + +delegate_components! { + ContextA { + NameImplComponent: DummyName, + } +} + +struct ContextB; + +delegate_components! { + ContextB { + NameImplComponent: RealName, + } +} + +fn main() { + let foo: Foo = Foo { + value: 1, + phantom: PhantomData, + }; + + ContextA.do_stuff(&foo); + + // type error: foo has type Foo but ContextB expects Foo + ContextB.do_stuff(&foo); +} diff --git a/example-code-nightly/tests/compile_fail/blog/incoherent_rust_today_struct_context.stderr b/example-code-nightly/tests/compile_fail/blog/incoherent_rust_today_struct_context.stderr new file mode 100644 index 00000000..fc6db448 --- /dev/null +++ b/example-code-nightly/tests/compile_fail/blog/incoherent_rust_today_struct_context.stderr @@ -0,0 +1,25 @@ +error[E0308]: mismatched types + --> tests/compile_fail/blog/incoherent_rust_today_struct_context.rs:58:23 + | +58 | ContextB.do_stuff(&foo); + | -------- ^^^^ expected `&Foo`, found `&Foo` + | | + | arguments to this method are incorrect + | + = note: expected reference `&Foo` + found reference `&Foo` +note: method defined here + --> tests/compile_fail/blog/incoherent_rust_today_struct_context.rs:29:8 + | +27 | #[cgp_fn] +28 | #[uses(Name)] +29 | pub fn do_stuff(&self, foo: &Foo) { + | ^^^^^^^^ --- + +warning: unused variable: `foo` + --> tests/compile_fail/blog/incoherent_rust_today_struct_context.rs:29:27 + | +29 | pub fn do_stuff(&self, foo: &Foo) { + | ^^^ help: if this is intentional, prefix it with an underscore: `_foo` + | + = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default diff --git a/example-code-nightly/tests/compile_fail_tests.rs b/example-code-nightly/tests/compile_fail_tests.rs new file mode 100644 index 00000000..36e4ea7c --- /dev/null +++ b/example-code-nightly/tests/compile_fail_tests.rs @@ -0,0 +1,11 @@ +//! Compile-fail checks for the nightly snippets the pages deliberately reject. +//! +//! Each fixture under `tests/compile_fail/` is a complete program the compiler must refuse. +//! `trybuild` compiles each one and compares its output against the sibling `.stderr` file. +//! Re-bless after a toolchain or `cgp` bump with +//! `TRYBUILD=overwrite cargo test --test compile_fail_tests`. + +#[test] +fn rejected_snippets_do_not_compile() { + trybuild::TestCases::new().compile_fail("tests/compile_fail/**/*.rs"); +} diff --git a/example-code/Cargo.toml b/example-code/Cargo.toml index 4c2229cd..f096e58e 100644 --- a/example-code/Cargo.toml +++ b/example-code/Cargo.toml @@ -12,7 +12,12 @@ cgp = { version = "0.8.0", features = ["alloc"] } [dev-dependencies] anyhow = "1.0.104" cap-std = "3.4.6" +cgp-error-anyhow = "0.8.0" +cgp-serde = "0.3.0" +cgp-serde-json = "0.3.0" futures = "0.3.34" +hypershell = "0.2.0" serde = { version = "1.0.229", features = ["derive"] } tokio = { version = "1.54.1", features = ["fs", "macros", "rt-multi-thread"] } trybuild = "1.0.125" +typed-arena = "2.0.2" diff --git a/example-code/README.md b/example-code/README.md index 116caaf8..13263740 100644 --- a/example-code/README.md +++ b/example-code/README.md @@ -47,6 +47,7 @@ One file per page, at the matching path with the file name in `snake_case`: | `docs/tutorials/` | partial — `area-calculation/checking.md`, whose three quoted diagnostics are the reason it is mirrored, and `storage-backend.md`, one module per step assembled from the page's blocks, with its deliberate mistake at `tests/compile_fail/tutorials/`; the rest is filled in lazily | | `docs/quickstart.md` | complete — `tests/quickstart.rs`, a standalone binary rather than a section tree | | `blog/2026-11-18-v0.8.0-release.md` | complete — `tests/blog/v0_8_0_release.rs` checks each wiring stage, the default-binding alternatives, and the migrated configuration; the deliberate missing-field error is a compile-fail fixture | +| `blog/2026-11-29-incoherent-rust-today.md` | complete for the CGP code the post keeps — `tests/blog/incoherent_rust_today.rs` checks each desugaring by heading, the arena deserializer against `cgp-serde`, and the Hypershell program against `hypershell`; the four sections that use the `Name` component need nightly's `const_type_name`, so they and the struct-binding type error are in [`example-code-nightly`](../example-code-nightly/README.md); the Cairo translation moves to a comparison page | | front page (`src/pages/index.tsx`) | complete — `tests/front_page.rs`, a standalone binary for the hero's CGP block, with the hero's rejected block at `tests/compile_fail/front_page/`; the text between each `front-page:` marker pair is exactly what the page shows, the rejected block starts at its fixture's first line so the page's quoted `E0119` names the lines the page numbers, and a test compares that quote with the fixture's snapshot | | `docs/overview.md` | complete — `tests/overview.rs`, a standalone binary with one module per key feature and stand-ins for the storage clients and the database pool the page names; the type-safe-wiring section's missing-field program is at `tests/compile_fail/overview/` | | remaining orientation pages | none yet | @@ -84,6 +85,13 @@ a wiring line, a provider name, an item that exists on one side and not the othe disagree, find out which is wrong rather than assuming: the crate is checked by the compiler and the page is not, so the page is the likelier culprit, but a stale file here is worse than no file. +## Nightly-only snippets + +A snippet that uses an unstable Rust feature cannot compile here, since this crate builds on the pinned +stable release. It lives in the sibling [`example-code-nightly`](../example-code-nightly/README.md) +crate instead, which follows the same conventions on a pinned nightly and runs in a CI job of its own. +Only a snippet the page shows with its feature attribute belongs there. + ## Code a page deliberately rejects Several pages show code the compiler refuses, quoting the error as the point of the snippet. That code diff --git a/example-code/tests/blog/incoherent_rust_today.rs b/example-code/tests/blog/incoherent_rust_today.rs new file mode 100644 index 00000000..d141c0d4 --- /dev/null +++ b/example-code/tests/blog/incoherent_rust_today.rs @@ -0,0 +1,494 @@ +//! Compiled counterparts of `blog/2026-11-29-incoherent-rust-today.md`, the incoherent-Rust post. +//! Modules follow the post's headings. Snippets written in Incoherent Rust or TIR syntax are +//! pseudocode and have no counterpart. The sections that use the `Name` component need nightly's +//! `const_type_name` feature, so they and the struct-binding type error are in +//! `example-code-nightly`. +#![allow(dead_code, unused_variables)] + +mod bypassing_coherence { + /// The first level: `Serialize` keeps the value as `Self`, and `Person` is its own context. + pub mod overlapping { + use cgp::prelude::*; + use core::fmt::{Display, Error, Formatter}; + use serde::Serializer; + + #[cgp_component(SerializeImpl)] + pub trait Serialize { + fn serialize(&self, serializer: S) -> Result; + } + + #[cgp_impl(new SerializeWithDisplay)] + #[uses(Display)] + impl SerializeImpl { + fn serialize(&self, serializer: S) -> Result { + // serde's own `Serialize`, implemented by `String` + serde::Serialize::serialize(&self.to_string(), serializer) + } + } + + pub struct Person { + pub first_name: String, + pub last_name: String, + } + + impl Display for Person { + fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { + write!(f, "{} {}", self.first_name, self.last_name) + } + } + + delegate_components! { + Person { + SerializeImplComponent: SerializeWithDisplay, + } + } + + check_components! { + Person { + SerializeImplComponent, + } + } + } + + /// The second level: the fully incoherent `Serialize`, wired on a separate context. + pub mod orphan { + use super::overlapping::Person; + use cgp::prelude::*; + use core::fmt::Display; + use serde::Serializer; + + #[cgp_component(SerializeImpl)] + pub trait Serialize { + fn serialize( + &self, + value: &T, + serializer: S, + ) -> Result; + } + + #[cgp_impl(new SerializeWithDisplay)] + impl SerializeImpl { + fn serialize( + &self, + value: &T, + serializer: S, + ) -> Result { + serde::Serialize::serialize(&value.to_string(), serializer) + } + } + + // inside a third party crate + pub struct MyApp; + + delegate_components! { + MyApp { + open SerializeImplComponent; + + @SerializeImplComponent.Person: SerializeWithDisplay, + } + } + + check_components! { + MyApp { + SerializeImplComponent: Person, + } + } + } +} + +mod incoherent_traits_and_named_impls { + // One module covers "Incoherent traits" and "Named impls", which build one program. + // The post places these items in four crates; modules stand in for them. + pub mod a { + use cgp::prelude::*; + + // A revised `Serialize`, following the simpler signature of Boxy's example + #[cgp_component(SerializeImpl)] + pub trait Serialize { + fn serialize(&self, value: &T) -> String; + } + } + + pub mod b { + pub struct Matrix(pub Vec>); + } + + pub mod c { + use super::{a, b}; + use cgp::prelude::*; + + #[cgp_impl(new CSerialize)] + impl a::SerializeImpl { + fn serialize(&self, value: &b::Matrix) -> String { + // The post elides this body. + format!("{:?}", value.0) + } + } + } + + pub mod d { + use super::{a, b}; + use cgp::prelude::*; + + #[cgp_impl(new DSerialize)] + impl a::SerializeImpl { + fn serialize(&self, value: &b::Matrix) -> String { + // The post elides this body. + format!("{} rows", value.0.len()) + } + } + } +} + +mod context_and_capabilities { + use cgp::core::error::{ErrorRaiserComponent, ErrorTypeProviderComponent}; + use cgp::prelude::*; + use cgp_error_anyhow::{RaiseAnyhowError, UseAnyhowError}; + use cgp_serde::components::{CanDeserializeValue, ValueDeserializer, ValueDeserializerComponent}; + use cgp_serde::providers::{DeserializeExtend, DeserializeRecordFields, UseSerde}; + use cgp_serde_json::impls::CanDeserializeJsonString; + use typed_arena::Arena; + + #[derive(Debug, PartialEq, CgpData)] + pub struct Foo { + pub id: u64, + } + + #[cgp_impl(new DeserializeFooRef)] + #[uses(CanDeserializeValue<'de, Foo>)] + impl<'de, 'a> ValueDeserializer<'de, &'a Foo> { + fn deserialize( + &self, + #[implicit] arena: &&'a Arena, + deserializer: D, + ) -> Result<&'a Foo, D::Error> + where + D: serde::Deserializer<'de>, + { + let foo = self.deserialize(deserializer)?; + Ok(arena.alloc(foo)) + } + } + + #[derive(HasField)] + pub struct Context<'a> { + pub arena: &'a Arena, + } + + delegate_components! { + <'a> Context<'a> { + open ValueDeserializerComponent; + + ErrorTypeProviderComponent: + UseAnyhowError, + ErrorRaiserComponent: + RaiseAnyhowError, + @ValueDeserializerComponent.u64: + UseSerde, + @ValueDeserializerComponent.Foo: + DeserializeRecordFields, + @ValueDeserializerComponent.<'b> &'b Foo: + DeserializeFooRef, + @ValueDeserializerComponent.<'b> Vec<&'b Foo>: + DeserializeExtend, + } + } + + #[test] + fn the_context_allocates_into_its_arena() -> Result<(), anyhow::Error> { + let arena = Arena::new(); + let context = Context { arena: &arena }; + + let foos: Vec<&Foo> = context.deserialize_json_string(r#"[{"id": 1}, {"id": 2}]"#)?; + + assert_eq!(foos, vec![&Foo { id: 1 }, &Foo { id: 2 }]); + Ok(()) + } +} + +mod context_aware_dictionaries { + use cgp::prelude::*; + + #[cgp_component(CloneImpl)] + trait Clone { + fn clone(&self, value: &T) -> T; + } + + #[cgp_impl(new CloneU32)] + impl CloneImpl { + fn clone(&self, value: &u32) -> u32 { + // The post elides this body. + *value + } + } + + #[cgp_impl(new CloneVec)] + #[uses(Clone)] + impl CloneImpl> { + fn clone(&self, values: &Vec) -> Vec { + values.iter().map(|value| self.clone(value)).collect() + } + } + + #[test] + fn the_context_clones_a_vec() { + struct Context; + + delegate_components! { + Context { + open CloneImplComponent; + + @CloneImplComponent.u32: CloneU32, + @CloneImplComponent.Vec: CloneVec, + } + } + + check_components! { + Context { + CloneImplComponent: [u32, Vec], + } + } + + let my_vec: Vec = vec![0, 1, 2]; + let cloned_vec = Context.clone(&my_vec); + + assert_eq!(cloned_vec, my_vec); + } +} + +mod multiple_implementations_on_the_same_name { + use cgp::prelude::*; + + pub struct Matrix; + + // The two components as the post's earlier sections define them, reduced to strings. + #[cgp_component(SerializeImpl)] + pub trait Serialize { + fn serialize(&self, value: &T) -> String; + } + + #[cgp_component(DeserializeImpl)] + pub trait Deserialize { + fn deserialize(&self, serialized: &str) -> T; + } + + // A provider is just a struct + pub struct MyMatrixSerde; + + #[cgp_impl(MyMatrixSerde)] + impl SerializeImpl { + fn serialize(&self, value: &Matrix) -> String { + // The post elides this body. + "matrix".to_owned() + } + } + + #[cgp_impl(MyMatrixSerde)] + impl DeserializeImpl { + fn deserialize(&self, serialized: &str) -> Matrix { + // The post elides this body. + Matrix + } + } +} + +mod contexts_as_explicit_types { + use cgp::prelude::*; + + // Stand-ins for the clients, domain types, and operation the post names without defining. + pub struct Database; + pub struct S3Client; + pub struct RedisClient; + pub struct UserId(pub u64); + pub struct User; + #[derive(Debug)] + pub struct Error; + pub struct Config; + + #[cgp_component(UserQuerier)] + pub trait CanQueryUser { + fn query_user(&self, user_id: &UserId) -> Result; + } + + #[cgp_impl(new QueryUserWithDatabase)] + impl UserQuerier { + fn query_user(&self, #[implicit] database: &Database, user_id: &UserId) -> Result { + // The post elides this body. + Ok(User) + } + } + + #[cgp_impl(new CachedQueryUser)] + #[use_provider(InnerQuerier: UserQuerier)] + impl UserQuerier { + fn query_user(&self, #[implicit] redis_cache: &RedisClient, user_id: &UserId) -> Result { + // The post elides this body: a cache lookup before the inner query. + InnerQuerier::query_user(self, user_id) + } + } + + #[derive(HasField)] + pub struct App { + // Runtime values accessible by providers + pub database: Database, + pub s3_client: S3Client, + pub redis_cache: RedisClient, + } + + delegate_components! { + App { + // Use higher-order provider to provide caching middlewares + UserQuerierComponent: + CachedQueryUser, + } + } + + check_components! { + App { + UserQuerierComponent, + } + } + + // App is used in the return type + pub async fn build_app_from_config(config: &Config) -> Result { + // The post elides this body. + Ok(App { + database: Database, + s3_client: S3Client, + redis_cache: RedisClient, + }) + } +} + +mod selfless_traits { + use cgp::prelude::*; + + #[cgp_component(GreetImpl)] + pub trait Greet { + fn greet(&self); + } + + #[cgp_impl(new GreetHello)] + impl GreetImpl { + fn greet(&self, #[implicit] name: &String) { + println!("Hello, {}!", name); + } + } + + // A context for the provider, which the post leaves out. + #[derive(HasField)] + pub struct Context { + pub name: String, + } + + delegate_components! { + Context { + GreetImplComponent: GreetHello, + } + } + + check_components! { + Context { + GreetImplComponent, + } + } +} + +mod abstract_types { + use cgp::prelude::*; + use core::fmt::Display; + + // `Greet` as the previous section defines it. + #[cgp_component(GreetImpl)] + pub trait Greet { + fn greet(&self); + } + + #[cgp_type] + pub trait HasNameType { + type Name: Display; + } + + #[cgp_impl(new GreetHello)] + #[use_type(HasNameType.Name)] + impl GreetImpl { + fn greet(&self, #[implicit] name: &Name) { + println!("Hello, {}!", name); + } + } +} + +mod using_abstract_types_across_incoherent_traits { + use cgp::prelude::*; + + #[cgp_type] + pub trait HasTimeType { + type Time; + } + + #[cgp_component(CurrentTimeImpl)] + #[use_type(HasTimeType.Time)] + pub trait CurrentTime { + fn current_time(&self) -> Time; + } + + #[cgp_component(UpdateLastModifiedImpl)] + #[use_type(HasTimeType.Time)] + pub trait UpdateLastModified { + fn update_last_modified(value: &mut T, time: Time); + } + + #[cgp_fn] + #[uses(CurrentTime, UpdateLastModified)] + pub fn touch(&self, value: &mut T) { + let time = self.current_time(); + Self::update_last_modified(value, time); + } + + // A context the post leaves out: a fixed clock and a file whose time it updates. + pub struct File { + pub last_modified: u64, + } + + #[cgp_impl(new FixedClock)] + #[use_type(HasTimeType.{Time = u64})] + impl CurrentTimeImpl { + fn current_time(&self) -> u64 { + 42 + } + } + + #[cgp_impl(new UpdateFile)] + #[use_type(HasTimeType.{Time = u64})] + impl UpdateLastModifiedImpl { + fn update_last_modified(value: &mut File, time: u64) { + value.last_modified = time; + } + } + + pub struct App; + + delegate_components! { + App { + open UpdateLastModifiedImplComponent; + + TimeTypeProviderComponent: UseType, + CurrentTimeImplComponent: FixedClock, + @UpdateLastModifiedImplComponent.File: UpdateFile, + } + } + + check_components! { + App { + CurrentTimeImplComponent, + UpdateLastModifiedImplComponent: File, + } + } + + #[test] + fn touch_sets_the_context_s_time() { + let mut file = File { last_modified: 0 }; + App.touch(&mut file); + assert_eq!(file.last_modified, 42); + } +} diff --git a/example-code/tests/blog_tests.rs b/example-code/tests/blog_tests.rs index 59fcb2d0..bf90594c 100644 --- a/example-code/tests/blog_tests.rs +++ b/example-code/tests/blog_tests.rs @@ -2,6 +2,9 @@ #[path = "blog/v0_8_0_release.rs"] mod v0_8_0_release; +#[path = "blog/incoherent_rust_today.rs"] +mod incoherent_rust_today; + #[test] fn missing_height_is_rejected() { trybuild::TestCases::new().compile_fail("tests/compile_fail/blog/v0_8_0_missing_height.rs"); diff --git a/example-code/tests/comparisons/dynamic_dispatch.rs b/example-code/tests/comparisons/dynamic_dispatch.rs index 203044df..efa242e9 100644 --- a/example-code/tests/comparisons/dynamic_dispatch.rs +++ b/example-code/tests/comparisons/dynamic_dispatch.rs @@ -1,211 +1,266 @@ //! Code from `docs/comparisons/dynamic-dispatch.md` — *Dynamic dispatch, dynamic typing, and //! prototypal inheritance*. +//! +//! The page's foreign snippets (JavaScript, Python, Java, Go) were run separately against the +//! toolchains its Sources name; this file holds the Rust and CGP code. -/// ## Calls on a generic receiver -pub mod calls_on_a_generic_receiver { - use cgp::prelude::*; - - #[cgp_auto_getter] - pub trait HasName { - fn name(&self) -> &str; - } - - #[cgp_component(Greeter)] +/// ## Method tables +pub mod method_tables { pub trait CanGreet { fn greet(&self) -> String; } - #[cgp_impl(new GreetHello)] - #[uses(HasName)] - impl Greeter { - fn greet(&self) -> String { - format!("Hello, {}!", self.name()) - } + pub struct Person { + pub name: String, } - #[cgp_fn] - pub fn greet_implicitly(&self, #[implicit] name: &str) -> String { - format!("Hello, {name}!") + pub struct FormalPerson { + pub salutation: String, + pub last_name: String, } - #[derive(HasField)] - pub struct Person { - pub name: String, + impl CanGreet for Person { + fn greet(&self) -> String { + format!("Hello, {}!", self.name) + } } - delegate_components! { Person { GreeterComponent: GreetHello } } - - mod check_person { - use super::*; - check_components! { Person { GreeterComponent } } + impl CanGreet for FormalPerson { + fn greet(&self) -> String { + format!("Good day, {} {}.", self.salutation, self.last_name) + } } #[test] - fn the_context_responds_to_the_message() { - let person = Person { - name: "Ada".to_owned(), + fn each_value_calls_through_its_vtable() { + let person: &dyn CanGreet = &Person { name: "Ada".into() }; + let formal_person: &dyn CanGreet = &FormalPerson { + salutation: "Dr.".into(), + last_name: "Lovelace".into(), }; + assert_eq!(person.greet(), "Hello, Ada!"); - assert_eq!(person.greet_implicitly(), "Hello, Ada!"); + assert_eq!(formal_person.greet(), "Good day, Dr. Lovelace."); + assert_eq!(size_of::<&dyn CanGreet>(), 2 * size_of::()); } } -/// ## Wiring as a vtable -/// ## Delegation and the original context -pub mod wiring_as_a_vtable { +/// ## Calls on a generic receiver +/// ## A table on the context +/// +/// One program: the component and its providers, then the contexts that wire them. +/// +/// Rejected snippets — trybuild fixtures +/// `tests/compile_fail/comparisons/dynamic_dispatch_a_table_on_the_context_1.rs` (the wrong greeter) +/// and `_2.rs` (the missing entry). +pub mod a_table_on_the_context { use cgp::prelude::*; - #[cgp_component(AreaCalculator)] - pub trait CanCalculateArea { - fn area(&self) -> f64; + #[cgp_component(Greeter)] + pub trait CanGreet { + fn greet(&self) -> String; } - #[cgp_component(PerimeterCalculator)] - pub trait CanCalculatePerimeter { - fn perimeter(&self) -> f64; + #[cgp_impl(new GreetHello)] + impl Greeter { + fn greet(&self, #[implicit] name: &str) -> String { + format!("Hello, {name}!") + } } - #[cgp_impl(new RectangleArea)] - impl AreaCalculator { - fn area(&self, #[implicit] width: f64, #[implicit] height: f64) -> f64 { - width * height + #[cgp_impl(new GreetFormally)] + impl Greeter { + fn greet(&self, #[implicit] salutation: &str, #[implicit] last_name: &str) -> String { + format!("Good day, {salutation} {last_name}.") } } - #[cgp_impl(new RectanglePerimeter)] - impl PerimeterCalculator { - fn perimeter(&self, #[implicit] width: f64, #[implicit] height: f64) -> f64 { - 2.0 * (width + height) - } + #[derive(HasField)] + pub struct Person { + pub name: String, } - delegate_components! { - new GeometryComponents { - AreaCalculatorComponent: RectangleArea, - PerimeterCalculatorComponent: RectanglePerimeter, - } + #[derive(HasField)] + pub struct PersonWithAge { + pub name: String, + pub age: u8, } #[derive(HasField)] - pub struct Rectangle { - pub width: f64, - pub height: f64, + pub struct FormalPerson { + pub salutation: String, + pub last_name: String, } - delegate_components! { - Rectangle { - [AreaCalculatorComponent, PerimeterCalculatorComponent]: GeometryComponents, - } + #[derive(HasField)] + pub struct FormalPersonWithEmail { + pub salutation: String, + pub last_name: String, + pub email: String, + } + + #[derive(HasField)] + pub struct Member { + pub name: String, + pub salutation: String, + pub last_name: String, } - mod check_rectangle { + delegate_components! { Person { GreeterComponent: GreetHello } } + delegate_components! { PersonWithAge { GreeterComponent: GreetHello } } + delegate_components! { FormalPerson { GreeterComponent: GreetFormally } } + delegate_components! { FormalPersonWithEmail { GreeterComponent: GreetFormally } } + delegate_components! { Member { GreeterComponent: GreetFormally } } // either would do + + check_components! { Person { GreeterComponent } } + check_components! { PersonWithAge { GreeterComponent } } + check_components! { FormalPerson { GreeterComponent } } + check_components! { FormalPersonWithEmail { GreeterComponent } } + check_components! { Member { GreeterComponent } } + + // Not on the page: `Member` has the fields for both providers, which the page's "either would + // do" claims. + mod check_member_suits_both { use super::*; check_components! { - Rectangle { - AreaCalculatorComponent, - PerimeterCalculatorComponent, - } + #[check_providers(GreetHello, GreetFormally)] + Member { GreeterComponent } } } #[test] - fn self_stays_bound_to_the_original_receiver() { - let rectangle = Rectangle { - width: 3.0, - height: 4.0, + fn each_context_greets_through_its_entry() { + let person = Person { + name: "Ada".to_owned(), + }; + let formal = FormalPerson { + salutation: "Dr.".to_owned(), + last_name: "Lovelace".to_owned(), + }; + + assert_eq!(person.greet(), "Hello, Ada!"); + assert_eq!(formal.greet(), "Good day, Dr. Lovelace."); + + // The extra fields do not matter. + let with_age = PersonWithAge { + name: "Bob".to_owned(), + age: 30, }; - // `RectangleArea` reads `width` and `height` from `Rectangle`, not from the bundle. - assert_eq!(rectangle.area(), 12.0); - assert_eq!(rectangle.perimeter(), 14.0); + let with_email = FormalPersonWithEmail { + salutation: "Mr.".to_owned(), + last_name: "Babbage".to_owned(), + email: "cb@example.com".to_owned(), + }; + assert_eq!(with_age.greet(), "Hello, Bob!"); + assert_eq!(with_email.greet(), "Good day, Mr. Babbage."); + + // `Member`'s table chose the formal greeter. + let member = Member { + name: "Eve".to_owned(), + salutation: "Ms.".to_owned(), + last_name: "Moore".to_owned(), + }; + assert_eq!(member.greet(), "Good day, Ms. Moore."); } } -/// ## Namespaces and inheritance -pub mod namespaces_and_inheritance { +/// ## A chain walked by the compiler +pub mod a_chain_walked_by_the_compiler { use cgp::prelude::*; - cgp_namespace! { new AppNamespace {} } - #[cgp_component(Greeter)] - #[prefix(@app.GreeterComponent in AppNamespace)] pub trait CanGreet { fn greet(&self) -> String; } - #[cgp_component(Farewell)] - #[prefix(@app.FarewellComponent in AppNamespace)] - pub trait CanSayGoodbye { - fn goodbye(&self) -> String; - } - #[cgp_impl(new GreetHello)] impl Greeter { - fn greet(&self) -> String { - "Hello!".to_owned() + fn greet(&self, #[implicit] name: &str) -> String { + format!("Hello, {name}!") } } - #[cgp_impl(new GreetQuietly)] - impl Greeter { - fn greet(&self) -> String { - "hello".to_owned() + delegate_components! { + new PersonPrototype { + GreeterComponent: GreetHello, } } - #[cgp_impl(new SayGoodbye)] - impl Farewell { - fn goodbye(&self) -> String { - "Goodbye!".to_owned() - } + #[derive(HasField)] + pub struct Person { + pub name: String, } - // The shared prototype: it binds the farewell and leaves the greeting path open. - cgp_namespace! { - new AppDefaults: AppNamespace { - @app.FarewellComponent: SayGoodbye, + delegate_components! { + Person { + GreeterComponent: PersonPrototype, } } - pub struct AppA; + check_components! { Person { GreeterComponent } } - delegate_components! { - AppA { - namespace AppDefaults; // inherit every wiring the namespace binds + #[test] + fn the_prototype_answers_with_the_context() { + let person = Person { + name: "Ada".to_owned(), + }; + // `GreetHello` reads `name` from `Person`, not from `PersonPrototype`. + assert_eq!(person.greet(), "Hello, Ada!"); + } +} - @app.GreeterComponent: GreetHello, // fill a slot the namespace leaves open - } +/// ## Runtime values inside a context +pub mod runtime_values_inside_a_context { + use cgp::prelude::*; + + #[cgp_component(Greeter)] + pub trait CanGreet { + fn greet(&self) -> String; } - // A child namespace may bind an open path; it may not redefine a bound one. - cgp_namespace! { - new QuietDefaults: AppDefaults { - @app.GreeterComponent: GreetQuietly, + #[cgp_impl(new GreetHello)] + impl Greeter { + fn greet(&self, #[implicit] name: &str) -> String { + format!("Hello, {name}!") } } - pub struct AppB; - - delegate_components! { - AppB { - namespace QuietDefaults; + #[cgp_impl(new GreetFormally)] + impl Greeter { + fn greet(&self, #[implicit] salutation: &str, #[implicit] last_name: &str) -> String { + format!("Good day, {salutation} {last_name}.") } } - mod check_app_a { - use super::*; - check_components! { AppA { GreeterComponent, FarewellComponent } } + #[derive(HasField)] + pub struct Person { + pub name: String, } - mod check_app_b { - use super::*; - check_components! { AppB { GreeterComponent, FarewellComponent } } + #[derive(HasField)] + pub struct FormalPerson { + pub salutation: String, + pub last_name: String, } + delegate_components! { Person { GreeterComponent: GreetHello } } + delegate_components! { FormalPerson { GreeterComponent: GreetFormally } } + + check_components! { Person { GreeterComponent } } + check_components! { FormalPerson { GreeterComponent } } + #[test] - fn the_chain_is_walked_by_the_type_checker() { - assert_eq!(AppA.greet(), "Hello!"); - assert_eq!(AppA.goodbye(), "Goodbye!"); - assert_eq!(AppB.greet(), "hello"); - assert_eq!(AppB.goodbye(), "Goodbye!"); + fn a_consumer_trait_is_a_trait_object_over_contexts() { + let contexts: Vec> = vec![ + Box::new(Person { + name: "Ada".to_owned(), + }), + Box::new(FormalPerson { + salutation: "Dr.".to_owned(), + last_name: "Lovelace".to_owned(), + }), + ]; + let greetings: Vec = contexts.iter().map(|context| context.greet()).collect(); + assert_eq!(greetings, ["Hello, Ada!", "Good day, Dr. Lovelace."]); } } diff --git a/example-code/tests/comparisons/mod.rs b/example-code/tests/comparisons/mod.rs index 24fc130a..2d54e070 100644 --- a/example-code/tests/comparisons/mod.rs +++ b/example-code/tests/comparisons/mod.rs @@ -14,4 +14,5 @@ pub mod policy_based_design; pub mod reflection; pub mod row_polymorphism; pub mod rust_language_proposals; +pub mod traits_without_coherence; pub mod type_classes; diff --git a/example-code/tests/comparisons/traits_without_coherence.rs b/example-code/tests/comparisons/traits_without_coherence.rs new file mode 100644 index 00000000..074c3a3d --- /dev/null +++ b/example-code/tests/comparisons/traits_without_coherence.rs @@ -0,0 +1,132 @@ +//! Code from `docs/comparisons/traits-without-coherence.md` — *Traits without coherence*. +//! +//! Only the CGP side is checked here; the Cairo snippet was run with Cairo 2.21.0, and the Haskell, +//! Scala, and OCaml snippets come from the pages that name their toolchains. + +/// ## Assembling the chain at the call +pub mod assembling_the_chain_at_the_call { + use cgp::prelude::*; + + #[cgp_component(ValueSerializer)] + pub trait CanSerializeValue { + fn serialize(&self, value: &T, output: &mut Vec); + } + + #[cgp_impl(new VecSerdeWith)] + #[use_provider(Inner: ValueSerializer)] + impl ValueSerializer> { + fn serialize(&self, value: &Vec, output: &mut Vec) { + output.push(value.len() as u64); + for item in value { + Inner::serialize(self, item, output); + } + } + } + + #[cgp_impl(new PairSerdeWith)] + #[use_provider(SA: ValueSerializer)] + #[use_provider(SB: ValueSerializer)] + impl ValueSerializer<(A, B)> { + fn serialize(&self, (a, b): &(A, B), output: &mut Vec) { + SA::serialize(self, a, output); + SB::serialize(self, b, output); + } + } + + #[cgp_impl(new U8Serde)] + impl ValueSerializer { + fn serialize(&self, value: &u8, output: &mut Vec) { + output.push(*value as u64); + } + } + + #[cgp_impl(new BoolSerde)] + impl ValueSerializer { + fn serialize(&self, value: &bool, output: &mut Vec) { + output.push(*value as u64); + } + } + + pub struct App; + + #[test] + fn the_caller_assembles_the_chain() { + let value = vec![(1u8, false), (2, true)]; + let mut output = Vec::new(); + > as ValueSerializer>>::serialize( + &App, &value, &mut output, + ); + assert_eq!(output, vec![2, 1, 0, 2, 1]); + } +} + +/// ## Fixing the choice on the context +pub mod fixing_the_choice_on_the_context { + use cgp::prelude::*; + + #[cgp_component(ValueSerializer)] + pub trait CanSerializeValue { + fn serialize(&self, value: &T, output: &mut Vec); + } + + #[cgp_impl(new VecSerde)] + #[uses(CanSerializeValue)] + impl ValueSerializer> { + fn serialize(&self, value: &Vec, output: &mut Vec) { + output.push(value.len() as u64); + for item in value { + self.serialize(item, output); + } + } + } + + #[cgp_impl(new PairSerde)] + #[uses(CanSerializeValue, CanSerializeValue)] + impl ValueSerializer<(A, B)> { + fn serialize(&self, (a, b): &(A, B), output: &mut Vec) { + self.serialize(a, output); + self.serialize(b, output); + } + } + + #[cgp_impl(new U8Serde)] + impl ValueSerializer { + fn serialize(&self, value: &u8, output: &mut Vec) { + output.push(*value as u64); + } + } + + #[cgp_impl(new BoolSerde)] + impl ValueSerializer { + fn serialize(&self, value: &bool, output: &mut Vec) { + output.push(*value as u64); + } + } + + pub struct App; + + delegate_components! { + App { + open ValueSerializerComponent; + + @ValueSerializerComponent. Vec: VecSerde, + @ValueSerializerComponent. (A, B): PairSerde, + @ValueSerializerComponent.u8: U8Serde, + @ValueSerializerComponent.bool: BoolSerde, + } + } + + check_components! { + App { + ValueSerializerComponent: Vec<(u8, bool)>, + } + } + + #[test] + fn the_context_fixes_the_chain() { + let value = vec![(1u8, false), (2, true)]; + let mut output = Vec::new(); + App.serialize(&value, &mut output); + assert_eq!(output, vec![2, 1, 0, 2, 1]); + } +} diff --git a/example-code/tests/compile_fail/comparisons/dynamic_dispatch_a_table_on_the_context_1.rs b/example-code/tests/compile_fail/comparisons/dynamic_dispatch_a_table_on_the_context_1.rs new file mode 100644 index 00000000..39b9fea7 --- /dev/null +++ b/example-code/tests/compile_fail/comparisons/dynamic_dispatch_a_table_on_the_context_1.rs @@ -0,0 +1,30 @@ +use cgp::prelude::*; + +#[cgp_component(Greeter)] +pub trait CanGreet { + fn greet(&self) -> String; +} + +#[cgp_impl(new GreetHello)] +impl Greeter { + fn greet(&self, #[implicit] name: &str) -> String { + format!("Hello, {name}!") + } +} + +#[cgp_impl(new GreetFormally)] +impl Greeter { + fn greet(&self, #[implicit] salutation: &str, #[implicit] last_name: &str) -> String { + format!("Good day, {salutation} {last_name}.") + } +} + +#[derive(HasField)] +pub struct Person { pub name: String } + +delegate_components! { Person { GreeterComponent: GreetFormally } } + +// error[E0277]: the trait bound `Person: CanUseComponent` is not satisfied +check_components! { Person { GreeterComponent } } + +fn main() {} diff --git a/example-code/tests/compile_fail/comparisons/dynamic_dispatch_a_table_on_the_context_1.stderr b/example-code/tests/compile_fail/comparisons/dynamic_dispatch_a_table_on_the_context_1.stderr new file mode 100644 index 00000000..2919b0f9 --- /dev/null +++ b/example-code/tests/compile_fail/comparisons/dynamic_dispatch_a_table_on_the_context_1.stderr @@ -0,0 +1,24 @@ +error[E0277]: the trait bound `Person: CanUseComponent` is not satisfied + --> tests/compile_fail/comparisons/dynamic_dispatch_a_table_on_the_context_1.rs:28:30 + | +28 | check_components! { Person { GreeterComponent } } + | ^^^^^^^^^^^^^^^^ unsatisfied trait bound + | +help: the trait `HasField>>>>>>>>>>>` is not implemented for `Person` + but trait `HasField>>>>>` is implemented for it + --> tests/compile_fail/comparisons/dynamic_dispatch_a_table_on_the_context_1.rs:23:25 + | +23 | pub struct Person { pub name: String } + | ^^^^ +note: required for `GreetFormally` to implement `IsProviderFor` + --> tests/compile_fail/comparisons/dynamic_dispatch_a_table_on_the_context_1.rs:15:1 + | +15 | #[cgp_impl(new GreetFormally)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: required for `Person` to implement `CanUseComponent` +note: required by a bound in `__CheckPerson` + --> tests/compile_fail/comparisons/dynamic_dispatch_a_table_on_the_context_1.rs:28:1 + | +28 | check_components! { Person { GreeterComponent } } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `__CheckPerson` + = note: this error originates in the attribute macro `cgp_impl` which comes from the expansion of the macro `check_components` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/example-code/tests/compile_fail/comparisons/dynamic_dispatch_a_table_on_the_context_2.rs b/example-code/tests/compile_fail/comparisons/dynamic_dispatch_a_table_on_the_context_2.rs new file mode 100644 index 00000000..6412faad --- /dev/null +++ b/example-code/tests/compile_fail/comparisons/dynamic_dispatch_a_table_on_the_context_2.rs @@ -0,0 +1,30 @@ +use cgp::prelude::*; + +#[cgp_component(Greeter)] +pub trait CanGreet { + fn greet(&self) -> String; +} + +#[cgp_impl(new GreetHello)] +impl Greeter { + fn greet(&self, #[implicit] name: &str) -> String { + format!("Hello, {name}!") + } +} + +#[cgp_impl(new GreetFormally)] +impl Greeter { + fn greet(&self, #[implicit] salutation: &str, #[implicit] last_name: &str) -> String { + format!("Good day, {salutation} {last_name}.") + } +} + +#[derive(HasField)] +pub struct Stranger { + pub name: String, +} + +// error[E0277]: the trait bound `Stranger: CanUseComponent` is not satisfied +check_components! { Stranger { GreeterComponent } } + +fn main() {} diff --git a/example-code/tests/compile_fail/comparisons/dynamic_dispatch_a_table_on_the_context_2.stderr b/example-code/tests/compile_fail/comparisons/dynamic_dispatch_a_table_on_the_context_2.stderr new file mode 100644 index 00000000..a6f7672d --- /dev/null +++ b/example-code/tests/compile_fail/comparisons/dynamic_dispatch_a_table_on_the_context_2.stderr @@ -0,0 +1,28 @@ +error[E0277]: the trait bound `Stranger: CanUseComponent` is not satisfied + --> tests/compile_fail/comparisons/dynamic_dispatch_a_table_on_the_context_2.rs:28:32 + | +28 | check_components! { Stranger { GreeterComponent } } + | ^^^^^^^^^^^^^^^^ unsatisfied trait bound + | +help: the trait `DelegateComponent` is not implemented for `Stranger` + --> tests/compile_fail/comparisons/dynamic_dispatch_a_table_on_the_context_2.rs:23:1 + | +23 | pub struct Stranger { + | ^^^^^^^^^^^^^^^^^^^ + = help: the following other types implement trait `DelegateComponent`: + `BuildAndMergeOutputs` implements `DelegateComponent` + `BuildAndMergeOutputs` implements `DelegateComponent` + `BuildAndMergeOutputs` implements `DelegateComponent` + `BuildAndMergeOutputs` implements `DelegateComponent` + `BuildAndMergeOutputs` implements `DelegateComponent` + `BuildAndMergeOutputs` implements `DelegateComponent` + `MatchFirstWithFieldHandlersInputs` implements `DelegateComponent<(Input, Args)>` + `MatchFirstWithFieldHandlersInputsMut` implements `DelegateComponent<(&'a mut Input, Args)>` + and $N others + = note: required for `Stranger` to implement `CanUseComponent` +note: required by a bound in `__CheckStranger` + --> tests/compile_fail/comparisons/dynamic_dispatch_a_table_on_the_context_2.rs:28:1 + | +28 | check_components! { Stranger { GreeterComponent } } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `__CheckStranger` + = note: this error originates in the macro `check_components` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/example-code/tests/compile_fail/concepts/namespaces_presets_and_per_type_dispatch.rs b/example-code/tests/compile_fail/concepts/namespaces_presets_and_per_type_dispatch.rs new file mode 100644 index 00000000..0f895e17 --- /dev/null +++ b/example-code/tests/compile_fail/concepts/namespaces_presets_and_per_type_dispatch.rs @@ -0,0 +1,34 @@ +use cgp::prelude::*; + +#[cgp_component(Converter)] +pub trait CanConvert { + fn convert(&self, source: Source) -> Target; +} + +#[cgp_impl(new ConvertFromU8)] +impl> Converter { + fn convert(&self, source: u8) -> Target { + Target::from(source) + } +} + +#[cgp_impl(new ConvertU8ToU64)] +impl Converter { + fn convert(&self, source: u8) -> u64 { + source as u64 + } +} + +pub struct App; + +delegate_components! { + App { + open ConverterComponent; + + // The shorter key matches every path beneath it, `@ConverterComponent.u8.u64` included. + @ConverterComponent.u8: ConvertFromU8, + @ConverterComponent.u8.u64: ConvertU8ToU64, + } +} + +fn main() {} diff --git a/example-code/tests/compile_fail/concepts/namespaces_presets_and_per_type_dispatch.stderr b/example-code/tests/compile_fail/concepts/namespaces_presets_and_per_type_dispatch.stderr new file mode 100644 index 00000000..a894e471 --- /dev/null +++ b/example-code/tests/compile_fail/concepts/namespaces_presets_and_per_type_dispatch.stderr @@ -0,0 +1,18 @@ +error[E0119]: conflicting implementations of trait `IsProviderFor>>, _, _>` for type `App` + --> tests/compile_fail/concepts/namespaces_presets_and_per_type_dispatch.rs:30:32 + | +29 | @ConverterComponent.u8: ConvertFromU8, + | -- first implementation here +30 | @ConverterComponent.u8.u64: ConvertU8ToU64, + | ^^^ conflicting implementation for `App` + | + = note: downstream crates may implement trait `cgp::macro_prelude::IsProviderFor>>, _, _>` for type `ConvertFromU8` + = note: downstream crates may implement trait `cgp::macro_prelude::IsProviderFor>>, _, _>` for type `ConvertU8ToU64` + +error[E0119]: conflicting implementations of trait `DelegateComponent>>>` for type `App` + --> tests/compile_fail/concepts/namespaces_presets_and_per_type_dispatch.rs:30:32 + | +29 | @ConverterComponent.u8: ConvertFromU8, + | -- first implementation here +30 | @ConverterComponent.u8.u64: ConvertU8ToU64, + | ^^^ conflicting implementation for `App` diff --git a/example-code/tests/compile_fail/concepts/type_level_tables_composite_keys.rs b/example-code/tests/compile_fail/concepts/type_level_tables_composite_keys.rs new file mode 100644 index 00000000..ff380ec6 --- /dev/null +++ b/example-code/tests/compile_fail/concepts/type_level_tables_composite_keys.rs @@ -0,0 +1,23 @@ +pub trait HasEntry { + type Value; +} + +pub struct MyTable; + +pub struct FooKey; + +pub struct Bar; +pub struct Baz; + +pub struct BarKey; + +impl HasEntry<(FooKey, BarKey)> for MyTable { + type Value = Baz; +} + +// error[E0119]: conflicting implementations of trait `HasEntry<(FooKey, BarKey)>` for type `MyTable` +impl HasEntry<(FooKey, Key)> for MyTable { + type Value = Bar; +} + +fn main() {} diff --git a/example-code/tests/compile_fail/concepts/type_level_tables_composite_keys.stderr b/example-code/tests/compile_fail/concepts/type_level_tables_composite_keys.stderr new file mode 100644 index 00000000..1c9c5b46 --- /dev/null +++ b/example-code/tests/compile_fail/concepts/type_level_tables_composite_keys.stderr @@ -0,0 +1,8 @@ +error[E0119]: conflicting implementations of trait `HasEntry<(FooKey, BarKey)>` for type `MyTable` + --> tests/compile_fail/concepts/type_level_tables_composite_keys.rs:19:1 + | +14 | impl HasEntry<(FooKey, BarKey)> for MyTable { + | ------------------------------------------- first implementation here +... +19 | impl HasEntry<(FooKey, Key)> for MyTable { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `MyTable` diff --git a/example-code/tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_1.rs b/example-code/tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_1.rs new file mode 100644 index 00000000..ad332386 --- /dev/null +++ b/example-code/tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_1.rs @@ -0,0 +1,21 @@ +pub trait HasEntry { + type Value; +} + +pub struct MyTable; + +pub struct FooKey; + +pub struct Bar; +pub struct Baz; + +impl HasEntry for MyTable { + type Value = Bar; +} + +// error[E0119]: conflicting implementations of trait `HasEntry` for type `MyTable` +impl HasEntry for MyTable { + type Value = Baz; +} + +fn main() {} diff --git a/example-code/tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_1.stderr b/example-code/tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_1.stderr new file mode 100644 index 00000000..da1ecc0c --- /dev/null +++ b/example-code/tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_1.stderr @@ -0,0 +1,8 @@ +error[E0119]: conflicting implementations of trait `HasEntry` for type `MyTable` + --> tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_1.rs:17:1 + | +12 | impl HasEntry for MyTable { + | --------------------------------- first implementation here +... +17 | impl HasEntry for MyTable { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `MyTable` diff --git a/example-code/tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_2.rs b/example-code/tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_2.rs new file mode 100644 index 00000000..e0fb8d7f --- /dev/null +++ b/example-code/tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_2.rs @@ -0,0 +1,23 @@ +use core::any::type_name; + +pub trait HasEntry { + type Value; +} + +pub struct MyTable; + +pub struct FooKey; + +pub struct Bar; +pub struct Baz; + +pub fn get_foo_value>() -> &'static str { + type_name::() +} + +pub struct OtherTable; + +fn main() { + // error[E0277]: the trait bound `OtherTable: HasEntry` is not satisfied + get_foo_value::(); +} diff --git a/example-code/tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_2.stderr b/example-code/tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_2.stderr new file mode 100644 index 00000000..fe85829f --- /dev/null +++ b/example-code/tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_2.stderr @@ -0,0 +1,21 @@ +error[E0277]: the trait bound `OtherTable: HasEntry` is not satisfied + --> tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_2.rs:22:21 + | +22 | get_foo_value::(); + | ^^^^^^^^^^ unsatisfied trait bound + | +help: the trait `HasEntry` is not implemented for `OtherTable` + --> tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_2.rs:18:1 + | +18 | pub struct OtherTable; + | ^^^^^^^^^^^^^^^^^^^^^ +help: this trait has no implementations, consider adding one + --> tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_2.rs:3:1 + | + 3 | pub trait HasEntry { + | ^^^^^^^^^^^^^^^^^^^^^^^ +note: required by a bound in `get_foo_value` + --> tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_2.rs:14:29 + | +14 | pub fn get_foo_value>() -> &'static str { + | ^^^^^^^^^^^^^^^^ required by this bound in `get_foo_value` diff --git a/example-code/tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_3.rs b/example-code/tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_3.rs new file mode 100644 index 00000000..7d0d187c --- /dev/null +++ b/example-code/tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_3.rs @@ -0,0 +1,21 @@ +pub trait HasEntry { + type Value; +} + +pub struct MyTable; + +pub struct FooKey; + +pub struct Bar; +pub struct Baz; + +impl HasEntry> for MyTable { + type Value = Bar; +} + +// error[E0119]: conflicting implementations of trait `HasEntry>` for type `MyTable` +impl HasEntry> for MyTable { + type Value = Baz; +} + +fn main() {} diff --git a/example-code/tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_3.stderr b/example-code/tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_3.stderr new file mode 100644 index 00000000..346e6346 --- /dev/null +++ b/example-code/tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_3.stderr @@ -0,0 +1,8 @@ +error[E0119]: conflicting implementations of trait `HasEntry>` for type `MyTable` + --> tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_3.rs:17:1 + | +12 | impl HasEntry> for MyTable { + | ------------------------------------ first implementation here +... +17 | impl HasEntry> for MyTable { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `MyTable` diff --git a/example-code/tests/compile_fail/concepts/type_level_tables_prototype_chains_1.rs b/example-code/tests/compile_fail/concepts/type_level_tables_prototype_chains_1.rs new file mode 100644 index 00000000..03e8c51f --- /dev/null +++ b/example-code/tests/compile_fail/concepts/type_level_tables_prototype_chains_1.rs @@ -0,0 +1,34 @@ +use core::any::type_name; +use core::marker::PhantomData; + +pub trait HasEntry { + type Value; +} + +pub trait HasStaticStringFor { + fn static_string() -> &'static str; +} + +pub struct Lookup
(pub PhantomData
); + +impl HasStaticStringFor for Lookup
+where + Table: HasEntry, +{ + fn static_string() -> &'static str { + type_name::() + } +} + +// A blanket implementation with a key parameter, beside the `Lookup` reader: +impl HasStaticStringFor for Table +where + Table: HasEntry, + Table::Value: HasStaticStringFor, +{ + fn static_string() -> &'static str { + >::static_string() + } +} + +fn main() {} diff --git a/example-code/tests/compile_fail/concepts/type_level_tables_prototype_chains_1.stderr b/example-code/tests/compile_fail/concepts/type_level_tables_prototype_chains_1.stderr new file mode 100644 index 00000000..8cba1ed7 --- /dev/null +++ b/example-code/tests/compile_fail/concepts/type_level_tables_prototype_chains_1.stderr @@ -0,0 +1,15 @@ +error[E0119]: conflicting implementations of trait `HasStaticStringFor<_>` for type `Lookup<_>` + --> tests/compile_fail/concepts/type_level_tables_prototype_chains_1.rs:24:1 + | +14 | / impl HasStaticStringFor for Lookup
+15 | | where +16 | | Table: HasEntry, + | |_________________________- first implementation here +... +24 | / impl HasStaticStringFor for Table +25 | | where +26 | | Table: HasEntry, +27 | | Table::Value: HasStaticStringFor, + | |__________________________________________^ conflicting implementation for `Lookup<_>` + | + = note: downstream crates may implement trait `HasEntry<_>` for type `Lookup<_>` diff --git a/example-code/tests/compile_fail/concepts/type_level_tables_prototype_chains_2.rs b/example-code/tests/compile_fail/concepts/type_level_tables_prototype_chains_2.rs new file mode 100644 index 00000000..769ed965 --- /dev/null +++ b/example-code/tests/compile_fail/concepts/type_level_tables_prototype_chains_2.rs @@ -0,0 +1,42 @@ +pub trait HasEntry { + type Value; +} + +pub trait HasStaticStringFor { + fn static_string() -> &'static str; +} + +pub struct FooKey; + +impl
HasStaticStringFor for Table +where + Table: HasEntry, + Table::Value: HasStaticStringFor, +{ + fn static_string() -> &'static str { + >::static_string() + } +} + +pub struct Bar; + +impl HasStaticStringFor for Bar { + fn static_string() -> &'static str { + "Bar" + } +} + +pub struct Shadow; + +impl HasEntry for Shadow { + type Value = Bar; +} + +// An implementation of its own, beside the entry: +impl HasStaticStringFor for Shadow { + fn static_string() -> &'static str { + "Shadow" + } +} + +fn main() {} diff --git a/example-code/tests/compile_fail/concepts/type_level_tables_prototype_chains_2.stderr b/example-code/tests/compile_fail/concepts/type_level_tables_prototype_chains_2.stderr new file mode 100644 index 00000000..30c328d6 --- /dev/null +++ b/example-code/tests/compile_fail/concepts/type_level_tables_prototype_chains_2.stderr @@ -0,0 +1,11 @@ +error[E0119]: conflicting implementations of trait `HasStaticStringFor` for type `Shadow` + --> tests/compile_fail/concepts/type_level_tables_prototype_chains_2.rs:36:1 + | +11 | / impl
HasStaticStringFor for Table +12 | | where +13 | | Table: HasEntry, +14 | | Table::Value: HasStaticStringFor, + | |_____________________________________________- first implementation here +... +36 | impl HasStaticStringFor for Shadow { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Shadow` diff --git a/example-code/tests/compile_fail/concepts/type_level_tables_what_it_costs.rs b/example-code/tests/compile_fail/concepts/type_level_tables_what_it_costs.rs new file mode 100644 index 00000000..8aff2ceb --- /dev/null +++ b/example-code/tests/compile_fail/concepts/type_level_tables_what_it_costs.rs @@ -0,0 +1,34 @@ +use core::marker::PhantomData; + +pub trait HasEntry { + type Value; +} + +pub trait HasStaticStringFor { + fn static_string() -> &'static str; +} + +pub struct Forward(pub PhantomData<(Table, KeyB)>); + +impl HasStaticStringFor for Forward +where + Table: HasEntry, + Table::Value: HasStaticStringFor, +{ + fn static_string() -> &'static str { + >::static_string() + } +} + +pub struct FooKey; + +pub struct Loop; + +impl HasEntry for Loop { + type Value = Forward; +} + +fn main() { + // error[E0275]: overflow evaluating the requirement `Forward: HasStaticStringFor` + as HasStaticStringFor>::static_string(); +} diff --git a/example-code/tests/compile_fail/concepts/type_level_tables_what_it_costs.stderr b/example-code/tests/compile_fail/concepts/type_level_tables_what_it_costs.stderr new file mode 100644 index 00000000..21d24ee1 --- /dev/null +++ b/example-code/tests/compile_fail/concepts/type_level_tables_what_it_costs.stderr @@ -0,0 +1,5 @@ +error[E0275]: overflow evaluating the requirement `Forward: HasStaticStringFor` + --> tests/compile_fail/concepts/type_level_tables_what_it_costs.rs:33:5 + | +33 | as HasStaticStringFor>::static_string(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/example-code/tests/concepts/check_traits.rs b/example-code/tests/concepts/check_traits.rs index 71f25503..d6f8d10d 100644 --- a/example-code/tests/concepts/check_traits.rs +++ b/example-code/tests/concepts/check_traits.rs @@ -92,6 +92,39 @@ pub mod writing_a_check_trait { } } +/// ## The `IsProviderFor` marker +/// +/// The provider trait with its `IsProviderFor` supertrait, the generated shape the section shows, +/// written by hand: a provider must implement the marker to implement the trait, and a check through +/// `CanUseComponent` reaches the provider's requirements through the table entry. The full trace, +/// with the table-reading blanket impl, is in +/// `consumer_and_provider_traits::how_a_call_finds_its_provider`. +pub mod the_isproviderfor_marker { + use cgp::core::component::IsProviderFor; + + pub struct StorageObjectFetcherComponent; + + pub trait StorageObjectFetcher: + IsProviderFor + { + fn fetch_storage_object( + context: &Context, + object_id: &str, + ) -> anyhow::Result>; + } + + pub struct FetchLocalObject; + + // The provider macros generate this with the provider's own bounds; here it has none. + impl IsProviderFor for FetchLocalObject {} + + impl StorageObjectFetcher for FetchLocalObject { + fn fetch_storage_object(context: &Context, object_id: &str) -> anyhow::Result> { + Ok(Vec::new()) + } + } +} + /// ## Checking each provider layer /// /// `#[check_providers]` asserts against each provider rather than against the context, so a broken diff --git a/example-code/tests/concepts/higher_order_providers.rs b/example-code/tests/concepts/higher_order_providers.rs index 95168884..0daf1367 100644 --- a/example-code/tests/concepts/higher_order_providers.rs +++ b/example-code/tests/concepts/higher_order_providers.rs @@ -252,6 +252,58 @@ pub mod falling_back_to_the_contexts_wiring { } } +/// ## A provider carried by a value +/// +/// A value type carries its provider as a type parameter, and a `#[cgp_fn]` function binds it with +/// `#[use_provider]`, so two contexts with no wiring of their own compute the same result. +pub mod a_provider_carried_by_a_value { + use core::marker::PhantomData; + + use cgp::prelude::*; + + #[cgp_component(ShapeAreaCalculator)] + pub trait CanCalculateShapeArea { + fn shape_area(&self, shape: &Shape) -> f64; + } + + pub struct Rectangle { + pub width: f64, + pub height: f64, + } + + #[cgp_impl(new RectangleArea)] + impl ShapeAreaCalculator { + fn shape_area(&self, shape: &Rectangle) -> f64 { + shape.width * shape.height + } + } + + pub struct Measured { + pub shape: Shape, + pub calculator: PhantomData, + } + + #[cgp_fn] + #[use_provider(Calculator: ShapeAreaCalculator)] + pub fn measured_area(&self, measured: &Measured) -> f64 { + Calculator::shape_area(self, &measured.shape) + } + + pub struct App; + pub struct TestApp; + + #[test] + fn the_value_fixes_the_calculation() { + let measured: Measured = Measured { + shape: Rectangle { width: 3.0, height: 4.0 }, + calculator: PhantomData, + }; + + assert_eq!(App.measured_area(&measured), 12.0); + assert_eq!(TestApp.measured_area(&measured), 12.0); + } +} + /// ## Other generic providers /// /// `GetName` is generic, and its parameter is a field name rather than a provider — nothing is diff --git a/example-code/tests/concepts/mod.rs b/example-code/tests/concepts/mod.rs index c8d92e9b..7c0b0666 100644 --- a/example-code/tests/concepts/mod.rs +++ b/example-code/tests/concepts/mod.rs @@ -1,6 +1,6 @@ //! Code from the pages under `docs/concepts/`, one module per page. //! -//! All eighteen pages of that section are written, and the ones that show code have a module here. +//! All nineteen pages of that section are written, and the ones that show code have a module here. //! The section index shows none, so it has no module. pub mod abstract_types; @@ -21,3 +21,4 @@ pub mod monadic_handlers; pub mod namespaces; pub mod send_bounds; pub mod type_level_dsls; +pub mod type_level_tables; diff --git a/example-code/tests/concepts/namespaces.rs b/example-code/tests/concepts/namespaces.rs index a7953ef6..ad3dc718 100644 --- a/example-code/tests/concepts/namespaces.rs +++ b/example-code/tests/concepts/namespaces.rs @@ -96,7 +96,7 @@ pub mod path_lookups { cgp_namespace! { new AppNamespace {} } #[cgp_component(Greeter)] - #[prefix(@app.GreeterComponent in AppNamespace)] + #[prefix(@app in AppNamespace)] pub trait CanGreet { fn greet(&self) -> String; } @@ -129,6 +129,52 @@ pub mod path_lookups { } } +/// ## Registering from the component's side +/// +/// A component registers its route in a namespace from the key's side with `#[prefix]`, and a +/// context that joins the namespace binds the provider at that path. The page's listing of the +/// registration impl is generated code; `cargo cgp expand` shows it, and this module checks that the +/// arrangement it describes resolves. +pub mod registering_from_the_components_side { + use cgp::prelude::*; + + cgp_namespace! { new AppNamespace {} } + + #[cgp_component(Greeter)] + #[prefix(@app in AppNamespace)] + pub trait CanGreet { + fn greet(&self) -> String; + } + + #[cgp_impl(new GreetHello)] + impl Greeter { + fn greet(&self) -> String { + "Hello!".to_owned() + } + } + + pub struct App; + + delegate_components! { + App { + namespace AppNamespace; + + @app.GreeterComponent: GreetHello, + } + } + + check_components! { + App { + GreeterComponent, + } + } + + #[test] + fn the_route_reaches_the_bound_provider() { + assert_eq!(App.greet(), "Hello!"); + } +} + /// ## Binding shared choices /// /// The preset shape. `AppDefaults` binds the leaf every context agrees on and leaves the varying @@ -139,13 +185,13 @@ pub mod binding_shared_choices { cgp_namespace! { new AppNamespace {} } #[cgp_component(Greeter)] - #[prefix(@app.GreeterComponent in AppNamespace)] + #[prefix(@app in AppNamespace)] pub trait CanGreet { fn greet(&self) -> String; } #[cgp_component(Farewell)] - #[prefix(@app.FarewellComponent in AppNamespace)] + #[prefix(@app in AppNamespace)] pub trait CanSayGoodbye { fn goodbye(&self) -> String; } @@ -240,13 +286,13 @@ pub mod one_namespace_per_configuration { cgp_namespace! { new AppNamespace {} } #[cgp_component(Greeter)] - #[prefix(@app.GreeterComponent in AppNamespace)] + #[prefix(@app in AppNamespace)] pub trait CanGreet { fn greet(&self) -> String; } #[cgp_component(Farewell)] - #[prefix(@app.FarewellComponent in AppNamespace)] + #[prefix(@app in AppNamespace)] pub trait CanSayGoodbye { fn goodbye(&self) -> String; } @@ -324,3 +370,10 @@ pub mod one_namespace_per_configuration { assert_eq!(App.goodbye(), "Goodbye!"); } } + +/// ## Presets and per-type dispatch +/// +/// A shorter path key and a longer key beneath it overlap: +/// +/// Rejected snippet — trybuild fixture `tests/compile_fail/concepts/namespaces_presets_and_per_type_dispatch.rs`. +pub mod presets_and_per_type_dispatch {} diff --git a/example-code/tests/concepts/type_level_tables.rs b/example-code/tests/concepts/type_level_tables.rs new file mode 100644 index 00000000..946f5613 --- /dev/null +++ b/example-code/tests/concepts/type_level_tables.rs @@ -0,0 +1,366 @@ +//! Code from `docs/concepts/type-level-tables.md` — *Look up a type in a type-level table*. +//! +//! Module names follow the page's headings. Each type-level step has a test, and each value-level +//! counterpart the page shows, reading a global `static` table, is a test beside it. The page uses no CGP, so neither does this file. +//! Rejected code lives in trybuild fixtures, except the cross-crate `E0210`, which the page states in +//! prose from the campaign's two-crate probe. + +/// ## A table and its entries +pub mod a_table_and_its_entries { + use core::any::type_name; + use std::collections::HashMap; + use std::sync::LazyLock; + + pub trait HasEntry { + type Value; + } + + pub struct MyTable; + + pub struct FooKey; + pub struct BarKey; + + pub struct Bar; + pub struct Baz; + + impl HasEntry for MyTable { + type Value = Bar; + } + + impl HasEntry for MyTable { + type Value = Baz; + } + + pub fn get_foo_value>() -> &'static str { + type_name::() + } + + pub fn my_table_foo_value() -> &'static str { + get_foo_value::() + } + + /// The generic-key form the page describes in prose. + pub fn get_value, Key>() -> &'static str { + type_name::() + } + + #[test] + fn the_foo_entry_is_bar() { + assert_eq!(my_table_foo_value(), type_name::()); + assert_eq!(get_value::(), type_name::()); + } + + /// The page's value-level counterpart. + pub fn get_foo_value_twin(table: &HashMap<&'static str, &'static str>) -> &'static str { + table["FooKey"] + } + + pub static MY_TABLE: LazyLock> = + LazyLock::new(|| HashMap::from([("FooKey", "Bar"), ("BarKey", "Baz")])); + + pub fn my_table_foo_value_twin() -> &'static str { + get_foo_value_twin(&MY_TABLE) + } + + #[test] + fn the_value_level_map_answers_the_same_key() { + assert_eq!(my_table_foo_value_twin(), "Bar"); + } +} + +/// ## Duplicate and missing keys +/// +/// All three snippets are rejected: +/// +/// Rejected snippets — trybuild fixtures +/// `tests/compile_fail/concepts/type_level_tables_duplicate_and_missing_keys_1.rs` (a second entry), +/// `_2.rs` (a missing key), and `_3.rs` (a generic key overlapping a specific one). +pub mod duplicate_and_missing_keys { + use super::a_table_and_its_entries::MY_TABLE; + + /// The value-level map finds a missing key only at runtime. + #[test] + fn the_value_level_map_misses_at_runtime() { + assert_eq!(MY_TABLE.get("OtherKey"), None); + } +} + +/// ## A lookup as a type +pub mod a_lookup_as_a_type { + use core::any::type_name; + use core::marker::PhantomData; + use std::collections::HashMap; + + use super::a_table_and_its_entries::{Bar, BarKey, Baz, FooKey, HasEntry, MyTable, MY_TABLE}; + + pub trait HasStaticStringFor { + fn static_string() -> &'static str; + } + + pub struct Lookup
(pub PhantomData
); + + impl HasStaticStringFor for Lookup
+ where + Table: HasEntry, + { + fn static_string() -> &'static str { + type_name::() + } + } + + #[test] + fn lookup_reads_the_table() { + assert_eq!( + as HasStaticStringFor>::static_string(), + type_name::(), + ); + assert_eq!( + as HasStaticStringFor>::static_string(), + type_name::(), + ); + } + + pub fn lookup(table: &HashMap<&'static str, &'static str>, key: &str) -> &'static str { + table[key] + } + + #[test] + fn the_value_level_lookup_takes_both_arguments() { + assert_eq!(lookup(&MY_TABLE, "BarKey"), "Baz"); + } +} + +/// ## Nested tables +pub mod nested_tables { + use core::any::type_name; + use core::marker::PhantomData; + use std::collections::HashMap; + use std::sync::LazyLock; + + use super::a_lookup_as_a_type::{HasStaticStringFor, Lookup}; + use super::a_table_and_its_entries::{Bar, FooKey, HasEntry, MyTable, MY_TABLE}; + + pub struct Forward(pub PhantomData<(Table, KeyB)>); + + impl HasStaticStringFor for Forward + where + Table: HasEntry, + Table::Value: HasStaticStringFor, + { + fn static_string() -> &'static str { + >::static_string() + } + } + + pub struct OuterTable; + pub struct InnerKey; + + impl HasEntry for OuterTable { + type Value = Lookup; + } + + #[test] + fn forward_reads_both_tables() { + assert_eq!( + as HasStaticStringFor>::static_string(), + type_name::(), + ); + } + + pub static OUTER_TABLE: LazyLock>> = + LazyLock::new(|| HashMap::from([("InnerKey", &*MY_TABLE)])); + + pub fn forward( + outer: &HashMap<&'static str, &'static HashMap<&'static str, &'static str>>, + key_b: &str, + key_a: &str, + ) -> &'static str { + outer[key_b][key_a] + } + + #[test] + fn the_value_level_map_of_maps() { + assert_eq!(forward(&OUTER_TABLE, "InnerKey", "FooKey"), "Bar"); + } +} + +/// ## Prototype chains +/// +/// The generic-key overlap and the implementation beside an entry are rejected: +/// +/// Rejected snippets — trybuild fixtures +/// `tests/compile_fail/concepts/type_level_tables_prototype_chains_1.rs` (a blanket implementation with a key +/// parameter beside `Lookup`) and `_2.rs` (an implementation of its own beside an entry). +pub mod prototype_chains { + use std::collections::HashMap; + use std::sync::LazyLock; + + use core::any::type_name; + + use super::a_lookup_as_a_type::HasStaticStringFor; + use super::a_table_and_its_entries::{Bar, FooKey, HasEntry, MyTable}; + + impl
HasStaticStringFor for Table + where + Table: HasEntry, + Table::Value: HasStaticStringFor, + { + fn static_string() -> &'static str { + >::static_string() + } + } + + impl HasStaticStringFor for Bar { + fn static_string() -> &'static str { + type_name::() + } + } + + pub struct Parent; + pub struct Child; + + impl HasEntry for Parent { + type Value = Bar; + } + + impl HasEntry for Child { + type Value = Parent; + } + + #[test] + fn the_chain_reaches_bar() { + assert_eq!(>::static_string(), type_name::()); + // `MyTable`'s entry for `FooKey` is `Bar`, so it answers through the same implementation. + assert_eq!(>::static_string(), type_name::()); + } + + pub struct Object { + pub own: HashMap<&'static str, &'static str>, + pub proto: Option<&'static Object>, + } + + pub fn get(object: &Object, key: &str) -> Option<&'static str> { + match object.own.get(key) { + Some(value) => Some(*value), + None => object.proto.and_then(|proto| get(proto, key)), + } + } + + pub static BAR: LazyLock = LazyLock::new(|| Object { + own: HashMap::from([("FooKey", "Bar")]), + proto: None, + }); + + pub static PARENT: LazyLock = + LazyLock::new(|| Object { own: HashMap::new(), proto: Some(&*BAR) }); + + pub static CHILD: LazyLock = + LazyLock::new(|| Object { own: HashMap::new(), proto: Some(&*PARENT) }); + + #[test] + fn the_value_level_chain_reaches_bar() { + assert_eq!(get(&CHILD, "FooKey"), Some("Bar")); + } +} + +/// ## Composite keys +/// +/// A generic position overlapping a specific pair is rejected: +/// +/// Rejected snippet — trybuild fixture `tests/compile_fail/concepts/type_level_tables_composite_keys.rs`. +pub mod composite_keys { + use core::any::type_name; + use core::marker::PhantomData; + use std::collections::HashMap; + use std::sync::LazyLock; + + use super::a_lookup_as_a_type::HasStaticStringFor; + use super::a_table_and_its_entries::{BarKey, Baz, FooKey, HasEntry, MyTable}; + + impl HasEntry<(FooKey, BarKey)> for MyTable { + type Value = Baz; + } + + pub struct Redirect(pub PhantomData<(Table, Prefix)>); + + impl HasStaticStringFor for Redirect + where + Table: HasEntry<(Prefix, Key)>, + { + fn static_string() -> &'static str { + type_name::<
>::Value>() + } + } + + #[test] + fn redirect_reads_the_pair() { + assert_eq!( + as HasStaticStringFor>::static_string(), + type_name::(), + ); + } + + pub static MY_PAIR_TABLE: LazyLock> = + LazyLock::new(|| HashMap::from([(("FooKey", "BarKey"), "Baz")])); + + pub fn redirect( + table: &HashMap<(&'static str, &'static str), &'static str>, + prefix: &'static str, + key: &'static str, + ) -> &'static str { + table[&(prefix, key)] + } + + #[test] + fn the_value_level_map_keyed_by_pairs() { + assert_eq!(redirect(&MY_PAIR_TABLE, "FooKey", "BarKey"), "Baz"); + } +} + +/// ## Entry ownership +/// +/// The page's two legal impls. The page places them in a crate other than the one defining +/// `HasEntry` and `TheirTable`; this file is one crate, so `TheirTable` is declared here, where the +/// impls are legal too. The rejected `impl
HasEntry for Table` is legal in one crate, +/// so it has no fixture: the page quotes its `E0210` from the campaign's two-crate probe. +pub mod entry_ownership { + use super::a_table_and_its_entries::HasEntry; + + pub struct TheirTable; + + pub struct MyKey; + pub struct MyValue; + + impl HasEntry for TheirTable { + type Value = MyValue; + } + + pub trait InTable
{ + type Value; + } + + impl
InTable
for MyKey { + type Value = MyValue; + } + + fn reads_entry>() {} + fn every_table_reads
() + where + MyKey: InTable, + { + } + + #[test] + fn both_entries_resolve() { + reads_entry::(); + every_table_reads::(); + every_table_reads::<()>(); + } +} + +/// ## What it costs +/// +/// A table whose entry forwards back to itself overflows the trait solver: +/// +/// Rejected snippet — trybuild fixture `tests/compile_fail/concepts/type_level_tables_what_it_costs.rs`. +pub mod what_it_costs {}