Skip to content

Commit

Permalink
Fix commit history
Browse files Browse the repository at this point in the history
  • Loading branch information
Bupaheh committed Dec 22, 2022
1 parent ce691f4 commit c33218a
Show file tree
Hide file tree
Showing 20 changed files with 1,999 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class TestProtocolModel private constructor(
private val _parseFile: RdCall<String, List<Long>>,
private val _convertAssertions: RdCall<List<Long>, TestConversionResult>,
private val _internalizeAndConvertBitwuzla: RdCall<TestInternalizeAndConvertParams, TestConversionResult>,
private val _internalizeAndConvertYices: RdCall<TestInternalizeAndConvertParams, TestConversionResult>,
private val _createSolver: RdCall<Unit, Int>,
private val _assert: RdCall<TestAssertParams, Unit>,
private val _check: RdCall<Int, TestCheckResult>,
Expand Down Expand Up @@ -67,7 +68,7 @@ class TestProtocolModel private constructor(
private val __LongListSerializer = FrameworkMarshallers.Long.list()
private val __IntNullableSerializer = FrameworkMarshallers.Int.nullable()

const val serializationHash = 3379332879384107871L
const val serializationHash = -4488913679358684177L

}
override val serializersOwner: ISerializersOwner get() = TestProtocolModel
Expand Down Expand Up @@ -100,6 +101,11 @@ class TestProtocolModel private constructor(
*/
val internalizeAndConvertBitwuzla: RdCall<TestInternalizeAndConvertParams, TestConversionResult> get() = _internalizeAndConvertBitwuzla

/**
* Internalize and convert expressions using Yices converter/internalizer
*/
val internalizeAndConvertYices: RdCall<TestInternalizeAndConvertParams, TestConversionResult> get() = _internalizeAndConvertYices

/**
* Create solver
*/
Expand Down Expand Up @@ -147,6 +153,7 @@ class TestProtocolModel private constructor(
_parseFile.async = true
_convertAssertions.async = true
_internalizeAndConvertBitwuzla.async = true
_internalizeAndConvertYices.async = true
_createSolver.async = true
_assert.async = true
_check.async = true
Expand All @@ -163,6 +170,7 @@ class TestProtocolModel private constructor(
bindableChildren.add("parseFile" to _parseFile)
bindableChildren.add("convertAssertions" to _convertAssertions)
bindableChildren.add("internalizeAndConvertBitwuzla" to _internalizeAndConvertBitwuzla)
bindableChildren.add("internalizeAndConvertYices" to _internalizeAndConvertYices)
bindableChildren.add("createSolver" to _createSolver)
bindableChildren.add("assert" to _assert)
bindableChildren.add("check" to _check)
Expand All @@ -181,6 +189,7 @@ class TestProtocolModel private constructor(
RdCall<String, List<Long>>(FrameworkMarshallers.String, __LongListSerializer),
RdCall<List<Long>, TestConversionResult>(__LongListSerializer, TestConversionResult),
RdCall<TestInternalizeAndConvertParams, TestConversionResult>(TestInternalizeAndConvertParams, TestConversionResult),
RdCall<TestInternalizeAndConvertParams, TestConversionResult>(TestInternalizeAndConvertParams, TestConversionResult),
RdCall<Unit, Int>(FrameworkMarshallers.Void, FrameworkMarshallers.Int),
RdCall<TestAssertParams, Unit>(TestAssertParams, FrameworkMarshallers.Void),
RdCall<Int, TestCheckResult>(FrameworkMarshallers.Int, TestCheckResult),
Expand All @@ -202,6 +211,7 @@ class TestProtocolModel private constructor(
print("parseFile = "); _parseFile.print(printer); println()
print("convertAssertions = "); _convertAssertions.print(printer); println()
print("internalizeAndConvertBitwuzla = "); _internalizeAndConvertBitwuzla.print(printer); println()
print("internalizeAndConvertYices = "); _internalizeAndConvertYices.print(printer); println()
print("createSolver = "); _createSolver.print(printer); println()
print("assert = "); _assert.print(printer); println()
print("check = "); _check.print(printer); println()
Expand All @@ -221,6 +231,7 @@ class TestProtocolModel private constructor(
_parseFile.deepClonePolymorphic(),
_convertAssertions.deepClonePolymorphic(),
_internalizeAndConvertBitwuzla.deepClonePolymorphic(),
_internalizeAndConvertYices.deepClonePolymorphic(),
_createSolver.deepClonePolymorphic(),
_assert.deepClonePolymorphic(),
_check.deepClonePolymorphic(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ object TestProtocolModel : Ext(TestProtocolRoot) {
async
documentation = "Internalize and convert expressions using Bitwuzla converter/internalizer"
}
call("internalizeAndConvertYices", testInternalizeAndConvertParams, testConversionResult).apply {
async
documentation = "Internalize and convert expressions using Yices converter/internalizer"
}
call("createSolver", PredefinedType.void, PredefinedType.int).apply {
async
documentation = "Create solver"
Expand Down
2 changes: 2 additions & 0 deletions ksmt-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ dependencies {
implementation(project(":ksmt-core"))
implementation(project(":ksmt-z3"))
implementation(project(":ksmt-bitwuzla"))
implementation(project(":ksmt-yices"))
implementation(testFixtures(project(":ksmt-yices")))
implementation(project(":ksmt-runner"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")

Expand Down
10 changes: 10 additions & 0 deletions ksmt-test/src/main/kotlin/org/ksmt/test/TestRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ class TestRunner(
}
}

suspend fun internalizeAndConvertYices(assertions: List<KExpr<KBoolSort>>): List<KExpr<KBoolSort>> =
withTimeoutAndExceptionHandling {
val params = TestInternalizeAndConvertParams(assertions)
val result = worker.protocolModel.internalizeAndConvertYices.startSuspending(worker.lifetime, params)
result.expressions.map {
@Suppress("UNCHECKED_CAST")
it as KExpr<KBoolSort>
}
}

suspend fun createSolver(): Int = withTimeoutAndExceptionHandling {
worker.protocolModel.createSolver.startSuspending(worker.lifetime, Unit)
}
Expand Down
28 changes: 28 additions & 0 deletions ksmt-test/src/main/kotlin/org/ksmt/test/TestWorkerProcess.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.microsoft.z3.Expr
import com.microsoft.z3.Native
import com.microsoft.z3.Solver
import com.microsoft.z3.Status
import org.ksmt.solver.fixtures.yices.KTestYicesContext
import org.ksmt.KContext
import org.ksmt.expr.KExpr
import org.ksmt.runner.core.ChildProcessBase
Expand All @@ -22,6 +23,7 @@ import org.ksmt.solver.bitwuzla.KBitwuzlaContext
import org.ksmt.solver.bitwuzla.KBitwuzlaExprConverter
import org.ksmt.solver.bitwuzla.KBitwuzlaExprInternalizer
import org.ksmt.solver.z3.KZ3Context
import org.ksmt.solver.yices.*
import org.ksmt.solver.z3.KZ3ExprConverter
import org.ksmt.solver.z3.KZ3ExprInternalizer
import org.ksmt.solver.z3.KZ3Solver
Expand Down Expand Up @@ -93,6 +95,27 @@ class TestWorkerProcess : ChildProcessBase<TestProtocolModel>() {
}
}

private fun internalizeAndConvertYices(assertions: List<KExpr<KBoolSort>>): List<KExpr<KBoolSort>> {
KTestYicesContext().use { internContext ->
val sortInternalizer = KYicesSortInternalizer(internContext)
val internalizer = KYicesExprInternalizer(
ctx, internContext, sortInternalizer,
KYicesDeclInternalizer(internContext, sortInternalizer),
KYicesVariableInternalizer(internContext, sortInternalizer)
)

val yicesAssertions = with(internalizer) {
assertions.map { it.internalize() }
}

val converter = KYicesExprConverter(ctx, internContext)

return with(converter) {
yicesAssertions.map { it.convert<KBoolSort>() }
}
}
}

private fun createSolver(): Int {
val solver = with(z3Ctx) {
mkSolver().apply {
Expand Down Expand Up @@ -207,6 +230,11 @@ class TestWorkerProcess : ChildProcessBase<TestProtocolModel>() {
val converted = internalizeAndConvertBitwuzla(params.expressions as List<KExpr<KBoolSort>>)
TestConversionResult(converted)
}
internalizeAndConvertYices.measureExecutionForTermination { params ->
@Suppress("UNCHECKED_CAST")
val converted = internalizeAndConvertYices(params.expressions as List<KExpr<KBoolSort>>)
TestConversionResult(converted)
}
createSolver.measureExecutionForTermination {
createSolver()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.ksmt.test

import org.junit.jupiter.api.parallel.Execution
import org.junit.jupiter.api.parallel.ExecutionMode
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import java.nio.file.Path

class YicesBenchmarksBasedTest : BenchmarksBasedTest() {

@Execution(ExecutionMode.CONCURRENT)
@ParameterizedTest(name = "{0}")
@MethodSource("yicesTestData")
fun testConverter(name: String, samplePath: Path) =
testConverter(name, samplePath) { assertions ->
internalizeAndConvertYices(assertions)
}

companion object {
@JvmStatic
fun yicesTestData() = testData().skipUnsupportedTheories()

private fun List<BenchmarkTestArguments>.skipUnsupportedTheories() =
filterNot { "FP" in it.name }
}
}
53 changes: 53 additions & 0 deletions ksmt-yices/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id("org.ksmt.ksmt-base")
id("com.github.johnrengelman.shadow") version "7.1.2"
`java-test-fixtures`
}

val distDir = projectDir.resolve("dist")

repositories {
mavenCentral()
flatDir { dirs(distDir) }
}

val yicesNative by configurations.creating

dependencies {
implementation(project(":ksmt-core"))
testFixturesImplementation(project(":ksmt-core"))

yicesNative("yices", "yices-native-linux-x86-64", "0.0", ext = "zip")
api(files("$distDir/com.sri.yices.jar"))
}

tasks.withType<ProcessResources> {
yicesNative.resolvedConfiguration.resolvedArtifacts.forEach { artifact ->
val destination = "lib/x64"
from(zipTree(artifact.file)) {
into(destination)
}
}
}

tasks.withType<ShadowJar> {
archiveClassifier.set("")
dependencies {
exclude { true }
}
val implementation = project.configurations["implementation"].dependencies.toSet()
val runtimeOnly = project.configurations["runtimeOnly"].dependencies.toSet()
val dependencies = (implementation + runtimeOnly)
project.configurations.shadow.get().dependencies.addAll(dependencies)
}

publishing {
publications {
create<MavenPublication>("maven") {
project.shadow.component(this)
artifact(tasks["kotlinSourcesJar"])
}
}
}
Binary file added ksmt-yices/dist/com.sri.yices.jar
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package org.ksmt.solver.yices

import org.ksmt.KContext
import org.ksmt.decl.KDecl
import org.ksmt.decl.KFuncDecl
import org.ksmt.expr.KApp
import org.ksmt.expr.KArrayLambda
import org.ksmt.expr.KExistentialQuantifier
import org.ksmt.expr.KExpr
import org.ksmt.expr.KFunctionAsArray
import org.ksmt.expr.KUniversalQuantifier
import org.ksmt.expr.transformer.KNonRecursiveTransformer
import org.ksmt.sort.KArraySort
import org.ksmt.sort.KBoolSort
import org.ksmt.sort.KSort
import org.ksmt.utils.mkFreshConstDecl

class KDeclSubstitutor(ctx: KContext) : KNonRecursiveTransformer(ctx) {
private val substitution = hashMapOf<KDecl<*>, KDecl<*>>()

fun <T: KSort> substitute(from: KDecl<T>, to: KDecl<T>) {
substitution[from] = to
}

@Suppress("UNCHECKED_CAST")
private fun <T : KSort> transformDecl(decl: KDecl<T>): KDecl<T> =
(substitution[decl] as? KDecl<T>) ?: decl

@Suppress("UNCHECKED_CAST")
override fun <T : KSort> transformApp(expr: KApp<T, *>): KExpr<T> =
transformAppAfterArgsTransformed(expr as KApp<T, KExpr<KSort>>) { transformedArgs ->
val transformedDecl = transformDecl(expr.decl)

ctx.mkApp(transformedDecl, transformedArgs)
}

@Suppress("UNCHECKED_CAST")
override fun <D : KSort, R : KSort> transform(
expr: KArrayLambda<D, R>
): KExpr<KArraySort<D, R>> = with(expr) {
transformQuantifierAfterBodyTransformed(body, listOf(indexVarDecl)) { transformedBody, transformedBounds ->
ctx.mkArrayLambda(transformedBounds.single() as KDecl<D>, transformedBody)
}
}

override fun transform(expr: KExistentialQuantifier): KExpr<KBoolSort> = with(expr) {
transformQuantifierAfterBodyTransformed(body, bounds) { transformedBody, transformedBounds ->
ctx.mkExistentialQuantifier(transformedBody, transformedBounds)
}
}

override fun transform(expr: KUniversalQuantifier): KExpr<KBoolSort> = with(expr) {
transformQuantifierAfterBodyTransformed(body, bounds) { transformedBody, transformedBounds ->
ctx.mkUniversalQuantifier(transformedBody, transformedBounds)
}
}

override fun <D : KSort, R : KSort> transform(expr: KFunctionAsArray<D, R>): KExpr<KArraySort<D, R>> {
val transformedFunction = transformDecl(expr.function)

return ctx.mkFunctionAsArray(transformedFunction as KFuncDecl<R>)
}

@Suppress("UNCHECKED_CAST")
private inline fun<T: KSort, S: KSort> transformQuantifierAfterBodyTransformed(
body: KExpr<T>,
bounds: List<KDecl<*>>,
transformer: (KExpr<T>, List<KDecl<*>>) -> KExpr<S>
): KExpr<S> {
val newSubstitutor = KDeclSubstitutor(ctx).also { currentSubstitutor ->
val boundsSet = bounds.toHashSet()

substitution
.filterNot { (from, _) ->
boundsSet.contains(from)
}.takeIf { it.isNotEmpty() }
?.forEach { (from, to) ->
currentSubstitutor.substitute(from as KDecl<KSort>, to as KDecl<KSort>)

if (boundsSet.contains(to) && !currentSubstitutor.substitution.contains(to))
currentSubstitutor.substitute(to, to.sort.mkFreshConstDecl(to.name))
} ?: return transformer(body, bounds)
}

return transformer(newSubstitutor.apply(body), bounds.map { newSubstitutor.transformDecl(it) })
}
}
Loading

0 comments on commit c33218a

Please sign in to comment.