Skip to content

Commit ed358f0

Browse files
committed
Update optimizer class path when release is set
1 parent e86724e commit ed358f0

File tree

7 files changed

+115
-5
lines changed

7 files changed

+115
-5
lines changed

src/compiler/scala/tools/nsc/Global.scala

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,22 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
135135

136136
type ThisPlatform = JavaPlatform { val global: Global.this.type }
137137
lazy val platform: ThisPlatform = new GlobalPlatform
138-
/* A hook for the REPL to add a classpath entry containing products of previous runs to inliner's bytecode repository*/
139-
// Fixes scala/bug#8779
140-
def optimizerClassPath(base: ClassPath): ClassPath = base
138+
139+
/* Create a class path for the backend, based on the given class path.
140+
* Used to make classes available to the inliner's bytecode repository.
141+
*
142+
* In particular, if ct.sym is used for compilation, replace it with jrt.
143+
*
144+
* See ReplGlobal, which appends a classpath entry containing products of previous runs. (Fixes scala/bug#8779.)
145+
*/
146+
def optimizerClassPath(base: ClassPath): ClassPath =
147+
base match {
148+
case AggregateClassPath(entries) if entries.head.isInstanceOf[CtSymClassPath] =>
149+
JrtClassPath(release = None, closeableRegistry)
150+
.map(jrt => AggregateClassPath(entries.drop(1).prepended(jrt)))
151+
.getOrElse(base)
152+
case _ => base
153+
}
141154

142155
def classPath: ClassPath = platform.classPath
143156

src/repl/scala/tools/nsc/interpreter/ReplGlobal.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,13 @@ trait ReplGlobal extends Global {
9898
}
9999

100100
override def optimizerClassPath(base: ClassPath): ClassPath = {
101+
val base1 = super.optimizerClassPath(base)
101102
settings.outputDirs.getSingleOutput match {
102-
case None => base
103+
case None => base1
103104
case Some(out) =>
104105
// Make bytecode of previous lines available to the inliner
105106
val replOutClasspath = ClassPathFactory.newClassPath(settings.outputDirs.getSingleOutput.get, settings, closeableRegistry)
106-
AggregateClassPath.createAggregate(platform.classPath, replOutClasspath)
107+
AggregateClassPath.createAggregate(base1, replOutClasspath)
107108
}
108109
}
109110

test/files/neg/t3420b.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
t3420b.scala:8: error: value translateEscapes is not a member of String
2+
def f(s: String) = s.translateEscapes
3+
^
4+
1 error

test/files/neg/t3420b.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
// scalac: --release 8 -opt:inline:** -Wopt -Werror
3+
//
4+
class C {
5+
val cv = Map[Int, Int](1 -> 2)
6+
lazy val cl = Map[Int, Int](1 -> 2)
7+
def cd = Map[Int, Int](1 -> 2)
8+
def f(s: String) = s.translateEscapes
9+
}

test/files/pos/t3420b.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
// scalac: --release 8 -opt:inline:** -Wopt -Werror
3+
//
4+
class C {
5+
val cv = Map[Int, Int](1 -> 2)
6+
lazy val cl = Map[Int, Int](1 -> 2)
7+
def cd = Map[Int, Int](1 -> 2)
8+
}

test/files/run/repl-release.check

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
scala> def callerOfCaller = Thread.currentThread.getStackTrace.drop(2).head.getMethodName
3+
def callerOfCaller: String
4+
5+
scala> @noinline def g = callerOfCaller
6+
def g: String
7+
8+
scala> @noinline def h = g
9+
def h: String
10+
11+
scala> assert(h == "g", h)
12+
13+
scala> @inline def g = callerOfCaller
14+
def g: String
15+
16+
scala> @noinline def h = g
17+
def h: String
18+
19+
scala> assert(h == "h", h)
20+
21+
scala> :quit
22+
23+
scala> def callerOfCaller = Thread.currentThread.getStackTrace.drop(2).head.getMethodName
24+
def callerOfCaller: String
25+
26+
scala> @noinline def g = callerOfCaller
27+
def g: String
28+
29+
scala> @noinline def h = g
30+
def h: String
31+
32+
scala> assert(h == "g", h)
33+
34+
scala> @inline def g = callerOfCaller
35+
def g: String
36+
37+
scala> @noinline def h = g
38+
def h: String
39+
40+
scala> assert(h == "h", h)
41+
42+
scala> :quit

test/files/run/repl-release.scala

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import scala.tools.partest.ReplTest
2+
import scala.tools.nsc._
3+
import scala.tools.nsc.Settings
4+
import scala.tools.nsc.interpreter.shell.ReplReporterImpl
5+
6+
// cf run/repl-inline.scala
7+
object Test extends ReplTest {
8+
9+
var count = 0
10+
11+
override def transformSettings(s: Settings) = {
12+
s.processArguments("-release:8" :: "-opt:inline:**" :: "-Wopt" :: Nil, processAll = true)
13+
s.Yreplclassbased.value = count > 0
14+
count += 1
15+
s
16+
}
17+
18+
override def code =
19+
"""
20+
def callerOfCaller = Thread.currentThread.getStackTrace.drop(2).head.getMethodName
21+
@noinline def g = callerOfCaller
22+
@noinline def h = g
23+
assert(h == "g", h)
24+
@inline def g = callerOfCaller
25+
@noinline def h = g
26+
assert(h == "h", h)
27+
"""
28+
29+
override def show() = {
30+
super.show()
31+
super.show()
32+
}
33+
}

0 commit comments

Comments
 (0)