Skip to content

Commit 6d7dd2c

Browse files
committed
Introduce @forceInline annotation
An annotation on methods that is equivalent to Dotty `inline` modifier. The annotation should be used instead of the `inline` modifier in code that needs to cross compile between Scala 2 and Dotty.
1 parent d761815 commit 6d7dd2c

40 files changed

+101
-74
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
10521052
def enclosingInlineds(implicit ctx: Context): List[Tree] =
10531053
ctx.property(InlinedCalls).getOrElse(Nil)
10541054

1055-
/** The source file where the symbol of the `@inline` method referred to by `call`
1055+
/** The source file where the symbol of the `inline` method referred to by `call`
10561056
* is defined
10571057
*/
10581058
def sourceFile(call: Tree)(implicit ctx: Context) = {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,8 @@ class Definitions {
707707
def ImplicitAmbiguousAnnot(implicit ctx: Context) = ImplicitAmbiguousAnnotType.symbol.asClass
708708
lazy val ImplicitNotFoundAnnotType = ctx.requiredClassRef("scala.annotation.implicitNotFound")
709709
def ImplicitNotFoundAnnot(implicit ctx: Context) = ImplicitNotFoundAnnotType.symbol.asClass
710-
lazy val InlineAnnotType = ctx.requiredClassRef("scala.inline")
711-
def InlineAnnot(implicit ctx: Context) = InlineAnnotType.symbol.asClass
710+
lazy val ForceInlineAnnotType = ctx.requiredClassRef("scala.forceInline")
711+
def ForceInlineAnnot(implicit ctx: Context) = ForceInlineAnnotType.symbol.asClass
712712
lazy val InlineParamAnnotType = ctx.requiredClassRef("scala.annotation.internal.InlineParam")
713713
def InlineParamAnnot(implicit ctx: Context) = InlineParamAnnotType.symbol.asClass
714714
lazy val InvariantBetweenAnnotType = ctx.requiredClassRef("scala.annotation.internal.InvariantBetween")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,6 @@ object Symbols {
803803
override def toString: String = value.asScala.toString()
804804
}
805805

806-
@inline def newMutableSymbolMap[T]: MutableSymbolMap[T] =
806+
@forceInline def newMutableSymbolMap[T]: MutableSymbolMap[T] =
807807
new MutableSymbolMap(new java.util.IdentityHashMap[Symbol, T]())
808808
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3935,7 +3935,7 @@ object Types {
39353935
abstract class VariantTraversal {
39363936
protected[core] var variance = 1
39373937

3938-
@inline protected def atVariance[T](v: Int)(op: => T): T = {
3938+
@forceInline protected def atVariance[T](v: Int)(op: => T): T = {
39393939
val saved = variance
39403940
variance = v
39413941
val res = op

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ object MarkupParsers {
316316
}
317317

318318
/** Some try/catch/finally logic used by xLiteral and xLiteralPattern. */
319-
@inline private def xLiteralCommon(f: () => Tree, ifTruncated: String => Unit): Tree = {
319+
@forceInline private def xLiteralCommon(f: () => Tree, ifTruncated: String => Unit): Tree = {
320320
var output: Tree = null.asInstanceOf[Tree]
321321
try output = f()
322322
catch {

compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ object SyntaxHighlighting {
5151
val newBuf = new StringBuilder
5252
var lastValDefToken = ""
5353

54-
@inline def keywordStart =
54+
@forceInline def keywordStart =
5555
prev == 0 || prev == ' ' || prev == '{' || prev == '(' ||
5656
prev == '\n' || prev == '[' || prev == ',' || prev == ':' ||
5757
prev == '|' || prev == '&'
5858

59-
@inline def numberStart(c: Char) =
59+
@forceInline def numberStart(c: Char) =
6060
c.isDigit && (!prev.isLetter || prev == '.' || prev == ' ' || prev == '(' || prev == '\u0000')
6161

6262
def takeChar(): Char = takeChars(1).head

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,7 @@ object messages {
17481748
val kind = "Syntax"
17491749
val msg = hl"no explicit ${"return"} allowed from inline $owner"
17501750
val explanation =
1751-
hl"""Methods marked with ${"@inline"} may not use ${"return"} statements.
1751+
hl"""Methods marked with ${"inline"} modifier may not use ${"return"} statements.
17521752
|Instead, you should rely on the last expression's value being
17531753
|returned from a method.
17541754
|"""

compiler/src/dotty/tools/dotc/reporting/trace.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ import core.Mode
99

1010
object trace {
1111

12-
@inline
12+
@forceInline
1313
def onDebug[TD](question: => String)(op: => TD)(implicit ctx: Context): TD =
1414
conditionally(ctx.settings.YdebugTrace.value, question, false)(op)
1515

16-
@inline
16+
@forceInline
1717
def conditionally[TC](cond: Boolean, question: => String, show: Boolean)(op: => TC)(implicit ctx: Context): TC =
1818
if (Config.tracingEnabled) {
1919
def op1 = op
2020
if (cond) apply[TC](question, Printers.default, show)(op1)
2121
else op1
2222
} else op
2323

24-
@inline
24+
@forceInline
2525
def apply[T](question: => String, printer: Printers.Printer, showOp: Any => String)(op: => T)(implicit ctx: Context): T =
2626
if (Config.tracingEnabled) {
2727
def op1 = op
@@ -30,7 +30,7 @@ object trace {
3030
}
3131
else op
3232

33-
@inline
33+
@forceInline
3434
def apply[T](question: => String, printer: Printers.Printer, show: Boolean)(op: => T)(implicit ctx: Context): T =
3535
if (Config.tracingEnabled) {
3636
def op1 = op
@@ -39,15 +39,15 @@ object trace {
3939
}
4040
else op
4141

42-
@inline
42+
@forceInline
4343
def apply[T](question: => String, printer: Printers.Printer)(op: => T)(implicit ctx: Context): T =
4444
apply[T](question, printer, false)(op)
4545

46-
@inline
46+
@forceInline
4747
def apply[T](question: => String, show: Boolean)(op: => T)(implicit ctx: Context): T =
4848
apply[T](question, Printers.default, show)(op)
4949

50-
@inline
50+
@forceInline
5151
def apply[T](question: => String)(op: => T)(implicit ctx: Context): T =
5252
apply[T](question, Printers.default, false)(op)
5353

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ object Inliner {
229229
}
230230

231231
/** `sym` has an inline method with a known body to inline (note: definitions coming
232-
* from Scala2x class files might be `@inline`, but still lack that body.
232+
* from Scala2x class files might be `@forceInline`, but still lack that body.
233233
*/
234234
def hasBodyToInline(sym: SymDenotation)(implicit ctx: Context): Boolean =
235235
sym.isInlinedMethod && sym.hasAnnotation(defn.BodyAnnot) // TODO: Open this up for transparent methods as well
@@ -240,7 +240,7 @@ object Inliner {
240240
def bodyToInline(sym: SymDenotation)(implicit ctx: Context): Tree =
241241
sym.unforcedAnnotation(defn.BodyAnnot).get.tree
242242

243-
/** Try to inline a call to a `@inline` method. Fail with error if the maximal
243+
/** Try to inline a call to a `inline` method. Fail with error if the maximal
244244
* inline depth is exceeded.
245245
*
246246
* @param tree The call to inline
@@ -281,7 +281,7 @@ object Inliner {
281281

282282
/** Produces an inlined version of `call` via its `inlined` method.
283283
*
284-
* @param call the original call to a `@inline` method
284+
* @param call the original call to an `inline` method
285285
* @param rhsToInline the body of the inline method that replaces the call.
286286
*/
287287
class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ class Namer { typer: Typer =>
751751
if (sym.unforcedAnnotation(cls).isEmpty) {
752752
val ann = Annotation.deferred(cls, implicit ctx => typedAheadAnnotation(annotTree))
753753
sym.addAnnotation(ann)
754-
if (cls == defn.InlineAnnot && sym.is(Method, butNot = Accessor))
754+
if (cls == defn.ForceInlineAnnot && sym.is(Method, butNot = Accessor))
755755
sym.setFlag(Inline)
756756
}
757757
}

0 commit comments

Comments
 (0)