Expand description
§gaia-types Maintenance Documentation
§Project Overview
gaia-types is the core type system library for the Gaia project, providing foundational functionalities such as unified error handling, architecture abstractions, and compilation target definitions. As a basic component of the entire toolchain, this library uses a zero-dependency design to ensure stability and portability.
§Architecture Design
§Core Design Principles
- Zero-Dependency Core: Core functions do not depend on external crates, ensuring a minimal dependency tree.
- Unified Error Model: Provides a consistent error handling interface with support for detailed error diagnostics.
- Architecture Abstraction: Supports unified abstraction for multiple architectures, facilitating cross-platform development.
- Type-Safe: Leverages the Rust type system to prevent common programming errors.
- Performance-First: Zero allocations on critical paths, prioritizing stack-based data structures.
§Tech Stack
- Language: Rust (Edition 2024)
- Features: Uses
#![feature(try_trait_v2)]for advanced error handling. - Serialization: Optional serde support (controlled via features).
- Documentation: Complete documentation test coverage.
§Module Architecture
§Module Responsibility Division
§1. errors Module - Unified Error Handling System
- Responsibility: Provides unified error types and diagnostic information.
- Key Types:
GaiaError,GaiaErrorKind,GaiaDiagnostics - Design Considerations:
- Uses
Boxwrapping to reduce enum size. - Supports structured error information.
- Integrates with the tracing logging system.
- Provides detailed source code location information.
- Uses
§2. helpers Module - Architecture and Target Abstraction
- Responsibility: Defines supported architectures and compilation targets.
- Key Types:
Architecture,CompilationTarget,AbiCompatible,ApiCompatible - Design Considerations:
- Supports physical architectures (x86, ARM, RISC-V, etc.).
- Supports virtual machine architectures (JVM, CLR).
- Provides architecture compatibility checks.
- Serialization support for easy configuration storage.
§3. reader Module - Binary Reading Abstraction
- Responsibility: Provides a unified interface for reading binary data.
- Key Types:
BinaryReader,SourceLocation,SourcePosition - Design Considerations:
- Supports both big-endian and little-endian byte orders.
- Provides detailed error location information.
- Zero-copy design avoids unnecessary memory allocations.
§4. writer Module - Text Writing Abstraction
- Responsibility: Provides a unified interface for text output.
- Key Types:
TextWriter - Design Considerations:
- Supports multiple output formats.
- Provides formatting options.
- Error handling integration.
§5. lexer Module - Lexical Analysis Foundation
- Responsibility: Provides general lexical analysis functionality.
- Design Considerations:
- Supports multiple token types.
- Provides detailed lexical error information.
§6. parser Module - Syntax Analysis Foundation
- Responsibility: Provides general syntax analysis functionality.
- Design Considerations:
- Recursive descent parser.
- Error recovery mechanism.
- Detailed syntax error information.
§7. assembler Module - Assembler Foundation
- Responsibility: Provides basic functionality related to assembly.
- Key Types:
BinaryWriter - Design Considerations:
- Supports multiple output formats.
- Provides assembly error handling.
§Core Types Details
§Error Handling System
§GaiaError Structure
Provides a unified error handling interface, including error levels and specific error types.
§GaiaErrorKind Enum
Includes all possible error types: syntax errors, IO errors, architecture errors, compilation errors, configuration errors, etc.
§Architecture Abstraction System
§Architecture Enum
Supports various physical architectures (x86, ARM, RISC-V, MIPS, WebAssembly) and virtual machine architectures (JVM, CLR).
§CompilationTarget Structure
Defines the compilation target, including information such as architecture, ABI, and API versions.
§Development Environment Configuration
§Required Tools
- Rust 1.70+ (recommended to manage via rustup)
- Cargo (installed with Rust)
§Common Commands
cargo build- Build the projectcargo test- Run testscargo test --doc- Run documentation testscargo doc --open- Generate documentationcargo clippy- Check code quality
§Key Design Decisions
§Error Handling Strategy
- Unified Error Type: All errors are represented by
GaiaError. - Structured Error Information: Provides machine-readable error details.
- Source Code Location: Every error includes detailed source code location information.
- Error Levels: Supports different levels such as error, warning, and information.
§Architecture Abstraction Strategy
- Enum Representation: Uses enums to ensure the completeness of architecture types.
- Display Implementation: Provides human-readable architecture names.
- Serialization Support: Facilitates configuration file storage and transmission.
- Extensibility: Supports custom architecture types.
§Performance Optimization Considerations
- Zero-Allocation Design: Avoids heap allocations on core paths.
- Box Wrapping: Uses Box to reduce enum size and improve cache efficiency.
- Inline Optimization: Critical functions use inline attributes.
§Maintenance Guide
§Process for Adding New Error Types
- Error Research: Analyze the scenarios and scope of the error.
- Type Definition: Add new error variants to
GaiaErrorKind. - Constructor Functions: Create convenient constructors for new error types.
- Error Conversion: Implement conversion from other error types.
- Display Implementation: Provide human-readable error messages.
- Test Coverage: Add unit tests and documentation tests.
§Process for Adding New Architecture Support
- Architecture Research: Confirm technical specifications and ABI of the new architecture.
- Enum Extension: Add the new architecture to the
Architectureenum. - Display Implementation: Update the
Displaytrait implementation. - Compatibility Check: Add architecture compatibility verification logic.
- Serialization Support: Ensure the new architecture can be correctly serialized.
- Documentation Update: Update relevant documentation and examples.
§Common Maintenance Pitfalls
- Error Size: Be careful to control the size of error types to avoid excessive stack allocation.
- Architecture Consistency: Ensure all architecture-related code correctly handles new architectures.
- Backward Compatibility: Consider serialization compatibility when modifying enums.
- Documentation Sync: Update documentation tests promptly after code changes.
§Detailed Module Documentation
Each sub-module contains specific maintenance documentation:
errors/readme.md- Detailed design of the error handling system.helpers/readme.md- Detailed explanation of architecture abstraction.reader/readme.md- Implementation details of binary reading.writer/readme.md- Implementation details of text writing.
§Release Process
§Version Management
- Follow Semantic Versioning (SemVer).
- Major version: Incompatible API changes.
- Minor version: Downward-compatible new functionality.
- Patch version: Downward-compatible bug fixes.
§Pre-release Checklist
-
All tests passed (
cargo test) -
Documentation tests passed (
cargo test --doc) -
No warnings (
cargo build) -
Documentation complete (
cargo doc) -
Version number updated (
Cargo.toml) - CHANGELOG updated
Re-exports§
pub use crate::source::QualifiedName;pub use crate::source::SourceLocation;pub use crate::source::SourcePosition;pub use crate::writer::TextWriter;
Modules§
- helpers
- Gaia Types - Helpers Module
- neural
- Neural network operator definitions
- source
- Source code location and position tracking.
- writer
- Text writing utilities.
Structs§
- Gaia
Diagnostics - Gaia diagnostics result container
- Gaia
Error - Gaia error type, wrapping a specific error kind GaiaErrorKind
Enums§
- Gaia
Error Kind - Gaia error kind enum, defining all possible error types
Type Aliases§
- Result
- Result type for this crate, using GaiaError as the error type