Skip to content

Commit 7b0c829

Browse files
jchybWojciechMazur
authored andcommitted
Revert "Fix inline proxy generation for opaque types referencing other opaque types"
This reverts commit bf7bfa5. [Cherry-picked fc41883]
1 parent 2e47114 commit 7b0c829

File tree

4 files changed

+2
-93
lines changed

4 files changed

+2
-93
lines changed

compiler/src/dotty/tools/dotc/inlines/Inliner.scala

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -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] =
@@ -441,9 +422,7 @@ class Inliner(val call: tpd.Tree)(using Context):
441422
val refiningRef = OpaqueProxy(ref, cls, call.span)
442423
val refiningSym = refiningRef.symbol.asTerm
443424
val refinedType = refiningRef.info
444-
val refiningDef = addProxiesForRecurrentOpaques(
445-
ValDef(refiningSym, tpd.ref(ref).cast(refinedType), inferred = true).withSpan(span)
446-
)
425+
val refiningDef = ValDef(refiningSym, tpd.ref(ref).cast(refinedType), inferred = true).withSpan(span)
447426
inlining.println(i"add opaque alias proxy $refiningDef for $ref in $tp")
448427
bindingsBuf += refiningDef
449428
opaqueProxies += ((ref, refiningSym.termRef))
@@ -463,27 +442,6 @@ class Inliner(val call: tpd.Tree)(using Context):
463442
}
464443
)
465444

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-
487445
/** If `binding` contains TermRefs that refer to objects with opaque
488446
* type aliases, add proxy definitions that expose these aliases
489447
* and substitute such TermRefs with theproxies. Example from pos/opaque-inline1.scala:

tests/pos/22359a.scala

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/pos/22359b.scala

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/pos/i17243.scala

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)