Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a4ae237
Add product types
soareschen Jun 28, 2026
2ac945f
Implement SumType
soareschen Jun 28, 2026
e83dd8d
Remove old product and sum constructs
soareschen Jun 28, 2026
88df1bb
Remove obsolete preset constructs
soareschen Jun 28, 2026
f1feea7
Migrate Symbol
soareschen Jun 28, 2026
ffbc009
Remove old symbol constructs
soareschen Jun 28, 2026
54840bd
Draft implement ItemCgpType
soareschen Jun 28, 2026
a7b6287
Implement ItemCgpType::to_items
soareschen Jun 28, 2026
683ec1a
Migate cgp_type impl
soareschen Jun 28, 2026
849b43f
Implement ItemCgpRecord
soareschen Jun 28, 2026
2087dd1
Move derive_has_fields
soareschen Jun 28, 2026
a9de662
Move derive_builder
soareschen Jun 28, 2026
dc09bcb
Move derive_extractor
soareschen Jun 28, 2026
02dcc3a
Implement to_build_field_items
soareschen Jun 28, 2026
c99377b
Add back derive_has_field_impls_from_struct
soareschen Jun 28, 2026
a31f21f
Implement to_from_variant_impls
soareschen Jun 28, 2026
e51c6f0
Implement to_extract_field_items
soareschen Jun 28, 2026
3225680
Use items in entrypoints
soareschen Jun 28, 2026
470bd9d
Flatten macro lib
soareschen Jun 28, 2026
ddc5b4d
Implement snapshot_derive_has_field
soareschen Jun 28, 2026
d6f290c
Use snapshot_derive_has_field
soareschen Jun 28, 2026
b3b683d
Omit empty type bounds in cgp_type
soareschen Jun 28, 2026
65a20d3
Move HasField tests
soareschen Jun 28, 2026
9c19658
AI-migrate HasField snapshot tests
soareschen Jun 28, 2026
44505d3
Add `snapshot_derive_has_fields!`
soareschen Jun 28, 2026
3fd6202
Use fully qualified constructs
soareschen Jun 28, 2026
c8add26
Implement snapshot_derive_cgp_data
soareschen Jun 28, 2026
b5f0ca8
AI adopt `snapshot_derive_cgp_data!` in tests
soareschen Jun 28, 2026
74efaf1
AI-revise macro qualification and remove greek identifiers
soareschen Jun 28, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ resolver = "3"
members = [
"crates/main/cgp",
"crates/main/cgp-base",
"crates/main/cgp-base-extra",
"crates/main/cgp-core",
"crates/main/cgp-extra",

Expand Down Expand Up @@ -50,6 +51,7 @@ keywords = ["cgp"]
[workspace.dependencies]
cgp = { version = "0.7.0", path = "./crates/main/cgp" }
cgp-base = { version = "0.7.0", path = "./crates/main/cgp-base" }
cgp-base-extra = { version = "0.7.0", path = "./crates/main/cgp-base-extra" }
cgp-core = { version = "0.7.0", path = "./crates/main/cgp-core" }
cgp-extra = { version = "0.7.0", path = "./crates/main/cgp-extra" }

Expand Down
2 changes: 0 additions & 2 deletions crates/core/cgp-base-types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(non_camel_case_types)]

pub mod macro_prelude;
pub mod traits;
pub mod types;
17 changes: 2 additions & 15 deletions crates/core/cgp-base-types/src/types/chars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::marker::PhantomData;
use crate::traits::StaticFormat;

/**
The `Chars` type, a.k.a. `ζ`, is used to represent _type-level_ list of
The `Chars` type is used to represent _type-level_ list of
`Chars`s, which are equivalent to type-level strings.

`Chars` is a specialized version of [`Cons`](crate::types::Cons), with the
Expand All @@ -13,11 +13,6 @@ use crate::traits::StaticFormat;
expected to be either the next `Chars`, or [`Nil`](crate::types::Nil) to
represent the end of the string.

Instead of reusing `Cons`, we combine the use of `Cons` within `Chars` so
that its representation is more compact when shown in compiler error messages.
Similar to `Cons`, `Chars` is also shown as `ζ` to further improve its
readability.

We represent type-level strings as list of `Chars`s, because it is currently
not possible to use types like `String` or `&str` as const-generic parameters.
On the other hand, a single `Chars` can be used as a const-generic parameter,
Expand All @@ -40,17 +35,9 @@ use crate::traits::StaticFormat;
```rust,ignore
type Hello = Chars<'h', Chars<'e', Chars<'l', Chars<'l', Chars<'o', Nil>>>>>;
```

which would be shown with the shortened representation as:

```rust,ignore
type Hello = ζ<'h', ζ<'e', ζ<'l', ζ<'l', ζ<'o', ε>>>>>;
```
*/
#[derive(Eq, PartialEq, Clone, Copy, Default)]
pub struct ζ<const CHAR: char, Tail>(pub PhantomData<Tail>);

