diff --git a/internal/compiler-bridge/src/main/scala-2.11/xsbt/Compat.scala b/internal/compiler-bridge/src/main/scala-2.11/xsbt/Compat.scala index dfc1836e6..35858ac10 100644 --- a/internal/compiler-bridge/src/main/scala-2.11/xsbt/Compat.scala +++ b/internal/compiler-bridge/src/main/scala-2.11/xsbt/Compat.scala @@ -31,6 +31,10 @@ object Compat { // IMain in 2.13 accepts ReplReporter def replReporter(settings: Settings, writer: PrintWriter) = writer + + implicit final class SettingsCompat(val settings: Settings) extends AnyVal { + @inline final def optInlinerEnabled: Boolean = false + } } /** Defines compatibility utils for [[ZincCompiler]]. */ diff --git a/internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala b/internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala index 6b1bea3d8..1cef8b220 100644 --- a/internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala +++ b/internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala @@ -519,9 +519,13 @@ class ExtractAPI[GlobalType <: Global]( } private def getModifiers(s: Symbol): xsbti.api.Modifiers = { import Flags._ + import xsbt.Compat._ val absOver = s.hasFlag(ABSOVERRIDE) val abs = s.hasFlag(ABSTRACT) || s.hasFlag(DEFERRED) || absOver val over = s.hasFlag(OVERRIDE) || absOver + val hasInline = global.settings.optInlinerEnabled && s.annotations.exists( + _.symbol.tpe == typeOf[scala.inline] + ) new xsbti.api.Modifiers( abs, over, @@ -529,7 +533,7 @@ class ExtractAPI[GlobalType <: Global]( s.hasFlag(SEALED), isImplicit(s), s.hasFlag(LAZY), - s.hasFlag(MACRO), + s.hasFlag(MACRO) || hasInline, s.hasFlag(SUPERACCESSOR) ) } diff --git a/internal/compiler-bridge/src/main/scala_2.10/xsbt/Compat.scala b/internal/compiler-bridge/src/main/scala_2.10/xsbt/Compat.scala index 83093eb7a..886dbb9c5 100644 --- a/internal/compiler-bridge/src/main/scala_2.10/xsbt/Compat.scala +++ b/internal/compiler-bridge/src/main/scala_2.10/xsbt/Compat.scala @@ -183,6 +183,8 @@ object Compat { implicit final class SettingsCompat(val settings: Settings) extends AnyVal { // Introduced in 2.11 @inline final def fatalWarnings = settings.Xwarnfatal + + @inline final def optInlinerEnabled: Boolean = false } implicit final class PositionOps(val self: sriu.Position) extends AnyVal { diff --git a/zinc/src/sbt-test/source-dependencies/inline/A.scala b/zinc/src/sbt-test/source-dependencies/inline/A.scala new file mode 100644 index 000000000..c89f4c2fa --- /dev/null +++ b/zinc/src/sbt-test/source-dependencies/inline/A.scala @@ -0,0 +1,14 @@ +/* + * Zinc - The incremental compiler for Scala. + * Copyright Scala Center, Lightbend, and Mark Harrah + * + * Licensed under Apache License 2.0 + * SPDX-License-Identifier: Apache-2.0 + * + * See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + */ +object A { + @inline + def x: Int = 1 +} \ No newline at end of file diff --git a/zinc/src/sbt-test/source-dependencies/inline/App.scala b/zinc/src/sbt-test/source-dependencies/inline/App.scala new file mode 100644 index 000000000..93ade3079 --- /dev/null +++ b/zinc/src/sbt-test/source-dependencies/inline/App.scala @@ -0,0 +1,21 @@ +/* + * Zinc - The incremental compiler for Scala. + * Copyright Scala Center, Lightbend, and Mark Harrah + * + * Licensed under Apache License 2.0 + * SPDX-License-Identifier: Apache-2.0 + * + * See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + */ +object App { + def main(args: Array[String]): Unit = { + val exp = args(0).toInt + val res = B.x + if (res != exp) { + val e = new Exception(s"assertion failed: expected $exp, obtained $res") + e.setStackTrace(Array()) + throw e + } + } +} diff --git a/zinc/src/sbt-test/source-dependencies/inline/B.scala b/zinc/src/sbt-test/source-dependencies/inline/B.scala new file mode 100644 index 000000000..359813247 --- /dev/null +++ b/zinc/src/sbt-test/source-dependencies/inline/B.scala @@ -0,0 +1,14 @@ +/* + * Zinc - The incremental compiler for Scala. + * Copyright Scala Center, Lightbend, and Mark Harrah + * + * Licensed under Apache License 2.0 + * SPDX-License-Identifier: Apache-2.0 + * + * See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + */ + +object B { + def x = A.x +} diff --git a/zinc/src/sbt-test/source-dependencies/inline/changes/A.scala b/zinc/src/sbt-test/source-dependencies/inline/changes/A.scala new file mode 100644 index 000000000..d54d9ea04 --- /dev/null +++ b/zinc/src/sbt-test/source-dependencies/inline/changes/A.scala @@ -0,0 +1,15 @@ +/* + * Zinc - The incremental compiler for Scala. + * Copyright Scala Center, Lightbend, and Mark Harrah + * + * Licensed under Apache License 2.0 + * SPDX-License-Identifier: Apache-2.0 + * + * See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + */ + +object A { + @inline + def x: Int = 2 +} \ No newline at end of file diff --git a/zinc/src/sbt-test/source-dependencies/inline/incOptions.properties b/zinc/src/sbt-test/source-dependencies/inline/incOptions.properties new file mode 100644 index 000000000..a2064e8ee --- /dev/null +++ b/zinc/src/sbt-test/source-dependencies/inline/incOptions.properties @@ -0,0 +1,12 @@ +# +# Zinc - The incremental compiler for Scala. +# Copyright Scala Center, Lightbend, and Mark Harrah +# +# Licensed under Apache License 2.0 +# SPDX-License-Identifier: Apache-2.0 +# +# See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. +# + +scalac.options = -opt:l:inline -opt-inline-from:** \ No newline at end of file diff --git a/zinc/src/sbt-test/source-dependencies/inline/test b/zinc/src/sbt-test/source-dependencies/inline/test new file mode 100644 index 000000000..ce6162ee1 --- /dev/null +++ b/zinc/src/sbt-test/source-dependencies/inline/test @@ -0,0 +1,3 @@ +> run 1 +$ copy-file changes/A.scala A.scala +> run 2 \ No newline at end of file