scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Compiler.parseTree not thread-safe #8030

Closed scabug closed 10 years ago

scabug commented 10 years ago

According to the contract of Compiler.parseTree, no symbol should be entered in the returned tree. This ticket in the Scala IDE project proves the contract is broken.

scabug commented 10 years ago

Imported From: https://issues.scala-lang.org/browse/SI-8030?orig=1 Reporter: @dotta Affected Versions: 2.11.0-M8

scabug commented 10 years ago

@retronym said:

ase: <no phase>] Please file a ticket with the current stack trace at https://www.assembla.com/spaces/scala-ide/support/tickets
    at scala.tools.nsc.interactive.Global.assertCorrectThread(Global.scala:517)
    at scala.reflect.internal.Symbols$Symbol.rawInfo(Symbols.scala:1395)
    at scala.reflect.internal.Symbols$Symbol.isCoDefinedWith(Symbols.scala:2041)
    at scala.reflect.internal.Symbols$ClassSymbol$$anonfun$companionModule0$1.apply(Symbols.scala:3085)
    at scala.reflect.internal.Symbols$ClassSymbol$$anonfun$companionModule0$1.apply(Symbols.scala:3085)
    at scala.reflect.internal.Symbols$Symbol.filter(Symbols.scala:1788)
    at scala.reflect.internal.Symbols$Symbol.suchThat(Symbols.scala:1792)
    at scala.reflect.internal.Symbols$ClassSymbol.companionModule0(Symbols.scala:3085)
    at scala.reflect.internal.Symbols$ClassSymbol.companionModule(Symbols.scala:3087)
    at scala.reflect.internal.TreeGen.mkTuple(TreeGen.scala:289)
    at scala.tools.nsc.ast.parser.TreeBuilder.makeTupleTerm(TreeBuilder.scala:42)
    at scala.tools.nsc.ast.parser.TreeBuilder.stripParens(TreeBuilder.scala:47)
    at scala.tools.nsc.ast.parser.Parsers$Parser.parseOther$1(Parsers.scala:1475)
    at scala.tools.nsc.ast.parser.Parsers$Parser.expr0(Parsers.scala:1477)

Seems like we need to force a few lazies in Definitions to make this work.

// On presentation compiler startup
definitions.TupleClass.seq.foreach(sym => fullyInitializeSymbol(sym))
// same for any other symbols used by Parsers.

This workaround could be done in the IDE in the meantime.

scabug commented 10 years ago

@retronym said: Denys, could you please audit what parts of Definitions are touched by Parsers, and see if you can force them in the presentation compiler initialization?

scabug commented 10 years ago

@densh said: Sure.

scabug commented 10 years ago

@dotta said: @Jason Thanks. I'll add TupleClass to this

scabug commented 10 years ago

@retronym said: You'll need to to that for the family of Tuple symbols, TupleClass.seq in master, or (1 to 22).map(TupleClass(_)) if you need to be compatible with 2.10 and 2.11.

And I would change that to fullyInitializeSymbol to be on the safe side as you have the tuple class, module, and module class symbols to worry about.

scabug commented 10 years ago

@dotta said: TupleClass.seq seems to exist on 2.10.4. Here is a link to the PR on Scala IDE, feel free to comment on it https://github.com/scala-ide/scala-ide/pull/595