@@ -29,6 +29,7 @@ import Nullables.{given _}
29
29
import collection .mutable
30
30
import reporting .trace
31
31
import util .Spans .Span
32
+ import util .NoSourcePosition
32
33
import dotty .tools .dotc .transform .{Splicer , TreeMapWithStages }
33
34
34
35
object Inliner {
@@ -71,14 +72,17 @@ object Inliner {
71
72
* and body that replace it.
72
73
*/
73
74
def inlineCall (tree : Tree )(using Context ): Tree = {
75
+ val startId = ctx.source.nextId
76
+
74
77
if tree.symbol.denot != SymDenotations .NoDenotation && tree.symbol.owner.companionModule == defn.CompiletimeTestingPackageObject
75
78
if (tree.symbol == defn.CompiletimeTesting_typeChecks ) return Intrinsics .typeChecks(tree)
76
79
if (tree.symbol == defn.CompiletimeTesting_typeCheckErrors ) return Intrinsics .typeCheckErrors(tree)
77
80
78
- /** Set the position of all trees logically contained in the expansion of
79
- * inlined call `call` to the position of `call`. This transform is necessary
80
- * when lifting bindings from the expansion to the outside of the call.
81
- */
81
+
82
+ /** Set the position of all trees logically contained in the expansion of
83
+ * inlined call `call` to the position of `call`. This transform is necessary
84
+ * when lifting bindings from the expansion to the outside of the call.
85
+ */
82
86
def liftFromInlined (call : Tree ) = new TreeMap :
83
87
override def transform (t : Tree )(using Context ) =
84
88
if call.span.exists then
@@ -115,20 +119,28 @@ object Inliner {
115
119
116
120
// assertAllPositioned(tree) // debug
117
121
val tree1 = liftBindings(tree, identity)
118
- if (bindings.nonEmpty)
119
- cpy.Block (tree)(bindings.toList, inlineCall(tree1))
120
- else if (enclosingInlineds.length < ctx.settings.XmaxInlines .value) {
121
- val body = bodyToInline(tree.symbol) // can typecheck the tree and thereby produce errors
122
- new Inliner (tree, body).inlined(tree.sourcePos)
123
- }
124
- else
125
- errorTree(
126
- tree,
127
- i """ |Maximal number of successive inlines ( ${ctx.settings.XmaxInlines .value}) exceeded,
128
- |Maybe this is caused by a recursive inline method?
129
- |You can use -Xmax-inlines to change the limit. """ ,
130
- (tree :: enclosingInlineds).last.sourcePos
131
- )
122
+ val tree2 =
123
+ if bindings.nonEmpty then
124
+ cpy.Block (tree)(bindings.toList, inlineCall(tree1))
125
+ else if enclosingInlineds.length < ctx.settings.XmaxInlines .value && ! reachedInlinedTreesLimit then
126
+ val body = bodyToInline(tree.symbol) // can typecheck the tree and thereby produce errors
127
+ new Inliner (tree, body).inlined(tree.sourcePos)
128
+ else
129
+ val (reason, setting) =
130
+ if reachedInlinedTreesLimit then (" inlined trees" , ctx.settings.XmaxInlinedTrees )
131
+ else (" successive inlines" , ctx.settings.XmaxInlines )
132
+ errorTree(
133
+ tree,
134
+ i """ |Maximal number of $reason ( ${setting.value}) exceeded,
135
+ |Maybe this is caused by a recursive inline method?
136
+ |You can use ${setting.name} to change the limit. """ ,
137
+ (tree :: enclosingInlineds).last.sourcePos
138
+ )
139
+
140
+ val endId = ctx.source.nextId
141
+ addInlinedTrees(endId - startId)
142
+
143
+ tree2
132
144
}
133
145
134
146
/** Try to inline a pattern with an inline unapply method. Fail with error if the maximal
0 commit comments