Skip to content

feat(laurel): Add Seq<T> and Array<T> types with sequence/array operations#787

Closed
fabiomadge wants to merge 3 commits intostrata-org:mainfrom
fabiomadge:feat/laurel-sequences-v2
Closed

feat(laurel): Add Seq<T> and Array<T> types with sequence/array operations#787
fabiomadge wants to merge 3 commits intostrata-org:mainfrom
fabiomadge:feat/laurel-sequences-v2

Conversation

@fabiomadge
Copy link
Copy Markdown
Contributor

Summary

Adds immutable sequences and mutable heap-backed arrays to Laurel with end-to-end SMT verification.

Sequences (immutable value types)

  • TSeq variant in HighType; Seq<T> grammar syntax
  • [1, 2, 3] sequence literals (desugared to Sequence.build chains)
  • s[i] subscript read and s[i := v] functional update
  • 9 external Sequence.* functions (empty, build, select, update, length, append, contains, take, drop)
  • Works with Seq<int>, Seq<bool>, Seq<Seq<int>>, Seq<Composite>

Arrays (mutable heap-backed)

  • TArray variant in HighType; Array<T> grammar syntax
  • a[i] read and a[i] := v write with heap semantics
  • Aliasing: b := a; b[0] := 99; assert a[0] == 99
  • Seq literal to Array conversion: var a: Array<int> := [1, 2, 3]
  • Synthetic Array composite with $data field, BoxSeq wrapping
  • Array<T> recognized as composite in modifies clauses
  • Currently supports Array<int>; other element types require heap model changes

Shared infrastructure

  • Subscript AST node with SubscriptElim type-aware pass (total, not partial)
  • Generic fix for 0-ary op formatting in Core VC output
  • Fix: AstNode.getType for .staticProcedure
  • Fix: targetTypeName for TArray types

Known limitations

  • Array<bool>, Array<Seq<T>>, Array<Array<T>> don't work due to monomorphic Box/heap model
  • Inter-procedural array contracts require bounds preconditions (by design — matches Sequence axiom guards)

…tions

Sequences (immutable value types):
- TSeq variant in HighType; Seq<T> grammar syntax
- [1, 2, 3] sequence literals (desugared to Sequence.build chains)
- s[i] subscript read and s[i := v] functional update
- 9 external Sequence.* functions (empty, build, select, update, length, append, contains, take, drop)
- Seq<T> translates to Core's Sequence type; SMT verification works end-to-end

Arrays (mutable heap-backed):
- TArray variant in HighType; Array<T> grammar syntax
- a[i] read and a[i] := v write with heap semantics
- Aliasing: b := a; b[0] := 99; assert a[0] == 99
- Seq literal to Array conversion: var a: Array<int> := [1, 2, 3]
- Synthetic Array composite with $data: Seq<int> field
- Box wrapping for Seq-typed fields (BoxSeq/Box..SeqVal!)
- Array<T> recognized as composite in modifies clauses

Shared infrastructure:
- Subscript AST node with SubscriptElim type-aware pass
- SubscriptElim dispatches Seq subscripts to StaticCall, Array subscripts to FieldSelect + Sequence.*
- Generic fix for 0-ary op formatting in Core VC output
- Fix: AstNode.getType for .staticProcedure
- Fix: targetTypeName for Applied/TArray types
Bug fixes:
- highEq: add TSeq/TArray cases for type equality
- collectTypeRefs: add TSeq/TArray for datatype SCC ordering
- computeExprType: derive element type for Subscript nodes
- elimProcedure: transform invokeOn expressions
- subscriptElim: transform instance procedures in composites
- classifyModifiesHighType: treat TArray as composite for modifies

Code quality:
- Centralize Sequence operation names in SeqOp namespace
- Centralize Array composite name in arrayCompositeName
- Clean up handleZeroaryOps with zeroAryBuiltinFunctions from Factory

Test coverage:
- T18_Sequences: append, contains, take, drop tests
- T19_Arrays: loop with invariants, inter-procedural with modifies,
  Sequence.append on arrays
- Remove implicit Sequence.* coercion on Arrays (redirectArrayArgs)
- Add Array.length as a declared function in CoreDefinitionsForLaurel
- SubscriptElim rewrites Array.length(a) → Sequence.length(a.$data)
- Add SeqOp.length constant, arrayLengthName constant
- Update T19_Arrays tests to use Array.length, drop appendOnArrays
@fabiomadge fabiomadge force-pushed the feat/laurel-sequences-v2 branch from 6365c90 to 74c59d4 Compare April 9, 2026 15:57
@github-actions
Copy link
Copy Markdown

👋 Hi, @fabiomadge,
I detected conflicts against the base branch 🙊
You'll want to sync 🔄 your branch with upstream!


This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant