@@ -158,7 +158,7 @@ class Inliner(val call: tpd.Tree)(using Context):
158
158
for arg <- callTypeArgs do
159
159
isFullyDefined(arg.tpe, ForceDegree .flipBottom)
160
160
161
- /** A map from parameter names of the inlineable method or trait to references of the actual arguments.
161
+ /** A map from parameter names of the inlineable method to references of the actual arguments.
162
162
* For a type argument this is the full argument type.
163
163
* For a value argument, it is a reference to either the argument value
164
164
* (if the argument is a pure expression of singleton type), or to `val` or `def` acting
@@ -169,7 +169,7 @@ class Inliner(val call: tpd.Tree)(using Context):
169
169
/** A map from parameter names of the inlineable method to spans of the actual arguments */
170
170
private val paramSpan = new mutable.HashMap [Name , Span ]
171
171
172
- /** A map from references to (type and value) parameters of the inlineable method or trait
172
+ /** A map from references to (type and value) parameters of the inlineable method
173
173
* to their corresponding argument or proxy references, as given by `paramBinding`.
174
174
*/
175
175
private [inlines] val paramProxy = new mutable.HashMap [Type , Type ]
@@ -187,8 +187,7 @@ class Inliner(val call: tpd.Tree)(using Context):
187
187
*
188
188
* These are different (wrt ==) types but represent logically the same key
189
189
*/
190
- protected val thisProxy = new mutable.HashMap [ClassSymbol , TermRef ]
191
- protected val thisInlineTraitProxy = new mutable.HashMap [ClassSymbol , ThisType ]
190
+ private val thisProxy = new mutable.HashMap [ClassSymbol , TermRef ]
192
191
193
192
/** A buffer for bindings that define proxies for actual arguments */
194
193
private val bindingsBuf = new mutable.ListBuffer [ValOrDefDef ]
@@ -439,11 +438,10 @@ class Inliner(val call: tpd.Tree)(using Context):
439
438
440
439
private def adaptToPrefix (tp : Type ) = tp.asSeenFrom(inlineCallPrefix.tpe, inlinedMethod.owner)
441
440
442
- /** Populate `thisProxy`, `thisInlineTraitProxy` and `paramProxy` as follows:
441
+ /** Populate `thisProxy` and `paramProxy` as follows:
443
442
*
444
443
* 1a. If given type refers to a static this, thisProxy binds it to corresponding global reference,
445
- * 1b. If given type refers to an inline trait, thisInlineTraitProxy binds it to the corresponding thistype,
446
- * 1c. If given type refers to an instance this to a class that is not contained in the
444
+ * 1b. If given type refers to an instance this to a class that is not contained in the
447
445
* inline method, create a proxy symbol and bind the thistype to refer to the proxy.
448
446
* The proxy is not yet entered in `bindingsBuf`; that will come later.
449
447
* 2. If given type refers to a parameter, make `paramProxy` refer to the entry stored
@@ -453,7 +451,7 @@ class Inliner(val call: tpd.Tree)(using Context):
453
451
* and MethodParams, not TypeRefs or TermRefs.
454
452
*/
455
453
private def registerType (tpe : Type ): Unit = tpe match {
456
- case tpe : ThisType if ! canElideThis(tpe) && ! thisProxy.contains(tpe.cls) =>
454
+ case tpe : ThisType if ! canElideThis(tpe) && ! thisProxy.contains(tpe.cls) && ! tpe.cls.isInlineTrait =>
457
455
val proxyName = s " ${tpe.cls.name}_this " .toTermName
458
456
val proxyType = inlineCallPrefix.tpe.dealias.tryNormalize match {
459
457
case typeMatchResult if typeMatchResult.exists => typeMatchResult
@@ -462,10 +460,6 @@ class Inliner(val call: tpd.Tree)(using Context):
462
460
thisProxy(tpe.cls) = newSym(proxyName, InlineProxy , proxyType).termRef
463
461
for (param <- tpe.cls.typeParams)
464
462
paramProxy(param.typeRef) = adaptToPrefix(param.typeRef)
465
- case tpe : ThisType if tpe.cls.isInlineTrait =>
466
- thisInlineTraitProxy(tpe.cls) = ThisType .raw(TypeRef (ctx.owner.prefix, ctx.owner))
467
- for (param <- tpe.cls.typeParams)
468
- paramProxy(param.typeRef) = adaptToPrefix(param.typeRef)
469
463
case tpe : NamedType
470
464
if tpe.symbol.is(Param )
471
465
&& tpe.symbol.owner == inlinedMethod
@@ -510,9 +504,23 @@ class Inliner(val call: tpd.Tree)(using Context):
510
504
511
505
val reducer = new InlineReducer (this )
512
506
507
+ protected class InlinerTypeMap extends DeepTypeMap {
508
+ override def stopAt =
509
+ if opaqueProxies.isEmpty then StopAt .Static else StopAt .Package
510
+ def apply (t : Type ) = t match {
511
+ case t : ThisType => thisProxy.get(t.cls).getOrElse(t)
512
+ case t : TypeRef => paramProxy.getOrElse(t, mapOver(t))
513
+ case t : SingletonType =>
514
+ if t.termSymbol.isAllOf(InlineParam ) then apply(t.widenTermRefExpr)
515
+ else paramProxy.getOrElse(t, mapOver(t))
516
+ case t => mapOver(t)
517
+ }
518
+ }
519
+
520
+ protected val inlinerTypeMap : InlinerTypeMap = InlinerTypeMap ()
521
+
513
522
/** The Inlined node representing the inlined call */
514
523
def inlined (rhsToInline : tpd.Tree ): (List [MemberDef ], Tree ) =
515
-
516
524
inlining.println(i " ----------------------- \n Inlining $call\n With RHS $rhsToInline" )
517
525
518
526
def paramTypess (call : Tree , acc : List [List [Type ]]): List [List [Type ]] = call match
@@ -564,19 +572,7 @@ class Inliner(val call: tpd.Tree)(using Context):
564
572
// corresponding arguments or proxies on the type and term level. It also changes
565
573
// the owner from the inlined method to the current owner.
566
574
val inliner = new InlinerMap (
567
- typeMap =
568
- new DeepTypeMap {
569
- override def stopAt =
570
- if opaqueProxies.isEmpty then StopAt .Static else StopAt .Package
571
- def apply (t : Type ) = t match {
572
- case t : ThisType => thisProxy.get(t.cls).orElse(thisInlineTraitProxy.get(t.cls)).getOrElse(t)
573
- case t : TypeRef => paramProxy.getOrElse(t, mapOver(t))
574
- case t : SingletonType =>
575
- if t.termSymbol.isAllOf(InlineParam ) then apply(t.widenTermRefExpr)
576
- else paramProxy.getOrElse(t, mapOver(t))
577
- case t => mapOver(t)
578
- }
579
- },
575
+ typeMap = inlinerTypeMap,
580
576
treeMap = {
581
577
case tree : This =>
582
578
tree.tpe match {
@@ -625,7 +621,6 @@ class Inliner(val call: tpd.Tree)(using Context):
625
621
inlining.println(
626
622
i """ inliner transform with
627
623
|thisProxy = ${thisProxy.toList.map(_._1)}%, % --> ${thisProxy.toList.map(_._2)}%, %
628
- |thisInlineTraitProxy = ${thisInlineTraitProxy.toList.map(_._1)}%, % --> ${thisInlineTraitProxy.toList.map(_._2)}%, %
629
624
|paramProxy = ${paramProxy.toList.map(_._1.typeSymbol.showLocated)}%, % --> ${paramProxy.toList.map(_._2)}%, % """ )
630
625
631
626
// Apply inliner to `rhsToInline`, split off any implicit bindings from result, and
0 commit comments