Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MixinExtras Expressions: Resolve FlowMaps sometimes becoming desync… #2335

Merged
merged 1 commit into from
Jul 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading