From 0adc0383c4a80f44cc524cd91264769b6dfba882 Mon Sep 17 00:00:00 2001 From: Alexander Kuechler Date: Tue, 12 Nov 2024 09:21:52 +0100 Subject: [PATCH 1/3] More equals --- .../aisec/cpg/helpers/BasicLatticesTest.kt | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/helpers/BasicLatticesTest.kt b/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/helpers/BasicLatticesTest.kt index ad501c2007..ade2648a9f 100644 --- a/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/helpers/BasicLatticesTest.kt +++ b/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/helpers/BasicLatticesTest.kt @@ -40,6 +40,7 @@ import kotlin.test.assertIs import kotlin.test.assertNotEquals import kotlin.test.assertNotSame import kotlin.test.assertSame +import kotlin.test.assertTrue class BasicLatticesTest { @Test @@ -124,11 +125,11 @@ class BasicLatticesTest { val aBlaLattice1 = MapLattice>(mapOf("a" to PowersetLattice(setOf("bla")))) - val bBlaLattice2 = + val aBlaLattice2 = MapLattice>(mapOf("a" to PowersetLattice(setOf("bla")))) - assertEquals(0, aBlaLattice1.compareTo(bBlaLattice2)) - assertEquals(aBlaLattice1, bBlaLattice2) - assertNotSame(aBlaLattice1, bBlaLattice2) + assertEquals(0, aBlaLattice1.compareTo(aBlaLattice2)) + assertEquals(aBlaLattice1, aBlaLattice2) + assertNotSame(aBlaLattice1, aBlaLattice2) val aBlaFooLattice = MapLattice>(mapOf("a" to PowersetLattice(setOf("bla", "foo")))) @@ -214,6 +215,8 @@ class BasicLatticesTest { assertEquals(setOf("bla"), aBlaFooBBla.elements["b"]?.elements) assertFalse(aBlaFooBBla == emptyLattice1) // Wrong elements + assertTrue(emptyLattice1 == emptyLattice2) // This is equal + assertTrue(aBlaLattice1 == aBlaLattice2) // This is equal assertFalse(aBlaFooBBla == aBlaFooBBla.elements["a"]) // Wrong types assertFalse(aBlaFooBBla.elements["a"] == aBlaFooBBla) // Wrong types } @@ -262,6 +265,8 @@ class BasicLatticesTest { // We explicitly want to call equals here assertFalse(blaBla == emptyBla) // Wrong elements + assertFalse(blaBla == blaEmpty) // Wrong elements + assertTrue(emptyBla2 == emptyBla) // Wrong elements assertFalse(blaBla == emptyBlaFirst) // Wrong types assertFalse(emptyBlaFirst == blaBla) // Wrong types } @@ -300,21 +305,21 @@ class BasicLatticesTest { emptyPowersetLattice() ) ) - val emptyBla2 = emptyEmptyBla.duplicate() - assertEquals(0, emptyEmptyBla.compareTo(emptyBla2)) - assertEquals(emptyEmptyBla, emptyBla2) - assertNotSame(emptyEmptyBla, emptyBla2) - assertNotSame(emptyEmptyBla.hashCode(), emptyBla2.hashCode()) + val emptyEmptyBla2 = emptyEmptyBla.duplicate() + assertEquals(0, emptyEmptyBla.compareTo(emptyEmptyBla2)) + assertEquals(emptyEmptyBla, emptyEmptyBla2) + assertNotSame(emptyEmptyBla, emptyEmptyBla2) + assertNotSame(emptyEmptyBla.hashCode(), emptyEmptyBla2.hashCode()) val (emptyBlaFirst, emptyBlaSecond, emptyBlaThird) = emptyEmptyBla assertSame(emptyBlaFirst, emptyEmptyBla.elements.first) assertSame(emptyBlaSecond, emptyEmptyBla.elements.second) assertSame(emptyBlaThird, emptyEmptyBla.elements.third) - assertNotSame(emptyBlaFirst, emptyBla2.elements.first) - assertEquals(emptyBlaFirst, emptyBla2.elements.first) - assertNotSame(emptyBlaSecond, emptyBla2.elements.second) - assertEquals(emptyBlaSecond, emptyBla2.elements.second) - assertNotSame(emptyBlaThird, emptyBla2.elements.third) - assertEquals(emptyBlaThird, emptyBla2.elements.third) + assertNotSame(emptyBlaFirst, emptyEmptyBla2.elements.first) + assertEquals(emptyBlaFirst, emptyEmptyBla2.elements.first) + assertNotSame(emptyBlaSecond, emptyEmptyBla2.elements.second) + assertEquals(emptyBlaSecond, emptyEmptyBla2.elements.second) + assertNotSame(emptyBlaThird, emptyEmptyBla2.elements.third) + assertEquals(emptyBlaThird, emptyEmptyBla2.elements.third) assertEquals(-1, emptyEmptyEmpty.compareTo(emptyEmptyBla)) assertEquals(-1, emptyEmptyEmpty.compareTo(emptyBlaEmpty)) @@ -337,6 +342,10 @@ class BasicLatticesTest { // We explicitly want to call equals here assertFalse(blaEmptyBla == emptyEmptyBla) // Wrong elements + assertFalse(emptyEmptyEmpty == emptyEmptyBla) // Wrong elements + assertFalse(emptyEmptyEmpty == emptyBlaEmpty) // Wrong elements + assertFalse(emptyEmptyEmpty == blaEmptyEmpty) // Wrong elements + assertTrue(emptyEmptyBla2 == emptyEmptyBla) // Same type and same elements assertFalse(blaEmptyBla == emptyBlaFirst) // Wrong types assertFalse(emptyBlaFirst == blaEmptyBla) // Wrong types } From 47d6f948b915c353169ac6dbc66ccd43839d949f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 12 Nov 2024 09:22:49 +0100 Subject: [PATCH 2/3] Update dependency gradle to v8.11 (#1832) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9355b41557..94113f200e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME From 9e5a85a585c3a85d3dfbc4cffa690eec3e816749 Mon Sep 17 00:00:00 2001 From: Alexander Kuechler Date: Tue, 12 Nov 2024 15:21:21 +0100 Subject: [PATCH 3/3] Update MapLattice iteration --- .../cpg/helpers/functional/BasicLattices.kt | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/helpers/functional/BasicLattices.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/helpers/functional/BasicLattices.kt index f9e6aa85ba..ab7203c8cd 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/helpers/functional/BasicLattices.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/helpers/functional/BasicLattices.kt @@ -98,15 +98,21 @@ open class MapLattice(elements: Map>) : override fun lub( other: LatticeElement>> ): LatticeElement>> { - return MapLattice( - this.elements.entries.fold(other.elements) { current, (thisKey, thisValue) -> - val mutableMap = current.toMutableMap() - mutableMap.compute(thisKey) { k, v -> - if (v == null) thisValue else thisValue.lub(v) - } - mutableMap + val allKeys = other.elements.keys.union(this.elements.keys) + val newMap = + allKeys.fold(mutableMapOf>()) { current, key -> + val otherValue = other.elements[key] + val thisValue = this.elements[key] + val newValue = + if (thisValue != null && otherValue != null) { + thisValue.lub(otherValue) + } else if (thisValue != null) { + thisValue + } else otherValue + newValue?.let { current[key] = it } + current } - ) + return MapLattice(newMap) } override fun duplicate(): LatticeElement>> {