Skip to content

Commit 1e2c226

Browse files
committed
Separate features related to tracked into a separate sub-feature
1 parent 65a5ddd commit 1e2c226

File tree

16 files changed

+31
-22
lines changed

16 files changed

+31
-22
lines changed

.github/workflows/ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ jobs:
11251125
needs: [build-msi-package]
11261126
with:
11271127
# Ensure that version starts with prefix 3.
1128-
# In the future it can be adapted to compare with with git tag or version set in the build.s
1128+
# In the future it can be adapted to compare with with git tag or version set in the build.s
11291129
version: "3."
11301130
java-version: 8
11311131

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ object Feature:
3535
val captureChecking = experimental("captureChecking")
3636
val into = experimental("into")
3737
val modularity = experimental("modularity")
38+
val tracked = experimental("tracked")
3839
val betterMatchTypeExtractors = experimental("betterMatchTypeExtractors")
3940
val quotedPatternsWithPolymorphicFunctions = experimental("quotedPatternsWithPolymorphicFunctions")
4041
val betterFors = experimental("betterFors")
@@ -66,6 +67,7 @@ object Feature:
6667
(captureChecking, "Enable experimental capture checking"),
6768
(into, "Allow into modifier on parameter types"),
6869
(modularity, "Enable experimental modularity features"),
70+
(tracked, "Enable tracked modifier"),
6971
(betterMatchTypeExtractors, "Enable better match type extractors"),
7072
(betterFors, "Enable improvements in `for` comprehensions")
7173
)
@@ -111,7 +113,7 @@ object Feature:
111113
* feature is defined.
112114
*/
113115
def enabled(feature: TermName)(using Context): Boolean =
114-
enabledBySetting(feature) || enabledByImport(feature) || feature == modularity
116+
enabledBySetting(feature) || enabledByImport(feature)
115117

116118
/** Is auto-tupling enabled? */
117119
def autoTuplingEnabled(using Context): Boolean = !enabled(nme.noAutoTupling)
@@ -127,6 +129,8 @@ object Feature:
127129

128130
def betterForsEnabled(using Context) = enabled(betterFors)
129131

132+
def trackedEnabled(using Context) = enabled(tracked) || enabled(modularity)
133+
130134
def genericNumberLiteralsEnabled(using Context) = enabled(genericNumberLiterals)
131135

