Skip to content

Commit fdd016d

Browse files
authored
Various fixes (#162)
* Various fixes * Rebuild z3-linux-x64 * Rollback cvc bv-reduction and/or fix as incorrect * Upgrade version to 0.5.25
1 parent e294ff4 commit fdd016d

File tree

12 files changed

+55
-23
lines changed

12 files changed

+55
-23
lines changed

Diff for: README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Get the most out of SMT solving with KSMT features:
1111
* Streamlined [solver delivery](#ksmt-distribution) with no need for building a solver or implementing JVM bindings
1212

1313
[![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)
14-
[![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)
14+
[![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)
1515
[![javadoc](https://javadoc.io/badge2/io.ksmt/ksmt-core/javadoc.svg)](https://javadoc.io/doc/io.ksmt/ksmt-core)
1616

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

2121
```kotlin
2222
// core
23-
implementation("io.ksmt:ksmt-core:0.5.24")
23+
implementation("io.ksmt:ksmt-core:0.5.25")
2424
// z3 solver
25-
implementation("io.ksmt:ksmt-z3:0.5.24")
25+
implementation("io.ksmt:ksmt-z3:0.5.25")
2626
```
2727

2828
Find basic instructions in the [Getting started](docs/getting-started.md) guide and try it out with the

Diff for: buildSrc/src/main/kotlin/io.ksmt.ksmt-base.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
}
1212

1313
group = "io.ksmt"
14-
version = "0.5.24"
14+
version = "0.5.25"
1515

1616
repositories {
1717
mavenCentral()

Diff for: docs/getting-started.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ repositories {
3434
```kotlin
3535
dependencies {
3636
// core
37-
implementation("io.ksmt:ksmt-core:0.5.24")
37+
implementation("io.ksmt:ksmt-core:0.5.25")
3838
}
3939
```
4040

@@ -43,9 +43,9 @@ dependencies {
4343
```kotlin
4444
dependencies {
4545
// z3
46-
implementation("io.ksmt:ksmt-z3:0.5.24")
46+
implementation("io.ksmt:ksmt-z3:0.5.25")
4747
// bitwuzla
48-
implementation("io.ksmt:ksmt-bitwuzla:0.5.24")
48+
implementation("io.ksmt:ksmt-bitwuzla:0.5.25")
4949
}
5050
```
5151

Diff for: examples/build.gradle.kts

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ repositories {
99

1010
dependencies {
1111
// core
12-
implementation("io.ksmt:ksmt-core:0.5.24")
12+
implementation("io.ksmt:ksmt-core:0.5.25")
1313
// z3 solver
14-
implementation("io.ksmt:ksmt-z3:0.5.24")
14+
implementation("io.ksmt:ksmt-z3:0.5.25")
1515
// Runner and portfolio solver
16-
implementation("io.ksmt:ksmt-runner:0.5.24")
16+
implementation("io.ksmt:ksmt-runner:0.5.25")
1717
}
1818

1919
java {

Diff for: ksmt-core/src/main/kotlin/io/ksmt/expr/rewrite/simplify/BvSimplificationRules.kt

+11-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import io.ksmt.expr.KBvNotExpr
1212
import io.ksmt.expr.KBvOrExpr
1313
import io.ksmt.expr.KBvShiftLeftExpr
1414
import io.ksmt.expr.KBvXorExpr
15+
import io.ksmt.expr.KBvZeroExtensionExpr
1516
import io.ksmt.expr.KExpr
1617
import io.ksmt.expr.KIteExpr
1718
import io.ksmt.sort.KBoolSort
@@ -826,15 +827,22 @@ inline fun <T : KBvSort> KContext.simplifyBvLogicalShiftRightExprLight(
826827
shift: KExpr<T>,
827828
cont: (KExpr<T>, KExpr<T>) -> KExpr<T>
828829
): KExpr<T> {
830+
val sizeBits = shift.sort.sizeBits
831+
829832
if (shift is KBitVecValue<T>) {
830833
// (x >>> 0) ==> x
831834
if (shift.isBvZero()) {
832835
return lhs
833836
}
834837

835838
// (x >>> shift), shift >= size ==> 0
836-
if (shift.signedGreaterOrEqual(shift.sort.sizeBits.toInt())) {
837-
return bvZero(shift.sort.sizeBits)
839+
if (shift.signedGreaterOrEqual(sizeBits.toInt())) {
840+
return bvZero(sizeBits)
841+
}
842+
843+
// ((zero-ext x E) >>> shift), shift >= sizeOf(x) ==> 0
844+
if (lhs is KBvZeroExtensionExpr && shift.signedGreaterOrEqual(lhs.value.sort.sizeBits.toInt())) {
845+
return bvZero(sizeBits)
838846
}
839847

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

845853
// (x >>> x) ==> 0
846854
if (lhs == shift) {
847-
return bvZero(shift.sort.sizeBits)
855+
return bvZero(sizeBits)
848856
}
849857

850858
return cont(lhs, shift)

Diff for: ksmt-core/src/test/kotlin/io/ksmt/BvSimplifyTest.kt

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class BvSimplifyTest: ExpressionSimplifyTest() {
121121
bvValue(it.sizeBits, 3),
122122
bvValue(it.sizeBits, BV_SIZE.toInt() + 5),
123123
bvZero(it.sizeBits),
124+
mkBvZeroExtensionExpr((it.sizeBits.toInt() - 3).coerceAtLeast(0), mkConst("b", mkBvSort(3u))),
124125
mkConst("a", it) // same as lhs
125126
)
126127
}

Diff for: ksmt-cvc5/ksmt-cvc5-core/src/main/kotlin/io/ksmt/solver/cvc5/KCvc5ExprInternalizer.kt

+10-4
Original file line numberDiff line numberDiff line change
@@ -1215,11 +1215,17 @@ class KCvc5ExprInternalizer(
12151215
private fun Term.mkFunctionApp(args: List<Term>): Term =
12161216
tm.mkTerm(Kind.APPLY_UF, arrayOf(this) + args)
12171217

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

1221-
private fun mkOrTerm(args: List<Term>): Term =
1222-
if (args.size == 1) args.single() else tm.mkTerm(Kind.OR, args.toTypedArray())
1224+
private fun mkOrTerm(args: List<Term>): Term = when (args.size) {
1225+
0 -> tm.builder { mkFalse() }
1226+
1 -> args.single()
1227+
else -> tm.mkTerm(Kind.OR, args.toTypedArray())
1228+
}
12231229

12241230
private fun mkArraySelectTerm(array: Term, indices: List<Term>): Term =
12251231
if (tm.termSort(array).isArray) {

Diff for: ksmt-test/src/main/kotlin/io/ksmt/test/TestWorkerProcess.kt

+8-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,14 @@ class TestWorkerProcess : ChildProcessBase<TestProtocolModel>() {
9191
}
9292

9393
private fun convertAssertions(nativeAssertions: List<Long>): List<KExpr<KBoolSort>> {
94-
val converter = KZ3ExprConverter(ctx, KZ3Context(ctx, z3Ctx))
95-
return with(converter) { nativeAssertions.map { it.convertExpr() } }
94+
val context = KZ3Context(ctx, z3Ctx)
95+
return try {
96+
val converter = KZ3ExprConverter(ctx, context)
97+
with(converter) { nativeAssertions.map { it.convertExpr() } }
98+
} finally {
99+
// Don't close native context, only release native refs
100+
context.releaseNativeMemory()
101+
}
96102
}
97103

98104
private fun internalizeAndConvertBitwuzla(assertions: List<KExpr<KBoolSort>>): List<KExpr<KBoolSort>> =

Diff for: ksmt-z3/dist/z3-native-linux-x86-64-4.13.0.zip

13.3 MB
Binary file not shown.

Diff for: ksmt-z3/ksmt-z3-core/src/main/kotlin/io/ksmt/solver/z3/ExpressionUninterpretedValuesTracker.kt

+8-1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ class ExpressionUninterpretedValuesTracker(val ctx: KContext, val z3Ctx: KZ3Cont
214214
}
215215
}
216216

217+
fun containsExpressionOnCurrentLevel(expr: KExpr<*>): Boolean {
218+
// Was not initialized --> has no expressions
219+
if (!initialized) return false
220+
221+
return expr in currentLevelExpressions
222+
}
223+
217224
fun addRegisteredValueToCurrentLevel(value: KUninterpretedSortValue) {
218225
val descriptor = tracker.registeredUninterpretedSortValues[value]
219226
?: error("Value $value was not registered")
@@ -250,7 +257,7 @@ class ExpressionUninterpretedValuesTracker(val ctx: KContext, val z3Ctx: KZ3Cont
250257
if (frameLevel < level) {
251258
val levelFrame = getFrame(frameLevel)
252259
// If expr is valid on its level we don't need to move it
253-
return expr !in levelFrame.currentLevelExpressions
260+
return !levelFrame.containsExpressionOnCurrentLevel(expr)
254261
}
255262
return super.exprTransformationRequired(expr)
256263
}

Diff for: ksmt-z3/ksmt-z3-core/src/main/kotlin/io/ksmt/solver/z3/KZ3Context.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@ class KZ3Context(
264264
if (isClosed) return
265265
isClosed = true
266266

267+
releaseNativeMemory()
268+
269+
ctx.close()
270+
}
271+
272+
fun releaseNativeMemory() {
267273
uninterpretedSortValueInterpreter.clear()
268274

269275
uninterpretedSortValueDecls.keys.decRefAll()
@@ -289,8 +295,6 @@ class KZ3Context(
289295
z3Sorts.keys.decRefAll()
290296
sorts.clear()
291297
z3Sorts.clear()
292-
293-
ctx.close()
294298
}
295299

296300
private fun LongSet.decRefAll() =

Diff for: ksmt-z3/ksmt-z3-native/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ val macDylibPath = listOf("**/libz3.dylib", "**/libz3java.dylib")
2727

2828
val z3Binaries = listOf(
2929
Triple(`windows-x64`, mkZ3ReleaseDownloadTask(z3Version, "x64-win", winDllPath), null),
30-
Triple(`linux-x64`, mkZ3ReleaseDownloadTask(z3Version, "x64-glibc-2.31", linuxSoPath), null),
30+
Triple(`linux-x64`, null, z3NativeLinuxX64),
3131
Triple(`mac-x64`, mkZ3ReleaseDownloadTask(z3Version, "x64-osx-11.7.10", macDylibPath), null),
3232
Triple(`mac-arm`, mkZ3ReleaseDownloadTask(z3Version, "arm64-osx-11.0", macDylibPath), null),
3333
Triple(`linux-arm`, mkZ3ReleaseDownloadTask(z3Version, "arm64-glibc-2.35", linuxSoPath), null),

0 commit comments

Comments
 (0)