Skip to content

Commit c611f7b

Browse files
committed
Merge pull request scala#3502 from retronym/ticket/8258
Fix regression for using Scala IDE on scala-library
2 parents 90aa12e + 894aee1 commit c611f7b

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

src/compiler/scala/tools/nsc/typechecker/Contexts.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ trait Contexts { self: Analyzer =>
8989
if (settings.noimports) Nil
9090
else if (unit.isJava) RootImports.javaList
9191
else if (settings.nopredef || treeInfo.noPredefImportForUnit(unit.body)) {
92+
// SI-8258 Needed for the presentation compiler using -sourcepath, otherwise cycles can occur. See the commit
93+
// message for this ticket for an example.
9294
debuglog("Omitted import of Predef._ for " + unit)
9395
RootImports.javaAndScalaList
9496
}

src/interactive/scala/tools/nsc/interactive/Global.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
534534
threadId += 1
535535
compileRunner = new PresentationCompilerThread(this, projectName)
536536
compileRunner.setDaemon(true)
537-
compileRunner.start()
538537
compileRunner
539538
}
540539

@@ -1253,11 +1252,21 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
12531252

12541253
forceSymbolsUsedByParser()
12551254

1255+
/** Start the compiler background thread and turn on thread confinement checks */
1256+
private def finishInitialization(): Unit = {
1257+
// this flag turns on `assertCorrectThread checks`
1258+
initializing = false
1259+
1260+
// Only start the thread if initialization was successful. A crash while forcing symbols (for example
1261+
// if the Scala library is not on the classpath) can leave running threads behind. See Scala IDE #1002016
1262+
compileRunner.start()
1263+
}
1264+
12561265
/** The compiler has been initialized. Constructors are evaluated in textual order,
1257-
* so this is set to true only after all super constructors and the primary constructor
1266+
* if we reached here, all super constructors and the primary constructor
12581267
* have been executed.
12591268
*/
1260-
initializing = false
1269+
finishInitialization()
12611270
}
12621271

12631272
object CancelException extends Exception

src/reflect/scala/reflect/internal/TreeInfo.scala

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,17 @@ abstract class TreeInfo {
735735
unapply(dissectApplied(tree))
736736
}
737737

738+
/** Does list of trees start with a definition of
739+
* a class of module with given name (ignoring imports)
740+
*/
741+
def firstDefinesClassOrObject(trees: List[Tree], name: Name): Boolean = trees match {
742+
case Import(_, _) :: xs => firstDefinesClassOrObject(xs, name)
743+
case Annotated(_, tree1) :: _ => firstDefinesClassOrObject(List(tree1), name)
744+
case ModuleDef(_, `name`, _) :: _ => true
745+
case ClassDef(_, `name`, _, _) :: _ => true
746+
case _ => false
747+
}
748+
738749
/** Locates the synthetic Apply node corresponding to an extractor's call to
739750
* unapply (unwrapping nested Applies) and returns the fun part of that Apply.
740751
*/
@@ -750,8 +761,7 @@ abstract class TreeInfo {
750761
}
751762

752763
/** Is this file the body of a compilation unit which should not
753-
* have Predef imported? This is the case iff the first import in the
754-
* unit explicitly refers to Predef.
764+
* have Predef imported?
755765
*/
756766
def noPredefImportForUnit(body: Tree) = {
757767
// Top-level definition whose leading imports include Predef.
@@ -760,7 +770,13 @@ abstract class TreeInfo {
760770
case Import(expr, _) => isReferenceToPredef(expr)
761771
case _ => false
762772
}
763-
isLeadingPredefImport(body)
773+
// Compilation unit is class or object 'name' in package 'scala'
774+
def isUnitInScala(tree: Tree, name: Name) = tree match {
775+
case PackageDef(Ident(nme.scala_), defs) => firstDefinesClassOrObject(defs, name)
776+
case _ => false
777+
}
778+
779+
isUnitInScala(body, nme.Predef) || isLeadingPredefImport(body)
764780
}
765781

766782
def isAbsTypeDef(tree: Tree) = tree match {

0 commit comments

Comments
 (0)