From 3beb5238e85b270e6f231fadcdcfa2344630dffb Mon Sep 17 00:00:00 2001 From: LlamaLad7 Date: Sun, 21 Jul 2024 00:17:06 +0100 Subject: [PATCH] MixinExtras Expressions: Resolve `FlowMap`s sometimes becoming desynced from their `MethodNode`s, causing expression targets to be unresolved until the IDE is restarted. --- .../platform/mixin/expression/MEExpressionMatchUtil.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/platform/mixin/expression/MEExpressionMatchUtil.kt b/src/main/kotlin/platform/mixin/expression/MEExpressionMatchUtil.kt index 541cdd455..8fc00d95f 100644 --- a/src/main/kotlin/platform/mixin/expression/MEExpressionMatchUtil.kt +++ b/src/main/kotlin/platform/mixin/expression/MEExpressionMatchUtil.kt @@ -25,7 +25,6 @@ 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 @@ -33,6 +32,7 @@ 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 @@ -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() + + 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 @@ 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()