Skip to content

Commit 16a2216

Browse files
committed
Drop redundant elements of Setup
1 parent 32f240d commit 16a2216

File tree

2 files changed

+16
-52
lines changed

2 files changed

+16
-52
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureOps.scala

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,6 @@ class NoCommonRoot(rs: Symbol*)(using Context) extends Exception(
7979
i"No common capture root nested in ${rs.mkString(" and ")}"
8080
)
8181

82-
trait FollowAliases extends TypeMap:
83-
def mapOverFollowingAliases(t: Type): Type = t match
84-
case t: LazyRef =>
85-
val t1 = this(t.ref)
86-
if t1 ne t.ref then t1 else t
87-
case _ =>
88-
val t1 = t.dealiasKeepAnnots
89-
if t1 ne t then
90-
val t2 = this(t1)
91-
if t2 ne t1 then return t2
92-
mapOver(t)
93-
9482
extension (tree: Tree)
9583

9684
/** Map tree with CaptureRef type to its type, throw IllegalCaptureRef otherwise */

compiler/src/dotty/tools/dotc/cc/Setup.scala

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,9 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
113113
def transformSym(symd: SymDenotation)(using Context): SymDenotation =
114114
if !pastRecheck && Feature.ccEnabledSomewhere then
115115
val sym = symd.symbol
116-
def rootTarget =
117-
if sym.isAliasType && sym.isStatic then NoSymbol else sym
118116
def mappedInfo =
119117
if toBeUpdated.contains(sym) then symd.info
120-
else transformExplicitType(symd.info, rootTarget)
118+
else transformExplicitType(symd.info)
121119
// TODO if sym is class && level owner: add a capture root
122120
if Synthetics.needsTransform(symd) then
123121
Synthetics.transform(symd, mappedInfo)
@@ -261,7 +259,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
261259
private def transformInferredType(tp: Type)(using Context): Type =
262260
mapInferred(refine = true)(tp)
263261

264-
private def transformExplicitType(tp: Type, rootTarget: Symbol, tptToCheck: Option[Tree] = None)(using Context): Type =
262+
private def transformExplicitType(tp: Type, tptToCheck: Option[Tree] = None)(using Context): Type =
265263
val expandAliases = new DeepTypeMap:
266264
override def toString = "expand aliases"
267265

@@ -314,9 +312,8 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
314312
else t.info match
315313
case TypeAlias(alias) =>
316314
val transformed =
317-
if sym.isStatic then this(alias)
318-
else transformExplicitType(alias,
319-
if rootTarget.exists then sym else NoSymbol)(
315+
if sym.isStatic || true then this(alias)
316+
else transformExplicitType(alias)(
320317
using ctx.withOwner(sym.owner))
321318
if transformed ne alias then transformed else t
322319
//.showing(i"EXPAND $t with ${t.info} to $result in ${t.symbol.owner}/${ctx.owner}")
@@ -367,13 +364,13 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
367364
end transformExplicitType
368365

369366
/** Transform type of type tree, and remember the transformed type as the type the tree */
370-
private def transformTT(tree: TypeTree, boxed: Boolean, exact: Boolean, rootTarget: Symbol)(using Context): Unit =
367+
private def transformTT(tree: TypeTree, boxed: Boolean, exact: Boolean)(using Context): Unit =
371368
if !tree.hasRememberedType then
372369
val tp = if boxed then Box(tree.tpe) else tree.tpe
373370
tree.rememberType(
374371
if tree.isInstanceOf[InferredTypeTree] && !exact
375372
then transformInferredType(tp)
376-
else transformExplicitType(tp, rootTarget, tptToCheck = Some(tree)))
373+
else transformExplicitType(tp, tptToCheck = Some(tree)))
377374

