From 7e802a71946f8372f0e38ad054b7ab88f2c3f23f Mon Sep 17 00:00:00 2001 From: Anatolii Date: Fri, 18 Oct 2019 13:29:43 +0200 Subject: [PATCH] Drop `forceInline` annotation It was needed to make Dotty cross-compile to Scala 2 before full bootstrap. Its direct semantics is about adding the `inline` flag to a symbol annotated by it. `inline` flag, however, is listed as one of the flags that are not supposed to be modified by completion of symbols. Hence, having `forceInline` annotation is in violation of our own assumptions about completion. Before full bootstrap, we were not able to drop this annotation, however, now that we have the full bootstrap, we can do it. --- .../tools/dotc/core/ConstraintHandling.scala | 2 +- .../src/dotty/tools/dotc/core/Definitions.scala | 1 - .../dotty/tools/dotc/core/SymDenotations.scala | 11 ++--------- .../src/dotty/tools/dotc/core/Symbols.scala | 2 +- compiler/src/dotty/tools/dotc/core/Types.scala | 2 +- .../tools/dotc/parsing/xml/MarkupParsers.scala | 2 +- .../src/dotty/tools/dotc/typer/ConstFold.scala | 2 +- .../src/dotty/tools/dotc/typer/Inliner.scala | 5 +---- compiler/src/dotty/tools/dotc/typer/Namer.scala | 2 -- .../tools/dotc/typer/QuotesAndSplices.scala | 2 +- compiler/src/dotty/tools/dotc/util/Stats.scala | 6 ++---- .../tools/backend/jvm/InlineBytecodeTests.scala | 2 +- library/src/dotty/DottyPredef.scala | 8 ++++---- library/src/scala/forceInline.scala | 17 ----------------- library/src/scala/internal/Chars.scala | 2 +- 15 files changed, 17 insertions(+), 49 deletions(-) delete mode 100644 library/src/scala/forceInline.scala diff --git a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala index c2800bb7dc58..e8c9c91cc144 100644 --- a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala +++ b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala @@ -205,7 +205,7 @@ trait ConstraintHandling[AbstractContext] { else isSubType(tp1, tp2) - @forceInline final def inFrozenConstraint[T](op: => T): T = { + inline final def inFrozenConstraint[T](op: => T): T = { val savedFrozen = frozenConstraint val savedLambda = caseLambda frozenConstraint = true diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 29ede1a187c2..f9ad5bd52925 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -750,7 +750,6 @@ class Definitions { @tu lazy val DeprecatedAnnot: ClassSymbol = ctx.requiredClass("scala.deprecated") @tu lazy val ImplicitAmbiguousAnnot: ClassSymbol = ctx.requiredClass("scala.annotation.implicitAmbiguous") @tu lazy val ImplicitNotFoundAnnot: ClassSymbol = ctx.requiredClass("scala.annotation.implicitNotFound") - @tu lazy val ForceInlineAnnot: ClassSymbol = ctx.requiredClass("scala.forceInline") @tu lazy val InlineParamAnnot: ClassSymbol = ctx.requiredClass("scala.annotation.internal.InlineParam") @tu lazy val InvariantBetweenAnnot: ClassSymbol = ctx.requiredClass("scala.annotation.internal.InvariantBetween") @tu lazy val MainAnnot: ClassSymbol = ctx.requiredClass("scala.main") diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 65aa4dc58d0d..54912ded4e28 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -918,17 +918,10 @@ object SymDenotations { /** Is this a Scala 2 macro */ final def isScala2Macro(implicit ctx: Context): Boolean = is(Macro) && symbol.owner.is(Scala2x) - /** An erased value or an inline method, excluding @forceInline annotated methods. - * The latter have to be kept around to get to parity with Scala. - * This is necessary at least until we have full bootstrap. Right now - * dotty-bootstrapped involves running the Dotty compiler compiled with Scala 2 with - * a Dotty runtime library compiled with Dotty. If we erase @forceInline annotated - * methods, this means that the support methods in dotty.runtime.LazyVals vanish. - * But they are needed for running the lazy val implementations in the Scala-2 compiled compiler. + /** An erased value or an inline method. */ def isEffectivelyErased(implicit ctx: Context): Boolean = - is(Erased) || - isInlineMethod && unforcedAnnotation(defn.ForceInlineAnnot).isEmpty + is(Erased) || isInlineMethod /** ()T and => T types should be treated as equivalent for this symbol. * Note: For the moment, we treat Scala-2 compiled symbols as loose matching, diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index f70288313aa8..3ee8751a1f19 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -908,6 +908,6 @@ object Symbols { override def toString: String = value.asScala.toString() } - @forceInline def newMutableSymbolMap[T]: MutableSymbolMap[T] = + inline def newMutableSymbolMap[T]: MutableSymbolMap[T] = new MutableSymbolMap(new java.util.IdentityHashMap[Symbol, T]()) } diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index d6a78a112865..fb0f712a3e8f 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -4432,7 +4432,7 @@ object Types { abstract class VariantTraversal { protected[core] var variance: Int = 1 - @forceInline protected def atVariance[T](v: Int)(op: => T): T = { + inline protected def atVariance[T](v: Int)(op: => T): T = { val saved = variance variance = v val res = op diff --git a/compiler/src/dotty/tools/dotc/parsing/xml/MarkupParsers.scala b/compiler/src/dotty/tools/dotc/parsing/xml/MarkupParsers.scala index 82a059b848c9..cef9cb488a4e 100644 --- a/compiler/src/dotty/tools/dotc/parsing/xml/MarkupParsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/xml/MarkupParsers.scala @@ -317,7 +317,7 @@ object MarkupParsers { } /** Some try/catch/finally logic used by xLiteral and xLiteralPattern. */ - @forceInline private def xLiteralCommon(f: () => Tree, ifTruncated: String => Unit): Tree = { + inline private def xLiteralCommon(f: () => Tree, ifTruncated: String => Unit): Tree = { assert(parser.in.token == Tokens.XMLSTART) val saved = parser.in.newTokenData saved.copyFrom(parser.in) diff --git a/compiler/src/dotty/tools/dotc/typer/ConstFold.scala b/compiler/src/dotty/tools/dotc/typer/ConstFold.scala index 00abab45a3eb..9b4eef28369a 100644 --- a/compiler/src/dotty/tools/dotc/typer/ConstFold.scala +++ b/compiler/src/dotty/tools/dotc/typer/ConstFold.scala @@ -48,7 +48,7 @@ object ConstFold { } } - @forceInline private def finish[T <: Tree](tree: T)(compX: => Constant)(implicit ctx: Context): T = + inline private def finish[T <: Tree](tree: T)(compX: => Constant)(implicit ctx: Context): T = try { val x = compX if (x ne null) tree.withType(ConstantType(x)).asInstanceOf[T] diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 2f3c43d07ca6..e42fd6141717 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -33,15 +33,12 @@ import dotty.tools.dotc.transform.{Splicer, TreeMapWithStages} object Inliner { import tpd._ - /** `sym` is an inline method with a known body to inline (note: definitions coming - * from Scala2x class files might be `@forceInline`, but still lack that body). + /** `sym` is an inline method with a known body to inline. */ def hasBodyToInline(sym: SymDenotation)(implicit ctx: Context): Boolean = sym.isInlineMethod && sym.hasAnnotation(defn.BodyAnnot) /** The body to inline for method `sym`, or `EmptyTree` if none exists. - * Note: definitions coming from Scala2x class files might be `@forceInline`, - * but still lack that body. * @pre hasBodyToInline(sym) */ def bodyToInline(sym: SymDenotation)(implicit ctx: Context): Tree = diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 76e51e87ae8b..cc2c7bcb5b28 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -830,8 +830,6 @@ class Namer { typer: Typer => else { val ann = Annotation.deferred(cls)(typedAnnotation(annotTree)) sym.addAnnotation(ann) - if (cls == defn.ForceInlineAnnot && sym.is(Method, butNot = Accessor)) - sym.setFlag(Inline) } } case _ => diff --git a/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala b/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala index f38cb69b3c7a..0685a8b7d488 100644 --- a/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala +++ b/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala @@ -165,7 +165,7 @@ trait QuotesAndSplices { object splitter extends tpd.TreeMap { private var variance: Int = 1 - @forceInline private def atVariance[T](v: Int)(op: => T): T = { + inline private def atVariance[T](v: Int)(op: => T): T = { val saved = variance variance = v val res = op diff --git a/compiler/src/dotty/tools/dotc/util/Stats.scala b/compiler/src/dotty/tools/dotc/util/Stats.scala index acbba5f7b90e..e7a28861fdd4 100644 --- a/compiler/src/dotty/tools/dotc/util/Stats.scala +++ b/compiler/src/dotty/tools/dotc/util/Stats.scala @@ -19,8 +19,7 @@ import collection.mutable override def default(key: String): Int = 0 } - @forceInline - def record(fn: => String, n: => Int = 1): Unit = + inline def record(fn: => String, n: => Int = 1): Unit = if (enabled) doRecord(fn, n) def doRecord(fn: String, n: Int) = @@ -29,8 +28,7 @@ import collection.mutable hits(name) += n } - @forceInline - def trackTime[T](fn: String)(op: => T): T = + inline def trackTime[T](fn: String)(op: => T): T = if (enabled) doTrackTime(fn)(op) else op def doTrackTime[T](fn: String)(op: => T): T = { diff --git a/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala b/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala index 6b206baacdab..78282717be8b 100644 --- a/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala +++ b/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala @@ -13,7 +13,7 @@ class InlineBytecodeTests extends DottyBytecodeTest { val source = """ |class Foo { | inline def foo: Int = 1 - | @forceInline def bar: Int = 1 + | inline def bar: Int = 1 | | def meth1: Unit = foo | def meth2: Unit = bar diff --git a/library/src/dotty/DottyPredef.scala b/library/src/dotty/DottyPredef.scala index 18b16a0283e6..529266cb3922 100644 --- a/library/src/dotty/DottyPredef.scala +++ b/library/src/dotty/DottyPredef.scala @@ -3,12 +3,12 @@ package dotty object DottyPredef { import compiletime.summonFrom - @forceInline final def assert(assertion: => Boolean, message: => Any): Unit = { + inline final def assert(assertion: => Boolean, message: => Any): Unit = { if (!assertion) assertFail(message) } - @forceInline final def assert(assertion: => Boolean): Unit = { + inline final def assert(assertion: => Boolean): Unit = { if (!assertion) assertFail() } @@ -16,9 +16,9 @@ object DottyPredef { def assertFail(): Unit = throw new java.lang.AssertionError("assertion failed") def assertFail(message: => Any): Unit = throw new java.lang.AssertionError("assertion failed: " + message) - @forceInline final def implicitly[T](implicit ev: T): T = ev + inline final def implicitly[T](implicit ev: T): T = ev - @forceInline def locally[T](body: => T): T = body + inline def locally[T](body: => T): T = body /** * Retrieve the single value of a type with a unique inhabitant. diff --git a/library/src/scala/forceInline.scala b/library/src/scala/forceInline.scala deleted file mode 100644 index b08f18fa4542..000000000000 --- a/library/src/scala/forceInline.scala +++ /dev/null @@ -1,17 +0,0 @@ -package scala - -/** An annotation on methods that is equivalent to Dotty `inline` modifier, - * except that it does not imply `erased`. - * - * The annotation should be used instead of the `inline` modifier in code - * that needs to cross compile between Scala 2 and Dotty. - * - * Note that Scala 2 ignores the `@forceInLine` annotation, and one must use - * both the `@inline` and `@forceInline` annotation to inline across the - * two compilers. E.g. - * - * ```scala - * @inline @forceInline def foo = ... - * ``` - */ -class forceInline extends scala.annotation.StaticAnnotation diff --git a/library/src/scala/internal/Chars.scala b/library/src/scala/internal/Chars.scala index 4c0ffeb24fa7..7faaa700007a 100644 --- a/library/src/scala/internal/Chars.scala +++ b/library/src/scala/internal/Chars.scala @@ -33,7 +33,7 @@ object Chars { /** Convert a character to a backslash-u escape */ def char2uescape(c: Char): String = { - @forceInline def hexChar(ch: Int): Char = + inline def hexChar(ch: Int): Char = (( if (ch < 10) '0' else 'A' - 10 ) + ch).toChar char2uescapeArray(2) = hexChar((c >> 12) )