File tree 4 files changed +39
-0
lines changed
compiler/src/dotty/tools/dotc
4 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -922,6 +922,9 @@ object Contexts {
922
922
923
923
private [core] var denotTransformers : Array [DenotTransformer ] = _
924
924
925
+ /** Flag to suppress inlining, set after overflow */
926
+ private [dotc] var stopInlining : Boolean = false
927
+
925
928
// Reporters state
926
929
private [dotc] var indent : Int = 0
927
930
Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ object Inliner {
70
70
|| (ctx.phase == Phases .typerPhase && needsTransparentInlining(tree))
71
71
)
72
72
&& ! ctx.typer.hasInliningErrors
73
+ && ! ctx.base.stopInlining
73
74
}
74
75
75
76
private def needsTransparentInlining (tree : Tree )(using Context ): Boolean =
@@ -140,6 +141,7 @@ object Inliner {
140
141
val body = bodyToInline(tree.symbol) // can typecheck the tree and thereby produce errors
141
142
new Inliner (tree, body).inlined(tree.srcPos)
142
143
else
144
+ ctx.base.stopInlining = true
143
145
val (reason, setting) =
144
146
if reachedInlinedTreesLimit then (" inlined trees" , ctx.settings.XmaxInlinedTrees )
145
147
else (" successive inlines" , ctx.settings.XmaxInlines )
@@ -150,6 +152,10 @@ object Inliner {
150
152
|You can use ${setting.name} to change the limit. """ ,
151
153
(tree :: enclosingInlineds).last.srcPos
152
154
)
155
+ if ctx.base.stopInlining && enclosingInlineds.isEmpty then
156
+ ctx.base.stopInlining = false
157
+ // we have completely backed out of the call that overflowed;
158
+ // reset so that further inline calls can be expanded
153
159
tree2
154
160
}
155
161
Original file line number Diff line number Diff line change
1
+ import compiletime .erasedValue
2
+
3
+ object test1 :
4
+
5
+ transparent inline def length [T ]: Int =
6
+ erasedValue[T ] match
7
+ case _ : (h *: t) => 1 + length[t]
8
+ case _ : EmptyTuple => 0
9
+
10
+ transparent inline def foo (): Int = 1 + foo()
11
+
12
+ val y = length[(1 , 2 , 3 )] // error
13
+ val x = foo() // error
14
+
15
+
Original file line number Diff line number Diff line change
1
+ import compiletime .erasedValue
2
+
3
+ object test1 :
4
+
5
+ inline def length [T ]: Int =
6
+ erasedValue[T ] match
7
+ case _ : (h *: t) => 1 + length[t]
8
+ case _ : EmptyTuple => 0
9
+
10
+ inline def foo (): Int = 1 + foo()
11
+
12
+ val y = length[(1 , 2 , 3 )] // error
13
+ val x = foo() // error
14
+
15
+
You can’t perform that action at this time.
0 commit comments