Skip to main content

clifford_codegen/codegen/
products.rs

1//! Product code generation.
2//!
3//! This module provides the `ProductGenerator` which generates an empty
4//! products.rs file. All product implementations are inlined into trait
5//! implementations in traits.rs (see PRD-24).
6//!
7//! Historical note: This module previously generated free functions for all
8//! products (geometric, wedge, inner, etc.). These were removed because:
9//! 1. They duplicated the trait implementations
10//! 2. Traits provide a cleaner, more idiomatic API
11//! 3. Inlining enables better optimization opportunities
12
13use proc_macro2::TokenStream;
14use quote::quote;
15
16use crate::algebra::{Algebra, ProductTable};
17use crate::spec::AlgebraSpec;
18
19/// Generates the products.rs file.
20///
21/// Note: This generator now produces an essentially empty file.
22/// All product implementations are in traits.rs.
23pub struct ProductGenerator<'a> {
24    /// The algebra specification.
25    spec: &'a AlgebraSpec,
26}
27
28impl<'a> ProductGenerator<'a> {
29    /// Creates a new product generator.
30    pub fn new(spec: &'a AlgebraSpec, _algebra: &'a Algebra, _table: ProductTable) -> Self {
31        Self { spec }
32    }
33
34    /// Generates the complete products.rs file.
35    ///
36    /// Note: As of PRD-24, all product implementations are inlined into trait
37    /// implementations in traits.rs. This file is now empty except for the header.
38    pub fn generate_products_file(&self) -> TokenStream {
39        let header = self.generate_header();
40
41        quote! {
42            #header
43
44            // ============================================================
45            // All product implementations are in traits.rs
46            // ============================================================
47            //
48            // Products are implemented as trait methods:
49            // - Wedge::wedge()         - exterior/wedge product
50            // - Antiwedge::antiwedge() - regressive/meet product
51            // - Inner::inner()         - symmetric inner product
52            // - LeftContract::left_contract()   - left contraction
53            // - RightContract::right_contract() - right contraction
54            // - Dot::dot()             - metric dot product
55            // - Antidot::antidot()     - metric antidot product
56            // - ScalarProduct::scalar_product() - grade-0 projection
57            // - BulkContract::bulk_contract()   - a ∨ b★
58            // - WeightContract::weight_contract() - a ∨ b☆
59            // - BulkExpand::bulk_expand()       - a ∧ b★
60            // - WeightExpand::weight_expand()   - a ∧ b☆
61            // - Sandwich::sandwich()   - v × x × rev(v)
62            // - Antisandwich::antisandwich() - v ⊛ x ⊛ antirev(v)
63            // - Reverse::reverse()     - grade reversal
64            // - Antireverse::antireverse() - antigrade reversal
65            // - RightComplement::right_complement() - Hodge dual
66        }
67    }
68
69    /// Generates the file header.
70    fn generate_header(&self) -> TokenStream {
71        let name = &self.spec.name;
72
73        let header_doc = format!(
74            r#"//! Products module for the {} algebra.
75//!
76//! All product implementations are in the traits module.
77//! See `traits.rs` for the trait implementations.
78//!
79//! This file is auto-generated by clifford-codegen. Do not edit manually."#,
80            name
81        );
82
83        header_doc.parse().unwrap_or_else(|_| quote! {})
84    }
85}