Skip to content

Commit

Permalink
MixinExtras Expressions: Resolve FlowMaps sometimes becoming desync…
Browse files Browse the repository at this point in the history
…ed from their `MethodNode`s, causing expression targets to be unresolved until the IDE is restarted. (#2335)
  • Loading branch information
LlamaLad7 authored Jul 20, 2024
1 parent df8907c commit 2293169
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import com.demonwav.mcdev.platform.mixin.handlers.MixinAnnotationHandler
import com.demonwav.mcdev.platform.mixin.handlers.injectionPoint.CollectVisitor
import com.demonwav.mcdev.platform.mixin.util.LocalInfo
import com.demonwav.mcdev.platform.mixin.util.MixinConstants
import com.demonwav.mcdev.platform.mixin.util.cached
import com.demonwav.mcdev.util.MemberReference
import com.demonwav.mcdev.util.computeStringArray
import com.demonwav.mcdev.util.constantStringValue
import com.demonwav.mcdev.util.descriptor
import com.demonwav.mcdev.util.findAnnotations
import com.demonwav.mcdev.util.resolveType
import com.demonwav.mcdev.util.resolveTypeArray
import com.github.benmanes.caffeine.cache.Caffeine
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.module.Module
import com.intellij.openapi.progress.ProcessCanceledException
Expand Down Expand Up @@ -78,12 +78,14 @@ object MEExpressionMatchUtil {
ExpressionService.offerInstance(MEExpressionService)
}

fun getFlowMap(project: Project, classIn: ClassNode, methodIn: MethodNode): FlowMap? {
private val flowCache = Caffeine.newBuilder().weakKeys().build<MethodNode, FlowMap?>()

fun getFlowMap(project: Project, classNode: ClassNode, methodIn: MethodNode): FlowMap? {
if (methodIn.instructions == null) {
return null
}

return methodIn.cached(classIn, project) { classNode, methodNode ->
return flowCache.asMap().computeIfAbsent(methodIn) { methodNode ->
val interpreter = object : FlowInterpreter(classNode, methodNode, MEFlowContext(project)) {
override fun newValue(type: Type?): FlowValue? {
ProgressManager.checkCanceled()
Expand Down Expand Up @@ -147,7 +149,7 @@ object MEExpressionMatchUtil {
throw e
}
LOGGER.warn("MEExpressionMatchUtil.getFlowMap failed", e)
return@cached null
return@computeIfAbsent null
}

interpreter.finish().asSequence().mapNotNull { flow -> flow.virtualInsnOrNull?.let { it to flow } }.toMap()
Expand Down

0 comments on commit 2293169

Please sign in to comment.