Skip to content

Commit 8073932

Browse files
committed
Refactor checking for symbol references in signatures, when infering tracked
1 parent dd530d5 commit 8073932

File tree

2 files changed

+16
-28
lines changed

2 files changed

+16
-28
lines changed

Diff for: compiler/src/dotty/tools/dotc/config/Feature.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ object Feature:
111111
* feature is defined.
112112
*/
113113
def enabled(feature: TermName)(using Context): Boolean =
114-
enabledBySetting(feature) || enabledByImport(feature) || feature == modularity
114+
enabledBySetting(feature) || enabledByImport(feature)
115115

116116
/** Is auto-tupling enabled? */
117117
def autoTuplingEnabled(using Context): Boolean = !enabled(nme.noAutoTupling)

Diff for: compiler/src/dotty/tools/dotc/typer/Namer.scala

+15-27
Original file line numberDiff line numberDiff line change
@@ -2003,13 +2003,9 @@ class Namer { typer: Typer =>
20032003
/** Try to infer if the parameter needs a `tracked` modifier
20042004
*/
20052005
def needsTracked(psym: Symbol, param: ValDef, owningSym: Symbol)(using Context) =
2006-
// println(i"Checking if $psym needs tracked")
20072006
lazy val abstractContextBound = isContextBoundWitnessWithAbstractMembers(psym, param, owningSym)
20082007
lazy val isRefInSignatures =
20092008
psym.maybeOwner.isPrimaryConstructor
2010-
// && !psym.flags.is(Synthetic)
2011-
// && !psym.maybeOwner.flags.is(Synthetic)
2012-
// && !psym.maybeOwner.maybeOwner.flags.is(Synthetic)
20132009
&& isReferencedInPublicSignatures(psym)
20142010
!psym.is(Tracked)
20152011
&& psym.isTerm
@@ -2046,29 +2042,21 @@ class Namer { typer: Typer =>
20462042
case _ => false
20472043
checkOwnerMemberSignatures(owner)
20482044

2049-
private def namedTypeWithPrefixContainsSymbolRef(tpe: Type, syms: List[Symbol])(using Context): Boolean = tpe match
2050-
case tpe: NamedType => tpe.prefix.exists && tpeContainsSymbolRef(tpe.prefix, syms)
2051-
case _ => false
2052-
2053-
private def tpeContainsSymbolRef(tpe0: Type, syms: List[Symbol])(using Context): Boolean =
2054-
val tpe = tpe0.dropAlias.safeDealias
2055-
tpe match
2056-
case ExprType(resType) => tpeContainsSymbolRef(resType, syms)
2057-
case m : MethodOrPoly =>
2058-
m.paramInfos.exists(tpeContainsSymbolRef(_, syms))
2059-
|| tpeContainsSymbolRef(m.resultType, syms)
2060-
case r @ RefinedType(parent, _, refinedInfo) => tpeContainsSymbolRef(parent, syms) || tpeContainsSymbolRef(refinedInfo, syms)
2061-
case TypeBounds(lo, hi) => tpeContainsSymbolRef(lo, syms) || tpeContainsSymbolRef(hi, syms)
2062-
case t: Type =>
2063-
tpe.termSymbol.exists && syms.contains(tpe.termSymbol)
2064-
|| tpe.argInfos.exists(tpeContainsSymbolRef(_, syms))
2065-
|| namedTypeWithPrefixContainsSymbolRef(tpe, syms)
2066-
2067-
private def maybeParamAccessors(owner: Symbol, sym: Symbol)(using Context): List[Symbol] =
2068-
owner.infoOrCompleter match
2069-
case info: ClassInfo =>
2070-
info.decls.lookupAll(sym.name).filter(d => d.is(ParamAccessor)).toList
2071-
case _ => List.empty
2045+
/** Check if any of syms are referenced in tpe */
2046+
private def tpeContainsSymbolRef(tpe: Type, syms: List[Symbol])(using Context): Boolean =
2047+
val acc = new ExistsAccumulator(
2048+
{ tpe => tpe.termSymbol.exists && syms.contains(tpe.termSymbol) },
2049+
StopAt.Static,
2050+
forceLazy = false
2051+
) {
2052+
override def apply(acc: Boolean, tpe: Type): Boolean = super.apply(acc, tpe.safeDealias)
2053+
}
2054+
acc(false, tpe)
2055+
2056+
private def maybeParamAccessors(owner: Symbol, sym: Symbol)(using Context): List[Symbol] = owner.infoOrCompleter match
2057+
case info: ClassInfo =>
2058+
info.decls.lookupAll(sym.name).filter(d => d.is(ParamAccessor)).toList
2059+
case _ => List.empty
20722060

20732061
/** Under x.modularity, set every context bound evidence parameter of a class to be tracked,
20742062
* provided it has a type that has an abstract type member. Reset private and local flags

0 commit comments

Comments
 (0)