Skip to content

Commit e486384

Browse files
committed
Treat @forceInline specially.
The comment in Namer explains why this is necessary.
1 parent 1e9e474 commit e486384

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,15 @@ class Namer { typer: Typer =>
11951195
instantiateDependent(restpe, typeParams, termParamss)
11961196
ctx.methodType(tparams map symbolOfTree, termParamss, restpe, isJava = ddef.mods is JavaDefined)
11971197
}
1198-
if (sym.is(Transparent)) sym.setFlag(Erased)
1198+
if (sym.is(Transparent) &&
1199+
sym.unforcedAnnotation(defn.ForceInlineAnnot).isEmpty)
1200+
// Need to keep @forceInline annotated methods around to get to parity with Scala.
1201+
// This is necessary at least until we have full bootstrap. Right now
1202+
// dotty-bootstrapped involves running the Dotty compiler compiled with Scala 2 with
1203+
// a Dotty runtime library compiled with Dotty. If we erase @forceInline annotated
1204+
// methods, this means that the support methods in dotty.runtime.LazyVals vanish.
1205+
// But they are needed for running the lazy val implementations in the Scala-2 compiled compiler.
1206+
sym.setFlag(Erased)
11991207
if (isConstructor) {
12001208
// set result type tree to unit, but take the current class as result type of the symbol
12011209
typedAheadType(ddef.tpt, defn.UnitType)

library/src/dotty/runtime/LazyVals.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ object LazyVals {
2525
final val LAZY_VAL_MASK = 3L
2626
final val debug = false
2727

28-
@inline def STATE(cur: Long, ord: Int) = {
28+
@forceInline def STATE(cur: Long, ord: Int) = {
2929
val r = (cur >> (ord * BITS_PER_LAZY_VAL)) & LAZY_VAL_MASK
3030
if (debug)
3131
println(s"STATE($cur, $ord) = $r")
3232
r
3333
}
34-
@inline def CAS(t: Object, offset: Long, e: Long, v: Int, ord: Int) = {
34+
@forceInline def CAS(t: Object, offset: Long, e: Long, v: Int, ord: Int) = {
3535
if (debug)
3636
println(s"CAS($t, $offset, $e, $v, $ord)")
3737
val mask = ~(LAZY_VAL_MASK << ord * BITS_PER_LAZY_VAL)
3838
val n = (e & mask) | (v.toLong << (ord * BITS_PER_LAZY_VAL))
3939
compareAndSet(t, offset, e, n)
4040
}
41-
@inline def setFlag(t: Object, offset: Long, v: Int, ord: Int) = {
41+
@forceInline def setFlag(t: Object, offset: Long, v: Int, ord: Int) = {
4242
if (debug)
4343
println(s"setFlag($t, $offset, $v, $ord)")
4444
var retry = true
@@ -57,7 +57,7 @@ object LazyVals {
5757
}
5858
}
5959
}
60-
@inline def wait4Notification(t: Object, offset: Long, cur: Long, ord: Int) = {
60+
@forceInline def wait4Notification(t: Object, offset: Long, cur: Long, ord: Int) = {
6161
if (debug)
6262
println(s"wait4Notification($t, $offset, $cur, $ord)")
6363
var retry = true
@@ -75,8 +75,8 @@ object LazyVals {
7575
}
7676
}
7777

78-
@inline def compareAndSet(t: Object, off: Long, e: Long, v: Long) = unsafe.compareAndSwapLong(t, off, e, v)
79-
@inline def get(t: Object, off: Long) = {
78+
@forceInline def compareAndSet(t: Object, off: Long, e: Long, v: Long) = unsafe.compareAndSwapLong(t, off, e, v)
79+
@forceInline def get(t: Object, off: Long) = {
8080
if (debug)
8181
println(s"get($t, $off)")
8282
unsafe.getLongVolatile(t, off)
@@ -88,7 +88,7 @@ object LazyVals {
8888
x => new Object()
8989
}.toArray
9090

91-
@inline def getMonitor(obj: Object, fieldId: Int = 0) = {
91+
@forceInline def getMonitor(obj: Object, fieldId: Int = 0) = {
9292
var id = (
9393
/*java.lang.System.identityHashCode(obj) + */ // should be here, but #548
9494
fieldId) % base
@@ -97,7 +97,7 @@ object LazyVals {
9797
monitors(id)
9898
}
9999

100-
@inline def getOffset(clz: Class[_], name: String) = {
100+
@forceInline def getOffset(clz: Class[_], name: String) = {
101101
val r = unsafe.objectFieldOffset(clz.getDeclaredField(name))
102102
if (debug)
103103
println(s"getOffset($clz, $name) = $r")

0 commit comments

Comments
 (0)