Skip to content

Commit e7f67c7

Browse files
Merge pull request #7475 from dotty-staging/remove-forceinline
Drop `forceInline` annotation
2 parents ef707e6 + 7e802a7 commit e7f67c7

File tree

15 files changed

+17
-49
lines changed

15 files changed

+17
-49
lines changed

compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ trait ConstraintHandling[AbstractContext] {
205205
else
206206
isSubType(tp1, tp2)
207207

208-
@forceInline final def inFrozenConstraint[T](op: => T): T = {
208+
inline final def inFrozenConstraint[T](op: => T): T = {
209209
val savedFrozen = frozenConstraint
210210
val savedLambda = caseLambda
211211
frozenConstraint = true

compiler/src/dotty/tools/dotc/core/Definitions.scala

-1
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,6 @@ class Definitions {
750750
@tu lazy val DeprecatedAnnot: ClassSymbol = ctx.requiredClass("scala.deprecated")
751751
@tu lazy val ImplicitAmbiguousAnnot: ClassSymbol = ctx.requiredClass("scala.annotation.implicitAmbiguous")
752752
@tu lazy val ImplicitNotFoundAnnot: ClassSymbol = ctx.requiredClass("scala.annotation.implicitNotFound")
753-
@tu lazy val ForceInlineAnnot: ClassSymbol = ctx.requiredClass("scala.forceInline")
754753
@tu lazy val InlineParamAnnot: ClassSymbol = ctx.requiredClass("scala.annotation.internal.InlineParam")
755754
@tu lazy val InvariantBetweenAnnot: ClassSymbol = ctx.requiredClass("scala.annotation.internal.InvariantBetween")
756755
@tu lazy val MainAnnot: ClassSymbol = ctx.requiredClass("scala.main")

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

+2-9
Original file line numberDiff line numberDiff line change
@@ -918,17 +918,10 @@ object SymDenotations {
918918
/** Is this a Scala 2 macro */
919919
final def isScala2Macro(implicit ctx: Context): Boolean = is(Macro) && symbol.owner.is(Scala2x)
920920

921-
/** An erased value or an inline method, excluding @forceInline annotated methods.
922-
* The latter have to be kept around to get to parity with Scala.
923-
* This is necessary at least until we have full bootstrap. Right now
924-
* dotty-bootstrapped involves running the Dotty compiler compiled with Scala 2 with
925-
* a Dotty runtime library compiled with Dotty. If we erase @forceInline annotated
926-
* methods, this means that the support methods in dotty.runtime.LazyVals vanish.
927-
* But they are needed for running the lazy val implementations in the Scala-2 compiled compiler.
921+
/** An erased value or an inline method.
928922
*/
929923
def isEffectivelyErased(implicit ctx: Context): Boolean =
930-
is(Erased) ||
931-
isInlineMethod && unforcedAnnotation(defn.ForceInlineAnnot).isEmpty
924+
is(Erased) || isInlineMethod
932925

933926
/** ()T and => T types should be treated as equivalent for this symbol.
934927
* Note: For the moment, we treat Scala-2 compiled symbols as loose matching,

compiler/src/dotty/tools/dotc/core/Symbols.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,6 @@ object Symbols {
908908
override def toString: String = value.asScala.toString()
909909
}
910910

911-
@forceInline def newMutableSymbolMap[T]: MutableSymbolMap[T] =
911+
inline def newMutableSymbolMap[T]: MutableSymbolMap[T] =
912912
new MutableSymbolMap(new java.util.IdentityHashMap[Symbol, T]())
913913
}

compiler/src/dotty/tools/dotc/core/Types.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -4432,7 +4432,7 @@ object Types {
44324432
abstract class VariantTraversal {
44334433
protected[core] var variance: Int = 1
44344434

4435-
@forceInline protected def atVariance[T](v: Int)(op: => T): T = {
4435+
inline protected def atVariance[T](v: Int)(op: => T): T = {
44364436
val saved = variance
44374437
variance = v
44384438
val res = op

compiler/src/dotty/tools/dotc/parsing/xml/MarkupParsers.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ object MarkupParsers {
317317
}
318318

319319
/** Some try/catch/finally logic used by xLiteral and xLiteralPattern. */
320-
@forceInline private def xLiteralCommon(f: () => Tree, ifTruncated: String => Unit): Tree = {
320+
inline private def xLiteralCommon(f: () => Tree, ifTruncated: String => Unit): Tree = {
321321
assert(parser.in.token == Tokens.XMLSTART)
322322
val saved = parser.in.newTokenData
323323
saved.copyFrom(parser.in)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ object ConstFold {
4848
}
4949
}
5050

51-
@forceInline private def finish[T <: Tree](tree: T)(compX: => Constant)(implicit ctx: Context): T =
51+
inline private def finish[T <: Tree](tree: T)(compX: => Constant)(implicit ctx: Context): T =
5252
try {
5353
val x = compX
5454
if (x ne null) tree.withType(ConstantType(x)).asInstanceOf[T]

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,12 @@ import dotty.tools.dotc.transform.{Splicer, TreeMapWithStages}
3333
object Inliner {
3434
import tpd._
3535

36-
/** `sym` is an inline method with a known body to inline (note: definitions coming
37-
* from Scala2x class files might be `@forceInline`, but still lack that body).
36+
/** `sym` is an inline method with a known body to inline.
3837
*/
3938
def hasBodyToInline(sym: SymDenotation)(implicit ctx: Context): Boolean =
4039
sym.isInlineMethod && sym.hasAnnotation(defn.BodyAnnot)
4140

4241
/** The body to inline for method `sym`, or `EmptyTree` if none exists.
43-
* Note: definitions coming from Scala2x class files might be `@forceInline`,
44-
* but still lack that body.
4542
* @pre hasBodyToInline(sym)
4643
*/
4744
def bodyToInline(sym: SymDenotation)(implicit ctx: Context): Tree =

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

-2
Original file line numberDiff line numberDiff line change
@@ -830,8 +830,6 @@ class Namer { typer: Typer =>
830830
else {
831831
val ann = Annotation.deferred(cls)(typedAnnotation(annotTree))
832832
sym.addAnnotation(ann)
833-
if (cls == defn.ForceInlineAnnot && sym.is(Method, butNot = Accessor))
834-
sym.setFlag(Inline)
835833
}
836834
}
837835
case _ =>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ trait QuotesAndSplices {
165165
object splitter extends tpd.TreeMap {
166166
private var variance: Int = 1
167167

168-
@forceInline private def atVariance[T](v: Int)(op: => T): T = {
168+
inline private def atVariance[T](v: Int)(op: => T): T = {
169169
val saved = variance
170170
variance = v
171171
val res = op

compiler/src/dotty/tools/dotc/util/Stats.scala

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ import collection.mutable
1919
override def default(key: String): Int = 0
2020
}
2121

22-
@forceInline
23-
def record(fn: => String, n: => Int = 1): Unit =
22+
inline def record(fn: => String, n: => Int = 1): Unit =
2423
if (enabled) doRecord(fn, n)
2524

2625
def doRecord(fn: String, n: Int) =
@@ -29,8 +28,7 @@ import collection.mutable
2928
hits(name) += n
3029
}
3130

32-
@forceInline
33-
def trackTime[T](fn: String)(op: => T): T =
31+
inline def trackTime[T](fn: String)(op: => T): T =
3432
if (enabled) doTrackTime(fn)(op) else op
3533

3634
def doTrackTime[T](fn: String)(op: => T): T = {

compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class InlineBytecodeTests extends DottyBytecodeTest {
1313
val source = """
1414
|class Foo {
1515
| inline def foo: Int = 1
16-
| @forceInline def bar: Int = 1
16+
| inline def bar: Int = 1
1717
|
1818
| def meth1: Unit = foo
1919
| def meth2: Unit = bar

library/src/dotty/DottyPredef.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ package dotty
33
object DottyPredef {
44
import compiletime.summonFrom
55

6-
@forceInline final def assert(assertion: => Boolean, message: => Any): Unit = {
6+
inline final def assert(assertion: => Boolean, message: => Any): Unit = {
77
if (!assertion)
88
assertFail(message)
99
}
1010

11-
@forceInline final def assert(assertion: => Boolean): Unit = {
11+
inline final def assert(assertion: => Boolean): Unit = {
1212
if (!assertion)
1313
assertFail()
1414
}
1515

1616
def assertFail(): Unit = throw new java.lang.AssertionError("assertion failed")
1717
def assertFail(message: => Any): Unit = throw new java.lang.AssertionError("assertion failed: " + message)
1818

19-
@forceInline final def implicitly[T](implicit ev: T): T = ev
19+
inline final def implicitly[T](implicit ev: T): T = ev
2020

21-
@forceInline def locally[T](body: => T): T = body
21+
inline def locally[T](body: => T): T = body
2222

2323
/**
2424
* Retrieve the single value of a type with a unique inhabitant.

library/src/scala/forceInline.scala

-17
This file was deleted.

library/src/scala/internal/Chars.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ object Chars {
3333

3434
/** Convert a character to a backslash-u escape */
3535
def char2uescape(c: Char): String = {
36-
@forceInline def hexChar(ch: Int): Char =
36+
inline def hexChar(ch: Int): Char =
3737
(( if (ch < 10) '0' else 'A' - 10 ) + ch).toChar
3838

3939
char2uescapeArray(2) = hexChar((c >> 12) )

0 commit comments

Comments
 (0)