Skip to content
PT

Static copy

Copied from docs/en/decisions/adp-002.md in https://github.com/poppy-team/aipo-lang (MIT). Pinned to revision ce47c4e070404fc41722ccd8e2b7b808b99062a8, blob 93c034ddbb12d0c7c9345ff225df6d14b10cbe62. The source repository remains canonical; this copy is refreshed through a sync pull request, not live.

ADP-002 — Construction Hooks and Runtime Contracts ​

  • Status: Approved & Implemented
  • Deciders: Poppy Team
  • Phase: Wave 1 (P00-G13 / P00-G14)

Context ​

The language needed a unified, low-cognitive-overhead mechanism to validate struct states without requiring developers to write verbose boilerplate constructors or artificial getters and setters.


Decisions Taken ​

  1. init() Hook:

    • Executes immediately after struct field assignment during instantiation.
    • Used for structural validation, normalization, and rejecting invalid initial states with fail.
  2. invariant() Invariants:

    • Declared directly in the struct body.
    • Evaluated upon creation and on all stable field mutations.
    • Predicate failures immediately reject the mutation.
  3. Transactional Rollback inside attempt:

    • When mutations occur inside an attempt block, the VM maintains an in-memory rollback journal.
    • Any failure automatically restores pre-block state, guaranteeing atomic consistency.