Darkyenus / glsl4idea

A GLSL language plugin for IntelliJ IDEA
GNU Lesser General Public License v3.0
100 stars 30 forks source link

high CPU and error: Reference element is not the same element for which references were queried [Plugin: GLSL] #163

Closed jeffpeck10x closed 1 year ago

jeffpeck10x commented 2 years ago

Just recently, when I open a project containing a couple relatively small glsl files, PyCharm slows down and my laptop fans turn on.

I just updated to the latest PyCharm:

PyCharm 2021.3.2 (Professional Edition)
Build #PY-213.6777.50, built on January 27, 2022

info.txt:

Element text: `vec`
Reference range: (0,3)

stacktrace.txt:

com.intellij.diagnostic.PluginException: Reference element is not the same element for which references were queried [Plugin: GLSL]
    at com.intellij.ide.plugins.PluginManagerCore.createPluginException(PluginManagerCore.java:290)
    at com.intellij.diagnostic.PluginProblemReporterImpl.createPluginExceptionByClass(PluginProblemReporterImpl.java:12)
    at com.intellij.diagnostic.PluginException.createByClass(PluginException.java:83)
    at com.intellij.diagnostic.PluginException.logPluginError(PluginException.java:100)
    at com.intellij.psi.PsiReferenceServiceImpl.assertReferencesHaveSameElement(PsiReferenceServiceImpl.java:54)
    at com.intellij.psi.PsiReferenceServiceImpl.getReferences(PsiReferenceServiceImpl.java:27)
    at com.intellij.psi.search.SingleTargetRequestResultProcessor.processTextOccurrence(SingleTargetRequestResultProcessor.java:32)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl$5.lambda$execute$0(PsiSearchHelperImpl.java:958)
    at com.intellij.psi.impl.search.LowLevelSearchUtil.processTreeUp(LowLevelSearchUtil.java:88)
    at com.intellij.psi.impl.search.LowLevelSearchUtil.lambda$processElementsAtOffsets$0(LowLevelSearchUtil.java:179)
    at com.intellij.psi.impl.search.LowLevelSearchUtil.processOffsets(LowLevelSearchUtil.java:206)
    at com.intellij.psi.impl.search.LowLevelSearchUtil.processElementsAtOffsets(LowLevelSearchUtil.java:178)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl$5.execute(PsiSearchHelperImpl.java:954)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl$1.processInReadAction(PsiSearchHelperImpl.java:245)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl$1.processInReadAction(PsiSearchHelperImpl.java:229)
    at com.intellij.openapi.application.ReadActionProcessor.lambda$process$0(ReadActionProcessor.java:11)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:865)
    at com.intellij.openapi.application.ReadAction.compute(ReadAction.java:61)
    at com.intellij.openapi.application.ReadActionProcessor.process(ReadActionProcessor.java:11)
    at com.intellij.concurrency.JobLauncherImpl.lambda$processImmediatelyIfTooFew$2(JobLauncherImpl.java:140)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$12(CoreProgressManager.java:624)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:698)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:646)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:623)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:66)
    at com.intellij.concurrency.JobLauncherImpl.lambda$processImmediatelyIfTooFew$3(JobLauncherImpl.java:136)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:839)
    at com.intellij.concurrency.JobLauncherImpl.processImmediatelyIfTooFew(JobLauncherImpl.java:147)
    at com.intellij.concurrency.JobLauncherImpl.invokeConcurrentlyUnderProgress(JobLauncherImpl.java:47)
    at com.intellij.concurrency.JobLauncher.invokeConcurrentlyUnderProgress(JobLauncher.java:49)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl.bulkProcessElementsWithWord(PsiSearchHelperImpl.java:253)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl.processSingleRequest(PsiSearchHelperImpl.java:1138)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl.processRequests(PsiSearchHelperImpl.java:776)
    at com.intellij.psi.search.SearchRequestQuery.processResults(SearchRequestQuery.java:24)
    at com.intellij.util.AbstractQuery.doProcessResults(AbstractQuery.java:91)
    at com.intellij.util.AbstractQuery.delegateProcessResults(AbstractQuery.java:108)
    at com.intellij.util.MergeQuery.processResults(MergeQuery.java:22)
    at com.intellij.util.AbstractQuery.doProcessResults(AbstractQuery.java:91)
    at com.intellij.util.AbstractQuery.delegateProcessResults(AbstractQuery.java:108)
    at com.intellij.util.UniqueResultsQuery.processResults(UniqueResultsQuery.java:37)
    at com.intellij.util.AbstractQuery.doProcessResults(AbstractQuery.java:91)
    at com.intellij.util.AbstractQuery.forEach(AbstractQuery.java:83)
    at com.intellij.util.AbstractQuery.findAll(AbstractQuery.java:28)
    at com.intellij.find.findUsages.FindUsagesHandlerBase.findReferencesToHighlight(FindUsagesHandlerBase.java:114)
    at com.intellij.codeInsight.highlighting.HighlightUsagesKt.getPsiUsageRanges(highlightUsages.kt:85)
    at com.intellij.codeInsight.highlighting.HighlightUsagesKt.getUsageRanges(highlightUsages.kt:56)
    at com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPass.lambda$highlightTargetUsages$0(IdentifierHighlighterPass.java:213)
    at com.intellij.util.AstLoadingFilter.lambda$toComputable$2(AstLoadingFilter.java:172)
    at com.intellij.util.AstLoadingFilter.disallowTreeLoading(AstLoadingFilter.java:130)
    at com.intellij.util.AstLoadingFilter.disallowTreeLoading(AstLoadingFilter.java:114)
    at com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPass.highlightTargetUsages(IdentifierHighlighterPass.java:212)
    at com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPass.highlightReferencesAndDeclarations(IdentifierHighlighterPass.java:188)
    at com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPass.doCollectInformation(IdentifierHighlighterPass.java:91)
    at com.intellij.codeInsight.highlighting.BackgroundHighlighter.lambda$updateHighlighted$1(BackgroundHighlighter.java:150)
    at com.intellij.codeInsight.highlighting.BackgroundHighlightingUtil.lambda$lookForInjectedFileInOtherThread$0(BackgroundHighlightingUtil.java:54)
    at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.insideReadAction(NonBlockingReadActionImpl.java:521)
    at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.lambda$attemptComputation$3(NonBlockingReadActionImpl.java:486)
    at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1084)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.lambda$runInReadActionWithWriteActionPriority$0(ProgressIndicatorUtils.java:75)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runActionAndCancelBeforeWrite(ProgressIndicatorUtils.java:158)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.lambda$runWithWriteActionPriority$1(ProgressIndicatorUtils.java:115)
    at com.intellij.openapi.progress.ProgressManager.lambda$runProcess$0(ProgressManager.java:57)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:188)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$12(CoreProgressManager.java:624)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:698)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:646)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:623)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:66)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:175)
    at com.intellij.openapi.progress.ProgressManager.runProcess(ProgressManager.java:57)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runWithWriteActionPriority(ProgressIndicatorUtils.java:112)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(ProgressIndicatorUtils.java:75)
    at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.attemptComputation(NonBlockingReadActionImpl.java:486)
    at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.lambda$transferToBgThread$1(NonBlockingReadActionImpl.java:407)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
    at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments: Element: glslplugin.lang.elements.GLSLIdentifier; reference: glslplugin.lang.elements.reference.GLSLTypeReference; reference element: glslplugin.lang.elements.declarations.GLSLTypename
    at com.intellij.psi.PsiReferenceServiceImpl.assertReferencesHaveSameElement(PsiReferenceServiceImpl.java:64)
    ... 76 more

