Skip to content

Commit 79491f1

Browse files
jchybtgodzik
authored andcommitted
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 07d3eba commit 79491f1

File tree

5 files changed

+72
-127
lines changed

5 files changed

+72
-127
lines changed

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,11 +1250,15 @@ trait Implicits:
12501250
val history = ctx.searchHistory.nest(cand, pt)
12511251
val typingCtx =
12521252
nestedContext().setNewTyperState().setFreshGADTBounds.setSearchHistory(history)
1253+
val alreadyStoppedInlining = ctx.base.stopInlining
12531254
val result = typedImplicit(cand, pt, argument, span)(using typingCtx)
12541255
result match
12551256
case res: SearchSuccess =>
12561257
ctx.searchHistory.defineBynameImplicit(wideProto, res)
12571258
case _ =>
1259+
if !alreadyStoppedInlining && ctx.base.stopInlining then
1260+
// a call overflowed as part of the expansion when typing the implicit
1261+
ctx.base.stopInlining = false
12581262
// Since the search failed, the local typerstate will be discarded
12591263
// without being committed, but type variables local to that state
12601264
// might still appear in an error message, so we run `gc()` here to

tests/neg/i13044.check

Lines changed: 8 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,18 @@
1-
-- Error: tests/neg/i13044.scala:46:40 ---------------------------------------------------------------------------------
2-
46 | implicit def typeSchema: Schema[A] = Schema.gen // error // error
1+
-- [E172] Type Error: tests/neg/i13044.scala:46: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:46:40 ---------------------------------------------------------------------------------
75-
46 | 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-
--------------------------------------------------------------------------------------------------------------------

tests/neg/i13044.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ case class B(c: C)
4343
case class A(a: A, b: B)
4444

4545
object TestApp {
46-
implicit def typeSchema: Schema[A] = Schema.gen // error // error
46+
implicit def typeSchema: Schema[A] = Schema.gen // error
4747
}

tests/neg/i22423.check

Lines changed: 24 additions & 0 deletions
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+
--------------------------------------------------------------------------------------------------------------------

tests/neg/i22423.scala

Lines changed: 35 additions & 0 deletions
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)