Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types for Parsing Invariants #396

Open
jonathan-g-davis opened this issue Mar 16, 2025 · 1 comment
Open

Types for Parsing Invariants #396

jonathan-g-davis opened this issue Mar 16, 2025 · 1 comment

Comments

@jonathan-g-davis
Copy link

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
@ChristopherRabotin
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants