@@ -445,6 +445,9 @@ class Inliner(val call: tpd.Tree)(using Context):
445
445
446
446
/** Map back all TermRefs that match the right element in `opaqueProxies` to the
447
447
* corresponding left element.
448
+ * E.g. for a previously created
449
+ * `val proxy$1 = Time {type OpaqueInt = Int}` as part of the ongoing inlining
450
+ * a `List[proxy$1.OpaqueInt]` will be mapped back into a `List[Time.OpaqueInt]`.
448
451
*/
449
452
protected val mapBackToOpaques = TreeTypeMap (
450
453
typeMap = new TypeMap :
@@ -507,8 +510,19 @@ class Inliner(val call: tpd.Tree)(using Context):
507
510
508
511
def thisTypeProxyExists = ! thisProxy.isEmpty
509
512
510
- // Unpacks `val ObjectDef$_this: ObjectDef.type = ObjectDef` reference back into ObjectDef reference
511
- // For nested transparent inline calls, ObjectDef will be an another proxy, but that is okay
513
+ /** Maps a type that includes a thisProxy (e.g. `TermRef(NoPrefix,val Foo$_this)`)
514
+ * by reading the defTree belonging to that thisProxy (`val Foo$_this: Foo.type = AnotherProxy`)
515
+ * back into its original reference (`AnotherProxy`, which is directly or indirectly a refinement on `Foo`)
516
+ *
517
+ * Usually when we end up with another proxy like this, we will be able to further unwrap it back
518
+ * into `Foo` with mapBackToOpaques, but, for nested transparent inline calls, `AnotherProxy` will be
519
+ * a proxy created by inlining the outer calls, that we might not be able to further unwrap this way
520
+ * (as those proxies will not be a part of opaqueProxies created during this inlining).
521
+ * We leave that as it is and treat this behavior as intended (see documentation with an example in
522
+ * `Opaque Types in Transparent Inline Methods` section in `opaques-details.md`),
523
+ * as we might need those opaques to have visible right hand sides for successful
524
+ * typechecking of the outer inline call.
525
+ */
512
526
val thisTypeUnpacker =
513
527
TreeTypeMap (
514
528
typeMap = new TypeMap :
@@ -522,6 +536,15 @@ class Inliner(val call: tpd.Tree)(using Context):
522
536
}
523
537
)
524
538
539
+ /** Returns the result type of the Inlined code block after removing thisProxy and opaqueProxy TermRefs.
540
+ * E.g. for an Inlined tree returning Block of type `Option[Foo$_this.OpaqueInt]`,
541
+ * and for proxies:
542
+ * ```
543
+ * val $proxy1: Foo.type{type OpaqueInt = Int} = = ...
544
+ * val Foo$_this: ($proxy1 : Foo.type{type OpaqueInt = Int}) = ...
545
+ * ```
546
+ * the method will return: `Foo.OpaqueInt`
547
+ */
525
548
def unpackProxiesFromResultType (inlined : Inlined ): Type =
526
549
if thisTypeProxyExists then mapBackToOpaques.typeMap(thisTypeUnpacker.typeMap(inlined.expansion.tpe))
527
550
else inlined.tpe
0 commit comments