Skip to content

Commit

Permalink
Separate features related to tracked into a separate sub-feature
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperFKorban committed Oct 28, 2024
1 parent 65a5ddd commit 1e2c226
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ jobs:
needs: [build-msi-package]
with:
# Ensure that version starts with prefix 3.
# In the future it can be adapted to compare with with git tag or version set in the build.s
# In the future it can be adapted to compare with with git tag or version set in the build.s
version: "3."
java-version: 8

Expand Down
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/config/Feature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ object Feature:
val captureChecking = experimental("captureChecking")
val into = experimental("into")
val modularity = experimental("modularity")
val tracked = experimental("tracked")
val betterMatchTypeExtractors = experimental("betterMatchTypeExtractors")
val quotedPatternsWithPolymorphicFunctions = experimental("quotedPatternsWithPolymorphicFunctions")
val betterFors = experimental("betterFors")
Expand Down Expand Up @@ -66,6 +67,7 @@ object Feature:
(captureChecking, "Enable experimental capture checking"),
(into, "Allow into modifier on parameter types"),
(modularity, "Enable experimental modularity features"),
(tracked, "Enable tracked modifier"),
(betterMatchTypeExtractors, "Enable better match type extractors"),
(betterFors, "Enable improvements in `for` comprehensions")
)
Expand Down Expand Up @@ -111,7 +113,7 @@ object Feature:
* feature is defined.
*/
def enabled(feature: TermName)(using Context): Boolean =
enabledBySetting(feature) || enabledByImport(feature) || feature == modularity
enabledBySetting(feature) || enabledByImport(feature)

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

def betterForsEnabled(using Context) = enabled(betterFors)

def trackedEnabled(using Context) = enabled(tracked) || enabled(modularity)

def genericNumberLiteralsEnabled(using Context) = enabled(genericNumberLiterals)

