Skip to content

Iterator infrastructure for collection models: snapshot iterators + generic-element annotation - #42

Open
tautschnig wants to merge 1 commit into
masterfrom
iterator-infrastructure
Open

Iterator infrastructure for collection models: snapshot iterators + generic-element annotation#42
tautschnig wants to merge 1 commit into
masterfrom
iterator-infrastructure

Conversation

@tautschnig

Copy link
Copy Markdown
Collaborator

Three top-level org.cprover support classes for the collection models' iterator()/enhanced-for support:

  • CProverArrayLikeIterator: generic snapshot iterator over an Object[]-backed collection; captures (storage, size) at iterator() time. Top-level rather than an inner class deliberately: a non-static inner class's implicit this$0 creates a Collection <-> Iterator lazy-class-loading cycle that aborts JBMC's nondet initialisation of abstract collection parameters. The class javadoc carries the full design rationale (snapshot-vs-fail-fast trade-off, iteration-order conformance, and the documented opt-in future paths for CME modelling and Iterator.remove()).
  • CProverMapEntry<K, V>: read-only snapshot Map.Entry for entrySet() views of parallel-array map models.
  • @CProverGenericArrayElement: marks an Object[] field as holding a model class's generic-parameter elements, so JBMC's nondet object factory can specialise the element type.

These are inert until collection models reference them; landing them separately keeps the model changes reviewable.

CopilotAI review requested due to automatic review settings July 28, 2026 23:06

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds new org.cprover infrastructure types intended to support iterator/enhanced-for modeling in JBMC collection models and to improve nondet initialization of generic-typed Object[] backing arrays.

Changes:

  • Introduces CProverArrayLikeIterator<E>: a snapshot iterator over an Object[] + logical size.
  • Introduces CProverMapEntry<K,V>: a snapshot/read-only Map.Entry implementation for map entry-set views.
  • Introduces @CProverGenericArrayElement: runtime field annotation to mark Object[] fields as holding a model class’s generic-parameter elements.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

FileDescription
src/main/java/org/cprover/CProverArrayLikeIterator.javaNew snapshot iterator utility for array-backed models (currently not yet wired into existing models).
src/main/java/org/cprover/CProverMapEntry.javaNew snapshot Map.Entry implementation for map entry iteration/views.
src/main/java/org/cprover/CProverGenericArrayElement.javaNew runtime annotation to convey generic element types for Object[] backing arrays.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadsrc/main/java/org/cprover/CProverMapEntry.java
Comment threadsrc/main/java/org/cprover/CProverGenericArrayElement.java Outdated
Comment threadsrc/main/java/org/cprover/CProverArrayLikeIterator.java Outdated
Comment threadsrc/main/java/org/cprover/CProverArrayLikeIterator.java
Comment threadsrc/main/java/org/cprover/CProverMapEntry.java Outdated
…eneric-element annotation
Three top-level org.cprover support classes for collection models'
iterator()/enhanced-for support. They are inert until collection models
reference them (none in this repo do yet -- the javadoc describes intended
usage); landing them separately keeps the model changes reviewable.
- CProverArrayLikeIterator<E>: generic snapshot iterator over an
Object[]-backed collection; captures (storage, size) at iterator()
time. Top-level rather than an inner class deliberately: a non-static
inner class's implicit this$0 creates a Collection <-> Iterator
lazy-class-loading cycle that aborts JBMC's nondet initialisation of
abstract collection parameters. The class javadoc carries the full
design rationale (snapshot-vs-fail-fast trade-off, iteration-order
conformance, and the documented opt-in future paths for CME modelling
and Iterator.remove()).
next() past the end throws NoSuchElementException per the JDK contract.
An assume() guard on the precondition would be unsound here: it would
prune exactly the executions in which target code over-iterates,
hiding those bugs behind vacuously-passing paths; modelling the throw
keeps them observable with the correct exception type.
- CProverMapEntry<K, V>: read-only snapshot Map.Entry for entrySet()
views of parallel-array map models. Deliberately final; entry-driven
mutation calls for a separate write-through entry class (documented),
not subclassing.
- @CProverGenericArrayElement: marks an Object[] field as holding a
model class's generic-parameter elements, so JBMC's nondet object
factory can specialise the element type.
Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Sign up for freeto 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.

2 participants

@tautschnig