anise icon indicating copy to clipboard operation
anise copied to clipboard

Types for Parsing Invariants

Open jonathan-g-davis opened this issue 11 months ago • 1 comments

High level description

ANISE currently contains instances where unreachable panics occur within match statements, as well as cases where malformed structs may cause panics during type conversions. To improve safety and robustness, this issue proposes introducing new struct and enum types that enforce invariants at the type level, preventing invalid states from being representable.

By encoding constraints directly in the type system, we can eliminate unreachable panics and reduce the risk of runtime failures due to malformed data.

Requirements

  • Prevent parsing from creating structs with invalid internal state
  • Replace unstructured types with domain-specific types

Test plans

  • Include regression tests that reproduce original error
  • Ensure that regression tests pass following implementation

Design

  • Replace match arms with unreachable statements with exhausting enums
  • Use the newtype pattern to prevent invalid data from being constructed
  • Use TryFrom to gracefully handle fallible conversions
  • Where necessary, annotate enums as non_exhaustive to prevent introducing breaking changes

jonathan-g-davis avatar Mar 16 '25 13:03 jonathan-g-davis

Thanks for creating all of these issues Johnathan, I think they're spot-on. One thing to keep in mind is the Python interface, which doesn't support the same level of generics as the Rust code. Let me know if the documentation needs clarifications on how to set up the Rust or Python development environments.

ChristopherRabotin avatar Mar 17 '25 04:03 ChristopherRabotin