User: llamalad7 Date: 20 Jul 24 23:29 Revision: 2293169cc59ae81f90be1ec2fb6216916473dcab Summary: MixinExtras Expressions: Resolve `FlowMap`s sometimes becoming desynced from their `MethodNode`s, causing expression targets to be unresolved until the IDE is restarted. (#2335) TeamCity URL: http://ci.mcdev.io:80/viewModification.html?tab=vcsModificationFiles&modId=9490&personal=false Index: src/main/kotlin/platform/mixin/expression/MEExpressionMatchUtil.kt =================================================================== --- src/main/kotlin/platform/mixin/expression/MEExpressionMatchUtil.kt (revision df8907cfcc86dbb3df9a0955ed3238c0fc21060a) +++ src/main/kotlin/platform/mixin/expression/MEExpressionMatchUtil.kt (revision 2293169cc59ae81f90be1ec2fb6216916473dcab) @@ -25,7 +25,6 @@ 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 @@ -33,6 +32,7 @@ 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 @@ -78,12 +78,14 @@ ExpressionService.offerInstance(MEExpressionService) } - fun getFlowMap(project: Project, classIn: ClassNode, methodIn: MethodNode): FlowMap? { + private val flowCache = Caffeine.newBuilder().weakKeys().build() + + 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() @@ -147,7 +149,7 @@ 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()