Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
fb0adca
Draft: model synthesis
Jun 20, 2022
11c47d9
m
AbdullinAM Jun 20, 2022
4aaa8e5
first prototype, needs debugging and tuning
AbdullinAM Jun 22, 2022
9c63ba0
prototype
AbdullinAM Jun 28, 2022
707fa6d
refactor
AbdullinAM Jun 29, 2022
10c4193
very early prototype
AbdullinAM Jul 8, 2022
4285a5c
UtConstraintModel implemented
AbdullinAM Jul 12, 2022
22e2266
partial UtConstraint to UtExpression convertion
AbdullinAM Jul 14, 2022
6b47a9a
working prototypes
AbdullinAM Jul 19, 2022
a75a840
bugfixes + expression support in constraints
AbdullinAM Jul 21, 2022
fb392f6
m
AbdullinAM Jul 26, 2022
5f35311
everything kind of works, but some constraints need to be added
AbdullinAM Jul 27, 2022
ba9bb62
first working protoype with arrays
AbdullinAM Aug 1, 2022
065924f
renaming
AbdullinAM Aug 1, 2022
8cc7515
first tests and fixes
AbdullinAM Aug 2, 2022
4a14606
more expressions supported
AbdullinAM Aug 3, 2022
bbf525b
some cleanup + more expressions supported
AbdullinAM Aug 8, 2022
850b530
cleanup
AbdullinAM Aug 8, 2022
8799691
support for multidimensional arrays + fix for array generation
AbdullinAM Aug 9, 2022
60df4a4
first support of lists
AbdullinAM Aug 10, 2022
8963a7e
support sets
AbdullinAM Aug 10, 2022
1578c96
small refactorings
AbdullinAM Aug 11, 2022
1dd4b25
maps
AbdullinAM Aug 12, 2022
313757d
some cleanup and parameters
AbdullinAM Aug 12, 2022
faa0047
test write fix
AbdullinAM Aug 12, 2022
94740c9
m
AbdullinAM Aug 22, 2022
9920283
Merge branch 'main' into abdullin/constraint-model-synthesis
AbdullinAM Aug 22, 2022
fd22077
merge with master
AbdullinAM Aug 24, 2022
4e97b5f
first prototype of constraint scoring selector
AbdullinAM Aug 26, 2022
2544b31
m
AbdullinAM Aug 30, 2022
e585371
fixes
AbdullinAM Aug 31, 2022
d2564e9
Merge branch 'main' into abdullin/constraint-model-synthesis
AbdullinAM Sep 7, 2022
bb1acbc
Merge branch 'main' into abdullin/constraint-model-synthesis
AbdullinAM Sep 7, 2022
c6fbeb0
Split constraint models into a set of non-intersecting subsets before…
AbdullinAM Sep 12, 2022
2553ef7
m
AbdullinAM Sep 12, 2022
e943a16
some cleanup
AbdullinAM Sep 13, 2022
cd5fff8
more cleanup
AbdullinAM Sep 13, 2022
c2a7d31
order models in the subsets
AbdullinAM Sep 13, 2022
d1b09c8
simple caching of synthesis unit contexts
AbdullinAM Sep 13, 2022
eedccb9
option to enable/disable caching of synthesis contexts
AbdullinAM Sep 14, 2022
11eea4d
m
AbdullinAM Sep 14, 2022
9712e70
tests
AbdullinAM Sep 14, 2022
1c6b679
unit tests fixed
AbdullinAM Sep 19, 2022
4e37763
Merge branch 'main' into abdullin/constraint-model-synthesis
AbdullinAM Sep 28, 2022
34ed6fe
merge with main
AbdullinAM Sep 28, 2022
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
first working protoype with arrays
  • Loading branch information
