Skip to content

Better ImmutableList #3816

Open
wadoon wants to merge 8 commits into
mainfrom
weigl/ilist
Open

Better ImmutableList #3816
wadoon wants to merge 8 commits into
mainfrom
weigl/ilist

Conversation

@wadoon

@wadoon wadoon commented May 16, 2026

Copy link
Copy Markdown
Member

Issue

We currently have two implementations of immutable sequences with ImmutableList and ImmutableArray. This requires conversions sometimes, but mainly it leads to confusion about which implementation should be taken.

Intended Change

This PR unifies everything under ImmutableList.

There are two fresh children classes: ImmutableListArray and ImmutableListList. Both behave like ImmutableList, but use different data storage (T[] or List<T>) in the background.

Some operations from ImmutableList are quite expensive on this data storages, e.g., tail() or reverse(). Therefore, I introduced views that emulate these operations, without copying the data, i.e.,

  • ImmutableListConcat as ImmutableList#prepend(other)
  • ImmutableListReverse for ImmutableList#reverse()
  • ImmutableListSubList for ImmutableList#take(n), ImmutableList#skip(n), ImmutableList#tail()

These operations are now in $O(1)$.

The class ImmutableArray should be considered obsolete.

Developers should use only the methods and functions of ImmutableList. Implementation may override them if there is a faster implementation, e.g, tail() on ImmutableSList.

Plan

  • Renaming ImmutableSList to ImmutableList.
  • More, even more test cases, coverage is not so bad, but could be better.
  • Update the JavaDoc documentation

Type of pull request

  • Refactoring (behaviour should not change or only minimally change)

  • New feature (non-breaking change which adds functionality)

  • There are changes to the (Java) code

Ensuring quality

  • I made sure that introduced/changed code is well documented (javadoc and inline comments).

@wadoon wadoon requested a review from unp1 May 16, 2026 14:55
@wadoon wadoon self-assigned this May 16, 2026
@wadoon wadoon added the Java Pull requests that update Java code label May 16, 2026
@wadoon wadoon added this to the v3.1.0 milestone May 16, 2026
@wadoon wadoon marked this pull request as ready for review May 18, 2026 20:34
@wadoon

wadoon commented May 18, 2026

Copy link
Copy Markdown
Member Author

There is one stupid error in DependencyTracker happening. Currently unclear where it comes from.

@wadoon wadoon force-pushed the weigl/ilist branch 2 times, most recently from 55024a9 to c08f219 Compare June 13, 2026 14:29

@Drodt Drodt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work! Do you have any idea why tests are failing?

Comment thread key.core/src/main/java/de/uka/ilkd/key/proof/Proof.java
Comment thread key.core/src/main/java/de/uka/ilkd/key/rule/match/vm/VMTacletMatcher.java Outdated
Comment thread key.core/src/main/java/de/uka/ilkd/key/rule/LoopApplyHeadRule.java
Comment thread key.core/src/main/java/de/uka/ilkd/key/rule/OneStepSimplifier.java
Comment thread key.util/src/main/java/org/key_project/util/collection/DefaultImmutableSet.java Outdated
Comment thread key.util/src/main/java/org/key_project/util/collection/ImmutableList.java Outdated

@Drodt Drodt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work! Do you have any idea why tests are failing?

Comment thread key.util/src/main/java/org/key_project/util/collection/ImmutableSLList.java Outdated
Comment thread key.util/src/main/java/org/key_project/util/collection/ImmutableListSubList.java Outdated
wadoon added 6 commits June 19, 2026 09:47
# Conflicts:
#	key.core/src/main/java/de/uka/ilkd/key/proof/init/InitConfig.java
#	key.core/src/main/java/de/uka/ilkd/key/taclettranslation/lemma/TacletLoader.java

# Conflicts:
#	key.core/src/main/java/de/uka/ilkd/key/nparser/builder/TacletPBuilder.java
#	key.core/src/main/java/de/uka/ilkd/key/rule/tacletbuilder/TacletBuilder.java
#	key.core/src/main/java/de/uka/ilkd/key/rule/tacletbuilder/TacletGenerator.java
@wadoon

wadoon commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

Thanks for the help. The tests is green now. The null pointer warning will be fixed.

@WolframPfeifer

Copy link
Copy Markdown
Member

Can we stay with Java's name scheme and call it ImmutableArrayList and ImmutableLinkedList? In particular ListList, but also ListArray really sound wrong.

@wadoon

wadoon commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

Can we stay with Java's name scheme and call it ImmutableArrayList and ImmutableLinkedList? In particular, ListList, but also ListArray really sound wrong.

It depends on how you read this. My reading is: ImmutableList backed by an array or by a java.util.List. ImmutableArrayList could lead you on a false track, that there is an java.util.ArrayList as the internal data structure, which is not the case.

The main idea of this PR is to get rid of ImmutableArray (which have nearly the same interface as ImmutableSLList). In many cases, ImmutableArray has memory and performance advantages, but some operations of ImmutableList are expensive on arrays (e.g., tail()).

To tackle this, the PR also contains operational wrappers for ImmutableList, providing views on lists, e.g., tail() resolves into new ImmutableListSlice(old, 1) which just hides the first element. No lists are copied.

@mattulbrich

Copy link
Copy Markdown
Member

Nice idea! Appears to make a lot of sense indeed!
I agreed with Wolfram's impression of the strange names, but I can now also see why you named them like this.
Still: Strange names and people will be puzzled at first contact.

So: Could you or Claude (& you checking) please provide a lot of documentation on the public interface, the static methods and the new classes?

Perhaps you can also mention there: Why does ImultabeListList exist? Can the array class not do the same job?

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

Labels

Java Pull requests that update Java code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants