Nesting a for within a for { (itm,i) <- items.zipWithIndex ...} pegs the CPU and freezes IDEA

I have a reproducable case that forces me to force quit IntelliJ IDEA 10.0.3 with the currently released scala plugin 0.4.735.

Here is a sample of the case:

// Example of what makes my MacBook cry
object Foo {
  val items = 1 to 10

  for {
    (itm, i) <- items
    for
  }{
    println("I am value: %d at index: %d!".format(itm, i))
  }
}


so... if I have the full structure shown in the example above, but without the second "for" (the one on the 7th line of the formated code block above), upon typing that second "for" the CPU imediately jumps into the danger zone and spikes and falls forever. Well... that is until I finally force quit IntelliJ of course.

I have reproduced this 3 times in a row and frankly do not want to ever nest a for again as the pain has changed my behavior.

3 comments
Comment actions Permalink

I cannot reproduce it on IDEA 10.5 build 0.4.983. So it seems it's fixed now or I need threaddump of this problem to fix it (http://devnet.jetbrains.net/docs/DOC-260).

Best regards,
Alexander Podkhalyuzin.

0
Comment actions Permalink

That's good to hear.  For the sake of more info (I'm a coworker of the Robbie :) ) I reprod the problem on Intellij 10.3 and grabbed the following stack:

"AWT-EventQueue-1 10.0.3#IU-103.255, eap:false" prio=6 tid=104be9800 nid=0x122c6b000 runnable [122c67000]
   java.lang.Thread.State: RUNNABLE
    at org.jetbrains.plugins.scala.lang.parser.parsing.patterns.SimplePattern$.parse(SimplePattern.scala:103)
    at org.jetbrains.plugins.scala.lang.parser.parsing.patterns.Pattern3$.parse(Pattern3.scala:31)
    at org.jetbrains.plugins.scala.lang.parser.parsing.patterns.Pattern2$.parse(Pattern2.scala:110)
    at org.jetbrains.plugins.scala.lang.parser.parsing.patterns.Pattern1$.parse(Pattern1.scala:80)
    at org.jetbrains.plugins.scala.lang.parser.parsing.expressions.Enumerator$.parseNonGuard$1(Enumerator.scala:28)
    at org.jetbrains.plugins.scala.lang.parser.parsing.expressions.Enumerator$.parse(Enumerator.scala:76)
    at org.jetbrains.plugins.scala.lang.parser.parsing.expressions.Enumerators$.parse(Enumerators.scala:38)
    at org.jetbrains.plugins.scala.lang.parser.parsing.expressions.Expr1$.foo$3(Expr1.scala:227)
    at org.jetbrains.plugins.scala.lang.parser.parsing.expressions.Expr1$$anonfun$parse$3.apply$mcV$sp(Expr1.scala:231)
    at org.jetbrains.plugins.scala.lang.parser.util.ParserUtils$.parseLoopUntilRBrace(ParserUtils.scala:111)
    at org.jetbrains.plugins.scala.lang.parser.parsing.expressions.Expr1$.parse(Expr1.scala:231)
    at org.jetbrains.plugins.scala.lang.parser.parsing.expressions.Expr$.parse(Expr.scala:69)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.template.TemplateStat$.parse(TemplateStat.scala:40)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.template.TemplateBody$.subparse$1(TemplateBody.scala:49)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.template.TemplateBody$.subparse$1(TemplateBody.scala:60)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.template.TemplateBody$.parse(TemplateBody.scala:75)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.ClassTemplateOpt$.parse(ClassTemplateOpt.scala:31)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.ObjectDef$.parse(ObjectDef.scala:30)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.TmplDef$.parse(TmplDef.scala:56)
    at org.jetbrains.plugins.scala.lang.parser.parsing.statements.Def$.parse(Def.scala:105)
    at org.jetbrains.plugins.scala.lang.parser.parsing.statements.Def$.parse(Def.scala:29)
    at org.jetbrains.plugins.scala.lang.parser.parsing.statements.Def$.parse(Def.scala:28)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.template.TemplateStat$.parse(TemplateStat.scala:34)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.template.TemplateBody$.subparse$1(TemplateBody.scala:49)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.template.TemplateBody$.subparse$1(TemplateBody.scala:60)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.template.TemplateBody$.subparse$1(TemplateBody.scala:60)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.template.TemplateBody$.subparse$1(TemplateBody.scala:60)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.template.TemplateBody$.subparse$1(TemplateBody.scala:60)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.template.TemplateBody$.subparse$1(TemplateBody.scala:60)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.template.TemplateBody$.subparse$1(TemplateBody.scala:60)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.template.TemplateBody$.subparse$1(TemplateBody.scala:60)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.template.TemplateBody$.subparse$1(TemplateBody.scala:60)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.template.TemplateBody$.parse(TemplateBody.scala:75)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.ClassTemplateOpt$.parse(ClassTemplateOpt.scala:112)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.ObjectDef$.parse(ObjectDef.scala:30)
    at org.jetbrains.plugins.scala.lang.parser.parsing.top.TmplDef$.parse(TmplDef.scala:56)
    at org.jetbrains.plugins.scala.lang.parser.parsing.TopStat$.parse(TopStat.scala:50)
    at org.jetbrains.plugins.scala.lang.parser.parsing.TopStatSeq$.parse(TopStatSeq.scala:40)
    at org.jetbrains.plugins.scala.lang.parser.parsing.CompilationUnit$.parsePackagingBody$1(CompilationUnit.scala:30)
    at org.jetbrains.plugins.scala.lang.parser.parsing.CompilationUnit$.parsePackageSequence$1(CompilationUnit.scala:84)
    at org.jetbrains.plugins.scala.lang.parser.parsing.CompilationUnit$.parse(CompilationUnit.scala:90)
    at org.jetbrains.plugins.scala.lang.parser.parsing.Program$.parse(Program.scala:22)
    at org.jetbrains.plugins.scala.lang.parser.ScalaParser.parse(ScalaParser.scala:21)
    at com.intellij.psi.tree.IFileElementType.parseContents(IFileElementType.java:41)
    at com.intellij.psi.impl.source.tree.LazyParseableElement.b(LazyParseableElement.java:173)
    at com.intellij.psi.impl.source.tree.LazyParseableElement.getFirstChildNode(LazyParseableElement.java:214)
    - locked <764ff1800> (a com.intellij.psi.impl.source.tree.LazyParseableElement$ChameleonLock)
    at com.intellij.psi.impl.source.tree.LazyParseableElement.getFirstChildNode(LazyParseableElement.java:31)
    at com.intellij.psi.impl.source.text.BlockSupportImpl.mergeTrees(BlockSupportImpl.java:233)
    - locked <757784f58> (a com.intellij.psi.PsiLock)
    at com.intellij.psi.impl.source.text.BlockSupportImpl.a(BlockSupportImpl.java:194)
    at com.intellij.psi.impl.source.text.BlockSupportImpl.a(BlockSupportImpl.java:157)
    at com.intellij.psi.impl.source.text.BlockSupportImpl.access$000(BlockSupportImpl.java:53)
    at com.intellij.psi.impl.source.text.BlockSupportImpl$2.run(BlockSupportImpl.java:81)
    at com.intellij.psi.impl.PsiManagerImpl$3.compute(PsiManagerImpl.java:211)
    at com.intellij.psi.impl.source.PostprocessReformattingAspect.disablePostprocessFormattingInside(PostprocessReformattingAspect.java:114)
    at com.intellij.psi.impl.PsiManagerImpl.performActionWithFormatterDisabled(PsiManagerImpl.java:209)
    at com.intellij.psi.impl.source.text.BlockSupportImpl.reparseRange(BlockSupportImpl.java:79)
    at com.intellij.psi.impl.PsiDocumentManagerImpl.commit(PsiDocumentManagerImpl.java:480)
    at com.intellij.psi.impl.PsiDocumentManagerImpl$1.run(PsiDocumentManagerImpl.java:254)
    at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:844)
    at com.intellij.psi.impl.PsiDocumentManagerImpl.a(PsiDocumentManagerImpl.java:241)
    at com.intellij.psi.impl.PsiDocumentManagerImpl.commitDocument(PsiDocumentManagerImpl.java:235)
    at com.intellij.psi.impl.PsiDocumentManagerImpl.commitAllDocuments(PsiDocumentManagerImpl.java:204)
    at com.intellij.codeInsight.daemon.impl.TextEditorBackgroundHighlighter.getPasses(TextEditorBackgroundHighlighter.java:83)
    at com.intellij.codeInsight.daemon.impl.TextEditorBackgroundHighlighter.createPassesForEditor(TextEditorBackgroundHighlighter.java:106)
    at com.intellij.codeInsight.daemon.impl.TextEditorBackgroundHighlighter.createPassesForEditor(TextEditorBackgroundHighlighter.java:35)
    at com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl$6.run(DaemonCodeAnalyzerImpl.java:675)
    at com.intellij.util.Alarm$Request$1.run(Alarm.java:229)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:332)
    - locked <757786e88> (a java.lang.Object)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:678)
    at java.awt.EventQueue.access$000(EventQueue.java:86)
    at java.awt.EventQueue$1.run(EventQueue.java:639)
    at java.awt.EventQueue$1.run(EventQueue.java:637)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:648)
    at com.intellij.ide.IdeEventQueue.e(IdeEventQueue.java:652)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:505)
    at com.intellij.ide.IdeEventQueue.b(IdeEventQueue.java:404)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:368)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

0
Comment actions Permalink

Commit from 26.04 fixed parser infinite loop. So you will get this fix with 10.5 EAP build (with the latest Scala plugin) or with 10.5, which will be released soon.

Best regards,
Alexander Podkhalyuzin.

0

Please sign in to leave a comment.