Skip to content

Commit

Permalink
fix set iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
oveeernight committed Aug 28, 2024
1 parent 6d98a69 commit 0afeba3
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 23 deletions.
6 changes: 3 additions & 3 deletions usvm-core/src/main/kotlin/org/usvm/Mocks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface UMocker<Method> : UMockEvaluator {
sort: Sort,
ownership: MutabilityOwnership,
): UMockSymbol<Sort>
val trackedLiterals: Collection<TrackedLiteral>
val trackedLiterals: Sequence<TrackedLiteral>

fun <Sort : USort> createMockSymbol(
trackedLiteral: TrackedLiteral?,
Expand Down Expand Up @@ -56,8 +56,8 @@ class UIndexedMocker<Method>(

override fun <Sort : USort> eval(symbol: UMockSymbol<Sort>): UExpr<Sort> = symbol

override val trackedLiterals: Collection<TrackedLiteral>
get() = trackedSymbols.keys().asSequence().toList()
override val trackedLiterals: Sequence<TrackedLiteral>
get() = trackedSymbols.keys

/**
* Creates a mock symbol. If [trackedLiteral] is not null, created expression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ internal class URefMapMemoryRegion<MapType, ValueSort : USort>(
write: (R, DstKeyId, UExpr<ValueSort>, UBoolExpr) -> R
) = mergeAllocatedKeys(
initial,
inputMapWithAllocatedKeys.keys().asSequence().toList(),
inputMapWithAllocatedKeys.keys,
guard,
keySet,
srcMapRef,
Expand All @@ -386,7 +386,7 @@ internal class URefMapMemoryRegion<MapType, ValueSort : USort>(
write: (R, DstKeyId, UExpr<ValueSort>, UBoolExpr) -> R
) = mergeAllocatedKeys(
initial,
allocatedMapWithAllocatedKeys.keys().asSequence().filter { it.mapAddress == srcMapRef.address }.toList(),
allocatedMapWithAllocatedKeys.keys.filter { it.mapAddress == srcMapRef.address },
guard,
keySet,
srcMapRef,
Expand All @@ -398,7 +398,7 @@ internal class URefMapMemoryRegion<MapType, ValueSort : USort>(

private inline fun <R, SrcKeyId, DstKeyId> mergeAllocatedKeys(
initial: R,
keys: Iterable<SrcKeyId>,
keys: Sequence<SrcKeyId>,
guard: UBoolExpr,
keySet: URefSetRegion<MapType>,
srcMapRef: UHeapRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class USetModelRegion<SetType, ElementSort : USort, Reg : Region<Reg>>(
check(inputSet.constValue.isFalse) { "Set model is not complete" }

val result = UPrimitiveSetEntries<SetType, ElementSort, Reg>()
inputSet.values.keys().forEach {
inputSet.values.keys.forEach {
if (it.first == setRef) {
result.add(USetEntryLValue(elementSort, setRef, it.second, setType, elementInfo))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class URefSetModelRegion<SetType>(
check(inputSet.constValue.isFalse) { "Set model is not complete" }

val result = URefSetEntries<SetType>()
inputSet.values.keys().forEach {
inputSet.values.keys.forEach {
if (it.first == setRef) {
result.add(URefSetEntryLValue(setRef, it.second, regionId.setType))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ internal class URefSetMemoryRegion<SetType>(
write: (R, DstKeyId, UBoolExpr, UBoolExpr) -> R
) = unionAllocatedElements(
initial,
inputSetWithAllocatedElements.keys().asSequence().toList(),
inputSetWithAllocatedElements.keys,
guard,
read,
{ mkDstKeyId(it.elementAddress) },
Expand All @@ -363,7 +363,7 @@ internal class URefSetMemoryRegion<SetType>(
write: (R, DstKeyId, UBoolExpr, UBoolExpr) -> R
) = unionAllocatedElements(
initial,
allocatedSetWithAllocatedElements.keys().asSequence().filter { it.setAddress == srcAddress }.toList(),
allocatedSetWithAllocatedElements.keys.filter { it.setAddress == srcAddress },
guard,
read,
{ mkDstKeyId(it.elementAddress) },
Expand All @@ -372,7 +372,7 @@ internal class URefSetMemoryRegion<SetType>(

private inline fun <R, SrcKeyId, DstKeyId> unionAllocatedElements(
initial: R,
keys: Iterable<SrcKeyId>,
keys: Sequence<SrcKeyId>,
guard: UBoolExpr,
read: (SrcKeyId) -> UBoolExpr,
mkDstKeyId: (SrcKeyId) -> DstKeyId,
Expand All @@ -391,7 +391,7 @@ internal class URefSetMemoryRegion<SetType>(
initial = URefSetEntries(),
initialGuard = ref.uctx.trueExpr,
blockOnConcrete = { entries, (concreteRef, _) ->
allocatedSetWithAllocatedElements.keys().forEach { entry ->
allocatedSetWithAllocatedElements.keys.forEach { entry ->
if (entry.setAddress == concreteRef.address) {
val elem = ref.uctx.mkConcreteHeapRef(entry.elementAddress)
entries.add(URefSetEntryLValue(concreteRef, elem, setType))
Expand All @@ -413,7 +413,7 @@ internal class URefSetMemoryRegion<SetType>(
entries
},
blockOnSymbolic = { entries, (symbolicRef, _) ->
inputSetWithAllocatedElements.keys().forEach { entry ->
inputSetWithAllocatedElements.keys.forEach { entry ->
val elem = ref.uctx.mkConcreteHeapRef(entry.elementAddress)
entries.add(URefSetEntryLValue(symbolicRef, elem, setType))
}
Expand Down
4 changes: 2 additions & 2 deletions usvm-core/src/main/kotlin/org/usvm/memory/Memory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ class UMemory<Type, Method>(
otherOwnership: MutabilityOwnership,
mergedOwnership: MutabilityOwnership,
): UMemory<Type, Method>? {
val ids = regions.keys().asSequence().toList()
val otherIds = other.regions.keys().asSequence().toList()
val ids = regions.keys.toList()
val otherIds = other.regions.keys.toList()
if (ids != otherIds) {
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ internal class JcStaticFieldsMemoryRegion<Sort : USort>(
fun mutatePrimitiveStaticFieldValuesToSymbolic(enclosingClass: JcClassOrInterface, ownership: MutabilityOwnership) {
val staticFields = fieldValuesByClass[enclosingClass] ?: return

val staticsToRemove = staticFields
.keys()
.filter { fieldShouldBeSymbolic(it) }
val staticsToRemove = staticFields.keys.filter { fieldShouldBeSymbolic(it) }

initialStatics = initialStatics.addAll(staticsToRemove)
for (static in staticsToRemove) {
initialStatics = initialStatics.add(static)
}

// Remove concrete fields from the region
val updatedStaticFields = staticsToRemove.fold(staticFields) { acc, field ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ class TrieNode<K, V>(
}
}

fun keys() = UPersistentHashMapKeysIterator(this) as Iterator<K>
val keys: Sequence<K> get() = UPersistentHashMapKeysIterator(this).asSequence()

fun isEmpty() = firstOrNull() == null
fun isNotEmpty() = firstOrNull() != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ class TrieNode<E>(
thisIsNode -> @Suppress("UNCHECKED_CAST") {
thisCell as TrieNode<E>
otherNodeCell as E
val oldCounter = this.calculateSize()
val oldCounter = mutableRemovesCount
val removed = thisCell.mutableRemove(
otherNodeCell.hashCode(),
otherNodeCell,
Expand Down Expand Up @@ -695,8 +695,8 @@ class TrieNode<E>(
return this
}

fun isEmpty() = singleOrNull() == null
fun isNotEmpty() = singleOrNull() != null
fun isEmpty() = firstOrNull() == null
fun isNotEmpty() = firstOrNull() != null

fun remove(element: E, owner: MutabilityOwnership): TrieNode<E> =
mutableRemove(element.hashCode(), element, 0, owner)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ internal open class UPersistentHashSetIterator<E>(node: TrieNode<E>) : Iterator<
}

override fun hasNext(): Boolean {
ensureNextElementIsReady()
return hasNext
}

override fun next(): E {
ensureNextElementIsReady()
if (!hasNext)
throw NoSuchElementException()

Expand Down

0 comments on commit 0afeba3

Please sign in to comment.