132136
def scala2ExperimentalMacroEnabled(using Context) = enabled(scala2macros)

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ class TreeUnpickler(reader: TastyReader,
924924
val resType =
925925
if name == nme.CONSTRUCTOR then
926926
effectiveResultType(sym, paramss)
927-
else if sym.isAllOf(Given | Method) && Feature.enabled(Feature.modularity) then
927+
else if sym.isAllOf(Given | Method) && Feature.trackedEnabled then
928928
addParamRefinements(tpt.tpe, paramss)
929929
else
930930
tpt.tpe

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -3525,7 +3525,7 @@ object Parsers {
35253525
if isErasedKw then
35263526
mods = addModifier(mods)
35273527
if paramOwner.isClass then
3528-
if isIdent(nme.tracked) && in.featureEnabled(Feature.modularity) && !in.lookahead.isColon then
3528+
if isIdent(nme.tracked) && (in.featureEnabled(Feature.tracked) || in.featureEnabled(Feature.modularity)) && !in.lookahead.isColon then
35293529
mods = addModifier(mods)
35303530
mods = addFlag(modifiers(start = mods), ParamAccessor)
35313531
mods =
@@ -3601,7 +3601,7 @@ object Parsers {
36013601
|| isIdent
36023602
&& (in.name == nme.inline // inline starts a name binding
36033603
|| in.name == nme.tracked // tracked starts a name binding under x.modularity
3604-
&& in.featureEnabled(Feature.modularity)
3604+
&& (in.featureEnabled(Feature.tracked) || in.featureEnabled(Feature.modularity))
36053605
|| in.lookahead.isColon) // a following `:` starts a name binding
36063606
(mods, paramsAreNamed)
36073607
val params =

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
378378
def checkClassType(tpe: Type, stablePrefixReq: Boolean) =
379379
ctx.typer.checkClassType(tpe, tree.srcPos,
380380
traitReq = false, stablePrefixReq = stablePrefixReq,
381-
refinementOK = Feature.enabled(Feature.modularity))
381+
refinementOK = Feature.trackedEnabled)
382382
checkClassType(tree.tpe, true)
383383
if !nu.tpe.isLambdaSub then
384384
// Check the constructor type as well; it could be an illegal singleton type

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ object Checking {
197197
* and that the instance conforms to the self type of the created class.
198198
*/
199199
def checkInstantiable(tp: Type, srcTp: Type, pos: SrcPos)(using Context): Unit =
200-
tp.underlyingClassRef(refinementOK = Feature.enabled(modularity)) match
200+
tp.underlyingClassRef(refinementOK = Feature.trackedEnabled) match
201201
case tref: TypeRef =>
202202
val cls = tref.symbol
203203
if (cls.isOneOf(AbstractOrTrait)) {

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

+5-6
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class Namer { typer: Typer =>
294294

295295
val completer = tree match
296296
case tree: TypeDef => TypeDefCompleter(tree)(cctx)
297-
case tree: ValOrDefDef if Feature.enabled(Feature.modularity) && isNonInferingTree(tree) =>
297+
case tree: ValOrDefDef if Feature.trackedEnabled && isNonInferingTree(tree) =>
298298
NonInferingCompleter(tree)(cctx)
299299
case _ => Completer(tree)(cctx)
300300
val info = adjustIfModule(completer, tree)
@@ -1614,7 +1614,7 @@ class Namer { typer: Typer =>
16141614
if (cls.isRefinementClass) ptype
16151615
else {
16161616
val pt = checkClassType(
1617-
if Feature.enabled(modularity)
1617+
if Feature.trackedEnabled
16181618
then ptype.separateRefinements(cls, parentRefinements)
16191619
else ptype,
16201620
parent.srcPos,
@@ -1790,8 +1790,7 @@ class Namer { typer: Typer =>
17901790
index(constr.leadingTypeParams)
17911791
sym.owner.typeParams.foreach(_.ensureCompleted())
17921792
completeTrailingParamss(constr, sym, indexingCtor = true)
1793-
if Feature.enabled(modularity) then
1794-
// println(i"[indexConstructor] Checking if params of $constr need tracked")
1793+
if Feature.trackedEnabled then
17951794
constr.termParamss.foreach(_.foreach(setTracked))
17961795

17971796
/** The signature of a module valdef.
@@ -1941,7 +1940,7 @@ class Namer { typer: Typer =>
19411940
wasSet = true
19421941
wasSet
19431942

1944-
if Feature.enabled(modularity) then addTrackedIfNeeded(ddef, sym.maybeOwner)
1943+
if Feature.trackedEnabled then addTrackedIfNeeded(ddef, sym.maybeOwner)
19451944

19461945
if isConstructor then
19471946
// set result type tree to unit, but take the current class as result type of the symbol
@@ -1950,7 +1949,7 @@ class Namer { typer: Typer =>
19501949
if sym.isPrimaryConstructor then checkCaseClassParamDependencies(mt, sym.owner)
19511950
mt
19521951
else
1953-
val paramFn = if Feature.enabled(Feature.modularity) && sym.isAllOf(Given | Method) then wrapRefinedMethType else wrapMethType
1952+
val paramFn = if Feature.trackedEnabled && sym.isAllOf(Given | Method) then wrapRefinedMethType else wrapMethType
19541953
valOrDefDefSig(ddef, sym, paramSymss, paramFn)
19551954
end defDefSig
19561955

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
11451145
if templ1.parents.isEmpty
11461146
&& isFullyDefined(pt, ForceDegree.flipBottom)
11471147
&& isSkolemFree(pt)
1148-
&& isEligible(pt.underlyingClassRef(refinementOK = Feature.enabled(modularity)))
1148+
&& isEligible(pt.underlyingClassRef(refinementOK = Feature.trackedEnabled))
11491149
then
11501150
templ1 = cpy.Template(templ)(parents = untpd.TypeTree(pt) :: Nil)
11511151
for case parent: RefTree <- templ1.parents do
@@ -4705,7 +4705,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
47054705
cpy.Ident(qual)(qual.symbol.name.sourceModuleName.toTypeName)
47064706
case _ =>
47074707
errorTree(tree, em"cannot convert from $tree to an instance creation expression")
4708-
val tycon = ctorResultType.underlyingClassRef(refinementOK = Feature.enabled(modularity))
4708+
val tycon = ctorResultType.underlyingClassRef(refinementOK = Feature.trackedEnabled)
47094709
typed(
47104710
untpd.Select(
47114711
untpd.New(untpd.TypedSplice(tpt.withType(tycon))),

library/src/scala/runtime/stdLibPatches/language.scala

+7
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ object language:
112112
@compileTimeOnly("`modularity` can only be used at compile time in import statements")
113113
object modularity
114114

115+
/** Experimental support for tracked modifier
116+
*
117+
* `tracked` is a subset of `modularity`
118+
*/
119+
@compileTimeOnly("`tracked` can only be used at compile time in import statements")
120+
object tracked
121+
115122
/** Was needed to add support for relaxed imports of extension methods.
116123
* The language import is no longer needed as this is now a standard feature since SIP was accepted.
117124
* @see [[http://dotty.epfl.ch/docs/reference/contextual/extension-methods]]

scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala

-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ case class ScaladocTastyInspector()(using ctx: DocContext) extends Inspector:
127127
topLevels ++= intrinsicTypeDefs
128128
val scalaPckg = defn.ScalaPackage
129129
given parser.qctx.type = parser.qctx
130-
import parser.dri
131130
topLevels += "scala" -> Member(scalaPckg.fullName, "", scalaPckg.dri, Kind.Package)
132131
topLevels += mergeAnyRefAliasAndObject(parser)
133132

tests/pos/infer-tracked-1.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.language.experimental.modularity
1+
import scala.language.experimental.tracked
22
import scala.language.future
33

44
trait Ordering {

tests/pos/infer-tracked-parent-refinements.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.language.experimental.modularity
1+
import scala.language.experimental.tracked
22
import scala.language.future
33

44
trait WithValue { type Value = Int }

tests/pos/infer-tracked-parsercombinators-expanded.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.language.experimental.modularity
1+
import scala.language.experimental.tracked
22
import scala.language.future
33

44
import collection.mutable

tests/pos/infer-tracked-parsercombinators-givens.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.language.experimental.modularity
1+
import scala.language.experimental.tracked
22
import scala.language.future
33
import collection.mutable
44

tests/pos/infer-tracked-vector.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.language.experimental.modularity
1+
import scala.language.experimental.tracked
22
import scala.language.future
33

44
object typeparams:

tests/pos/infer-tracked.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.language.experimental.modularity
1+
import scala.language.experimental.tracked
22
import scala.language.future
33

44
abstract class C:

0 commit comments

Comments
 (0)