Skip to content

Laurel: add constrained type support#505

Draft
fabiomadge wants to merge 1 commit intomainfrom
fabiomadge/constrained-types
Draft

Laurel: add constrained type support#505
fabiomadge wants to merge 1 commit intomainfrom
fabiomadge/constrained-types

Conversation

@fabiomadge
Copy link
Contributor

@fabiomadge fabiomadge commented Mar 3, 2026

Adds constrained types to Laurel via a Laurel-to-Laurel elimination pass that inserts verification checks at type boundaries.

Syntax

constrained nat = x: int where x >= 0 witness 0
constrained posnat = x: nat where x > 0 witness 1

How it works

The pass inserts checks where constrained types cross boundaries:

  • Receiving a value (procedure inputs, call return values): assume the constraint
  • Providing a value (assignments, arguments, return values): assert the constraint

All constrained type references are then resolved to their base types. The Core translator sees only base types and regular assert/assume — no translator changes needed.

Changes

  • ConstrainedTypeElim.lean — the elimination pass
  • LaurelGrammar.st — constrained type syntax
  • ConcreteToAbstractTreeTranslator.lean — parser
  • LaurelToCoreTranslator.lean — pipeline wiring (2 lines)
  • T09_ConstrainedTypes.lean — 11 test procedures

Known limitations

  • Witness is parsed but not used (we don't rely on constrained types being inhabited)
  • Multi-target assignments not yet handled
  • Quantifier constraint injection is a follow-up

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@fabiomadge fabiomadge force-pushed the fabiomadge/constrained-types branch from 1c60132 to b2d41d6 Compare March 3, 2026 07:41
@fabiomadge fabiomadge force-pushed the fabiomadge/early-return-soundness branch 3 times, most recently from 579e349 to dd1139d Compare March 4, 2026 05:41
Base automatically changed from fabiomadge/early-return-soundness to main March 5, 2026 15:37
@fabiomadge fabiomadge force-pushed the fabiomadge/constrained-types branch from b2d41d6 to 5d83688 Compare March 6, 2026 00:42
A Laurel-to-Laurel elimination pass (ConstrainedTypeElim.lean) that:
- Inserts assume for inputs and call return values
- Inserts assert for assignments, variable init, and call arguments
- Resolves all constrained type references to base types

No Core translator changes needed.

Grammar: constrained type syntax
Parser: parseConstrainedType + topLevelConstrainedType
Test: T09_ConstrainedTypes — 11 test procedures
@fabiomadge fabiomadge force-pushed the fabiomadge/constrained-types branch from 5d83688 to c219ed8 Compare March 6, 2026 00:54
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

Successfully merging this pull request may close these issues.

1 participant