pub use ζ as Chars;
pub struct Chars<const CHAR: char, Tail>(pub PhantomData<Tail>);

impl<const CHAR: char, Tail> Display for Chars<CHAR, Tail>
where
Expand Down
18 changes: 2 additions & 16 deletions crates/core/cgp-base-types/src/types/cons.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
/**
The `Cons` type, a.k.a. `π`, is used to represent the head of a _type-level list_,
The `Cons` type is used to represent the head of a _type-level list_,
also known as an _anonymous product type_.

`Cons` is used together with [`Nil`] to produce a type-level list using
the `Product!` macro.

`Cons` is also shown as `π`, together with [`Nil`] shown as `ε`, to improve the
readability of compiler error messages. Through the shortened name, a product
type would take slightly less space, making it more likely to fit on a single
line for the user to read what the type is.

## Example

Given the following product type definition:
Expand All @@ -23,15 +18,6 @@
```rust,ignore
type MyTypes = Cons<u32, Cons<String, Cons<bool, Nil>>>;
```

which would be shown with the shortened representation as:

```rust,ignore
type MyTypes = π<u32, π<String, π<bool, ε>>>;
```
*/
#[derive(Eq, PartialEq, Clone, Default, Debug)]
#[allow(non_camel_case_types)]
pub struct π<Head, Tail>(pub Head, pub Tail);

pub use π as Cons;
pub struct Cons<Head, Tail>(pub Head, pub Tail);
7 changes: 2 additions & 5 deletions crates/core/cgp-base-types/src/types/nil.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
The `Nil` type, a.k.a. `ε`, is used to represent the end of a _type-level list_,
The `Nil` type is used to represent the end of a _type-level list_,
or an empty type-level list.

`Nil` is commonly used as the `Tail` of a [`Cons`] type, to terminate the list.
Expand All @@ -8,7 +8,4 @@
Read more about type-level lists, a.k.a. the product types, in [`Cons`].
*/
#[derive(Eq, PartialEq, Clone, Default, Debug)]
#[allow(non_camel_case_types)]
pub struct ε;

pub use ε as Nil;
pub struct Nil;
4 changes: 1 addition & 3 deletions crates/core/cgp-base-types/src/types/symbol.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use core::fmt::Display;
use core::marker::PhantomData;

pub struct ψ<const LEN: usize, Chars>(pub PhantomData<Chars>);

pub use ψ as Symbol;
pub struct Symbol<const LEN: usize, Chars>(pub PhantomData<Chars>);

use crate::traits::StaticFormat;

Expand Down
2 changes: 1 addition & 1 deletion crates/core/cgp-error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ rust-version = { workspace = true }
keywords = { workspace = true }

[dependencies]
cgp = { version = "0.7.0", path = "../../main/cgp-base", package = "cgp-base" }
cgp = { version = "0.7.0", path = "../../main/cgp-base-extra", package = "cgp-base-extra" }
cgp-macro = { workspace = true }
cgp-type = { workspace = true }
cgp-field = { workspace = true }
2 changes: 1 addition & 1 deletion crates/core/cgp-error/src/traits/can_raise_error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cgp::macro_prelude::*;
use cgp::component::{DefaultNamespace, UseDelegate};
use cgp_macro::cgp_component;

use crate::traits::has_error_type::HasErrorType;
Expand Down
2 changes: 1 addition & 1 deletion crates/core/cgp-error/src/traits/can_wrap_error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cgp::macro_prelude::*;
use cgp::component::{DefaultNamespace, UseDelegate};
use cgp_macro::cgp_component;

use crate::traits::HasErrorType;
Expand Down
3 changes: 1 addition & 2 deletions crates/core/cgp-error/src/traits/has_error_type.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use core::fmt::Debug;

use cgp::macro_prelude::*;
use cgp::component::DefaultNamespace;
use cgp_macro::cgp_type;
use cgp_type::{TypeProvider, UseType};