378375
/** Substitute parameter symbols in `from` to paramRefs in corresponding
379376
* method or poly types `to`. We use a single BiTypeMap to do everything.
@@ -428,12 +425,11 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
428425

429426
def transformResultType(tpt: TypeTree, sym: Symbol)(using Context): Unit =
430427
transformTT(tpt,
431-
boxed =
432-
!allowUniversalInBoxed && sym.is(Mutable, butNot = Method),
433-
// types of mutable variables are boxed in pre 3.3 codee
434-
exact = sym.allOverriddenSymbols.hasNext,
435-
// types of symbols that override a parent don't get a capture set TODO drop
436-
rootTarget = ctx.owner)
428+
boxed = !allowUniversalInBoxed && sym.is(Mutable, butNot = Method),
429+
// types of mutable variables are boxed in pre 3.3 codee
430+
exact = sym.allOverriddenSymbols.hasNext,
431+
// types of symbols that override a parent don't get a capture set TODO drop
432+
)
437433
val addDescription = new TypeTraverser:
438434
def traverse(tp: Type) = tp match
439435
case tp @ CapturingType(parent, refs) =>
@@ -457,16 +453,6 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
457453
//println(i"TYPE of ${tree.symbol.showLocated} = ${tpt.knownType}")
458454

459455
case tree @ ValDef(_, tpt: TypeTree, _) =>
460-
def containsCap(tp: Type) = tp.existsPart:
461-
case CapturingType(_, refs) => refs.isUniversal
462-
case _ => false
463-
def mentionsCap(tree: Tree): Boolean = tree match
464-
case Apply(fn, _) => mentionsCap(fn)
465-
case TypeApply(fn, args) => args.exists(mentionsCap)
466-
case _: InferredTypeTree => false
467-
case _: TypeTree => containsCap(transformExplicitType(tree.tpe, rootTarget = NoSymbol))
468-
case _ => false
469-
470456
val sym = tree.symbol
471457
val defCtx = if sym.isOneOf(TermParamOrAccessor) then ctx else ctx.withOwner(sym)
472458
inContext(defCtx):
@@ -480,7 +466,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
480466
case tree @ TypeApply(fn, args) =>
481467
traverse(fn)
482468
for case arg: TypeTree <- args do
483-
transformTT(arg, boxed = true, exact = false, rootTarget = ctx.owner) // type arguments in type applications are boxed
469+
transformTT(arg, boxed = true, exact = false) // type arguments in type applications are boxed
484470

485471
if allowUniversalInBoxed then
486472
val polyType = fn.tpe.widen.asInstanceOf[TypeLambda]
@@ -498,7 +484,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
498484

499485
case tree @ SeqLiteral(elems, tpt: TypeTree) =>
500486
traverse(elems)
501-
transformTT(tpt, boxed = true, exact = false, rootTarget = ctx.owner)
487+
transformTT(tpt, boxed = true, exact = false)
502488

503489
case _ =>
504490
traverseChildren(tree)
@@ -507,11 +493,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
507493

508494
def postProcess(tree: Tree)(using Context): Unit = tree match
509495
case tree: TypeTree =>
510-
val lowner =
511-
transformTT(tree, boxed = false, exact = false,
512-
rootTarget = if ctx.owner.isStaticOwner then NoSymbol else ctx.owner
513-
// roots of other types in static locations are not mapped
514-
)
496+
transformTT(tree, boxed = false, exact = false)
515497
case tree: ValOrDefDef =>
516498
val sym = tree.symbol
517499

@@ -573,10 +555,8 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
573555
else SubstParams(prevPsymss, prevLambdas)(resType)
574556

575557
if sym.exists && signatureChanges then
576-
def absInfo(resType: Type): Type =
577-
integrateRT(sym.info, sym.paramSymss, resType, Nil, Nil)
558+
val newInfo = integrateRT(sym.info, sym.paramSymss, localReturnType, Nil, Nil)
578559
.showing(i"update info $sym: ${sym.info} = $result", ccSetup)
579-
val newInfo = absInfo(localReturnType)
580560
if newInfo ne sym.info then
581561
val updatedInfo =
582562
if sym.isAnonymousFunction
@@ -608,13 +588,9 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
608588
val cinfo @ ClassInfo(prefix, _, ps, decls, selfInfo) = cls.classInfo
609589
if (selfInfo eq NoType) || cls.is(ModuleClass) && !cls.isStatic then
610590
// add capture set to self type of nested classes if no self type is given explicitly.
611-
// It's unclear what the right level owner should be. A self type should
612-
// be able to mention class parameters, which are owned by the class; that's
613-
// why the class was picked as level owner. But self types should not be able
614-
// to mention other fields.
615591
val newSelfType = CapturingType(cinfo.selfType, CaptureSet.Var(cls))
616592
val ps1 = inContext(ctx.withOwner(cls)):
617-
ps.mapConserve(transformExplicitType(_, rootTarget = cls))
593+
ps.mapConserve(transformExplicitType(_))
618594
val newInfo = ClassInfo(prefix, cls, ps1, decls, newSelfType)
619595
updateInfo(cls, newInfo)
620596
ccSetup.println(i"update class info of $cls with parents $ps selfinfo $selfInfo to $newInfo")

0 commit comments

Comments
 (0)