Skip to content

Adapt inline parameters #8110

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 2 commits into from
Jan 29, 2020
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
58 changes: 13 additions & 45 deletions compiler/src/dotty/tools/dotc/reporting/trace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,69 +25,37 @@ object trace extends TraceSyntax {
abstract class TraceSyntax {
val isForced: Boolean

// FIXME Use this signature after reference compiler is updated
// inline def onDebug[TD](inline question: String)(inline op: TD)(implicit ctx: Context): TD =
inline def onDebug[TD](question: => String)(op: => TD)(implicit ctx: Context): TD =
inline def onDebug[TD](inline question: String)(inline op: TD)(implicit ctx: Context): TD =
conditionally(ctx.settings.YdebugTrace.value, question, false)(op)

// FIXME Use this implementation after reference compiler is updated
// inline def conditionally[TC](inline cond: Boolean, inline question: String, inline show: Boolean)(op: => TC)(implicit ctx: Context): TC =
// inline if (isForced || Config.tracingEnabled) {
// if (cond) apply[TC](question, Printers.default, show)(op)
// else op
// }
// else op
inline def conditionally[TC](cond: Boolean, question: => String, show: Boolean)(op: => TC)(implicit ctx: Context): TC =
inline def conditionally[TC](inline cond: Boolean, inline question: String, inline show: Boolean)(op: => TC)(implicit ctx: Context): TC =
inline if (isForced || Config.tracingEnabled) {
def op1 = op
if (cond) apply[TC](question, Printers.default, show)(op1)
else op1
if (cond) apply[TC](question, Printers.default, show)(op)
else op
}
else op

// FIXME Use this implementation after reference compiler is updated
// inline def apply[T](inline question: String, inline printer: Printers.Printer, inline showOp: Any => String)(op: => T)(implicit ctx: Context): T =
// inline if (isForced || Config.tracingEnabled) {
// if (!isForced && printer.eq(config.Printers.noPrinter)) op
// else doTrace[T](question, printer, showOp)(op)
// }
// else op
inline def apply[T](question: => String, printer: Printers.Printer, showOp: Any => String)(op: => T)(implicit ctx: Context): T =
inline def apply[T](inline question: String, inline printer: Printers.Printer, inline showOp: Any => String)(op: => T)(implicit ctx: Context): T =
inline if (isForced || Config.tracingEnabled) {
def op1 = op
if (!isForced && printer.eq(config.Printers.noPrinter)) op1
else doTrace[T](question, printer, showOp)(op1)
if (!isForced && printer.eq(config.Printers.noPrinter)) op
else doTrace[T](question, printer, showOp)(op)
}
else op

// FIXME Use this implementation after reference compiler is updated
// inline def apply[T](inline question: String, inline printer: Printers.Printer, inline show: Boolean)(op: => T)(implicit ctx: Context): T =
// inline if (isForced || Config.tracingEnabled) {
// if (!isForced && printer.eq(config.Printers.noPrinter)) op
// else doTrace[T](question, printer, if (show) showShowable(_) else alwaysToString)(op)
// }
// else op
inline def apply[T](question: => String, printer: Printers.Printer, show: Boolean)(op: => T)(implicit ctx: Context): T =
inline def apply[T](inline question: String, inline printer: Printers.Printer, inline show: Boolean)(op: => T)(implicit ctx: Context): T =
inline if (isForced || Config.tracingEnabled) {
def op1 = op
if (!isForced && printer.eq(config.Printers.noPrinter)) op1
else doTrace[T](question, printer, if (show) showShowable(_) else alwaysToString)(op1)
if (!isForced && printer.eq(config.Printers.noPrinter)) op
else doTrace[T](question, printer, if (show) showShowable(_) else alwaysToString)(op)
}
else op

// FIXME Use this signature after reference compiler is updated
// inline def apply[T](inline question: String, inline printer: Printers.Printer)(inline op: T)(implicit ctx: Context): T =
inline def apply[T](question: => String, printer: Printers.Printer)(op: => T)(implicit ctx: Context): T =
inline def apply[T](inline question: String, inline printer: Printers.Printer)(inline op: T)(implicit ctx: Context): T =
apply[T](question, printer, false)(op)

// FIXME Use this signature after reference compiler is updated
// inline def apply[T](inline question: String, inline show: Boolean)(inline op: T)(implicit ctx: Context): T =
inline def apply[T](question: => String, show: Boolean)(op: => T)(implicit ctx: Context): T =
inline def apply[T](inline question: String, inline show: Boolean)(inline op: T)(implicit ctx: Context): T =
apply[T](question, Printers.default, show)(op)

// FIXME Use this signature after reference compiler is updated
// inline def apply[T](inline question: String)(inline op: T)(implicit ctx: Context): T =
inline def apply[T](question: => String)(op: => T)(implicit ctx: Context): T =
inline def apply[T](inline question: String)(inline op: T)(implicit ctx: Context): T =
apply[T](question, Printers.default, false)(op)

private def showShowable(x: Any)(implicit ctx: Context) = x match {
Expand Down
8 changes: 2 additions & 6 deletions compiler/src/dotty/tools/dotc/util/Stats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import collection.mutable
override def default(key: String): Int = 0
}

// FIXME Use this signature after reference compiler is updated
// inline def record(inline fn: String, inline n: Int = 1): Unit =
inline def record(fn: => String, n: => Int = 1): Unit =
inline def record(inline fn: String, inline n: Int = 1): Unit =
if (enabled) doRecord(fn, n)

def doRecord(fn: String, n: Int) =
Expand All @@ -30,9 +28,7 @@ import collection.mutable
hits(name) += n
}

// FIXME Use this signature after reference compiler is updated
// inline def trackTime[T](fn: String)(inline op: T): T =
inline def trackTime[T](fn: String)(op: => T): T =
inline def trackTime[T](fn: String)(inline op: T): T =
if (enabled) doTrackTime(fn)(op) else op

def doTrackTime[T](fn: String)(op: => T): T = {
Expand Down
58 changes: 28 additions & 30 deletions compiler/test/dotty/tools/backend/jvm/ArrayApplyOptTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import scala.tools.asm.Opcodes._
class ArrayApplyOptTest extends DottyBytecodeTest {
import ASMConverters._

// FIXME: Re-enable IArray bytecode tests (requires updated reference compiler)
// Also change: library/src/scala/IArray.scala
@Test def testArrayEmptyGenericApply= {
@Test def testArrayEmptyGenericApply = {
test("Array[String]()", List(Op(ICONST_0), TypeOp(ANEWARRAY, "java/lang/String"), Op(POP), Op(RETURN)))
test("Array[Unit]()", List(Op(ICONST_0), TypeOp(ANEWARRAY, "scala/runtime/BoxedUnit"), Op(POP), Op(RETURN)))
test("Array[Object]()", List(Op(ICONST_0), TypeOp(ANEWARRAY, "java/lang/Object"), Op(POP), Op(RETURN)))
Expand All @@ -24,91 +22,91 @@ class ArrayApplyOptTest extends DottyBytecodeTest {
test("Array[Char]()", newArray0Opcodes(T_CHAR))
test("Array[T]()", newArray0Opcodes(T_INT))

// test("IArray[String]()", List(Op(ICONST_0), TypeOp(ANEWARRAY, "java/lang/String"), TypeOp(CHECKCAST, "[Ljava/lang/String;"), Op(POP), Op(RETURN)))
// test("IArray[Unit]()", List(Op(ICONST_0), TypeOp(ANEWARRAY, "scala/runtime/BoxedUnit"), TypeOp(CHECKCAST, "[Lscala/runtime/BoxedUnit;"), Op(POP), Op(RETURN)))
// test("IArray[Object]()", List(Op(ICONST_0), TypeOp(ANEWARRAY, "java/lang/Object"), TypeOp(CHECKCAST, "[Ljava/lang/Object;"), Op(POP), Op(RETURN)))
// test("IArray[Boolean]()", newArray0Opcodes(T_BOOLEAN, TypeOp(CHECKCAST, "[Z") :: Nil))
// test("IArray[Byte]()", newArray0Opcodes(T_BYTE, TypeOp(CHECKCAST, "[B") :: Nil))
// test("IArray[Short]()", newArray0Opcodes(T_SHORT, TypeOp(CHECKCAST, "[S") :: Nil))
// test("IArray[Int]()", newArray0Opcodes(T_INT, TypeOp(CHECKCAST, "[I") :: Nil))
// test("IArray[Long]()", newArray0Opcodes(T_LONG, TypeOp(CHECKCAST, "[J") :: Nil))
// test("IArray[Float]()", newArray0Opcodes(T_FLOAT, TypeOp(CHECKCAST, "[F") :: Nil))
// test("IArray[Double]()", newArray0Opcodes(T_DOUBLE, TypeOp(CHECKCAST, "[D") :: Nil))
// test("IArray[Char]()", newArray0Opcodes(T_CHAR, TypeOp(CHECKCAST, "[C") :: Nil))
// test("IArray[T]()", newArray0Opcodes(T_INT, TypeOp(CHECKCAST, "[I") :: Nil))
test("IArray[String]()", List(Op(ICONST_0), TypeOp(ANEWARRAY, "java/lang/String"), TypeOp(CHECKCAST, "[Ljava/lang/String;"), Op(POP), Op(RETURN)))
test("IArray[Unit]()", List(Op(ICONST_0), TypeOp(ANEWARRAY, "scala/runtime/BoxedUnit"), TypeOp(CHECKCAST, "[Lscala/runtime/BoxedUnit;"), Op(POP), Op(RETURN)))
test("IArray[Object]()", List(Op(ICONST_0), TypeOp(ANEWARRAY, "java/lang/Object"), TypeOp(CHECKCAST, "[Ljava/lang/Object;"), Op(POP), Op(RETURN)))
test("IArray[Boolean]()", newArray0Opcodes(T_BOOLEAN, TypeOp(CHECKCAST, "[Z") :: Nil))
test("IArray[Byte]()", newArray0Opcodes(T_BYTE, TypeOp(CHECKCAST, "[B") :: Nil))
test("IArray[Short]()", newArray0Opcodes(T_SHORT, TypeOp(CHECKCAST, "[S") :: Nil))
test("IArray[Int]()", newArray0Opcodes(T_INT, TypeOp(CHECKCAST, "[I") :: Nil))
test("IArray[Long]()", newArray0Opcodes(T_LONG, TypeOp(CHECKCAST, "[J") :: Nil))
test("IArray[Float]()", newArray0Opcodes(T_FLOAT, TypeOp(CHECKCAST, "[F") :: Nil))
test("IArray[Double]()", newArray0Opcodes(T_DOUBLE, TypeOp(CHECKCAST, "[D") :: Nil))
test("IArray[Char]()", newArray0Opcodes(T_CHAR, TypeOp(CHECKCAST, "[C") :: Nil))
test("IArray[T]()", newArray0Opcodes(T_INT, TypeOp(CHECKCAST, "[I") :: Nil))
}

@Test def testArrayGenericApply= {
@Test def testArrayGenericApply = {
def opCodes(tpe: String) =
List(Op(ICONST_2), TypeOp(ANEWARRAY, tpe), Op(DUP), Op(ICONST_0), Ldc(LDC, "a"), Op(AASTORE), Op(DUP), Op(ICONST_1), Ldc(LDC, "b"), Op(AASTORE), Op(POP), Op(RETURN))
test("""Array("a", "b")""", opCodes("java/lang/String"))
test("""Array[Object]("a", "b")""", opCodes("java/lang/Object"))

def opCodes2(tpe: String) =
List(Op(ICONST_2), TypeOp(ANEWARRAY, tpe), Op(DUP), Op(ICONST_0), Ldc(LDC, "a"), Op(AASTORE), Op(DUP), Op(ICONST_1), Ldc(LDC, "b"), Op(AASTORE), TypeOp(CHECKCAST, s"[L$tpe;"), Op(POP), Op(RETURN))
// test("""IArray("a", "b")""", opCodes2("java/lang/String"))
// test("""IArray[Object]("a", "b")""", opCodes2("java/lang/Object"))
test("""IArray("a", "b")""", opCodes2("java/lang/String"))
test("""IArray[Object]("a", "b")""", opCodes2("java/lang/Object"))
}

@Test def testArrayApplyBoolean = {
val init = List(Op(DUP), Op(ICONST_0), Op(ICONST_1), Op(BASTORE), Op(DUP), Op(ICONST_1), Op(ICONST_0), Op(BASTORE))
test("Array(true, false)", newArray2Opcodes(T_BOOLEAN, init))
// test("IArray(true, false)", newArray2Opcodes(T_BOOLEAN, init :+ TypeOp(CHECKCAST, "[Z")))
test("IArray(true, false)", newArray2Opcodes(T_BOOLEAN, init :+ TypeOp(CHECKCAST, "[Z")))
}

@Test def testArrayApplyByte = {
val init = List(Op(DUP), Op(ICONST_0), Op(ICONST_1), Op(BASTORE), Op(DUP), Op(ICONST_1), Op(ICONST_2), Op(BASTORE))
test("Array[Byte](1, 2)", newArray2Opcodes(T_BYTE, init))
// test("IArray[Byte](1, 2)", newArray2Opcodes(T_BYTE, init :+ TypeOp(CHECKCAST, "[B")))
test("IArray[Byte](1, 2)", newArray2Opcodes(T_BYTE, init :+ TypeOp(CHECKCAST, "[B")))
}

@Test def testArrayApplyShort = {
val init = List(Op(DUP), Op(ICONST_0), Op(ICONST_1), Op(SASTORE), Op(DUP), Op(ICONST_1), Op(ICONST_2), Op(SASTORE))
test("Array[Short](1, 2)", newArray2Opcodes(T_SHORT, init))
// test("IArray[Short](1, 2)", newArray2Opcodes(T_SHORT, init :+ TypeOp(CHECKCAST, "[S")))
test("IArray[Short](1, 2)", newArray2Opcodes(T_SHORT, init :+ TypeOp(CHECKCAST, "[S")))
}

@Test def testArrayApplyInt = {
val init = List(Op(DUP), Op(ICONST_0), Op(ICONST_1), Op(IASTORE), Op(DUP), Op(ICONST_1), Op(ICONST_2), Op(IASTORE))
test("Array(1, 2)", newArray2Opcodes(T_INT, init))
// test("IArray(1, 2)", newArray2Opcodes(T_INT, init :+ TypeOp(CHECKCAST, "[I")))
test("IArray(1, 2)", newArray2Opcodes(T_INT, init :+ TypeOp(CHECKCAST, "[I")))

val init2 = List(Op(DUP), Op(ICONST_0), Field(GETSTATIC, "Foo$", "MODULE$", "LFoo$;"), Invoke(INVOKEVIRTUAL, "Foo$", "t", "()I", false), Op(IASTORE), Op(DUP), Op(ICONST_1), Field(GETSTATIC, "Foo$", "MODULE$", "LFoo$;"), Invoke(INVOKEVIRTUAL, "Foo$", "t", "()I", false), Op(IASTORE))
test("""Array[T](t, t)""", newArray2Opcodes(T_INT, init2))
// test("""IArray[T](t, t)""", newArray2Opcodes(T_INT, init2 :+ TypeOp(CHECKCAST, "[I")))
test("""IArray[T](t, t)""", newArray2Opcodes(T_INT, init2 :+ TypeOp(CHECKCAST, "[I")))
}

@Test def testArrayApplyLong = {
val init = List(Op(DUP), Op(ICONST_0), Ldc(LDC, 2), Op(LASTORE), Op(DUP), Op(ICONST_1), Ldc(LDC, 3), Op(LASTORE))
test("Array(2L, 3L)", newArray2Opcodes(T_LONG, init))
// test("IArray(2L, 3L)", newArray2Opcodes(T_LONG, init :+ TypeOp(CHECKCAST, "[J")))
test("IArray(2L, 3L)", newArray2Opcodes(T_LONG, init :+ TypeOp(CHECKCAST, "[J")))
}

@Test def testArrayApplyFloat = {
val init = List(Op(DUP), Op(ICONST_0), Ldc(LDC, 2.1f), Op(FASTORE), Op(DUP), Op(ICONST_1), Ldc(LDC, 3.1f), Op(FASTORE))
test("Array(2.1f, 3.1f)", newArray2Opcodes(T_FLOAT, init))
// test("IArray(2.1f, 3.1f)", newArray2Opcodes(T_FLOAT, init :+ TypeOp(CHECKCAST, "[F")))
test("IArray(2.1f, 3.1f)", newArray2Opcodes(T_FLOAT, init :+ TypeOp(CHECKCAST, "[F")))
}

@Test def testArrayApplyDouble = {
val init = List(Op(DUP), Op(ICONST_0), Ldc(LDC, 2.2d), Op(DASTORE), Op(DUP), Op(ICONST_1), Ldc(LDC, 3.2d), Op(DASTORE))
test("Array(2.2d, 3.2d)", newArray2Opcodes(T_DOUBLE, init))
// test("IArray(2.2d, 3.2d)", newArray2Opcodes(T_DOUBLE, init :+ TypeOp(CHECKCAST, "[D")))
test("IArray(2.2d, 3.2d)", newArray2Opcodes(T_DOUBLE, init :+ TypeOp(CHECKCAST, "[D")))
}

@Test def testArrayApplyChar = {
val init = List(Op(DUP), Op(ICONST_0), IntOp(BIPUSH, 120), Op(CASTORE), Op(DUP), Op(ICONST_1), IntOp(BIPUSH, 121), Op(CASTORE))
test("Array('x', 'y')", newArray2Opcodes(T_CHAR, init))
// test("IArray('x', 'y')", newArray2Opcodes(T_CHAR, init :+ TypeOp(CHECKCAST, "[C")))
test("IArray('x', 'y')", newArray2Opcodes(T_CHAR, init :+ TypeOp(CHECKCAST, "[C")))
}

@Test def testArrayApplyUnit = {
test("Array[Unit]((), ())", List(Op(ICONST_2), TypeOp(ANEWARRAY, "scala/runtime/BoxedUnit"), Op(DUP),
Op(ICONST_0), Field(GETSTATIC, "scala/runtime/BoxedUnit", "UNIT", "Lscala/runtime/BoxedUnit;"), Op(AASTORE), Op(DUP),
Op(ICONST_1), Field(GETSTATIC, "scala/runtime/BoxedUnit", "UNIT", "Lscala/runtime/BoxedUnit;"), Op(AASTORE), Op(POP), Op(RETURN)))
// test("IArray[Unit]((), ())", List(Op(ICONST_2), TypeOp(ANEWARRAY, "scala/runtime/BoxedUnit"), Op(DUP),
// Op(ICONST_0), Field(GETSTATIC, "scala/runtime/BoxedUnit", "UNIT", "Lscala/runtime/BoxedUnit;"), Op(AASTORE), Op(DUP),
// Op(ICONST_1), Field(GETSTATIC, "scala/runtime/BoxedUnit", "UNIT", "Lscala/runtime/BoxedUnit;"), Op(AASTORE), TypeOp(CHECKCAST, "[Lscala/runtime/BoxedUnit;"), Op(POP), Op(RETURN)))
test("IArray[Unit]((), ())", List(Op(ICONST_2), TypeOp(ANEWARRAY, "scala/runtime/BoxedUnit"), Op(DUP),
Op(ICONST_0), Field(GETSTATIC, "scala/runtime/BoxedUnit", "UNIT", "Lscala/runtime/BoxedUnit;"), Op(AASTORE), Op(DUP),
Op(ICONST_1), Field(GETSTATIC, "scala/runtime/BoxedUnit", "UNIT", "Lscala/runtime/BoxedUnit;"), Op(AASTORE), TypeOp(CHECKCAST, "[Lscala/runtime/BoxedUnit;"), Op(POP), Op(RETURN)))
}

@Test def testArrayInlined = test(
Expand Down
23 changes: 10 additions & 13 deletions library/src/scala/IArray.scala
Original file line number Diff line number Diff line change
Expand Up @@ -284,29 +284,26 @@ object IArray {
/** An immutable object array of length 0. */
def emptyObjectIArray = Array.emptyObjectArray.asInstanceOf[IArray[Object]]

// FIXME: add inline parameters (requires updated reference compiler)
// Also change: compiler/test/dotty/tools/backend/jvm/ArrayApplyOptTest.scala

/** An immutable array with given elements. */
inline def apply[T](/*inline*/ xs: T*)(given ct: => ClassTag[T]): IArray[T] = Array(xs: _*).asInstanceOf
inline def apply[T](inline xs: T*)(given inline ct: ClassTag[T]): IArray[T] = Array(xs: _*).asInstanceOf
/** An immutable array with given elements. */
inline def apply(/*inline*/ x: Boolean, /*inline*/ xs: Boolean*): IArray[Boolean] = Array(x, xs: _*).asInstanceOf
inline def apply(inline x: Boolean, inline xs: Boolean*): IArray[Boolean] = Array(x, xs: _*).asInstanceOf
/** An immutable array with given elements. */
inline def apply(/*inline*/ x: Byte, /*inline*/ xs: Byte*): IArray[Byte] = Array(x, xs: _*).asInstanceOf
inline def apply(inline x: Byte, inline xs: Byte*): IArray[Byte] = Array(x, xs: _*).asInstanceOf
/** An immutable array with given elements. */
inline def apply(/*inline*/ x: Short, /*inline*/ xs: Short*): IArray[Short] = Array(x, xs: _*).asInstanceOf
inline def apply(inline x: Short, inline xs: Short*): IArray[Short] = Array(x, xs: _*).asInstanceOf
/** An immutable array with given elements. */
inline def apply(/*inline*/ x: Char, /*inline*/ xs: Char*): IArray[Char] = Array(x, xs: _*).asInstanceOf
inline def apply(inline x: Char, inline xs: Char*): IArray[Char] = Array(x, xs: _*).asInstanceOf
/** An immutable array with given elements. */
inline def apply(/*inline*/ x: Int, /*inline*/ xs: Int*): IArray[Int] = Array(x, xs: _*).asInstanceOf
inline def apply(inline x: Int, inline xs: Int*): IArray[Int] = Array(x, xs: _*).asInstanceOf
/** An immutable array with given elements. */
inline def apply(/*inline*/ x: Long, /*inline*/ xs: Long*): IArray[Long] = Array(x, xs: _*).asInstanceOf
inline def apply(inline x: Long, inline xs: Long*): IArray[Long] = Array(x, xs: _*).asInstanceOf
/** An immutable array with given elements. */
inline def apply(/*inline*/ x: Float, /*inline*/ xs: Float*): IArray[Float] = Array(x, xs: _*).asInstanceOf
inline def apply(inline x: Float, inline xs: Float*): IArray[Float] = Array(x, xs: _*).asInstanceOf
/** An immutable array with given elements. */
inline def apply(/*inline*/ x: Double, /*inline*/ xs: Double*): IArray[Double] = Array(x, xs: _*).asInstanceOf
inline def apply(inline x: Double, inline xs: Double*): IArray[Double] = Array(x, xs: _*).asInstanceOf
/** An immutable array with given elements. */
inline def apply(/*inline*/ x: Unit, /*inline*/ xs: Unit*): IArray[Unit] = Array(x, xs: _*).asInstanceOf
inline def apply(inline x: Unit, inline xs: Unit*): IArray[Unit] = Array(x, xs: _*).asInstanceOf

/** Concatenates all arrays into a single immutable array.
*
Expand Down
2 changes: 1 addition & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ object MyScalaJSPlugin extends AutoPlugin {
}

object Build {
val referenceVersion = "0.22.0-bin-20200114-193f7de-NIGHTLY"
val referenceVersion = "0.22.0-bin-20200127-f00fa72-NIGHTLY"

val baseVersion = "0.22.0"
val baseSbtDottyVersion = "0.4.0"
Expand Down