AbdullinAM committed Aug 1, 2022
commit ba9bb6281c3c042c41096c8cfe38f61759f8b4f3
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ data class UtExecution(
var summary: List<DocStatement>? = null,
var testMethodName: String? = null,
var displayName: String? = null,
val hole: Any? = null
val constrainedExecution: ConstrainedExecution? = null
) : UtResult() {
/**
* By design the 'before' and 'after' states contain info about the same fields.
Expand Down Expand Up @@ -479,7 +479,12 @@ data class UtArrayConstraintModel(
val length: UtModel,
val elements: Map<UtModel, UtModel>,
override val utConstraints: Set<UtConstraint> = emptySet()
) : UtConstraintModel(variable, utConstraints)
) : UtConstraintModel(variable, utConstraints) {
val allConstraints get() = elements.toList().fold((length as UtConstraintModel).utConstraints) { acc, pair ->
acc + ((pair.first as? UtConstraintModel)?.utConstraints
?: emptySet()) + ((pair.second as? UtConstraintModel)?.utConstraints ?: emptySet())
}
}

/**
* Model for complex objects with assemble instructions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,11 @@ data class UtOrConstraint(val lhv: UtConstraint, val rhv: UtConstraint) : UtPrim
}
}

data class ConstrainedExecution(
val modelsBefore: List<UtModel>,
val modelsAfter: List<UtModel>
)


val ClassId.defaultVariable: UtConstraintVariable
get() = when (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.utbot.engine.MemoryState.CURRENT
import org.utbot.engine.MemoryState.INITIAL
import org.utbot.engine.MemoryState.STATIC_INITIAL
import org.utbot.engine.pc.*
import org.utbot.engine.z3.value
import org.utbot.framework.plugin.api.*
import org.utbot.framework.plugin.api.util.intClassId

Expand Down Expand Up @@ -58,7 +59,7 @@ class ConstraintResolver(
}
}

internal fun resolveModels(parameters: List<SymbolicValue>): ResolvedExecution {
internal fun resolveModels(parameters: List<SymbolicValue>): ConstrainedExecution {
varBuilder = UtVarBuilder(holder, typeRegistry, typeResolver)
val allAddresses = UtExprCollector { it is UtAddrExpression }.let {
holder.constraints.hard.forEach { constraint -> constraint.accept(it) }
Expand All @@ -77,7 +78,7 @@ class ConstraintResolver(
resolvedModels
}

return ResolvedExecution(modelsBefore, modelsAfter, emptyList())
return ConstrainedExecution(modelsBefore.parameters, modelsAfter.parameters)
}

private fun internalResolveModel(
Expand All @@ -103,6 +104,7 @@ class ConstraintResolver(
value.expr.variable,
emptySet()
)

is ReferenceValue -> buildModel(
collectAtoms(value, addrs),
value.addr.variable,
Expand Down Expand Up @@ -143,9 +145,11 @@ class ConstraintResolver(
variable,
resolvedConstraints.getValue(variable.addr)
)

variable.isArray -> buildArrayModel(atoms, variable, aliases).also {
resolvedConstraints[variable.addr] = it
}

else -> buildObjectModel(atoms, variable, aliases).also {
resolvedConstraints[variable.addr] = it
}
Expand Down Expand Up @@ -199,15 +203,20 @@ class ConstraintResolver(
val lengths = atoms.flatMap { it.flatMap() }.filter {
it is UtConstraintArrayLength && it.instance in allAliases
}.toSet()
val lengthModel = buildModel(atoms, UtConstraintArrayLength(variable), lengths)

val indexMap = atoms.flatMap {
it.accept(UtConstraintVariableCollector { indx ->
indx is UtConstraintArrayAccess && indx.instance in allAliases
})
}.map { (it as UtConstraintArrayAccess).index }.groupBy {
holder.eval(varBuilder[it])
}.map { it.value.toSet() }
val lengthVariable = UtConstraintArrayLength(variable)
val lengthModel = buildModel(atoms, lengthVariable, lengths)
val concreteLength = holder.eval(lengths.first().expr).value() as Int

val indexMap = atoms
.flatMap {
it.accept(UtConstraintVariableCollector { indx ->
indx is UtConstraintArrayAccess && indx.instance in allAliases
})
}
.map { (it as UtConstraintArrayAccess).index }
.filter { (holder.eval(it.expr).value() as Int) < concreteLength }
.groupBy { holder.eval(varBuilder[it]) }
.map { it.value.toSet() }

var indexCount = 0
val elements = indexMap.associate { indices ->
Expand All @@ -221,25 +230,25 @@ class ConstraintResolver(
)

val arrayAccess = UtConstraintArrayAccess(variable, indexVariable, elementClassId)
varBuilder.backMapping[arrayAccess] = varBuilder.backMapping[UtConstraintArrayAccess(variable, indices.first(), elementClassId)]!!
varBuilder.backMapping[arrayAccess] =
varBuilder.backMapping[UtConstraintArrayAccess(variable, indices.first(), elementClassId)]!!
val indexAliases = indices.flatMap { idx ->
allAliases.map { UtConstraintArrayAccess(it, idx, elementClassId) }
}.toSet()
val res = buildModel(atoms, arrayAccess, indexAliases).withConstraints(
indices.map { UtEqConstraint(it, indexVariable) }.toSet()
indices.map { UtEqConstraint(it, indexVariable) }.toSet() + setOf(
UtGeConstraint(indexVariable, UtConstraintNumericConstant(0)),
UtLtConstraint(indexVariable, lengthVariable)
)
)
(indexModel as UtModel) to res
}

val allConstraints = elements.toList().fold((lengthModel as UtConstraintModel).utConstraints) { acc, pair ->
acc + ((pair.first as? UtConstraintModel)?.utConstraints ?: emptySet()) + ((pair.second as? UtConstraintModel)?.utConstraints ?: emptySet())
}

return UtArrayConstraintModel(
variable,
lengthModel,
elements,
atoms
setOf()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3607,10 +3607,10 @@ class UtBotSymbolicEngine(
}

if (!isInNestedMethod()) {
val postConditionUpdates =
postConditionConstructor.constructPostCondition(this@UtBotSymbolicEngine, symbolicResult)
logger.error { "HARD POST CONDITION" }
logger.error { postConditionUpdates.hardConstraints.constraints.joinToString("\n") }
val postConditionUpdates = postConditionConstructor.constructPostCondition(
this@UtBotSymbolicEngine,
symbolicResult
)
queuedSymbolicStateUpdates += postConditionUpdates
}

Expand Down Expand Up @@ -3701,7 +3701,7 @@ class UtBotSymbolicEngine(
instrumentation,
entryMethodPath(),
state.fullPath(),
hole = resolvedConstraints
constrainedExecution = resolvedConstraints
)

globalGraph.traversed(state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class UtConstraintTransformer(
}

override fun visitUtRefNeqConstraint(expr: UtRefNeqConstraint) = with(expr) {
UtRefEqConstraint(
UtRefNeqConstraint(
lhv.accept(this@UtConstraintTransformer),
rhv.accept(this@UtConstraintTransformer)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import mu.KotlinLogging
import org.utbot.engine.*
import org.utbot.engine.selectors.strategies.ScoringStrategyBuilder
import org.utbot.framework.UtSettings.enableSynthesis
import org.utbot.framework.modifications.StatementsStorage
import org.utbot.framework.synthesis.ConstrainedSynthesizer
import org.utbot.framework.synthesis.postcondition.constructors.EmptyPostCondition
import org.utbot.framework.synthesis.postcondition.constructors.PostConditionConstructor
Expand Down Expand Up @@ -478,11 +477,8 @@ object UtBotTestCaseGenerator : TestCaseGenerator {
map { execution ->
val oldStateBefore = execution.stateBefore

System.err.println("-------------------------------")
System.err.println("CONSTRAINTS")
System.err.println((execution.hole as ResolvedExecution).modelsAfter)
System.err.println("-------------------------------")
val aa = ConstrainedSynthesizer((execution.hole as ResolvedExecution).modelsAfter)
val constrainedExecution = execution.constrainedExecution ?: return@map execution
val aa = ConstrainedSynthesizer(constrainedExecution.modelsAfter)
val synthesizedModels = try {
aa.synthesize() ?: return@map execution
} catch (e: Throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.utbot.framework.UtSettings
import org.utbot.framework.UtSettings.enableSynthesis
import org.utbot.framework.plugin.api.MockStrategyApi
import org.utbot.framework.plugin.api.UtBotTestCaseGenerator
import org.utbot.framework.plugin.api.UtExecutionSuccess
import org.utbot.framework.plugin.api.UtModel
import org.utbot.framework.synthesis.postcondition.constructors.ConstraintBasedPostConditionConstructor
import soot.SootClass
Expand Down Expand Up @@ -42,7 +43,7 @@ class ConstrainedSynthesisUnitChecker(
synthesisMethodContext
),
scoringStrategy
).firstOrNull().also {
).firstOrNull { it.result is UtExecutionSuccess }.also {
enableSynthesis = true
}
} ?: return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ import org.utbot.framework.synthesis.postcondition.constructors.toSoot
internal fun Collection<ClassId>.expandable() = filter { !it.isArray && !it.isPrimitive }.toSet()

class ConstrainedSynthesizer(
models: ResolvedModels,
val parameters: List<UtModel>,
val depth: Int = 4
) {
val parameters = models.parameters

companion object {
private val logger = KotlinLogging.logger("ConstrainedSynthesizer")
private var attempts = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.utbot.engine.symbolic.asSoftConstraint
import org.utbot.framework.plugin.api.*
import org.utbot.framework.plugin.api.UtConstraintParameter
import org.utbot.framework.plugin.api.util.*
import org.utbot.framework.synthesis.ArrayUnit
import org.utbot.framework.synthesis.SynthesisMethodContext
import org.utbot.framework.synthesis.SynthesisUnitContext
import soot.ArrayType
Expand Down Expand Up @@ -64,6 +63,9 @@ class ConstraintBasedPostConditionConstructor(
addAll(buildPostCondition(element, builder, parameters, localVariableMemory))
}
}
for (constraint in model.utConstraints) {
add(constraint.accept(builder))
}
add(mkEq(symbolicValue, model.variable.accept(builder)))
}
else -> error("Unknown model: ${model::class}")
Expand Down