Skip to content

Commit 8ba380a

Browse files
committed
Experiment with simpler inference for tracked
1 parent 481e173 commit 8ba380a

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

compiler/src/dotty/tools/dotc/config/Feature.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ object Feature:
108108
* feature is defined.
109109
*/
110110
def enabled(feature: TermName)(using Context): Boolean =
111-
enabledBySetting(feature) || enabledByImport(feature)
111+
enabledBySetting(feature) || enabledByImport(feature) || feature == modularity
112112

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

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,12 +2034,10 @@ class Namer { typer: Typer =>
20342034
lazy val isRefInSignatures =
20352035
psym.maybeOwner.isPrimaryConstructor
20362036
&& isReferencedInPublicSignatures(psym)
2037+
lazy val needsTrackedSimp = needsTrackedSimple(psym, param, owningSym)
20372038
!psym.is(Tracked)
20382039
&& psym.isTerm
2039-
&& (
2040-
abstractContextBound
2041-
|| isRefInSignatures
2042-
)
2040+
&& needsTrackedSimp
20432041

20442042
/** Under x.modularity, we add `tracked` to context bound witnesses and
20452043
* explicit evidence parameters that have abstract type members
@@ -2050,6 +2048,13 @@ class Namer { typer: Typer =>
20502048
&& (param.hasAttachment(ContextBoundParam) || (psym.isOneOf(GivenOrImplicit) && !accessorSyms.forall(_.isOneOf(PrivateLocal))))
20512049
&& psym.info.memberNames(abstractTypeNameFilter).nonEmpty
20522050

2051+
private def needsTrackedSimple(psym: Symbol, param: ValDef, owningSym: Symbol)(using Context): Boolean =
2052+
val accessorSyms = maybeParamAccessors(owningSym, psym)
2053+
(owningSym.isClass || owningSym.isAllOf(Given | Method))
2054+
&& !accessorSyms.exists(_.is(Mutable))
2055+
&& (param.hasAttachment(ContextBoundParam) || !accessorSyms.forall(_.isOneOf(PrivateLocal)))
2056+
&& psym.info.memberNames(abstractTypeNameFilter).nonEmpty
2057+
20532058
extension (sym: Symbol)
20542059
private def infoWithForceNonInferingCompleter(using Context): Type = sym.infoOrCompleter match
20552060
case tpe: LazyType if tpe.isExplicit => sym.info
@@ -2097,8 +2102,7 @@ class Namer { typer: Typer =>
20972102
def setTrackedConstrParam(param: ValDef)(using Context): Unit =
20982103
val sym = symbolOfTree(param)
20992104
sym.maybeOwner.maybeOwner.infoOrCompleter match
2100-
case info: ClassInfo
2101-
if !sym.is(Tracked) && isContextBoundWitnessWithAbstractMembers(sym, param, sym.maybeOwner.maybeOwner) =>
2105+
case info: ClassInfo if needsTracked(sym, param, sym.maybeOwner.maybeOwner) =>
21022106
typr.println(i"set tracked $param, $sym: ${sym.info} containing ${sym.info.memberNames(abstractTypeNameFilter).toList}")
21032107
setParamTrackedWithAccessors(sym, info)
21042108
case _ =>

tests/pos/tracked.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import scala.language.experimental.modularity
2+
3+
trait T:
4+
type X
5+
6+
class C(var t: T)

0 commit comments

Comments
 (0)