Skip to content

Commit a5cf785

Browse files
committed
wip
1 parent 3607b74 commit a5cf785

File tree

2 files changed

+13
-107
lines changed

2 files changed

+13
-107
lines changed

module/core/former/plan.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Increments
44

5-
* **Increment 1: Implement Multi-Field Struct Variant - Subformer - Storage**
5+
* **Increment 1: Implement Multi-Field Struct Variant - Subformer - Storage**
66
* Goal: Generate the implicit storage struct for the default/subform case for multi-field struct variants.
77
* Detailed Plan Step 1: Locate the `Struct Variant (len > 1)` case in `former_enum.rs`.
88
* Detailed Plan Step 2: Remove the `return Err(...)` for the default case.
@@ -13,7 +13,7 @@
1313
* Detailed Plan Step 4: Implement `impl Default` for the storage struct.
1414
* Crucial Design Rules: [Handling Panics vs Recoverable Errors](#handling-panics-vs-recoverable-errors), [Visibility: Keep Implementation Details Private](#visibility-keep-implementation-details-private).
1515
* Verification Strategy: Compile check (`cargo check --package former_meta`). **Hypothesis H2, H6 Check:** Verify the generated storage struct compiles with correct fields, generics, and phantom data.
16-
* **Increment 2: Implement Multi-Field Struct Variant - Subformer - Storage Impls**
16+
* **Increment 2: Implement Multi-Field Struct Variant - Subformer - Storage Impls**
1717
* Goal: Generate `impl Storage` and `impl StoragePreform` for the implicit storage struct.
1818
* Detailed Plan Step 1: Implement `impl Storage` for `VariantNameFormerStorage`. Define `type Preformed = ( #( #field_types ),* );`.
1919
* Detailed Plan Step 2: Implement `impl StoragePreform` for `VariantNameFormerStorage`.
@@ -22,7 +22,7 @@
2222
* Return the preformed tuple `( #( #preformed_fields ),* )`.
2323
* Crucial Design Rules: [Handling Panics vs Recoverable Errors](#handling-panics-vs-recoverable-errors).
2424
* Verification Strategy: Compile check (`cargo check --package former_meta`). **Hypothesis H3, H6 Check:** Verify `preform` returns the correct tuple type and handles defaults.
25-
* **Increment 3: Implement Multi-Field Struct Variant - Subformer - DefTypes**
25+
* **Increment 3: Implement Multi-Field Struct Variant - Subformer - DefTypes**
2626
* Goal: Generate the implicit DefinitionTypes struct and impl.
2727
* Detailed Plan Step 1: Generate the `VariantNameFormerDefinitionTypes` struct definition with appropriate generics (`#enum_generics_impl`, `Context2`, `Formed2`) and phantom data.
2828
* Detailed Plan Step 2: Implement `impl Default` for `VariantNameFormerDefinitionTypes`.
@@ -110,4 +110,7 @@
110110
* **[2024-04-25/Inc 6 Hypothesis]** Confirmed hypotheses for implicit former generation for multi-field struct variants. Key points: generate dedicated former ecosystem for the variant, storage holds `Option<FieldType>` for all variant fields, `preform` returns tuple, former has setters for all variant fields, `End::call` uses preformed tuple to construct variant. Generics handling (H6) and `End::call` logic (H8) require careful implementation.
111111
* **[2024-04-25/Inc 6 Plan Revision]** Further decomposed Increment 6. Will now implement logic for each variant type incrementally (Unit, Tuple(0), Tuple(1), Tuple(N), Struct(0), Struct(1), Struct(N)-Scalar). The complex Struct(N)-Subformer case is broken into multiple increments (12-21) based on verified hypotheses.
112112
* **[2024-04-25/Plan Update 2]** Added explicit test enabling steps to increments 6-11, 23-26. Renumbered final increments.
113-
* **[2024-04-26/Plan Revision 3]** Focused plan on fixing `generics_shared_struct_derive.rs` failure by implementing the multi-field struct subformer logic (Increments 1-10). Added final verification increment (11). Preserved previous notes.
113+
* **[2024-04-26/Plan Revision 3]** Focused plan on fixing `generics_shared_struct_derive.rs` failure by implementing the multi-field struct subformer logic (Increments 1-10). Added final verification increment (11). Preserved previous notes.
114+
* **[2024-04-26/Inc 1]** Completed implementation of storage struct definition and default impl for multi-field struct variant subformer case. Compile check passed.
115+
* **[2024-04-26/Inc 2]** Completed implementation of `Storage` and `StoragePreform` traits for the implicit storage struct. Compile check passed.
116+
* **[2024-04-26/Inc 3]** Completed implementation of `DefinitionTypes` struct and its trait impls (`Default`, `FormerDefinitionTypes`, `FormerMutator`) for the implicit former. Compile check passed.

module/core/former_meta/src/derive_former/former_enum.rs

Lines changed: 6 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,110 +1046,13 @@ pub(super) fn former_for_enum
10461046
} // Brace on new line
10471047
};
10481048

