Skip to content

Commit 3eb7178

Browse files
authored
Made plusAssign of UPathConstraints non-recursive (#338)
1 parent 99fa6cd commit 3eb7178

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

usvm-core/src/main/kotlin/org/usvm/constraints/PathConstraints.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,17 @@ open class UPathConstraints<Type>(
9494
typeConstraints.constraints()
9595
}
9696

97+
operator fun plusAssign(constraint: UBoolExpr) {
98+
val queue = ArrayDeque<UBoolExpr>()
99+
queue.add(constraint)
100+
while (queue.isNotEmpty()) {
101+
val c = queue.removeFirst()
102+
addConstraint(c, queue)
103+
}
104+
}
105+
97106
@Suppress("UNCHECKED_CAST")
98-
open operator fun plusAssign(constraint: UBoolExpr): Unit =
107+
protected open fun addConstraint(constraint: UBoolExpr, queue: ArrayDeque<UBoolExpr>): Unit =
99108
with(constraint.uctx) {
100109
when {
101110
constraint == falseExpr -> contradiction(this)
@@ -131,7 +140,7 @@ open class UPathConstraints<Type>(
131140
typeConstraints.addSubtype(constraint.ref, constraint.subtype as Type)
132141
}
133142

134-
constraint is UAndExpr -> constraint.args.forEach(::plusAssign)
143+
constraint is UAndExpr -> queue.addAll(constraint.args)
135144

136145
constraint is UNotExpr -> {
137146
val notConstraint = constraint.arg
@@ -172,7 +181,7 @@ open class UPathConstraints<Type>(
172181

173182
notConstraint in logicalConstraints -> contradiction(ctx)
174183

175-
notConstraint is UOrExpr -> notConstraint.args.forEach { plusAssign(ctx.mkNot(it)) }
184+
notConstraint is UOrExpr -> queue.addAll(notConstraint.args.map(::mkNot))
176185

177186
else -> logicalConstraints.add(constraint, ownership)
178187
}

0 commit comments

Comments
 (0)