Skip to content

Commit 981b4ed

Browse files
committed
cleanup
1 parent 0ccac56 commit 981b4ed

File tree

6 files changed

+27
-22
lines changed

6 files changed

+27
-22
lines changed

usvm-ts-dataflow/src/main/kotlin/org/usvm/dataflow/ts/infer/ForwardAnalyzer.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ class ForwardAnalyzer(
3737
private val liveVariablesCache = hashMapOf<EtsMethod, LiveVariables>()
3838
private fun liveVariables(method: EtsMethod) =
3939
liveVariablesCache.computeIfAbsent(method) {
40-
if (doLiveVariablesAnalysis)
41-
LiveVariables.from(method)
42-
else
43-
AlwaysAlive
40+
if (doLiveVariablesAnalysis) LiveVariables.from(method) else AlwaysAlive
4441
}
4542

4643
override fun handleNewEdge(edge: Edge<ForwardTypeDomainFact, EtsStmt>): List<AnalyzerEvent> {

usvm-ts-dataflow/src/main/kotlin/org/usvm/dataflow/ts/infer/ForwardFlowFunctions.kt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,22 @@ class ForwardFlowFunctions(
5656
private val aliasesCache: MutableMap<EtsMethod, List<StmtAliasInfo>> = hashMapOf()
5757
private fun getAliases(method: EtsMethod): List<StmtAliasInfo> {
5858
return aliasesCache.computeIfAbsent(method) {
59-
if (doAliasAnalysis)
59+
if (doAliasAnalysis) {
6060
MethodAliasInfoImpl(method).computeAliases()
61-
else
61+
} else {
6262
NoMethodAliasInfo(method).computeAliases()
63+
}
6364
}
6465
}
6566

6667
private val liveVariablesCache = hashMapOf<EtsMethod, LiveVariables>()
6768
private fun liveVariables(method: EtsMethod) =
6869
liveVariablesCache.computeIfAbsent(method) {
69-
if (doLiveVariablesAnalysis)
70+
if (doLiveVariablesAnalysis) {
7071
LiveVariables.from(method)
71-
else
72+
} else {
7273
AlwaysAlive
74+
}
7375
}
7476

7577
override fun obtainPossibleStartFacts(method: EtsMethod): Collection<ForwardTypeDomainFact> {
@@ -170,7 +172,7 @@ class ForwardFlowFunctions(
170172
sequentFact(current, fact).myFilter()
171173
.filter {
172174
when (val base = it.variable.base) {
173-
is AccessPathBase.Local -> liveVars.isAliveAt(base.name, current) //|| liveVars.isAliveAt(base.name, next)
175+
is AccessPathBase.Local -> liveVars.isAliveAt(base.name, current)
174176
else -> true
175177
}
176178
}
@@ -372,20 +374,27 @@ class ForwardFlowFunctions(
372374
// Using the cast type directly is just a temporary solution to satisfy simple tests.
373375
if (current.rhv is EtsCastExpr) {
374376
val path = AccessPath(lhv.base, fact.variable.accesses)
375-
// val type = EtsTypeFact.from((current.rhv as EtsCastExpr).type).intersect(fact.type) ?: fact.type
376377
val type = EtsTypeFact.from((current.rhv as EtsCastExpr).type)
378+
377379
return listOf(fact, TypedVariable(path, type))
378380
} else if (current.rhv is EtsAwaitExpr) {
379381
val path = AccessPath(lhv.base, fact.variable.accesses)
380382
val promiseType = fact.type
383+
381384
if (promiseType is EtsTypeFact.ObjectEtsTypeFact) {
382385
val promiseClass = promiseType.cls
386+
383387
if (promiseClass is EtsClassType && promiseClass.signature.name == "Promise") {
384-
val type = EtsTypeFact.from(promiseClass.typeParameters.singleOrNull() ?: return listOf(fact))
388+
val type = EtsTypeFact.from(
389+
type = promiseClass.typeParameters.singleOrNull() ?: return listOf(fact)
390+
)
385391
return listOf(fact, TypedVariable(path, type))
386392
}
393+
387394
if (promiseClass is EtsUnclearRefType && promiseClass.name.startsWith("Promise")) {
388-
val type = EtsTypeFact.from(promiseClass.typeParameters.singleOrNull() ?: return listOf(fact))
395+
val type = EtsTypeFact.from(
396+
type = promiseClass.typeParameters.singleOrNull() ?: return listOf(fact)
397+
)
389398
return listOf(fact, TypedVariable(path, type))
390399
}
391400
}

usvm-ts-dataflow/src/main/kotlin/org/usvm/dataflow/ts/infer/LiveVariables.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ interface LiveVariables {
2929
private const val THRESHOLD: Int = 20
3030

3131
fun from(method: EtsMethod): LiveVariables =
32-
if (method.cfg.stmts.size > THRESHOLD)
33-
LiveVariablesImpl(method)
34-
else AlwaysAlive
32+
if (method.cfg.stmts.size > THRESHOLD) LiveVariablesImpl(method) else AlwaysAlive
3533
}
3634
}
3735

@@ -40,7 +38,7 @@ object AlwaysAlive : LiveVariables {
4038
}
4139

4240
class LiveVariablesImpl(
43-
val method: EtsMethod
41+
val method: EtsMethod,
4442
) : LiveVariables {
4543
companion object {
4644
private fun EtsEntity.used(): List<String> = when (this) {

usvm-ts-dataflow/src/main/kotlin/org/usvm/dataflow/ts/infer/TypeInferenceManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import kotlinx.coroutines.newSingleThreadContext
1212
import kotlinx.coroutines.runBlocking
1313
import kotlinx.coroutines.withTimeout
1414
import mu.KotlinLogging
15-
import org.jacodb.ets.base.ANONYMOUS_CLASS_PREFIX
1615
import org.jacodb.ets.base.CONSTRUCTOR_NAME
1716
import org.jacodb.ets.base.EtsReturnStmt
1817
import org.jacodb.ets.base.EtsStmt
@@ -193,7 +192,8 @@ class TypeInferenceManager(
193192
typeInfo,
194193
doAddKnownTypes,
195194
doAliasAnalysis = true,
196-
doLiveVariablesAnalysis = true)
195+
doLiveVariablesAnalysis = true,
196+
)
197197

198198
val forwardRunner = UniRunner(
199199
traits = traits,

usvm-ts-dataflow/src/test/kotlin/org/usvm/dataflow/ts/test/EtsTypeResolverPerformanceTest.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,14 @@ class EtsTypeResolverPerformanceTest {
7676
)
7777
)
7878

79-
val file = File(OUTPUT_FILE)
80-
file.writeText(buildString {
79+
val reportStr = buildString {
8180
appendLine("|project|min time|max time|avg time|median time|%|")
8281
appendLine("|:--|:--|:--|:--|:--|:--|")
8382
reports.forEach {
8483
appendLine(it.dumpToString())
8584
}
86-
})
85+
}
86+
val file = File(OUTPUT_FILE)
87+
file.writeText(reportStr)
8788
}
8889
}

usvm-ts-dataflow/src/test/kotlin/org/usvm/dataflow/ts/test/utils/PerformanceReport.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fun generateReportForProject(
4848
projectId: String,
4949
abcPath: String,
5050
warmupIterationsCount: Int,
51-
runIterationsCount: Int
51+
runIterationsCount: Int,
5252
): PerformanceReport {
5353
val abcScene = AbcProjects.getAbcProject(abcPath)
5454

0 commit comments

Comments
 (0)