I am not clear on whether it is the plugin or a PyCharm bug, but PyCharm only reports the above error when the plugin is present. (It seems like the high CPU still happened when the plugin was disabled, although it might have just been that the fans were still running from before.)

Darkyenus commented 2 years ago

That might be a bug in this plugin. Could you please share a file that causes that problem? If you want, you can do it privately, my e-mail is public. I'd appreciate it if you send a minimal file that still reproduces this problem. I don't have much free time nowadays, so simple repro will massively increase the chance of me fixing it. Thanks!

Darkyenus commented 2 years ago

This is caused by the messy reference-handling implementation of the plugin. Fixing it will require a partial rewrite/refactor of the reference handling code. In particular, getReferenceProxy needs to go away and elements that actually are references must create the references from themselves, not through the proxy, because IDE asserts that this exact thing does not happen.

Darkyenus commented 2 years ago

Unreliable repro:

attribute highp vec2 aVertPos;
    attribute mediump vec3 aVertCol;

    varying mediump vec3 vVertCol;

    uniform highp mat4 uModelViewProjectionMatrix; // Rename this variable to something else

    void main() {
      vVertCol = aVertCol;
      gl_Position = uModelViewProjectionMatrix * vec4(aVertPos, 0.0, 1.0);
      //gl_Position = vec4(aVertPos, 0.0, 1.0);
    }
HughPH commented 1 year ago

Is there a plan to fix this?

Darkyenus commented 1 year ago

Should be fixed by c0a3b3051ecc6dc909654264113fe6151d5a25b4 and following commits.