From fdd883e1935b5d885266dad71abe438478e11a0b Mon Sep 17 00:00:00 2001 From: friendseeker <66892505+Friendseeker@users.noreply.github.com> Date: Fri, 15 Dec 2023 13:24:11 -0800 Subject: [PATCH 1/4] Scripted Test for -opt:l:inline --- .../source-dependencies/inline/A.scala | 14 +++++++++++++ .../source-dependencies/inline/App.scala | 21 +++++++++++++++++++ .../source-dependencies/inline/B.scala | 14 +++++++++++++ .../inline/changes/A.scala | 15 +++++++++++++ .../inline/incOptions.properties | 12 +++++++++++ .../sbt-test/source-dependencies/inline/test | 3 +++ 6 files changed, 79 insertions(+) create mode 100644 zinc/src/sbt-test/source-dependencies/inline/A.scala create mode 100644 zinc/src/sbt-test/source-dependencies/inline/App.scala create mode 100644 zinc/src/sbt-test/source-dependencies/inline/B.scala create mode 100644 zinc/src/sbt-test/source-dependencies/inline/changes/A.scala create mode 100644 zinc/src/sbt-test/source-dependencies/inline/incOptions.properties create mode 100644 zinc/src/sbt-test/source-dependencies/inline/test 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 From 63b29e73acf0d7d05e136e5454aa8daee6934b7b Mon Sep 17 00:00:00 2001 From: friendseeker <66892505+Friendseeker@users.noreply.github.com> Date: Fri, 15 Dec 2023 14:24:00 -0800 Subject: [PATCH 2/4] Mark inline annotation as Macro --- internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala b/internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala index 6b1bea3d8..efafd3386 100644 --- a/internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala +++ b/internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala @@ -522,6 +522,7 @@ class ExtractAPI[GlobalType <: Global]( val absOver = s.hasFlag(ABSOVERRIDE) val abs = s.hasFlag(ABSTRACT) || s.hasFlag(DEFERRED) || absOver val over = s.hasFlag(OVERRIDE) || absOver + val hasInline = s.annotations.exists(_.symbol.tpe == typeOf[scala.inline]) new xsbti.api.Modifiers( abs, over, @@ -529,7 +530,7 @@ class ExtractAPI[GlobalType <: Global]( s.hasFlag(SEALED), isImplicit(s), s.hasFlag(LAZY), - s.hasFlag(MACRO), + s.hasFlag(MACRO) || hasInline, s.hasFlag(SUPERACCESSOR) ) } From eb69747e4ceecc89226637b512b4ad849c461c9a Mon Sep 17 00:00:00 2001 From: friendseeker <66892505+Friendseeker@users.noreply.github.com> Date: Fri, 15 Dec 2023 16:00:10 -0800 Subject: [PATCH 3/4] Only check when optInlinerEnabled No idea whether getModifiers is a hotspot or not. But it only takes a few extra lines anyways. --- .../compiler-bridge/src/main/scala-2.11/xsbt/Compat.scala | 4 ++++ .../compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala | 5 ++++- .../compiler-bridge/src/main/scala_2.10/xsbt/Compat.scala | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) 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 efafd3386..62847e6ca 100644 --- a/internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala +++ b/internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala @@ -519,10 +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 = s.annotations.exists(_.symbol.tpe == typeOf[scala.inline]) + val hasInline = global.settings.optInlinerEnabled || s.annotations.exists( + _.symbol.tpe == typeOf[scala.inline] + ) new xsbti.api.Modifiers( abs, over, 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 { From a0d8ccf3a6408873b0f25db134024e81cfeb044c Mon Sep 17 00:00:00 2001 From: friendseeker <66892505+Friendseeker@users.noreply.github.com> Date: Fri, 15 Dec 2023 16:03:02 -0800 Subject: [PATCH 4/4] Fix early stopping condition --- internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala b/internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala index 62847e6ca..1cef8b220 100644 --- a/internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala +++ b/internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala @@ -523,7 +523,7 @@ class ExtractAPI[GlobalType <: Global]( 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( + val hasInline = global.settings.optInlinerEnabled && s.annotations.exists( _.symbol.tpe == typeOf[scala.inline] ) new xsbti.api.Modifiers(