Skip to content

Commit

Permalink
Merge pull request #1310 from Friendseeker/track-inline-dep
Browse files Browse the repository at this point in the history
Invalidate sources that depends on `@inline` methods
  • Loading branch information
eed3si9n authored Dec 18, 2023
2 parents 5eb0de1 + a0d8ccf commit 150ed32
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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]]. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,17 +519,21 @@ 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,
s.isFinal,
s.hasFlag(SEALED),
isImplicit(s),
s.hasFlag(LAZY),
s.hasFlag(MACRO),
s.hasFlag(MACRO) || hasInline,
s.hasFlag(SUPERACCESSOR)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions zinc/src/sbt-test/source-dependencies/inline/A.scala
Original file line number Diff line number Diff line change
@@ -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
}
21 changes: 21 additions & 0 deletions zinc/src/sbt-test/source-dependencies/inline/App.scala
Original file line number Diff line number Diff line change
@@ -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
}
}
}
14 changes: 14 additions & 0 deletions zinc/src/sbt-test/source-dependencies/inline/B.scala
Original file line number Diff line number Diff line change
@@ -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
}
15 changes: 15 additions & 0 deletions zinc/src/sbt-test/source-dependencies/inline/changes/A.scala
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 12 additions & 0 deletions zinc/src/sbt-test/source-dependencies/inline/incOptions.properties
Original file line number Diff line number Diff line change
@@ -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:**
3 changes: 3 additions & 0 deletions zinc/src/sbt-test/source-dependencies/inline/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
> run 1
$ copy-file changes/A.scala A.scala
> run 2

0 comments on commit 150ed32

Please sign in to comment.