def scala2ExperimentalMacroEnabled(using Context) = enabled(scala2macros)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ class TreeUnpickler(reader: TastyReader,
val resType =
if name == nme.CONSTRUCTOR then
effectiveResultType(sym, paramss)
else if sym.isAllOf(Given | Method) && Feature.enabled(Feature.modularity) then
else if sym.isAllOf(Given | Method) && Feature.trackedEnabled then
addParamRefinements(tpt.tpe, paramss)
else
tpt.tpe
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3525,7 +3525,7 @@ object Parsers {
if isErasedKw then
mods = addModifier(mods)
if paramOwner.isClass then
if isIdent(nme.tracked) && in.featureEnabled(Feature.modularity) && !in.lookahead.isColon then
if isIdent(nme.tracked) && (in.featureEnabled(Feature.tracked) || in.featureEnabled(Feature.modularity)) && !in.lookahead.isColon then
mods = addModifier(mods)
mods = addFlag(modifiers(start = mods), ParamAccessor)
mods =
Expand Down Expand Up @@ -3601,7 +3601,7 @@ object Parsers {
|| isIdent
&& (in.name == nme.inline // inline starts a name binding
|| in.name == nme.tracked // tracked starts a name binding under x.modularity
&& in.featureEnabled(Feature.modularity)
&& (in.featureEnabled(Feature.tracked) || in.featureEnabled(Feature.modularity))
|| in.lookahead.isColon) // a following `:` starts a name binding
(mods, paramsAreNamed)
val params =
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
def checkClassType(tpe: Type, stablePrefixReq: Boolean) =
ctx.typer.checkClassType(tpe, tree.srcPos,
traitReq = false, stablePrefixReq = stablePrefixReq,
refinementOK = Feature.enabled(Feature.modularity))
refinementOK = Feature.trackedEnabled)
checkClassType(tree.tpe, true)
if !nu.tpe.isLambdaSub then
// Check the constructor type as well; it could be an illegal singleton type
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ object Checking {
* and that the instance conforms to the self type of the created class.
*/
def checkInstantiable(tp: Type, srcTp: Type, pos: SrcPos)(using Context): Unit =
tp.underlyingClassRef(refinementOK = Feature.enabled(modularity)) match
tp.underlyingClassRef(refinementOK = Feature.trackedEnabled) match
case tref: TypeRef =>
val cls = tref.symbol
if (cls.isOneOf(AbstractOrTrait)) {
Expand Down
11 changes: 5 additions & 6 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class Namer { typer: Typer =>

val completer = tree match
case tree: TypeDef => TypeDefCompleter(tree)(cctx)
case tree: ValOrDefDef if Feature.enabled(Feature.modularity) && isNonInferingTree(tree) =>
case tree: ValOrDefDef if Feature.trackedEnabled && isNonInferingTree(tree) =>
NonInferingCompleter(tree)(cctx)
case _ => Completer(tree)(cctx)
val info = adjustIfModule(completer, tree)
Expand Down Expand Up @@ -1614,7 +1614,7 @@ class Namer { typer: Typer =>
if (cls.isRefinementClass) ptype
else {
val pt = checkClassType(
if Feature.enabled(modularity)
if Feature.trackedEnabled
then ptype.separateRefinements(cls, parentRefinements)
else ptype,
parent.srcPos,
Expand Down Expand Up @@ -1790,8 +1790,7 @@ class Namer { typer: Typer =>
index(constr.leadingTypeParams)
sym.owner.typeParams.foreach(_.ensureCompleted())
completeTrailingParamss(constr, sym, indexingCtor = true)
if Feature.enabled(modularity) then
// println(i"[indexConstructor] Checking if params of $constr need tracked")
if Feature.trackedEnabled then
constr.termParamss.foreach(_.foreach(setTracked))

/** The signature of a module valdef.
Expand Down Expand Up @@ -1941,7 +1940,7 @@ class Namer { typer: Typer =>
wasSet = true
wasSet

if Feature.enabled(modularity) then addTrackedIfNeeded(ddef, sym.maybeOwner)
if Feature.trackedEnabled then addTrackedIfNeeded(ddef, sym.maybeOwner)

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

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
if templ1.parents.isEmpty
&& isFullyDefined(pt, ForceDegree.flipBottom)
&& isSkolemFree(pt)
&& isEligible(pt.underlyingClassRef(refinementOK = Feature.enabled(modularity)))
&& isEligible(pt.underlyingClassRef(refinementOK = Feature.trackedEnabled))
then
templ1 = cpy.Template(templ)(parents = untpd.TypeTree(pt) :: Nil)
for case parent: RefTree <- templ1.parents do
Expand Down Expand Up @@ -4705,7 +4705,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
cpy.Ident(qual)(qual.symbol.name.sourceModuleName.toTypeName)
case _ =>
errorTree(tree, em"cannot convert from $tree to an instance creation expression")
val tycon = ctorResultType.underlyingClassRef(refinementOK = Feature.enabled(modularity))
val tycon = ctorResultType.underlyingClassRef(refinementOK = Feature.trackedEnabled)
typed(
untpd.Select(
untpd.New(untpd.TypedSplice(tpt.withType(tycon))),
Expand Down
7 changes: 7 additions & 0 deletions library/src/scala/runtime/stdLibPatches/language.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ object language:
@compileTimeOnly("`modularity` can only be used at compile time in import statements")
object modularity

/** Experimental support for tracked modifier
*
* `tracked` is a subset of `modularity`
*/
@compileTimeOnly("`tracked` can only be used at compile time in import statements")
object tracked

/** Was needed to add support for relaxed imports of extension methods.
* The language import is no longer needed as this is now a standard feature since SIP was accepted.
* @see [[http://dotty.epfl.ch/docs/reference/contextual/extension-methods]]
Expand Down
1 change: 0 additions & 1 deletion scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ case class ScaladocTastyInspector()(using ctx: DocContext) extends Inspector:
topLevels ++= intrinsicTypeDefs
val scalaPckg = defn.ScalaPackage
given parser.qctx.type = parser.qctx
import parser.dri
topLevels += "scala" -> Member(scalaPckg.fullName, "", scalaPckg.dri, Kind.Package)
topLevels += mergeAnyRefAliasAndObject(parser)

Expand Down
2 changes: 1 addition & 1 deletion tests/pos/infer-tracked-1.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import scala.language.experimental.modularity
import scala.language.experimental.tracked
import scala.language.future

trait Ordering {
Expand Down
2 changes: 1 addition & 1 deletion tests/pos/infer-tracked-parent-refinements.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import scala.language.experimental.modularity
import scala.language.experimental.tracked
import scala.language.future

trait WithValue { type Value = Int }
Expand Down
2 changes: 1 addition & 1 deletion tests/pos/infer-tracked-parsercombinators-expanded.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import scala.language.experimental.modularity
import scala.language.experimental.tracked
import scala.language.future

import collection.mutable
Expand Down
2 changes: 1 addition & 1 deletion tests/pos/infer-tracked-parsercombinators-givens.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import scala.language.experimental.modularity
import scala.language.experimental.tracked
import scala.language.future
import collection.mutable

Expand Down
2 changes: 1 addition & 1 deletion tests/pos/infer-tracked-vector.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import scala.language.experimental.modularity
import scala.language.experimental.tracked
import scala.language.future

object typeparams:
Expand Down
2 changes: 1 addition & 1 deletion tests/pos/infer-tracked.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import scala.language.experimental.modularity
import scala.language.experimental.tracked
import scala.language.future

abstract class C:
Expand Down

0 comments on commit 1e2c226

Please sign in to comment.