Skip to content

Commit 0396584

Browse files
committed
Fail not inlined inline methods calls early
All of them would be achieved with implicit resolution, during which the global state (ctx.base) would have stopInlining set to true, but the corresponding error might not have been shown as part of the implicit resolution - now we reset that value after failing the implicit, if it was not set before typing the implicit.
1 parent a5e029a commit 0396584

File tree

5 files changed

+72
-127
lines changed

5 files changed

+72
-127
lines changed

Diff for: compiler/src/dotty/tools/dotc/typer/Implicits.scala

+4
Original file line numberDiff line numberDiff line change
@@ -1294,11 +1294,15 @@ trait Implicits:
12941294
val history = ctx.searchHistory.nest(cand, pt)
12951295
val typingCtx =
12961296
searchContext().setNewTyperState().setFreshGADTBounds.setSearchHistory(history)
1297+
val alreadyStoppedInlining = ctx.base.stopInlining
12971298
val result = typedImplicit(cand, pt, argument, span)(using typingCtx)
12981299
result match
12991300
case res: SearchSuccess =>
13001301
ctx.searchHistory.defineBynameImplicit(wideProto, res)
13011302
case _ =>
1303+
if !alreadyStoppedInlining && ctx.base.stopInlining then
1304+
// a call overflowed as part of the expansion when typing the implicit
1305+
ctx.base.stopInlining = false
13021306
// Since the search failed, the local typerstate will be discarded
13031307
// without being committed, but type variables local to that state
13041308
// might still appear in an error message, so we run `gc()` here to

Diff for: tests/neg/i13044.check

+8-126
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,18 @@
1-
-- Error: tests/neg/i13044.scala:61:40 ---------------------------------------------------------------------------------
2-
61 | implicit def typeSchema: Schema[A] = Schema.gen // error // error
1+
-- [E172] Type Error: tests/neg/i13044.scala:61:40 ---------------------------------------------------------------------
2+
61 | implicit def typeSchema: Schema[A] = Schema.gen // error
33
| ^^^^^^^^^^
4-
| given instance gen is declared as `inline`, but was not inlined
4+
| No given instance of type Schema[B] was found.
5+
| I found:
56
|
6-
| Try increasing `-Xmax-inlines` above 32
7+
| Schema.gen[B]
8+
|
9+
| But given instance gen in trait SchemaDerivation does not match type Schema[B].
710
|--------------------------------------------------------------------------------------------------------------------
811
|Inline stack trace
912
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1013
|This location contains code that was inlined from i13044.scala:17
1114
17 | val builder = summonInline[Schema[t]].asInstanceOf[Schema[Any]]
12-
| ^
13-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14-
|This location contains code that was inlined from i13044.scala:17
15-
29 | lazy val fields = recurse[m.MirroredElemTypes]
16-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
18-
|This location contains code that was inlined from i13044.scala:17
19-
33 | inline given gen[A]: Schema[A] = derived
20-
| ^^^^^^^
21-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
22-
|This location contains code that was inlined from i13044.scala:17
23-
17 | val builder = summonInline[Schema[t]].asInstanceOf[Schema[Any]]
24-
| ^
25-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
26-
|This location contains code that was inlined from i13044.scala:17
27-
29 | lazy val fields = recurse[m.MirroredElemTypes]
28-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
29-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
30-
|This location contains code that was inlined from i13044.scala:17
31-
33 | inline given gen[A]: Schema[A] = derived
32-
| ^^^^^^^
33-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
34-
|This location contains code that was inlined from i13044.scala:17
35-
17 | val builder = summonInline[Schema[t]].asInstanceOf[Schema[Any]]
36-
| ^
37-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
38-
|This location contains code that was inlined from i13044.scala:17
39-
29 | lazy val fields = recurse[m.MirroredElemTypes]
40-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
41-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
42-
|This location contains code that was inlined from i13044.scala:17
43-
33 | inline given gen[A]: Schema[A] = derived
44-
| ^^^^^^^
45-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
46-
|This location contains code that was inlined from i13044.scala:17
47-
17 | val builder = summonInline[Schema[t]].asInstanceOf[Schema[Any]]
48-
| ^
49-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50-
|This location contains code that was inlined from i13044.scala:17
51-
29 | lazy val fields = recurse[m.MirroredElemTypes]
52-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
53-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
54-
|This location contains code that was inlined from i13044.scala:17
55-
33 | inline given gen[A]: Schema[A] = derived
56-
| ^^^^^^^
57-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
58-
|This location contains code that was inlined from i13044.scala:17
59-
17 | val builder = summonInline[Schema[t]].asInstanceOf[Schema[Any]]
60-
| ^
15+
| ^^^^^^^^^^^^^^^^^^^^^^^
6116
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6217
|This location contains code that was inlined from i13044.scala:17
6318
18 | builder :: recurse[ts]
@@ -71,76 +26,3 @@
7126
33 | inline given gen[A]: Schema[A] = derived
7227
| ^^^^^^^
7328
--------------------------------------------------------------------------------------------------------------------
74-
-- Error: tests/neg/i13044.scala:61:40 ---------------------------------------------------------------------------------
75-
61 | implicit def typeSchema: Schema[A] = Schema.gen // error // error
76-
| ^^^^^^^^^^
77-
| method recurse is declared as `inline`, but was not inlined
78-
|
79-
| Try increasing `-Xmax-inlines` above 32
80-
|--------------------------------------------------------------------------------------------------------------------
81-
|Inline stack trace
82-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
83-
|This location contains code that was inlined from i13044.scala:18
84-
18 | builder :: recurse[ts]
85-
| ^^^^^^^
86-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
87-
|This location contains code that was inlined from i13044.scala:18
88-
29 | lazy val fields = recurse[m.MirroredElemTypes]
89-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
90-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
91-
|This location contains code that was inlined from i13044.scala:18
92-
33 | inline given gen[A]: Schema[A] = derived
93-
| ^^^^^^^
94-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
95-
|This location contains code that was inlined from i13044.scala:18
96-
17 | val builder = summonInline[Schema[t]].asInstanceOf[Schema[Any]]
97-
| ^
98-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
99-
|This location contains code that was inlined from i13044.scala:18
100-
29 | lazy val fields = recurse[m.MirroredElemTypes]
101-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
102-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
103-
|This location contains code that was inlined from i13044.scala:18
104-
33 | inline given gen[A]: Schema[A] = derived
105-
| ^^^^^^^
106-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
107-
|This location contains code that was inlined from i13044.scala:18
108-
17 | val builder = summonInline[Schema[t]].asInstanceOf[Schema[Any]]
109-
| ^
110-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
111-
|This location contains code that was inlined from i13044.scala:18
112-
29 | lazy val fields = recurse[m.MirroredElemTypes]
113-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
114-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
115-
|This location contains code that was inlined from i13044.scala:18
116-
33 | inline given gen[A]: Schema[A] = derived
117-
| ^^^^^^^
118-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
119-
|This location contains code that was inlined from i13044.scala:18
120-
17 | val builder = summonInline[Schema[t]].asInstanceOf[Schema[Any]]
121-
| ^
122-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
123-
|This location contains code that was inlined from i13044.scala:18
124-
29 | lazy val fields = recurse[m.MirroredElemTypes]
125-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
126-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
127-
|This location contains code that was inlined from i13044.scala:18
128-
33 | inline given gen[A]: Schema[A] = derived
129-
| ^^^^^^^
130-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
131-
|This location contains code that was inlined from i13044.scala:18
132-
17 | val builder = summonInline[Schema[t]].asInstanceOf[Schema[Any]]
133-
| ^
134-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
135-
|This location contains code that was inlined from i13044.scala:18
136-
18 | builder :: recurse[ts]
137-
| ^^^^^^^^^^^
138-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
139-
|This location contains code that was inlined from i13044.scala:18
140-
29 | lazy val fields = recurse[m.MirroredElemTypes]
141-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
142-
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
143-
|This location contains code that was inlined from i13044.scala:18
144-
33 | inline given gen[A]: Schema[A] = derived
145-
| ^^^^^^^
146-
--------------------------------------------------------------------------------------------------------------------

