Skip to content

Commit

Permalink
Various fixes (#162)
Browse files Browse the repository at this point in the history
* Various fixes

* Rebuild z3-linux-x64

* Rollback cvc bv-reduction and/or fix as incorrect

* Upgrade version to 0.5.25
  • Loading branch information
Saloed authored Aug 16, 2024
1 parent e294ff4 commit fdd016d
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 23 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Get the most out of SMT solving with KSMT features:
* Streamlined [solver delivery](#ksmt-distribution) with no need for building a solver or implementing JVM bindings

[![KSMT: build](https://github.com/UnitTestBot/ksmt/actions/workflows/build-and-run-tests.yml/badge.svg)](https://github.com/UnitTestBot/ksmt/actions/workflows/build-and-run-tests.yml)
[![Maven Central](https://img.shields.io/maven-central/v/io.ksmt/ksmt-core)](https://central.sonatype.com/artifact/io.ksmt/ksmt-core/0.5.24)
[![Maven Central](https://img.shields.io/maven-central/v/io.ksmt/ksmt-core)](https://central.sonatype.com/artifact/io.ksmt/ksmt-core/0.5.25)
[![javadoc](https://javadoc.io/badge2/io.ksmt/ksmt-core/javadoc.svg)](https://javadoc.io/doc/io.ksmt/ksmt-core)

## Get started
Expand All @@ -20,9 +20,9 @@ To start using KSMT, install it via [Gradle](https://gradle.org/):

```kotlin
// core
implementation("io.ksmt:ksmt-core:0.5.24")
implementation("io.ksmt:ksmt-core:0.5.25")
// z3 solver
implementation("io.ksmt:ksmt-z3:0.5.24")
implementation("io.ksmt:ksmt-z3:0.5.25")
```

Find basic instructions in the [Getting started](docs/getting-started.md) guide and try it out with the
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/io.ksmt.ksmt-base.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
}

group = "io.ksmt"
version = "0.5.24"
version = "0.5.25"

repositories {
mavenCentral()
Expand Down
6 changes: 3 additions & 3 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ repositories {
```kotlin
dependencies {
// core
implementation("io.ksmt:ksmt-core:0.5.24")
implementation("io.ksmt:ksmt-core:0.5.25")
}
```

Expand All @@ -43,9 +43,9 @@ dependencies {
```kotlin
dependencies {
// z3
implementation("io.ksmt:ksmt-z3:0.5.24")
implementation("io.ksmt:ksmt-z3:0.5.25")
// bitwuzla
implementation("io.ksmt:ksmt-bitwuzla:0.5.24")
implementation("io.ksmt:ksmt-bitwuzla:0.5.25")
}
```

Expand Down
6 changes: 3 additions & 3 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ repositories {

dependencies {
// core
implementation("io.ksmt:ksmt-core:0.5.24")
implementation("io.ksmt:ksmt-core:0.5.25")
// z3 solver
implementation("io.ksmt:ksmt-z3:0.5.24")
implementation("io.ksmt:ksmt-z3:0.5.25")
// Runner and portfolio solver
implementation("io.ksmt:ksmt-runner:0.5.24")
implementation("io.ksmt:ksmt-runner:0.5.25")
}

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import io.ksmt.expr.KBvNotExpr
import io.ksmt.expr.KBvOrExpr
import io.ksmt.expr.KBvShiftLeftExpr
import io.ksmt.expr.KBvXorExpr
import io.ksmt.expr.KBvZeroExtensionExpr
import io.ksmt.expr.KExpr
import io.ksmt.expr.KIteExpr
import io.ksmt.sort.KBoolSort
Expand Down Expand Up @@ -826,15 +827,22 @@ inline fun <T : KBvSort> KContext.simplifyBvLogicalShiftRightExprLight(
shift: KExpr<T>,
cont: (KExpr<T>, KExpr<T>) -> KExpr<T>
): KExpr<T> {
val sizeBits = shift.sort.sizeBits

if (shift is KBitVecValue<T>) {
// (x >>> 0) ==> x
if (shift.isBvZero()) {
return lhs
}

// (x >>> shift), shift >= size ==> 0
if (shift.signedGreaterOrEqual(shift.sort.sizeBits.toInt())) {
return bvZero(shift.sort.sizeBits)
if (shift.signedGreaterOrEqual(sizeBits.toInt())) {
return bvZero(sizeBits)
}

// ((zero-ext x E) >>> shift), shift >= sizeOf(x) ==> 0
if (lhs is KBvZeroExtensionExpr && shift.signedGreaterOrEqual(lhs.value.sort.sizeBits.toInt())) {
return bvZero(sizeBits)
}

if (lhs is KBitVecValue<T>) {
Expand All @@ -844,7 +852,7 @@ inline fun <T : KBvSort> KContext.simplifyBvLogicalShiftRightExprLight(

// (x >>> x) ==> 0
if (lhs == shift) {
return bvZero(shift.sort.sizeBits)
return bvZero(sizeBits)
}

return cont(lhs, shift)
Expand Down
1 change: 1 addition & 0 deletions ksmt-core/src/test/kotlin/io/ksmt/BvSimplifyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class BvSimplifyTest: ExpressionSimplifyTest() {
bvValue(it.sizeBits, 3),
bvValue(it.sizeBits, BV_SIZE.toInt() + 5),
bvZero(it.sizeBits),
mkBvZeroExtensionExpr((it.sizeBits.toInt() - 3).coerceAtLeast(0), mkConst("b", mkBvSort(3u))),
mkConst("a", it) // same as lhs
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1215,11 +1215,17 @@ class KCvc5ExprInternalizer(
private fun Term.mkFunctionApp(args: List<Term>): Term =
tm.mkTerm(Kind.APPLY_UF, arrayOf(this) + args)

private fun mkAndTerm(args: List<Term>): Term =
if (args.size == 1) args.single() else tm.mkTerm(Kind.AND, args.toTypedArray())
private fun mkAndTerm(args: List<Term>): Term = when (args.size) {
0 -> tm.builder { mkTrue() }
1 -> args.single()
else -> tm.mkTerm(Kind.AND, args.toTypedArray())
}

private fun mkOrTerm(args: List<Term>): Term =
if (args.size == 1) args.single() else tm.mkTerm(Kind.OR, args.toTypedArray())
private fun mkOrTerm(args: List<Term>): Term = when (args.size) {
0 -> tm.builder { mkFalse() }
1 -> args.single()
else -> tm.mkTerm(Kind.OR, args.toTypedArray())
}

private fun mkArraySelectTerm(array: Term, indices: List<Term>): Term =
if (tm.termSort(array).isArray) {
Expand Down
10 changes: 8 additions & 2 deletions ksmt-test/src/main/kotlin/io/ksmt/test/TestWorkerProcess.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,14 @@ class TestWorkerProcess : ChildProcessBase<TestProtocolModel>() {
}

private fun convertAssertions(nativeAssertions: List<Long>): List<KExpr<KBoolSort>> {
val converter = KZ3ExprConverter(ctx, KZ3Context(ctx, z3Ctx))
return with(converter) { nativeAssertions.map { it.convertExpr() } }
val context = KZ3Context(ctx, z3Ctx)
return try {
val converter = KZ3ExprConverter(ctx, context)
with(converter) { nativeAssertions.map { it.convertExpr() } }
} finally {
// Don't close native context, only release native refs
context.releaseNativeMemory()
}
}

private fun internalizeAndConvertBitwuzla(assertions: List<KExpr<KBoolSort>>): List<KExpr<KBoolSort>> =
Expand Down
Binary file added ksmt-z3/dist/z3-native-linux-x86-64-4.13.0.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ class ExpressionUninterpretedValuesTracker(val ctx: KContext, val z3Ctx: KZ3Cont
}
}

fun containsExpressionOnCurrentLevel(expr: KExpr<*>): Boolean {
// Was not initialized --> has no expressions
if (!initialized) return false

return expr in currentLevelExpressions
}

fun addRegisteredValueToCurrentLevel(value: KUninterpretedSortValue) {
val descriptor = tracker.registeredUninterpretedSortValues[value]
?: error("Value $value was not registered")
Expand Down Expand Up @@ -250,7 +257,7 @@ class ExpressionUninterpretedValuesTracker(val ctx: KContext, val z3Ctx: KZ3Cont
if (frameLevel < level) {
val levelFrame = getFrame(frameLevel)
// If expr is valid on its level we don't need to move it
return expr !in levelFrame.currentLevelExpressions
return !levelFrame.containsExpressionOnCurrentLevel(expr)
}
return super.exprTransformationRequired(expr)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ class KZ3Context(
if (isClosed) return
isClosed = true

releaseNativeMemory()

ctx.close()
}

fun releaseNativeMemory() {
uninterpretedSortValueInterpreter.clear()

uninterpretedSortValueDecls.keys.decRefAll()
Expand All @@ -289,8 +295,6 @@ class KZ3Context(
z3Sorts.keys.decRefAll()
sorts.clear()
z3Sorts.clear()

ctx.close()
}

private fun LongSet.decRefAll() =
Expand Down
2 changes: 1 addition & 1 deletion ksmt-z3/ksmt-z3-native/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ val macDylibPath = listOf("**/libz3.dylib", "**/libz3java.dylib")

val z3Binaries = listOf(
Triple(`windows-x64`, mkZ3ReleaseDownloadTask(z3Version, "x64-win", winDllPath), null),
Triple(`linux-x64`, mkZ3ReleaseDownloadTask(z3Version, "x64-glibc-2.31", linuxSoPath), null),
Triple(`linux-x64`, null, z3NativeLinuxX64),
Triple(`mac-x64`, mkZ3ReleaseDownloadTask(z3Version, "x64-osx-11.7.10", macDylibPath), null),
Triple(`mac-arm`, mkZ3ReleaseDownloadTask(z3Version, "arm64-osx-11.0", macDylibPath), null),
Triple(`linux-arm`, mkZ3ReleaseDownloadTask(z3Version, "arm64-glibc-2.35", linuxSoPath), null),
Expand Down

0 comments on commit fdd016d

Please sign in to comment.