Summary
Analysis of the syster-base crate reveals several cross-cutting concerns and duplications that should be consolidated for better maintainability.
Identified Issues
1. Duplicate Type Definitions
Position/Span duplication:
core::span::Position and semantic::types::diagnostic::Position - SAME type defined twice
core::span::Span and semantic::types::diagnostic::Range - SAME concept with different names
core::span::SymbolReference and semantic::symbol_table::symbol::SymbolReference - SAME type defined twice
Recommendation: Consolidate all position/span types into core::span and re-export from semantic where needed. The Range type should be an alias or import from Span.
2. Parallel KerML/SysML Implementations
The following files have nearly identical structure with only language-specific types swapped:
| SysML |
KerML |
Lines |
Similarity |
| adapters/sysml/folding.rs |
adapters/kerml/folding.rs |
83/82 |
~95% |
| adapters/sysml/selection.rs |
adapters/kerml/selection.rs |
130/127 |
~90% |
| adapters/sysml/inlay_hints.rs |
adapters/kerml/inlay_hints.rs |
137/109 |
~85% |
| adapters/sysml/helpers.rs |
adapters/kerml/helpers.rs |
137/34 |
~70% |
| adapters/sysml/visitors.rs |
adapters/kerml/visitors.rs |
285/226 |
~80% |
| adapters/sysml/validator.rs |
adapters/kerml/validator.rs |
109/47 |
~60% |
| syntax/sysml/parser.rs |
syntax/kerml/parser.rs |
157/63 |
~70% |
| sysml_adapter.rs |
kerml_adapter.rs |
identical structs |
~100% |
Recommendation: Create a generic/trait-based approach:
- Define a
LanguageAdapter<T> trait
- Create shared implementations with type parameters
- Reduce boilerplate while maintaining type safety
3. File I/O Scattered Across Modules
File loading concerns are spread across:
core::file_io - low-level file operations
project::file_loader - re-exports from core + adds collection
syntax::parser - uses file_io for parsing
Recommendation: Clarify the layers:
core::file_io - pure file operations (no language awareness)
syntax::parser - language-aware parsing (owns parse dispatch)
project::file_loader - higher-level workspace operations (remove re-exports)
4. Error Types Fragmentation
Error-related types are scattered:
core::error_codes - error code constants
core::parse_result - ParseError, ParseErrorKind
semantic::types::error - SemanticError, SemanticErrorKind
semantic::types::diagnostic - Diagnostic, Severity
Recommendation: Consider a unified error hierarchy in core::errors:
core::errors/
codes.rs # Error code constants
parse.rs # ParseError
semantic.rs # SemanticError
diagnostic.rs # Diagnostic (unified format)
5. Re-export Chains
Several modules have long re-export chains that obscure the source:
project::mod.rs re-exports from core
semantic::mod.rs has 15+ re-exports
- This creates confusion about where types are defined
Recommendation:
- Document the canonical import path for each type
- Reduce re-exports to only the most common use cases
- Use explicit paths in internal code
Proposed Consolidation
Phase 1: Type Deduplication (Low Risk)
- Remove
semantic::types::diagnostic::Position - use core::Position
- Alias
Range to Span or unify them
- Remove duplicate
SymbolReference
Phase 2: Adapter Generalization (Medium Risk)
- Create
LanguageAdapter<T> trait
- Create
FoldingExtractor<T> trait
- Create
SelectionExtractor<T> trait
- Implement for both SysML and KerML
Phase 3: Module Restructuring (Higher Risk)
- Consolidate error types
- Simplify file_loader module
- Reduce re-export chains
Success Criteria
Related
Summary
Analysis of the syster-base crate reveals several cross-cutting concerns and duplications that should be consolidated for better maintainability.
Identified Issues
1. Duplicate Type Definitions
Position/Span duplication:
core::span::Positionandsemantic::types::diagnostic::Position- SAME type defined twicecore::span::Spanandsemantic::types::diagnostic::Range- SAME concept with different namescore::span::SymbolReferenceandsemantic::symbol_table::symbol::SymbolReference- SAME type defined twiceRecommendation: Consolidate all position/span types into
core::spanand re-export from semantic where needed. TheRangetype should be an alias or import fromSpan.2. Parallel KerML/SysML Implementations
The following files have nearly identical structure with only language-specific types swapped:
Recommendation: Create a generic/trait-based approach:
LanguageAdapter<T>trait3. File I/O Scattered Across Modules
File loading concerns are spread across:
core::file_io- low-level file operationsproject::file_loader- re-exports from core + adds collectionsyntax::parser- uses file_io for parsingRecommendation: Clarify the layers:
core::file_io- pure file operations (no language awareness)syntax::parser- language-aware parsing (owns parse dispatch)project::file_loader- higher-level workspace operations (remove re-exports)4. Error Types Fragmentation
Error-related types are scattered:
core::error_codes- error code constantscore::parse_result- ParseError, ParseErrorKindsemantic::types::error- SemanticError, SemanticErrorKindsemantic::types::diagnostic- Diagnostic, SeverityRecommendation: Consider a unified error hierarchy in
core::errors:5. Re-export Chains
Several modules have long re-export chains that obscure the source:
project::mod.rsre-exports fromcoresemantic::mod.rshas 15+ re-exportsRecommendation:
Proposed Consolidation
Phase 1: Type Deduplication (Low Risk)
semantic::types::diagnostic::Position- usecore::PositionRangetoSpanor unify themSymbolReferencePhase 2: Adapter Generalization (Medium Risk)
LanguageAdapter<T>traitFoldingExtractor<T>traitSelectionExtractor<T>traitPhase 3: Module Restructuring (Higher Risk)
Success Criteria
cargo clippypasses without dead_code warningsRelated