@@ -5,7 +5,6 @@ import org.usvm.PathSelectorCombinationStrategy
55import org.usvm.UMachineOptions
66import org.usvm.UPathSelector
77import org.usvm.UState
8- import org.usvm.UTarget
98import org.usvm.algorithms.DeterministicPriorityCollection
109import org.usvm.algorithms.RandomizedPriorityCollection
1110import org.usvm.statistics.ApplicationGraph
@@ -17,18 +16,22 @@ import org.usvm.statistics.distances.InterprocDistance
1716import org.usvm.statistics.distances.InterprocDistanceCalculator
1817import org.usvm.statistics.distances.MultiTargetDistanceCalculator
1918import org.usvm.statistics.distances.ReachabilityKind
19+ import org.usvm.targets.UTarget
2020import org.usvm.util.log2
2121import kotlin.math.max
2222import kotlin.random.Random
2323
24- fun <Method , Statement , Target : UTarget < Statement , Target , State >, State : UState < * , Method , Statement , * , Target , State > > createPathSelector (
24+ fun <Method , Statement , Target , State > createPathSelector (
2525 initialState : State ,
2626 options : UMachineOptions ,
2727 applicationGraph : ApplicationGraph <Method , Statement >,
2828 coverageStatistics : () -> CoverageStatistics <Method , Statement , State >? = { null },
2929 cfgStatistics : () -> CfgStatistics <Method , Statement >? = { null },
30- callGraphStatistics : () -> CallGraphStatistics <Method >? = { null }
31- ): UPathSelector <State > {
30+ callGraphStatistics : () -> CallGraphStatistics <Method >? = { null },
31+ ): UPathSelector <State >
32+ where Target : UTarget <Statement , Target >,
33+ State : UState <* , Method , Statement , * , Target , State > {
34+
3235 val strategies = options.pathSelectionStrategies
3336 require(strategies.isNotEmpty()) { " At least one path selector strategy should be specified" }
3437
@@ -56,6 +59,7 @@ fun <Method, Statement, Target : UTarget<Statement, Target, State>, State : USta
5659 requireNotNull(cfgStatistics()) { " CFG statistics is required for closest to uncovered path selector" },
5760 applicationGraph
5861 )
62+
5963 PathSelectionStrategy .CLOSEST_TO_UNCOVERED_RANDOM -> createClosestToUncoveredPathSelector(
6064 requireNotNull(coverageStatistics()) { " Coverage statistics is required for closest to uncovered path selector" },
6165 requireNotNull(cfgStatistics()) { " CFG statistics is required for closest to uncovered path selector" },
@@ -68,6 +72,7 @@ fun <Method, Statement, Target : UTarget<Statement, Target, State>, State : USta
6872 requireNotNull(callGraphStatistics()) { " Call graph statistics is required for targeted path selector" },
6973 applicationGraph
7074 )
75+
7176 PathSelectionStrategy .TARGETED_RANDOM -> createTargetedPathSelector<Method , Statement , Target , State >(
7277 requireNotNull(cfgStatistics()) { " CFG statistics is required for targeted path selector" },
7378 requireNotNull(callGraphStatistics()) { " Call graph statistics is required for targeted path selector" },
@@ -79,6 +84,7 @@ fun <Method, Statement, Target : UTarget<Statement, Target, State>, State : USta
7984 requireNotNull(cfgStatistics()) { " CFG statistics is required for targeted call stack local path selector" },
8085 applicationGraph
8186 )
87+
8288 PathSelectionStrategy .TARGETED_CALL_STACK_LOCAL_RANDOM -> createTargetedPathSelector<Method , Statement , Target , State >(
8389 requireNotNull(cfgStatistics()) { " CFG statistics is required for targeted call stack local path selector" },
8490 applicationGraph,
@@ -160,7 +166,12 @@ private fun <Method, Statement, State : UState<*, Method, Statement, *, *, State
160166 applicationGraph
161167 )
162168
163- coverageStatistics.addOnCoveredObserver { _, method, statement -> distanceCalculator.removeTarget(method, statement) }
169+ coverageStatistics.addOnCoveredObserver { _, method, statement ->
170+ distanceCalculator.removeTarget(
171+ method,
172+ statement
173+ )
174+ }
164175
165176 if (random == null ) {
166177 return WeightedPathSelector (
@@ -171,7 +182,12 @@ private fun <Method, Statement, State : UState<*, Method, Statement, *, *, State
171182
172183 return WeightedPathSelector (
173184 priorityCollectionFactory = { RandomizedPriorityCollection (compareById()) { random.nextDouble() } },
174- weighter = { 1.0 / max(distanceCalculator.calculateDistance(it.currentStatement, it.callStack).toDouble(), 1.0 ) }
185+ weighter = {
186+ 1.0 / max(
187+ distanceCalculator.calculateDistance(it.currentStatement, it.callStack).toDouble(),
188+ 1.0
189+ )
190+ }
175191 )
176192}
177193
@@ -191,11 +207,14 @@ private fun <Method, Statement, State : UState<*, Method, Statement, *, *, State
191207 )
192208}
193209
194- internal fun <Method , Statement , Target : UTarget < Statement , Target , State >, State : UState < * , Method , Statement , * , Target , State > > createTargetedPathSelector (
210+ internal fun <Method , Statement , Target , State > createTargetedPathSelector (
195211 cfgStatistics : CfgStatistics <Method , Statement >,
196212 applicationGraph : ApplicationGraph <Method , Statement >,
197213 random : Random ? = null,
198- ): UPathSelector <State > {
214+ ): UPathSelector <State >
215+ where Target : UTarget <Statement , Target >,
216+ State : UState <* , Method , Statement , * , Target , State > {
217+
199218 val distanceCalculator = MultiTargetDistanceCalculator <Method , Statement , _ > { loc ->
200219 CallStackDistanceCalculator (
201220 targets = listOf (loc),
@@ -206,13 +225,14 @@ internal fun <Method, Statement, Target : UTarget<Statement, Target, State>, Sta
206225
207226 fun calculateDistanceToTargets (state : State ) =
208227 state.targets.minOfOrNull { target ->
209- if (target.location == null ) {
228+ val location = target.location
229+ if (location == null ) {
210230 0u
211231 } else {
212232 distanceCalculator.calculateDistance(
213233 state.currentStatement,
214234 state.callStack,
215- target. location
235+ location
216236 )
217237 }
218238 } ? : UInt .MAX_VALUE
@@ -249,12 +269,15 @@ private fun InterprocDistance.logWeight(): UInt {
249269 return weight
250270}
251271
252- internal fun <Method , Statement , Target : UTarget < Statement , Target , State >, State : UState < * , Method , Statement , * , Target , State > > createTargetedPathSelector (
272+ internal fun <Method , Statement , Target , State > createTargetedPathSelector (
253273 cfgStatistics : CfgStatistics <Method , Statement >,
254274 callGraphStatistics : CallGraphStatistics <Method >,
255275 applicationGraph : ApplicationGraph <Method , Statement >,
256276 random : Random ? = null,
257- ): UPathSelector <State > {
277+ ): UPathSelector <State >
278+ where Target : UTarget <Statement , Target >,
279+ State : UState <* , Method , Statement , * , Target , State > {
280+
258281 val distanceCalculator = MultiTargetDistanceCalculator <Method , Statement , _ > { stmt ->
259282 InterprocDistanceCalculator (
260283 targetLocation = stmt,
@@ -266,13 +289,14 @@ internal fun <Method, Statement, Target : UTarget<Statement, Target, State>, Sta
266289
267290 fun calculateWeight (state : State ) =
268291 state.targets.minOfOrNull { target ->
269- if (target.location == null ) {
292+ val location = target.location
293+ if (location == null ) {
270294 0u
271295 } else {
272296 distanceCalculator.calculateDistance(
273297 state.currentStatement,
274298 state.callStack,
275- target. location
299+ location
276300 ).logWeight()
277301 }
278302 } ? : UInt .MAX_VALUE
0 commit comments