Skip to content

Commit dd5eb6f

Browse files
committed
Make namedPartsWith return a list
We never need it to be a set.
1 parent 9e1a411 commit dd5eb6f

File tree

3 files changed

+21
-29
lines changed

3 files changed

+21
-29
lines changed

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ object TypeOps:
404404

405405
def apply(tp: Type): Type = tp match {
406406
case tp: TermRef
407-
if toAvoid(tp.symbol) || partsToAvoid(mutable.Set.empty, tp.info).nonEmpty =>
407+
if toAvoid(tp.symbol) || partsToAvoid(Nil, tp.info).nonEmpty =>
408408
tp.info.widenExpr.dealias match {
409409
case info: SingletonType => apply(info)
410410
case info => range(defn.NothingType, apply(info))
@@ -422,7 +422,7 @@ object TypeOps:
422422
}
423423
case tp: ThisType if toAvoid(tp.cls) =>
424424
range(defn.NothingType, apply(classBound(tp.cls.classInfo)))
425-
case tp: SkolemType if partsToAvoid(mutable.Set.empty, tp.info).nonEmpty =>
425+
case tp: SkolemType if partsToAvoid(Nil, tp.info).nonEmpty =>
426426
range(defn.NothingType, apply(tp.info))
427427
case tp: TypeVar if mapCtx.typerState.constraint.contains(tp) =>
428428
val lo = TypeComparer.instanceType(

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -392,18 +392,13 @@ object Types {
392392
final def foreachPart(p: Type => Unit, stopAtStatic: Boolean = false)(using Context): Unit =
393393
new ForeachAccumulator(p, stopAtStatic).apply((), this)
394394

395-
/** The parts of this type which are type or term refs */
396-
final def namedParts(using Context): collection.Set[NamedType] =
397-
namedPartsWith(alwaysTrue)
398-
399395
/** The parts of this type which are type or term refs and which
400396
* satisfy predicate `p`.
401397
*
402398
* @param p The predicate to satisfy
403399
*/
404-
def namedPartsWith(p: NamedType => Boolean)
405-
(using Context): collection.Set[NamedType] =
406-
new NamedPartsAccumulator(p).apply(mutable.LinkedHashSet(), this)
400+
def namedPartsWith(p: NamedType => Boolean)(using Context): List[NamedType] =
401+
new NamedPartsAccumulator(p).apply(Nil, this)
407402

408403
/** Map function `f` over elements of an AndType, rebuilding with function `g` */
409404
def mapReduceAnd[T](f: Type => T)(g: (T, T) => T)(using Context): T = stripTypeVar match {
@@ -5519,36 +5514,33 @@ object Types {
55195514
override def isEqual(x: Type, y: Type) = x.eq(y)
55205515

55215516
class NamedPartsAccumulator(p: NamedType => Boolean)(using Context)
5522-
extends TypeAccumulator[mutable.Set[NamedType]] {
5523-
def maybeAdd(x: mutable.Set[NamedType], tp: NamedType): mutable.Set[NamedType] = if (p(tp)) x += tp else x
5517+
extends TypeAccumulator[List[NamedType]]:
5518+
def maybeAdd(xs: List[NamedType], tp: NamedType): List[NamedType] = if p(tp) then tp :: xs else xs
55245519
val seen = TypeHashSet()
5525-
def apply(x: mutable.Set[NamedType], tp: Type): mutable.Set[NamedType] =
5526-
if (seen contains tp) x
5527-
else {
5520+
def apply(xs: List[NamedType], tp: Type): List[NamedType] =
5521+
if seen contains tp then xs
5522+
else
55285523
seen.addEntry(tp)
5529-
tp match {
5524+
tp match
55305525
case tp: TypeRef =>
5531-
foldOver(maybeAdd(x, tp), tp)
5526+
foldOver(maybeAdd(xs, tp), tp)
55325527
case tp: ThisType =>
5533-
apply(x, tp.tref)
5528+
apply(xs, tp.tref)
55345529
case NoPrefix =>
5535-
foldOver(x, tp)
5530+
foldOver(xs, tp)
55365531
case tp: TermRef =>
5537-
apply(foldOver(maybeAdd(x, tp), tp), tp.underlying)
5532+
apply(foldOver(maybeAdd(xs, tp), tp), tp.underlying)
55385533
case tp: AppliedType =>
5539-
foldOver(x, tp)
5534+
foldOver(xs, tp)
55405535
case TypeBounds(lo, hi) =>
5541-
apply(x, lo)
5542-
apply(x, hi)
5536+
apply(apply(xs, lo), hi)
55435537
case tp: ParamRef =>
5544-
apply(x, tp.underlying)
5538+
apply(xs, tp.underlying)
55455539
case tp: ConstantType =>
5546-
apply(x, tp.underlying)
5540+
apply(xs, tp.underlying)
55475541
case _ =>
5548-
foldOver(x, tp)
5549-
}
5550-
}
5551-
}
5542+
foldOver(xs, tp)
5543+
end NamedPartsAccumulator
55525544

55535545
class isGroundAccumulator(using Context) extends TypeAccumulator[Boolean] {
55545546
def apply(x: Boolean, tp: Type): Boolean = x && {

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ class Typer extends Namer
907907
pt, localSyms(stats1))
908908
}
909909

910-
def escapingRefs(block: Tree, localSyms: => List[Symbol])(using Context): collection.Set[NamedType] = {
910+
def escapingRefs(block: Tree, localSyms: => List[Symbol])(using Context): List[NamedType] = {
911911
lazy val locals = localSyms.toSet
912912
block.tpe.namedPartsWith(tp => locals.contains(tp.symbol) && !tp.isErroneous)
913913
}

0 commit comments

Comments
 (0)