@@ -29,6 +29,7 @@ import Nullables.{given _}
2929import collection .mutable
3030import reporting .trace
3131import util .Spans .Span
32+ import util .NoSourcePosition
3233import dotty .tools .dotc .transform .{Splicer , TreeMapWithStages }
3334
3435object Inliner {
@@ -71,14 +72,17 @@ object Inliner {
7172 * and body that replace it.
7273 */
7374 def inlineCall (tree : Tree )(using Context ): Tree = {
75+ val startId = ctx.source.nextId
76+
7477 if tree.symbol.denot != SymDenotations .NoDenotation && tree.symbol.owner.companionModule == defn.CompiletimeTestingPackageObject
7578 if (tree.symbol == defn.CompiletimeTesting_typeChecks ) return Intrinsics .typeChecks(tree)
7679 if (tree.symbol == defn.CompiletimeTesting_typeCheckErrors ) return Intrinsics .typeCheckErrors(tree)
7780
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+ */
8286 def liftFromInlined (call : Tree ) = new TreeMap :
8387 override def transform (t : Tree )(using Context ) =
8488 if call.span.exists then
@@ -115,20 +119,28 @@ object Inliner {
115119
116120 // assertAllPositioned(tree) // debug
117121 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
132144 }
133145
134146 /** Try to inline a pattern with an inline unapply method. Fail with error if the maximal
0 commit comments