Skip to content

Commit f4460fb

Browse files
authored
Migrate remaining macro implementations and polish up cgp-macro-core (#243)
* Add product types * Implement SumType * Remove old product and sum constructs * Remove obsolete preset constructs * Migrate Symbol * Remove old symbol constructs * Draft implement ItemCgpType * Implement ItemCgpType::to_items * Migate cgp_type impl * Implement ItemCgpRecord * Move derive_has_fields * Move derive_builder * Move derive_extractor * Implement to_build_field_items * Add back derive_has_field_impls_from_struct * Implement to_from_variant_impls * Implement to_extract_field_items * Use items in entrypoints * Flatten macro lib * Implement snapshot_derive_has_field * Use snapshot_derive_has_field * Omit empty type bounds in cgp_type * Move HasField tests * AI-migrate HasField snapshot tests * Add `snapshot_derive_has_fields!` * Use fully qualified constructs * Implement snapshot_derive_cgp_data * AI adopt `snapshot_derive_cgp_data!` in tests * AI-revise macro qualification and remove greek identifiers
1 parent 28f0235 commit f4460fb

163 files changed

Lines changed: 5986 additions & 2061 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ resolver = "3"
55
members = [
66
"crates/main/cgp",
77
"crates/main/cgp-base",
8+
"crates/main/cgp-base-extra",
89
"crates/main/cgp-core",
910
"crates/main/cgp-extra",
1011

@@ -50,6 +51,7 @@ keywords = ["cgp"]
5051
[workspace.dependencies]
5152
cgp = { version = "0.7.0", path = "./crates/main/cgp" }
5253
cgp-base = { version = "0.7.0", path = "./crates/main/cgp-base" }
54+
cgp-base-extra = { version = "0.7.0", path = "./crates/main/cgp-base-extra" }
5355
cgp-core = { version = "0.7.0", path = "./crates/main/cgp-core" }
5456
cgp-extra = { version = "0.7.0", path = "./crates/main/cgp-extra" }
5557

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![allow(non_camel_case_types)]
2-
31
pub mod macro_prelude;
42
pub mod traits;
53
pub mod types;

crates/core/cgp-base-types/src/types/chars.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::marker::PhantomData;
44
use crate::traits::StaticFormat;
55

66
/**
7-
The `Chars` type, a.k.a. `ζ`, is used to represent _type-level_ list of
7+
The `Chars` type is used to represent _type-level_ list of
88
`Chars`s, which are equivalent to type-level strings.
99
1010
`Chars` is a specialized version of [`Cons`](crate::types::Cons), with the
@@ -13,11 +13,6 @@ use crate::traits::StaticFormat;
1313
expected to be either the next `Chars`, or [`Nil`](crate::types::Nil) to
1414
represent the end of the string.
1515
16-
Instead of reusing `Cons`, we combine the use of `Cons` within `Chars` so
17-
that its representation is more compact when shown in compiler error messages.
18-
Similar to `Cons`, `Chars` is also shown as `ζ` to further improve its
19-
readability.
20-
2116
We represent type-level strings as list of `Chars`s, because it is currently
2217
not possible to use types like `String` or `&str` as const-generic parameters.
2318
On the other hand, a single `Chars` can be used as a const-generic parameter,
@@ -40,17 +35,9 @@ use crate::traits::StaticFormat;
4035
```rust,ignore
4136
type Hello = Chars<'h', Chars<'e', Chars<'l', Chars<'l', Chars<'o', Nil>>>>>;
4237
```
43-
44-
which would be shown with the shortened representation as:
45-
46-
```rust,ignore
47-
type Hello = ζ<'h', ζ<'e', ζ<'l', ζ<'l', ζ<'o', ε>>>>>;
48-
```
4938
*/
5039
#[derive(Eq, PartialEq, Clone, Copy, Default)]
51-
pub struct ζ<const CHAR: char, Tail>(pub PhantomData<Tail>);
52-
53-
pub use ζ as Chars;
40+
pub struct Chars<const CHAR: char, Tail>(pub PhantomData<Tail>);
5441

5542
impl<const CHAR: char, Tail> Display for Chars<CHAR, Tail>
5643
where
Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
/**
2-
The `Cons` type, a.k.a. `π`, is used to represent the head of a _type-level list_,
2+
The `Cons` type is used to represent the head of a _type-level list_,
33
also known as an _anonymous product type_.
44
55
`Cons` is used together with [`Nil`] to produce a type-level list using
66
the `Product!` macro.
77
8-
`Cons` is also shown as `π`, together with [`Nil`] shown as `ε`, to improve the
9-
readability of compiler error messages. Through the shortened name, a product
10-
type would take slightly less space, making it more likely to fit on a single
11-
line for the user to read what the type is.
12-
138
## Example
149
1510
Given the following product type definition:
@@ -23,15 +18,6 @@
2318
```rust,ignore
2419
type MyTypes = Cons<u32, Cons<String, Cons<bool, Nil>>>;
2520
```
26-
27-
which would be shown with the shortened representation as:
28-
29-
```rust,ignore
30-
type MyTypes = π<u32, π<String, π<bool, ε>>>;
31-
```
3221
*/
3322
#[derive(Eq, PartialEq, Clone, Default, Debug)]
34-
#[allow(non_camel_case_types)]
35-
pub struct π<Head, Tail>(pub Head, pub Tail);
36-
37-
pub use π as Cons;
23+
pub struct Cons<Head, Tail>(pub Head, pub Tail);
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
The `Nil` type, a.k.a. `ε`, is used to represent the end of a _type-level list_,
2+
The `Nil` type is used to represent the end of a _type-level list_,
33
or an empty type-level list.
44
55
`Nil` is commonly used as the `Tail` of a [`Cons`] type, to terminate the list.
@@ -8,7 +8,4 @@
88
Read more about type-level lists, a.k.a. the product types, in [`Cons`].
99
*/
1010
#[derive(Eq, PartialEq, Clone, Default, Debug)]
11-
#[allow(non_camel_case_types)]
12-
pub struct ε;
13-
14-
pub use ε as Nil;
11+
pub struct Nil;

crates/core/cgp-base-types/src/types/symbol.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use core::fmt::Display;
22
use core::marker::PhantomData;
33

4-
pub struct ψ<const LEN: usize, Chars>(pub PhantomData<Chars>);
5-
6-
pub use ψ as Symbol;
4+
pub struct Symbol<const LEN: usize, Chars>(pub PhantomData<Chars>);
75

86
use crate::traits::StaticFormat;
97

crates/core/cgp-error/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ rust-version = { workspace = true }
99
keywords = { workspace = true }
1010

1111
[dependencies]
12-
cgp = { version = "0.7.0", path = "../../main/cgp-base", package = "cgp-base" }
12+
cgp = { version = "0.7.0", path = "../../main/cgp-base-extra", package = "cgp-base-extra" }
1313
cgp-macro = { workspace = true }
1414
cgp-type = { workspace = true }
1515
cgp-field = { workspace = true }

crates/core/cgp-error/src/traits/can_raise_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cgp::macro_prelude::*;
1+
use cgp::component::{DefaultNamespace, UseDelegate};
22
use cgp_macro::cgp_component;
33

44
use crate::traits::has_error_type::HasErrorType;

crates/core/cgp-error/src/traits/can_wrap_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cgp::macro_prelude::*;
1+
use cgp::component::{DefaultNamespace, UseDelegate};
22
use cgp_macro::cgp_component;
33

44
use crate::traits::HasErrorType;

0 commit comments

Comments
 (0)