Skip to content

Add a common Simplificator in the Traverser #1261

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

Merged
merged 6 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
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
@@ -1,7 +1,7 @@
package org.utbot.features

import org.utbot.analytics.FeatureExtractor
import org.utbot.engine.ExecutionState
import org.utbot.engine.state.ExecutionState
import org.utbot.engine.InterProceduralUnitGraph
import org.utbot.engine.selectors.strategies.StatementsStatistics
import org.utbot.engine.selectors.strategies.SubpathStatistics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.utbot.features

import org.utbot.analytics.EngineAnalyticsContext
import org.utbot.analytics.FeatureProcessor
import org.utbot.engine.ExecutionState
import org.utbot.engine.state.ExecutionState
import org.utbot.engine.InterProceduralUnitGraph
import org.utbot.framework.UtSettings
import soot.jimple.Stmt
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.utbot.analytics

import org.utbot.engine.ExecutionState
import org.utbot.engine.state.ExecutionState

/**
* Class that encapsulates work with FeatureExtractor during symbolic execution.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.utbot.engine.pc.UtIsExpression
import org.utbot.engine.pc.UtTrue
import org.utbot.engine.pc.mkAnd
import org.utbot.engine.pc.mkOr
import org.utbot.engine.state.ExecutionState
import org.utbot.engine.symbolic.*
import org.utbot.engine.types.TypeResolver
import org.utbot.framework.plugin.api.FieldId
Expand Down Expand Up @@ -160,8 +161,6 @@ data class MethodResult(
val symbolicResult: SymbolicResult,
val symbolicStateUpdate: SymbolicStateUpdate = SymbolicStateUpdate()
) : InvokeResult() {
val memoryUpdates by symbolicStateUpdate::memoryUpdates

constructor(
symbolicResult: SymbolicResult,
hardConstraints: HardConstraint = emptyHardConstraint(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.utbot.engine.pc.mkInt
import org.utbot.engine.pc.mkLong
import org.utbot.engine.pc.mkShort
import org.utbot.engine.pc.toSort
import org.utbot.engine.state.ExecutionState
import org.utbot.framework.UtSettings.checkNpeInNestedMethods
import org.utbot.framework.UtSettings.checkNpeInNestedNotPrivateMethods
import org.utbot.framework.plugin.api.FieldId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.utbot.engine

import org.utbot.engine.selectors.strategies.TraverseGraphStatistics
import org.utbot.engine.state.CALL_DECISION_NUM
import org.utbot.engine.state.Edge
import org.utbot.engine.state.ExecutionState
import soot.SootClass
import soot.SootMethod
import soot.jimple.Stmt
Expand Down
33 changes: 5 additions & 28 deletions utbot-framework/src/main/kotlin/org/utbot/engine/Memory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.utbot.engine
import org.utbot.engine.MemoryState.CURRENT
import org.utbot.engine.MemoryState.INITIAL
import org.utbot.engine.MemoryState.STATIC_INITIAL
import org.utbot.engine.pc.RewritingVisitor
import org.utbot.engine.pc.UtAddrExpression
import org.utbot.engine.pc.UtAddrSort
import org.utbot.engine.pc.UtArrayExpressionBase
Expand Down Expand Up @@ -49,28 +48,6 @@ import soot.Scene
import soot.Type


/**
* Represents a memory associated with a certain method call. For now consists only of local variables mapping.
* TODO: think on other fields later
*
* @param [locals] represents a mapping from [LocalVariable]s of a specific method call to [SymbolicValue]s.
*/
data class LocalVariableMemory(
private val locals: PersistentMap<LocalVariable, SymbolicValue> = persistentHashMapOf()
) {
fun memoryForNestedMethod(): LocalVariableMemory = this.copy(locals = persistentHashMapOf())

fun update(update: LocalMemoryUpdate): LocalVariableMemory = this.copy(locals = locals.update(update.locals))

/**
* Returns local variable value.
*/
fun local(variable: LocalVariable): SymbolicValue? = locals[variable]

val localValues: Set<SymbolicValue>
get() = locals.values.toSet()
}

/**
* Local memory implementation based on arrays.
*
Expand Down Expand Up @@ -439,20 +416,20 @@ data class UtNamedStore(
)

/**
* Create [UtNamedStore] with simplified [index] and [value] expressions.
* Create [UtNamedStore] with unsimplified [index] and [value] expressions.
*
* @see RewritingVisitor
* @note simplifications occur explicitly in [Traverser]
*/
fun simplifiedNamedStore(
fun namedStore(
chunkDescriptor: MemoryChunkDescriptor,
index: UtExpression,
value: UtExpression
) = RewritingVisitor().let { visitor -> UtNamedStore(chunkDescriptor, index.accept(visitor), value.accept(visitor)) }
) = UtNamedStore(chunkDescriptor, index, value)

/**
* Updates persistent map where value = null in update means deletion of original key-value
*/
private fun <K, V> PersistentMap<K, V>.update(update: Map<K, V?>): PersistentMap<K, V> {
fun <K, V> PersistentMap<K, V>.update(update: Map<K, V?>): PersistentMap<K, V> {
if (update.isEmpty()) return this
val deletions = mutableListOf<K>()
val updates = mutableMapOf<K, V>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ private fun Traverser.arrayToMethodResult(
}

val memoryUpdate = MemoryUpdate(
stores = persistentListOf(simplifiedNamedStore(descriptor, newAddr, updatedArray)),
stores = persistentListOf(namedStore(descriptor, newAddr, updatedArray)),
touchedChunkDescriptors = persistentSetOf(descriptor),
)

Expand Down
7 changes: 3 additions & 4 deletions utbot-framework/src/main/kotlin/org/utbot/engine/Strings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.github.curiousoddman.rgxgen.RgxGen
import org.utbot.engine.overrides.strings.UtString
import org.utbot.engine.overrides.strings.UtStringBuffer
import org.utbot.engine.overrides.strings.UtStringBuilder
import org.utbot.engine.pc.RewritingVisitor
import org.utbot.engine.pc.UtAddrExpression
import org.utbot.engine.pc.UtBoolExpression
import org.utbot.engine.pc.UtFalse
Expand Down Expand Up @@ -122,17 +121,17 @@ class StringWrapper : BaseOverriddenWrapper(utStringClass.name) {
parameters: List<SymbolicValue>
): List<InvokeResult>? {
val arg = parameters[0] as ObjectValue
val matchingLengthExpr = getIntFieldValue(arg, STRING_LENGTH).accept(RewritingVisitor())
val matchingLengthExpr = getIntFieldValue(arg, STRING_LENGTH).accept(this.simplificator)

if (!matchingLengthExpr.isConcrete) return null

val matchingValueExpr =
selectArrayExpressionFromMemory(getValueArray(arg.addr)).accept(RewritingVisitor())
selectArrayExpressionFromMemory(getValueArray(arg.addr)).accept(this.simplificator)
val matchingLength = matchingLengthExpr.toConcrete() as Int
val matchingValue = CharArray(matchingLength)

for (i in 0 until matchingLength) {
val charExpr = matchingValueExpr.select(mkInt(i)).accept(RewritingVisitor())
val charExpr = matchingValueExpr.select(mkInt(i)).accept(this.simplificator)

if (!charExpr.isConcrete) return null

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.utbot.engine

import org.utbot.engine.state.ExecutionState

/**
* Represents a mutable _Context_ during the [ExecutionState] traversing. This _Context_ consists of all mutable and
* immutable properties and fields which are created and updated during analysis of a **single** Jimple instruction.
Expand Down
Loading