1049-
// Generate Definition struct and impls
1050-
let def_name = format_ident!( "{}{}FormerDefinition", enum_name, variant_ident );
1051-
let end_struct_name = format_ident!( "{}{}End", enum_name, variant_ident ); // Needed for default End type
1052-
1053-
// <<< Start Correction 7 >>>
1054-
// Calculate phantom data type based on combined generics for the definition
1055-
let def_phantom_generics_impl = generic_params::merge( &generics, &parse_quote!{ < Context2, Formed2, End2 > } );
1056-
let ( _ , def_phantom_generics_impl, _, _ ) = generic_params::decompose( &def_phantom_generics_impl );
1057-
let def_phantom = phantom::tuple( &def_phantom_generics_impl );
1058-
1059-
// FIX: Remove trailing comma from enum_generics_ty when used inside <> with other args
1060-
let enum_generics_ty_no_comma = {
1061-
let mut ty = enum_generics_ty.clone();
1062-
ty.pop_punct(); // Remove trailing comma if it exists
1063-
ty
1064-
};
1065-
1066-
let def_struct = quote!
1067-
{
1068-
#[ derive( Debug ) ]
1069-
#vis struct #def_name < #enum_generics_impl Context2 = (), Formed2 = #enum_name< #enum_generics_ty >, End2 = #end_struct_name< #enum_generics_ty > >
1070-
where // Where clause on new line
1071-
End2 : former::FormingEnd< #def_types_name< #enum_generics_ty_no_comma, Context2, Formed2 > >, // <<< Use no_comma version
1072-
#merged_where_clause // Use original enum where clause + End2 bound
1073-
{ // Brace on new line
1074-
_phantom : #def_phantom, // Use calculated phantom
1075-
} // Brace on new line
1076-
};
1077-
1078-
let def_default_impl = quote!
1079-
{
1080-
impl< #enum_generics_impl Context2, Formed2, End2 > ::core::default::Default
1081-
for #def_name < #enum_generics_ty Context2, Formed2, End2 >
1082-
where // Where clause on new line
1083-
End2 : former::FormingEnd< #def_types_name< #enum_generics_ty_no_comma, Context2, Formed2 > >, // <<< Use no_comma version
1084-
#merged_where_clause
1085-
{ // Brace on new line
1086-
fn default() -> Self
1087-
{ // Brace on new line
1088-
Self { _phantom : ::core::marker::PhantomData }
1089-
} // Brace on new line
1090-
} // Brace on new line
1091-
};
1092-
1093-
let def_former_impl = quote!
1094-
{
1095-
impl< #enum_generics_impl Context2, Formed2, End2 > former::FormerDefinition
1096-
for #def_name < #enum_generics_ty Context2, Formed2, End2 >
1097-
where // Where clause on new line
1098-
End2 : former::FormingEnd< #def_types_name< #enum_generics_ty_no_comma, Context2, Formed2 > >, // <<< Use no_comma version
1099-
#merged_where_clause
1100-
{ // Brace on new line
1101-
type Storage = #storage_struct_name< #enum_generics_ty >;
1102-
type Context = Context2;
1103-
type Formed = Formed2;
1104-
type Types = #def_types_name< #enum_generics_ty_no_comma, Context2, Formed2 >; // <<< Use no_comma version
1105-
type End = End2;
1106-
} // Brace on new line
1107-
};
1108-
// <<< End Correction 7 >>>
1109-
1110-
// Generate Former struct definition
1111-
let former_name = format_ident!( "{}{}Former", enum_name, variant_ident );
1112-
// <<< Start Correction 8 >>>
1113-
// Construct generics for Former struct manually
1114-
let mut former_generics = generics.clone();
1115-
former_generics.params.push( parse_quote!( Definition = #def_name< #enum_generics_ty > ) );
1116-
let former_where_clause = former_generics.make_where_clause();
1117-
former_where_clause.predicates.push( parse_quote!{ Definition : former::FormerDefinition< Storage = #storage_struct_name< #enum_generics_ty > > } );
1118-
former_where_clause.predicates.push( parse_quote!{ Definition::Types : former::FormerDefinitionTypes< Storage = #storage_struct_name< #enum_generics_ty > > } );
1119-
if let Some( enum_where ) = &generics.where_clause
1120-
{
1121-
for predicate in &enum_where.predicates
1122-
{
1123-
former_where_clause.predicates.push( predicate.clone() );
1124-
}
1125-
}
1126-
let ( _former_generics_with_defaults, former_generics_impl, former_generics_ty, former_generics_where ) = generic_params::decompose( &former_generics );
1127-
// <<< End Correction 8 >>>
1128-
1129-
let former_struct_def = quote!
1130-
{
1131-
#[ doc = "Former for the #variant_ident variant." ]
1132-
#vis struct #former_name < #former_generics_impl > // Use decomposed impl generics
1133-
where // Where clause on new line
1134-
#former_generics_where // Use decomposed where clause
1135-
{ // Brace on new line
1136-
/// Temporary storage for all fields during the formation process.
1137-
pub storage : Definition::Storage,
1138-
/// Optional context.
1139-
pub context : ::core::option::Option< Definition::Context >,
1140-
/// Optional handler for the end of formation.
1141-
pub on_end : ::core::option::Option< Definition::End >,
1142-
} // Brace on new line
1143-
};
1144-
1145-
11461049
// Add generated storage, DefTypes, Definition, and Former code to end_impls
11471050
end_impls.push( quote!
11481051
{
11491052
#storage_def #storage_default_impl #storage_trait_impl #storage_preform_impl
11501053
#def_types_struct #def_types_default_impl #def_types_former_impl #def_types_mutator_impl
1151-
#def_struct #def_default_impl #def_former_impl
1152-
#former_struct_def // <<< Added Former struct definition
1054+
// #def_struct #def_default_impl #def_former_impl // Will be added in Increment 4
1055+
// #former_struct_def // Will be added in Increment 5
11531056
});
11541057

11551058
// --- Force Debug Print for EnumG4::V1 ---
@@ -1166,18 +1069,18 @@ pub(super) fn former_for_enum
11661069
// Implicit Former Components
11671070
#storage_def #storage_default_impl #storage_trait_impl #storage_preform_impl
11681071
#def_types_struct #def_types_default_impl #def_types_former_impl #def_types_mutator_impl
1169-
#def_struct #def_default_impl #def_former_impl
1170-
#former_struct_def // <<< Added Former struct definition
1072+
// #def_struct #def_default_impl #def_former_impl // Placeholder
1073+
// #former_struct_def // Placeholder
11711074
// Placeholder for Former impl, End struct/impl
11721075
};
11731076
diag::report_print( about, original_input, &variant_code );
11741077
}
11751078
// --- End Force Debug Print ---
11761079

11771080

1178-
// Placeholder for the rest of the implicit former generation (Increments 6-10)
1081+
// Placeholder for the rest of the implicit former generation (Increments 4-10)
11791082
// methods.push( quote!{ /* TODO: Add static method for subformer */ } );
1180-
// end_impls.push( quote!{ /* TODO: Add Former impl, End impls */ } );
1083+
// end_impls.push( quote!{ /* TODO: Add Def, Former, End impls */ } );
11811084
// standalone_constructors.push( quote!{ /* TODO: Add standalone constructor */ } );
11821085
}
11831086
}

0 commit comments

Comments
 (0)