Skip to content

Drop forceInline annotation #7475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
11 changes: 2 additions & 9 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]())
}
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/ConstFold.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 1 addition & 4 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 _ =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions compiler/src/dotty/tools/dotc/util/Stats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand All @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions library/src/dotty/DottyPredef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ 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()
}

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.
Expand Down
17 changes: 0 additions & 17 deletions library/src/scala/forceInline.scala

This file was deleted.

2 changes: 1 addition & 1 deletion library/src/scala/internal/Chars.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) )
Expand Down