Skip to content

Commit

Permalink
Simplified and more basic fixpoint iteration (#1810)
Browse files Browse the repository at this point in the history
* Try a new eog iteration

* Small changes

* remove comment

* small cleanup

* Cleanup

* Test PowersetLattice

* MapLattice test

* Comment

* Test tuple lattice

* Test triple lattice

* More equals

* Update MapLattice iteration

* Formatting

* Fix bug in comparison

* Remove debug things

* Fix cpg core

* Reduce heap size again

* Rename stuff

* Explain and use the typealiases

* Update description

* Try more redesign

* provide bottom element

* Try to test

* Some fixes, transfer tests

* fix broken equals check

* More redesign

* Some more documentation

* More open, minor fix

* Fix bug with element set

* Remove obsolete files

* Improved performance options in identity set

* Improved performance of comparisons and lub

* Reduce amount of duplicate code

* Adapt test to less copying of objects

* IdentitySet coverage

* Lattice compare coverage

* More coverage of PowersetLattice

* powerset lattice glb

* MapLattice glb

* Test coverage

* Rename and refactor

* Some more documentation

* Nicer order
  • Loading branch information
KuechA authored Feb 5, 2025
1 parent 3236e15 commit dbf050d
Show file tree
Hide file tree
Showing 5 changed files with 938 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import de.fraunhofer.aisec.cpg.graph.edges.flows.EvaluationOrder
import de.fraunhofer.aisec.cpg.graph.statements.IfStatement
import de.fraunhofer.aisec.cpg.graph.statements.WhileStatement
import de.fraunhofer.aisec.cpg.helpers.*
import de.fraunhofer.aisec.cpg.helpers.LatticeElement
import de.fraunhofer.aisec.cpg.passes.configuration.DependsOn

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,20 @@ import java.util.concurrent.atomic.AtomicInteger
* as [Node.hashCode] or even worse [Node.equals], if the hashcode is the same. This can potentially
* be very resource-intensive if nodes are very similar but not the *same*, in a work-list however
* we only want just to avoid to place the exact node twice.
*
* The magic size of 16 comes from the implementation of Java and is randomly chosen. The
* [expectedMaxSize] should be 2^n but this will be enforced internally anyway.
*/
open class IdentitySet<T> : MutableSet<T> {
open class IdentitySet<T>(expectedMaxSize: Int = 16) : MutableSet<T> {
/**
* The backing hashmap for our set. The [IdentityHashMap] offers reference-equality for keys and
* values. In this case we use it to determine, if a node is already in our set or not. The
* value of the map is not used and is always true. A [Boolean] is used because it seems to be
* the smallest data type possible.
*
* The map is twice the [expectedMaxSize] to avoid resizing too often which is expensive.
*/
private val map: IdentityHashMap<T, Int> = IdentityHashMap()
private val map: IdentityHashMap<T, Int> = IdentityHashMap(expectedMaxSize * 2)
private val counter = AtomicInteger()

override operator fun contains(element: T): Boolean {
Expand All @@ -60,9 +65,8 @@ open class IdentitySet<T> : MutableSet<T> {
}

override fun equals(other: Any?): Boolean {
if (other !is IdentitySet<*>) return false
val otherSet = other as? IdentitySet<*>
return otherSet != null && this.containsAll(otherSet) && otherSet.containsAll(this)
if (other !is Set<*>) return false
return this.size == other.size && this.containsAll(other)
}

override fun add(element: T): Boolean {
Expand Down Expand Up @@ -141,21 +145,21 @@ open class IdentitySet<T> : MutableSet<T> {
}

fun <T> identitySetOf(vararg elements: T): IdentitySet<T> {
val set = IdentitySet<T>()
val set = IdentitySet<T>(elements.size)
for (element in elements) set.add(element)

return set
}

infix fun <T> IdentitySet<T>.union(other: Iterable<T>): IdentitySet<T> {
val set = identitySetOf<T>()
val set = IdentitySet<T>(this.size * 2)
set += this
set += other
return set
}

fun <T> Collection<T>.toIdentitySet(): IdentitySet<T> {
val set = identitySetOf<T>()
val set = IdentitySet<T>(this.size)
set += this
return set
}
Loading

0 comments on commit dbf050d

Please sign in to comment.