Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Bitwuzla solver support #71

Merged
merged 72 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
2a26cd9
Fp 16 fixes && eval for fp.add
Saloed Jan 25, 2023
f348bea
Fix fp 16
Saloed Jan 27, 2023
878ba3e
KAst structural equality methods
Saloed Jan 17, 2023
28708b9
tmp
Saloed Jan 17, 2023
642d517
KInternedObject
Saloed Jan 18, 2023
1961d8a
Optimizations
Saloed Jan 18, 2023
e328f36
ConcurrentWeakHashMap
Saloed Jan 18, 2023
84806be
Ast interner
Saloed Jan 18, 2023
88cd4eb
remove caffeine
Saloed Jan 18, 2023
d5d3120
Faster cache
Saloed Jan 19, 2023
e39833f
Parametrize ast management modes
Saloed Jan 19, 2023
4c093d9
Single thread weak caches
Saloed Jan 19, 2023
d472ffd
Bv compare
Saloed Jan 31, 2023
80c6f7e
Fix after rebase
Saloed Feb 2, 2023
2517bd8
Comment empty arith add simplified args
Saloed Feb 17, 2023
e723c10
JNA to JNI migration (#69)
DKARAGODIN Feb 6, 2023
3f6d231
Initial native part fix
Saloed Feb 6, 2023
69d26f4
Timeouts
Saloed Feb 6, 2023
006b789
check exception handling
Saloed Feb 7, 2023
f9d5c18
better timeout handling
Saloed Feb 7, 2023
b66c9d4
enable ipo
Saloed Feb 7, 2023
0b29768
Fix default array value handling
Saloed Feb 7, 2023
f54375d
Jni bindings
Saloed Feb 7, 2023
8ee97cc
Fix Native documentation
Saloed Feb 7, 2023
fbd04c3
Enum wrappers
Saloed Feb 7, 2023
4d68757
Cleanup
Saloed Feb 7, 2023
825f3fc
Remove dummy test
Saloed Feb 7, 2023
7361b30
Fix timeout test
Saloed Feb 7, 2023
be4759d
Fix detekt issues
Saloed Feb 7, 2023
bc30f08
Rework unsupported theories for Bitwuzla
Saloed Feb 7, 2023
8ffea7a
Support quantifiers in bitwuzla
Saloed Feb 7, 2023
34f93d2
Fix nested quantifiers conversion
Saloed Feb 7, 2023
8f2c173
Small fixes
Saloed Feb 7, 2023
e0240c1
Better Bitwuzla bv bits api
Saloed Feb 7, 2023
f068d93
New API based converter
Saloed Feb 7, 2023
8c0550d
New API based internalizer
Saloed Feb 7, 2023
df32c30
Update docs
Saloed Feb 7, 2023
8ed1ea2
axioms
Saloed Feb 7, 2023
304feae
Minor
Saloed Feb 8, 2023
8979662
fix bigInt to bits
Saloed Feb 8, 2023
c844f24
fix bigInt to bits
Saloed Feb 8, 2023
bba6a02
Fix fp64 conversion
Saloed Feb 8, 2023
1dc5633
Use KSMT based model evaluation
Saloed Feb 8, 2023
9a5671c
Better model evaluator for partial functions
Saloed Feb 8, 2023
aede677
Fix bv bit utils
Saloed Feb 8, 2023
96cf82b
Better handling of as-array expressions in model evaluator
Saloed Feb 8, 2023
8fbcedf
Fix bit utils
Saloed Feb 8, 2023
1ce7211
Better doc for bits
Saloed Feb 8, 2023
affaf0b
m
Saloed Feb 8, 2023
e8d5c0e
Fix as-array rewrite loops
Saloed Feb 8, 2023
67708ba
Special test data-source for Bitwuzla model conversion
Saloed Feb 8, 2023
f04efda
Fix detekt issues
Saloed Feb 8, 2023
103267f
Ensure bitwuzla ctx is active
Saloed Feb 8, 2023
825dc43
Rebase
Saloed Feb 10, 2023
5aa72de
Skip Z3 fma failures
Saloed Feb 10, 2023
ebec86d
Skip fp max/min with +/- 0
Saloed Feb 10, 2023
a39692e
Fix Z3 fma test issues
Saloed Feb 10, 2023
fc2a859
minor change
Saloed Feb 10, 2023
0118ddc
fix vars management
Saloed Feb 10, 2023
3637e72
Move comment
Saloed Feb 13, 2023
ec7a9dd
Use unsat assumptions instead of core
Saloed Feb 13, 2023
82f0e34
Support for uninterpreted sorts
Saloed Feb 13, 2023
8b2e66e
Rework declaration scoping
Saloed Feb 13, 2023
525574c
Better tests parametrization
Saloed Feb 13, 2023
2854d7d
Fix model detach
Saloed Feb 13, 2023
14f5976
Fix detekt issues
Saloed Feb 13, 2023
a855f76
Minor fix
Saloed Feb 14, 2023
284eda3
Use adapter for uninterpreted sort conversion
Saloed Feb 14, 2023
c83e78f
rebase
Saloed Feb 14, 2023
3597679
Fix pointer formatting
Saloed Feb 17, 2023
e8c95dc
Fixes
Saloed Feb 17, 2023
e73a487
Rebase
Saloed Feb 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tmp
  • Loading branch information
Saloed committed Feb 17, 2023
commit 28708b9d8fb844cd1897eb9b29cb771724f691bf
2 changes: 2 additions & 0 deletions ksmt-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ plugins {
}

dependencies {
implementation("com.github.ben-manes.caffeine:caffeine:3.1.2")

testImplementation(project(":ksmt-z3"))
testImplementation("org.junit.jupiter", "junit-jupiter-params", "5.8.2")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package com.github.benmanes.caffeine.cache

import com.github.benmanes.caffeine.cache.References.InternalReference
import org.ksmt.cache.CustomObjectEquality
import java.lang.ref.Reference
import java.lang.ref.ReferenceQueue
import java.lang.ref.WeakReference

private val cacheNodeFactory by lazy {
BoundedLocalCache::class.java.declaredFields
.first { it.name == "nodeFactory" }
.also { it.isAccessible = true }
}

internal class WeakKeyCustomEqualityReference<K : CustomObjectEquality>(
key: K?, queue: ReferenceQueue<K>?
) : WeakReference<K>(key, queue), InternalReference<K> {
private val hashCode: Int = key?.customHashCode() ?: 0

override fun getKeyReference(): Any = this

override fun equals(other: Any?): Boolean = when {
other === this -> true
other is InternalReference<*> -> CustomObjectEquality.objectEquality(get(), other.get())
else -> false
}

override fun hashCode(): Int = hashCode

override fun toString(): String =
"{key=${get()} hash=$hashCode}"
}

internal class LookupKeyCustomEqualityReference<K : CustomObjectEquality>(
private val key: K
) : InternalReference<K> {
private val hashCode: Int = key.customHashCode()

override fun get(): K = key

override fun getKeyReference(): Any = this

override fun equals(other: Any?): Boolean = when {
other === this -> true
other is InternalReference<*> -> CustomObjectEquality.objectEquality(get(), other.get())
else -> false
}

override fun hashCode(): Int = hashCode

override fun toString(): String =
"{key=${get()} hash=$hashCode}"
}

internal class CustomEqualityObjectInterned<K : CustomObjectEquality> : Node<K, Any?>, NodeFactory<K, Any?> {
@Volatile
private var keyReference: Reference<*>? = null

constructor()

constructor(keyReference: Reference<K>?) {
this.keyReference = keyReference
}

@Suppress("UNCHECKED_CAST")
override fun getKey(): K? = keyReference?.get() as K?

override fun getKeyReference(): Any? = keyReference

override fun getValue(): Any = valueStub

override fun getValueReference(): Any = valueStub

override fun setValue(value: Any?, referenceQueue: ReferenceQueue<Any?>?) {}

override fun containsValue(value: Any?): Boolean = value == getValue()

override fun newNode(
key: K?, keyReferenceQueue: ReferenceQueue<K>?,
value: Any?, valueReferenceQueue: ReferenceQueue<Any?>?,
weight: Int, now: Long
): Node<K, Any?> = CustomEqualityObjectInterned<K>(WeakKeyCustomEqualityReference(key, keyReferenceQueue))

@Suppress("UNCHECKED_CAST")
override fun newNode(
keyReference: Any?, value: Any?,
valueReferenceQueue: ReferenceQueue<Any?>?,
weight: Int, now: Long
): Node<K, Any?> = CustomEqualityObjectInterned(keyReference as Reference<K>?)

@Suppress("UNCHECKED_CAST")
override fun newLookupKey(key: Any): Any =
LookupKeyCustomEqualityReference(key as K)

override fun newReferenceKey(key: K?, referenceQueue: ReferenceQueue<K>?): Any =
WeakKeyCustomEqualityReference(key, referenceQueue)

override fun isAlive(): Boolean {
val keyRef = keyReference
return keyRef !== NodeFactory.RETIRED_WEAK_KEY && keyRef !== NodeFactory.DEAD_WEAK_KEY
}

override fun isRetired(): Boolean = keyReference === NodeFactory.RETIRED_WEAK_KEY

override fun retire() {
val keyRef = keyReference
keyReference = NodeFactory.RETIRED_WEAK_KEY
keyRef?.clear()
}

override fun isDead(): Boolean = keyReference === NodeFactory.DEAD_WEAK_KEY

override fun die() {
val keyRef = keyReference
keyReference = NodeFactory.DEAD_WEAK_KEY
keyRef?.clear()
}

companion object {
@JvmStatic
internal val valueStub = Any()
}
}

@Suppress("UNCHECKED_CAST")
private fun <K : CustomObjectEquality> mkWeakCustomEqualityCache(): BoundedLocalCache<K, Any?> {
val internCache = Caffeine.newWeakInterner<K>()
val customEqualityNodeFactory = CustomEqualityObjectInterned<K>()
cacheNodeFactory.set(internCache, customEqualityNodeFactory)
return internCache as BoundedLocalCache<K, Any?>
}


internal class WeakCustomEqualityInterner<E: CustomObjectEquality> : Interner<E> {
private val cache = mkWeakCustomEqualityCache<E>()

override fun intern(sample: E): E {
while (true) {
val canonical = cache.getKey(sample)
if (canonical != null) {
return canonical
}
val value = cache.putIfAbsent(sample, CustomEqualityObjectInterned.valueStub)

if (value == null) {
return sample
}
}
}
}

fun <T : CustomObjectEquality> mkWeakCustomEqualityInterner(): Interner<T> =
WeakCustomEqualityInterner()