Skip to content

Types for Parsing Invariants #396

Open
@jonathan-g-davis

Description

@jonathan-g-davis

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions