Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MForest7 committed Mar 7, 2025
1 parent 18f6a33 commit 71892b4
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ class ForwardAnalyzer(
private val liveVariablesCache = hashMapOf<EtsMethod, LiveVariables>()
private fun liveVariables(method: EtsMethod) =
liveVariablesCache.computeIfAbsent(method) {
if (doLiveVariablesAnalysis)
LiveVariables.from(method)
else
AlwaysAlive
if (doLiveVariablesAnalysis) LiveVariables.from(method) else AlwaysAlive
}

override fun handleNewEdge(edge: Edge<ForwardTypeDomainFact, EtsStmt>): List<AnalyzerEvent> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,22 @@ class ForwardFlowFunctions(
private val aliasesCache: MutableMap<EtsMethod, List<StmtAliasInfo>> = hashMapOf()
private fun getAliases(method: EtsMethod): List<StmtAliasInfo> {
return aliasesCache.computeIfAbsent(method) {
if (doAliasAnalysis)
if (doAliasAnalysis) {
MethodAliasInfoImpl(method).computeAliases()
else
} else {
NoMethodAliasInfo(method).computeAliases()
}
}
}

private val liveVariablesCache = hashMapOf<EtsMethod, LiveVariables>()
private fun liveVariables(method: EtsMethod) =
liveVariablesCache.computeIfAbsent(method) {
if (doLiveVariablesAnalysis)
if (doLiveVariablesAnalysis) {
LiveVariables.from(method)
else
} else {
AlwaysAlive
}
}

override fun obtainPossibleStartFacts(method: EtsMethod): Collection<ForwardTypeDomainFact> {
Expand Down Expand Up @@ -170,7 +172,7 @@ class ForwardFlowFunctions(
sequentFact(current, fact).myFilter()
.filter {
when (val base = it.variable.base) {
is AccessPathBase.Local -> liveVars.isAliveAt(base.name, current) //|| liveVars.isAliveAt(base.name, next)
is AccessPathBase.Local -> liveVars.isAliveAt(base.name, current)
else -> true
}
}
Expand Down Expand Up @@ -372,20 +374,27 @@ class ForwardFlowFunctions(
// Using the cast type directly is just a temporary solution to satisfy simple tests.
if (current.rhv is EtsCastExpr) {
val path = AccessPath(lhv.base, fact.variable.accesses)
// val type = EtsTypeFact.from((current.rhv as EtsCastExpr).type).intersect(fact.type) ?: fact.type
val type = EtsTypeFact.from((current.rhv as EtsCastExpr).type)

return listOf(fact, TypedVariable(path, type))
} else if (current.rhv is EtsAwaitExpr) {
val path = AccessPath(lhv.base, fact.variable.accesses)
val promiseType = fact.type

if (promiseType is EtsTypeFact.ObjectEtsTypeFact) {
val promiseClass = promiseType.cls

if (promiseClass is EtsClassType && promiseClass.signature.name == "Promise") {
val type = EtsTypeFact.from(promiseClass.typeParameters.singleOrNull() ?: return listOf(fact))
val type = EtsTypeFact.from(
type = promiseClass.typeParameters.singleOrNull() ?: return listOf(fact)
)
return listOf(fact, TypedVariable(path, type))
}

if (promiseClass is EtsUnclearRefType && promiseClass.name.startsWith("Promise")) {
val type = EtsTypeFact.from(promiseClass.typeParameters.singleOrNull() ?: return listOf(fact))
val type = EtsTypeFact.from(
type = promiseClass.typeParameters.singleOrNull() ?: return listOf(fact)
)
return listOf(fact, TypedVariable(path, type))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ interface LiveVariables {
private const val THRESHOLD: Int = 20

fun from(method: EtsMethod): LiveVariables =
if (method.cfg.stmts.size > THRESHOLD)
LiveVariablesImpl(method)
else AlwaysAlive
if (method.cfg.stmts.size > THRESHOLD) LiveVariablesImpl(method) else AlwaysAlive
}
}

Expand All @@ -40,7 +38,7 @@ object AlwaysAlive : LiveVariables {
}

class LiveVariablesImpl(
val method: EtsMethod
val method: EtsMethod,
) : LiveVariables {
companion object {
private fun EtsEntity.used(): List<String> = when (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import kotlinx.coroutines.newSingleThreadContext
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
import mu.KotlinLogging
import org.jacodb.ets.base.ANONYMOUS_CLASS_PREFIX
import org.jacodb.ets.base.CONSTRUCTOR_NAME
import org.jacodb.ets.base.EtsReturnStmt
import org.jacodb.ets.base.EtsStmt
Expand Down Expand Up @@ -193,7 +192,8 @@ class TypeInferenceManager(
typeInfo,
doAddKnownTypes,
doAliasAnalysis = true,
doLiveVariablesAnalysis = true)
doLiveVariablesAnalysis = true,
)

val forwardRunner = UniRunner(
traits = traits,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ class EtsTypeResolverPerformanceTest {
)
)

val file = File(OUTPUT_FILE)
file.writeText(buildString {
val reportStr = buildString {
appendLine("|project|min time|max time|avg time|median time|%|")
appendLine("|:--|:--|:--|:--|:--|:--|")
reports.forEach {
appendLine(it.dumpToString())
}
})
}
val file = File(OUTPUT_FILE)
file.writeText(reportStr)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fun generateReportForProject(
projectId: String,
abcPath: String,
warmupIterationsCount: Int,
runIterationsCount: Int
runIterationsCount: Int,
): PerformanceReport {
val abcScene = AbcProjects.getAbcProject(abcPath)

Expand Down

0 comments on commit 71892b4

Please sign in to comment.