Diff for: tests/neg/i13044.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ case class B(c: C)
5858
case class A(a: A, b: B)
5959

6060
object TestApp {
61-
implicit def typeSchema: Schema[A] = Schema.gen // error // error
61+
implicit def typeSchema: Schema[A] = Schema.gen // error
6262
}

Diff for: tests/neg/i22423.check

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- Error: tests/neg/i22423.scala:35:14 ---------------------------------------------------------------------------------
2+
35 | exportReader[Settings] // error
3+
| ^^^^^^^^^^^^^^^^^^^^^^
4+
| cannot reduce summonFrom with
5+
| patterns : case given reader @ _:ConfigReader[List[String]]
6+
|--------------------------------------------------------------------------------------------------------------------
7+
|Inline stack trace
8+
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9+
|This location contains code that was inlined from i22423.scala:12
10+
12 | summonFrom { case reader: ConfigReader[A] => reader }
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
13+
|This location contains code that was inlined from i22423.scala:12
14+
15 | summonConfigReader[List[String]]
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
17+
|This location contains code that was inlined from i22423.scala:12
18+
8 | readCaseClass()
19+
| ^^^^^^^^^^^^^^^
20+
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
21+
|This location contains code that was inlined from i22423.scala:12
22+
30 |inline given exportReader[A]: Exported[ConfigReader[A]] = Exported(HintsAwareConfigReaderDerivation.deriveReader[A])
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24+
--------------------------------------------------------------------------------------------------------------------

Diff for: tests/neg/i22423.scala

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//> using options -Xmax-inlines:7
2+
import scala.deriving.Mirror
3+
import scala.compiletime._
4+
import scala.compiletime.ops.int._
5+
6+
object HintsAwareConfigReaderDerivation {
7+
inline def deriveReader[A]: ConfigReader[A] =
8+
readCaseClass()
9+
???
10+
11+
private inline def summonConfigReader[A]: ConfigReader[A] =
12+
summonFrom { case reader: ConfigReader[A] => reader }
13+
14+
private inline def readCaseClass(): Unit =
15+
summonConfigReader[List[String]]
16+
val a1: Int = ???
17+
val a2: EmptyTuple = ???
18+
a1 *: a2
19+
???
20+
}
21+
22+
trait ConfigReader[A]
23+
object ConfigReader {
24+
implicit def traversableReader[A, F[A] <: TraversableOnce[A]](implicit configConvert: ConfigReader[A]): ConfigReader[F[A]] = ???
25+
implicit def exportedReader[A](implicit exported: Exported[ConfigReader[A]]): ConfigReader[A] = exported.instance
26+
case class Exported[A](instance: A)
27+
}
28+
29+
import ConfigReader._
30+
inline given exportReader[A]: Exported[ConfigReader[A]] = Exported(HintsAwareConfigReaderDerivation.deriveReader[A])
31+
32+
case class Settings(rules: List[String])
33+
34+
val settings =
35+
exportReader[Settings] // error

0 commit comments

Comments
 (0)