@@ -165,28 +165,9 @@ object Inliner:
165
165
else Nil
166
166
case _ => Nil
167
167
val refinements = openOpaqueAliases(cls.givenSelfType)
168
-
169
- // Map references in the refinements from the proxied termRef
170
- // to the recursive type of the refined type
171
- // e.g.: Obj.type{type A = Obj.B; type B = Int} -> Obj.type{type A = <recthis>.B; type B = Int}
172
- def mapRecTermRefReferences (recType : RecType , refinedType : Type ) =
173
- new TypeMap {
174
- def apply (tp : Type ) = tp match
175
- case RefinedType (a : RefinedType , b, info) => RefinedType (apply(a), b, apply(info))
176
- case RefinedType (a, b, info) => RefinedType (a, b, apply(info))
177
- case TypeRef (prefix, des) => TypeRef (apply(prefix), des)
178
- case termRef : TermRef if termRef == ref => recType.recThis
179
- case _ => mapOver(tp)
180
- }.apply(refinedType)
181
-
182
168
val refinedType = refinements.foldLeft(ref : Type ): (parent, refinement) =>
183
169
RefinedType (parent, refinement._1, TypeAlias (refinement._2))
184
-
185
- val recType = RecType .closeOver ( recType =>
186
- mapRecTermRefReferences(recType, refinedType)
187
- )
188
-
189
- val refiningSym = newSym(InlineBinderName .fresh(), Synthetic , recType, span)
170
+ val refiningSym = newSym(InlineBinderName .fresh(), Synthetic , refinedType, span)
190
171
refiningSym.termRef
191
172
192
173
def unapply (refiningRef : TermRef )(using Context ): Option [TermRef ] =
@@ -405,9 +386,6 @@ class Inliner(val call: tpd.Tree)(using Context):
405
386
*/
406
387
private val opaqueProxies = new mutable.ListBuffer [(TermRef , TermRef )]
407
388
408
- /** TermRefs for which we already started synthesising proxies */
409
- private val visitedTermRefs = new mutable.HashSet [TermRef ]
410
-
411
389
protected def hasOpaqueProxies = opaqueProxies.nonEmpty
412
390
413
391
/** Map first halves of opaqueProxies pairs to second halves, using =:= as equality */
@@ -435,15 +413,12 @@ class Inliner(val call: tpd.Tree)(using Context):
435
413
for cls <- ref.widen.baseClasses do
436
414
if cls.containsOpaques
437
415
&& (forThisProxy || inlinedMethod.isContainedIn(cls))
438
- && ! visitedTermRefs.contains (ref)
416
+ && mapRef (ref).isEmpty
439
417
then
440
- visitedTermRefs += ref
441
418
val refiningRef = OpaqueProxy (ref, cls, call.span)
442
419
val refiningSym = refiningRef.symbol.asTerm
443
420
val refinedType = refiningRef.info
444
- val refiningDef = addProxiesForRecurrentOpaques(
445
- ValDef (refiningSym, tpd.ref(ref).cast(refinedType), inferred = true ).withSpan(span)
446
- )
421
+ val refiningDef = ValDef (refiningSym, tpd.ref(ref).cast(refinedType), inferred = true ).withSpan(span)
447
422
inlining.println(i " add opaque alias proxy $refiningDef for $ref in $tp" )
448
423
bindingsBuf += refiningDef
449
424
opaqueProxies += ((ref, refiningSym.termRef))
@@ -463,27 +438,6 @@ class Inliner(val call: tpd.Tree)(using Context):
463
438
}
464
439
)
465
440
466
- /** Transforms proxies that reference other opaque types, like for:
467
- * object Obj1 { opaque type A = Int }
468
- * object Obj2 { opaque type B = A }
469
- * and proxy$1 of type Obj2.type{type B = Obj1.A}
470
- * creates proxy$2 of type Obj1.type{type A = Int}
471
- * and transforms proxy$1 into Obj2.type{type B = proxy$2.A}
472
- */
473
- private def addProxiesForRecurrentOpaques (binding : ValDef )(using Context ): ValDef =
474
- def fixRefinedTypes (ref : Type ): Unit =
475
- ref match
476
- case recType : RecType => fixRefinedTypes(recType.underlying)
477
- case RefinedType (parent, name, info) =>
478
- addOpaqueProxies(info.widen, binding.span, true )
479
- fixRefinedTypes(parent)
480
- case _ =>
481
- fixRefinedTypes(binding.symbol.info)
482
- binding.symbol.info = mapOpaques.typeMap(binding.symbol.info)
483
- mapOpaques.transform(binding).asInstanceOf [ValDef ]
484
- .showing(i " transformed this binding exposing opaque aliases: $result" , inlining)
485
- end addProxiesForRecurrentOpaques
486
-
487
441
/** If `binding` contains TermRefs that refer to objects with opaque
488
442
* type aliases, add proxy definitions that expose these aliases
489
443
* and substitute such TermRefs with theproxies. Example from pos/opaque-inline1.scala:
0 commit comments