@@ -165,28 +165,9 @@ object Inliner:
165165 else Nil
166166 case _ => Nil
167167 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-
182168 val refinedType = refinements.foldLeft(ref : Type ): (parent, refinement) =>
183169 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)
190171 refiningSym.termRef
191172
192173 def unapply (refiningRef : TermRef )(using Context ): Option [TermRef ] =
@@ -405,9 +386,6 @@ class Inliner(val call: tpd.Tree)(using Context):
405386 */
406387 private val opaqueProxies = new mutable.ListBuffer [(TermRef , TermRef )]
407388
408- /** TermRefs for which we already started synthesising proxies */
409- private val visitedTermRefs = new mutable.HashSet [TermRef ]
410-
411389 protected def hasOpaqueProxies = opaqueProxies.nonEmpty
412390
413391 /** Map first halves of opaqueProxies pairs to second halves, using =:= as equality */
@@ -435,15 +413,12 @@ class Inliner(val call: tpd.Tree)(using Context):
435413 for cls <- ref.widen.baseClasses do
436414 if cls.containsOpaques
437415 && (forThisProxy || inlinedMethod.isContainedIn(cls))
438- && ! visitedTermRefs.contains (ref)
416+ && mapRef (ref).isEmpty
439417 then
440- visitedTermRefs += ref
441418 val refiningRef = OpaqueProxy (ref, cls, call.span)
442419 val refiningSym = refiningRef.symbol.asTerm
443420 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)
447422 inlining.println(i " add opaque alias proxy $refiningDef for $ref in $tp" )
448423 bindingsBuf += refiningDef
449424 opaqueProxies += ((ref, refiningSym.termRef))
@@ -463,27 +438,6 @@ class Inliner(val call: tpd.Tree)(using Context):
463438 }
464439 )
465440
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-
487441 /** If `binding` contains TermRefs that refer to objects with opaque
488442 * type aliases, add proxy definitions that expose these aliases
489443 * and substitute such TermRefs with theproxies. Example from pos/opaque-inline1.scala:
0 commit comments