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

Fix composer handling in set union adapter cache #228

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import org.usvm.memory.USymbolicCollectionKeyInfo
import org.usvm.memory.UUpdateNode
import org.usvm.memory.UWritableMemory
import org.usvm.memory.key.UHeapRefKeyInfo
import org.usvm.uctx
import org.usvm.regions.Region
import org.usvm.uctx
import java.lang.ref.WeakReference

sealed class USymbolicSetUnionAdapter<
SetType, SrcKey, DstKey,
Expand All @@ -46,13 +47,13 @@ sealed class USymbolicSetUnionAdapter<
* */
val prevIncludesSymbolicallyCache = lastIncludesSymbolicallyCheck
if (prevIncludesSymbolicallyCache != null) {
if (prevIncludesSymbolicallyCache.key == srcKey) {
if (prevIncludesSymbolicallyCache.containsCachedValue(srcKey, composer)) {
return prevIncludesSymbolicallyCache.result
}
}

return setOfKeys.read(srcKey, composer).also {
lastIncludesSymbolicallyCheck = IncludesSymbolicallyCache(srcKey, it)
lastIncludesSymbolicallyCheck = IncludesSymbolicallyCache(srcKey, composer, it)
}
}

Expand All @@ -66,7 +67,30 @@ sealed class USymbolicSetUnionAdapter<

abstract override fun collectSetElements(elements: USymbolicSetElementsCollector.Elements<DstKey>)

private data class IncludesSymbolicallyCache<Key>(val key: Key, val result: UBoolExpr)
private data class IncludesSymbolicallyCache<Key>(
val key: WeakReference<Key>,
val composer: WeakReference<UComposer<*, *>>?,
val result: UBoolExpr
) {
Dismissed Show dismissed Hide dismissed
constructor(key: Key, composer: UComposer<*, *>?, result: UBoolExpr) :
this(WeakReference(key), composer?.let { WeakReference(it) }, result)
Dismissed Show dismissed Hide dismissed

fun containsCachedValue(key: Key, composer: UComposer<*, *>?): Boolean {
if (!this.key.equalTo(key)) return false

val thisComposer = this.composer ?: return composer == null
if (composer == null) return false

return thisComposer.equalTo(composer)
}

companion object {
private fun <T> WeakReference<T>.equalTo(other: T): Boolean {
val value = get() ?: return false
return value == other
}
}
}
}

class UAllocatedToAllocatedSymbolicSetUnionAdapter<SetType, ElemSort : USort>(
Expand Down
Loading