Skip to content
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

Improve message when -Xmax-inlines limit reached #13783

Merged
merged 1 commit into from
Oct 22, 2021
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
10 changes: 8 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,14 @@ object Erasure {
*/
private def checkNotErased(tree: Tree)(using Context): tree.type = {
if (!ctx.mode.is(Mode.Type)) {
if (isErased(tree))
report.error(em"${tree.symbol} is declared as erased, but is in fact used", tree.srcPos)
if isErased(tree) then
val msg =
if tree.symbol.is(Flags.Inline) then
em"""${tree.symbol} is declared as `inline`, but was not inlined
|
|Try increasing `-Xmax-inlines` above ${ctx.settings.XmaxInlines.value}""".stripMargin
else em"${tree.symbol} is declared as `erased`, but is in fact used"
report.error(msg, tree.srcPos)
tree.symbol.getAnnotation(defn.CompileTimeOnlyAnnot) match {
case Some(annot) =>
def defaultMsg =
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class CompilationTests {
compileFile("tests/pos-special/extend-java-enum.scala", defaultOptions.and("-source", "3.0-migration")),
compileFile("tests/pos-custom-args/help.scala", defaultOptions.and("-help", "-V", "-W", "-X", "-Y")),
compileFile("tests/pos-custom-args/i10383.scala", defaultOptions.and("-source", "future", "-deprecation", "-Xfatal-warnings")),
compileFile("tests/pos-custom-args/i13044.scala", defaultOptions.and("-Xmax-inlines:33")),
).checkCompile()
}

Expand Down
44 changes: 44 additions & 0 deletions tests/neg/i13044.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
-- Error: tests/neg/i13044.scala:50:40 ---------------------------------------------------------------------------------
50 | implicit def typeSchema: Schema[A] = Schema.gen // error // error
| ^^^^^^^^^^
| given instance gen is declared as `inline`, but was not inlined
|
| Try increasing `-Xmax-inlines` above 32
| This location contains code that was inlined from i13044.scala:17
| This location contains code that was inlined from i13044.scala:31
| This location contains code that was inlined from i13044.scala:37
| This location contains code that was inlined from i13044.scala:17
| This location contains code that was inlined from i13044.scala:31
| This location contains code that was inlined from i13044.scala:37
| This location contains code that was inlined from i13044.scala:17
| This location contains code that was inlined from i13044.scala:31
| This location contains code that was inlined from i13044.scala:37
| This location contains code that was inlined from i13044.scala:17
| This location contains code that was inlined from i13044.scala:31
| This location contains code that was inlined from i13044.scala:37
| This location contains code that was inlined from i13044.scala:17
| This location contains code that was inlined from i13044.scala:18
| This location contains code that was inlined from i13044.scala:31
| This location contains code that was inlined from i13044.scala:37
-- Error: tests/neg/i13044.scala:50:40 ---------------------------------------------------------------------------------
50 | implicit def typeSchema: Schema[A] = Schema.gen // error // error
| ^^^^^^^^^^
| method recurse is declared as `inline`, but was not inlined
|
| Try increasing `-Xmax-inlines` above 32
| This location contains code that was inlined from i13044.scala:18
| This location contains code that was inlined from i13044.scala:31
| This location contains code that was inlined from i13044.scala:37
| This location contains code that was inlined from i13044.scala:17
| This location contains code that was inlined from i13044.scala:31
| This location contains code that was inlined from i13044.scala:37
| This location contains code that was inlined from i13044.scala:17
| This location contains code that was inlined from i13044.scala:31
| This location contains code that was inlined from i13044.scala:37
| This location contains code that was inlined from i13044.scala:17
| This location contains code that was inlined from i13044.scala:31
| This location contains code that was inlined from i13044.scala:37
| This location contains code that was inlined from i13044.scala:17
| This location contains code that was inlined from i13044.scala:18
| This location contains code that was inlined from i13044.scala:31
| This location contains code that was inlined from i13044.scala:37
51 changes: 51 additions & 0 deletions tests/neg/i13044.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import scala.deriving.Mirror
import scala.compiletime._

trait Schema[T] {
def build: T
}

object Schema extends SchemaDerivation {
implicit lazy val int: Schema[Int] = ???
implicit def option[A](implicit ev: Schema[A]): Schema[Option[A]] = ???
}

trait SchemaDerivation {
inline def recurse[A <: Tuple]: List[Schema[Any]] =
inline erasedValue[A] match {
case _: (t *: ts) =>
val builder = summonInline[Schema[t]].asInstanceOf[Schema[Any]]
builder :: recurse[ts]
case _: EmptyTuple => Nil
}

inline def derived[A]: Schema[A] =
inline summonInline[Mirror.Of[A]] match {
case m: Mirror.SumOf[A] =>
lazy val subTypes = recurse[m.MirroredElemTypes]
new Schema[A] {
def build: A = ???
}

case m: Mirror.ProductOf[A] =>
lazy val fields = recurse[m.MirroredElemTypes]
new Schema[A] {
def build: A = ???
}
}

inline given gen[A]: Schema[A] = derived
}

case class H(i: Int)
case class G(h: H)
case class F(g: G)
case class E(f: Option[F])
case class D(e: E)
case class C(d: D)
case class B(c: C)
case class A(a: A, b: B)

object TestApp {
implicit def typeSchema: Schema[A] = Schema.gen // error // error
}
51 changes: 51 additions & 0 deletions tests/pos-custom-args/i13044.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import scala.deriving.Mirror
import scala.compiletime._

trait Schema[T] {
def build: T
}

object Schema extends SchemaDerivation {
implicit lazy val int: Schema[Int] = ???
implicit def option[A](implicit ev: Schema[A]): Schema[Option[A]] = ???
}

trait SchemaDerivation {
inline def recurse[A <: Tuple]: List[Schema[Any]] =
inline erasedValue[A] match {
case _: (t *: ts) =>
val builder = summonInline[Schema[t]].asInstanceOf[Schema[Any]]
builder :: recurse[ts]
case _: EmptyTuple => Nil
}

inline def derived[A]: Schema[A] =
inline summonInline[Mirror.Of[A]] match {
case m: Mirror.SumOf[A] =>
lazy val subTypes = recurse[m.MirroredElemTypes]
new Schema[A] {
def build: A = ???
}

case m: Mirror.ProductOf[A] =>
lazy val fields = recurse[m.MirroredElemTypes]
new Schema[A] {
def build: A = ???
}
}

inline given gen[A]: Schema[A] = derived
}

case class H(i: Int)
case class G(h: H)
case class F(g: G)
case class E(f: Option[F])
case class D(e: E)
case class C(d: D)
case class B(c: C)
case class A(a: A, b: B)

object TestApp {
implicit def typeSchema: Schema[A] = Schema.gen
}