/**
The `HasErrorType` trait provides an abstract error type that can be used by
Expand Down
2 changes: 0 additions & 2 deletions crates/core/cgp-field/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#![no_std]
#![allow(mixed_script_confusables)]
#![allow(non_camel_case_types)]

pub mod impls;
pub mod traits;
Expand Down
22 changes: 2 additions & 20 deletions crates/core/cgp-field/src/types/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::fmt::Debug;
use core::marker::PhantomData;

/**
The `Field` type, a.k.a. `ω`, is used to represent a _named_ field entry
The `Field` type is used to represent a _named_ field entry
within a product type or a sum type.

`Field` is parameterized by a phantom `Tag` type, which is used to represent
Expand All @@ -14,11 +14,6 @@ use core::marker::PhantomData;
implementations, to include the field name in the generic product or sum
representation of the given struct or enum.

`Field` is also shown as `ω` to improve the readability of compiler error
messages. It is mainly useful when the type from `HasFields::Fields` is shown,
which would contain a lot of `Field`s and tend to take up a lot of screen space
to read.

## Example

Given the following struct definition:
Expand All @@ -38,25 +33,12 @@ use core::marker::PhantomData;
type Fields = Product![Field<Symbol!("name"), String>, Field<Symbol!("age"), u8>];
}
```

which would be shown with the shortened representation as:

```rust,ignore
impl HasFields for MyContext {
type Fields =
π<ω<Symbol!("name"), String>,
π<ω<Symbol!("age"), u8>,
ε>>;
}
```
*/
pub struct ω<Tag, Value> {
pub struct Field<Tag, Value> {
pub value: Value,
pub phantom: PhantomData<Tag>,
}

pub use ω as Field;

impl<Tag, Value> From<Value> for Field<Tag, Value> {
fn from(value: Value) -> Self {
Self {
Expand Down
9 changes: 2 additions & 7 deletions crates/core/cgp-field/src/types/index.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use core::fmt::{Debug, Display};

/**
The `Index` type, a.k.a. `δ`, is used to represent a `usize` value at
The `Index` type is used to represent a `usize` value at
the _type level_.

`Index` is simply defined to be parameterized by a _const-generic_ value
of type `usize`. It is most often used to access generic fields by their
_index_, instead of by their _name_.

`Index` is also shown as `δ` to improve the readability of compiler error
messages.

## Example

Given the following struct definition:
Expand All @@ -32,9 +29,7 @@ use core::fmt::{Debug, Display};
}
*/
#[derive(Eq, PartialEq, Clone, Copy, Default)]
pub struct δ<const I: usize>;

pub use δ as Index;
pub struct Index<const I: usize>;

impl<const I: usize> Display for Index<I> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
Expand Down
22 changes: 4 additions & 18 deletions crates/core/cgp-field/src/types/sum.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
/**
The `Either` type, a.k.a. `σ`, is used to represent an _anonymous sum type_.
The `Either` type is used to represent an _anonymous sum type_.

Similar to [`Cons`](crate::types::Cons), `Either` is used to form a sum type
by combining a chain of `Either` types, and terminated with a [`Void`] type.
But unlike product types, a sum type has values that belong to one
of the variants in the list.

`Either` is also shown as `σ`, together with [`Void`] shown as `θ`, to improve
the readability of compiler error messages. Through the shortened name, a sum
type would take slightly less space, making it more likely to fit on a single
line for the user to read what the type is.

`Either` is most often used through the `Sum!` macro, which accepts a list of
types and turns them into a chain of `Either` types.

Expand All @@ -27,21 +22,15 @@
```rust,ignore
type MyUnion = Either<u32, Either<String, Either<bool, Void>>>;
```

which would be shown with the shortened representation as:

```rust,ignore
type MyUnion = σ<u32, σ<String, σ<bool, θ>>>;
```
*/
#[derive(Eq, PartialEq, Debug, Clone)]
pub enum σ<Head, Tail> {
pub enum Either<Head, Tail> {
Left(Head),
Right(Tail),
}

/**
The `Void` type, a.k.a. `θ`, is used to represent the end of an _anonymous sum type_,
The `Void` type is used to represent the end of an _anonymous sum type_,
or an _empty_ sum type.

`Void` is commonly used as the `Tail` of a [`Either`] type, to terminate the list.
Expand All @@ -57,7 +46,4 @@ pub enum σ<Head, Tail> {
Read more about sum types in [`Either`].
*/
#[derive(Eq, PartialEq, Debug, Clone)]
pub enum θ {}

pub use θ as Void;
pub use σ as Either;
pub enum Void {}
38 changes: 36 additions & 2 deletions crates/macros/cgp-macro-core/src/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,51 @@ use crate::export_constructs;
export_constructs! {
Nil,
Cons,
Void,
Either,
Chars,
Symbol,
Index,
Field,
PathCons,
ConcatPath,
RedirectLookup,
DelegateComponent,
IsProviderFor,
CanUseComponent,
HasField,
HasFieldMut,
UseContext,
UseType,
TypeProvider,
WithProvider,
UseFields,
UseField,
Life,

HasField,
HasFields,
HasFieldsRef,
HasFieldMut,
FieldGetter,
MutFieldGetter,
FromFields,
FromVariant,
HasBuilder,
HasExtractor,
HasExtractorRef,
HasExtractorMut,
ExtractField,
IntoBuilder,
UpdateField,
ToFields,
ToFieldsRef,
FinalizeBuild,
FinalizeExtract,
PartialData,
IsPresent,
IsNothing,
IsVoid,
IsRef,
IsMut,
MapType,
MapTypeRef,
}
2 changes: 0 additions & 2 deletions crates/macros/cgp-macro-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(mixed_script_confusables)]

pub mod exports;
pub mod functions;
pub mod macros;
Expand Down
Loading
Loading