From 1e2c226cb0113b9d8dfb2ff0204693451bea2fdc Mon Sep 17 00:00:00 2001 From: Kacper Korban Date: Mon, 28 Oct 2024 15:39:58 +0100 Subject: [PATCH] Separate features related to tracked into a separate sub-feature --- .github/workflows/ci.yaml | 2 +- compiler/src/dotty/tools/dotc/config/Feature.scala | 6 +++++- .../dotty/tools/dotc/core/tasty/TreeUnpickler.scala | 2 +- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 4 ++-- .../src/dotty/tools/dotc/transform/PostTyper.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Checking.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Namer.scala | 11 +++++------ compiler/src/dotty/tools/dotc/typer/Typer.scala | 4 ++-- .../src/scala/runtime/stdLibPatches/language.scala | 7 +++++++ .../src/dotty/tools/scaladoc/tasty/TastyParser.scala | 1 - tests/pos/infer-tracked-1.scala | 2 +- tests/pos/infer-tracked-parent-refinements.scala | 2 +- .../infer-tracked-parsercombinators-expanded.scala | 2 +- .../pos/infer-tracked-parsercombinators-givens.scala | 2 +- tests/pos/infer-tracked-vector.scala | 2 +- tests/pos/infer-tracked.scala | 2 +- 16 files changed, 31 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ffa7e515b926..94f89ecdad6c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 diff --git a/compiler/src/dotty/tools/dotc/config/Feature.scala b/compiler/src/dotty/tools/dotc/config/Feature.scala index c70d4f9e9da6..ab2597f290da 100644 --- a/compiler/src/dotty/tools/dotc/config/Feature.scala +++ b/compiler/src/dotty/tools/dotc/config/Feature.scala @@ -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") @@ -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") ) @@ -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) @@ -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) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index e62db9af520a..635919b4e117 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -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 diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 47391a4114cf..466aaa260155 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -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 = @@ -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 = diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index 0feee53ca50f..e62ecfadaaaa 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -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 diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 700bd483ff38..ae79d621d719 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -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)) { diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 8a592583bf68..bc34d8175905 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -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) @@ -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, @@ -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. @@ -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 @@ -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 diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 817e7baf1c8c..3cecc5ff2142 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -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 @@ -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))), diff --git a/library/src/scala/runtime/stdLibPatches/language.scala b/library/src/scala/runtime/stdLibPatches/language.scala index b8d990cf56f5..8b696f96feb8 100644 --- a/library/src/scala/runtime/stdLibPatches/language.scala +++ b/library/src/scala/runtime/stdLibPatches/language.scala @@ -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]] diff --git a/scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala b/scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala index 8e1ca9b40109..f55451fdc636 100644 --- a/scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala +++ b/scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala @@ -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) diff --git a/tests/pos/infer-tracked-1.scala b/tests/pos/infer-tracked-1.scala index b4976a963074..e75fb88b7521 100644 --- a/tests/pos/infer-tracked-1.scala +++ b/tests/pos/infer-tracked-1.scala @@ -1,4 +1,4 @@ -import scala.language.experimental.modularity +import scala.language.experimental.tracked import scala.language.future trait Ordering { diff --git a/tests/pos/infer-tracked-parent-refinements.scala b/tests/pos/infer-tracked-parent-refinements.scala index 0d71d7cc2897..b50c6e88383d 100644 --- a/tests/pos/infer-tracked-parent-refinements.scala +++ b/tests/pos/infer-tracked-parent-refinements.scala @@ -1,4 +1,4 @@ -import scala.language.experimental.modularity +import scala.language.experimental.tracked import scala.language.future trait WithValue { type Value = Int } diff --git a/tests/pos/infer-tracked-parsercombinators-expanded.scala b/tests/pos/infer-tracked-parsercombinators-expanded.scala index 63c6aec9e84a..30828b1341bb 100644 --- a/tests/pos/infer-tracked-parsercombinators-expanded.scala +++ b/tests/pos/infer-tracked-parsercombinators-expanded.scala @@ -1,4 +1,4 @@ -import scala.language.experimental.modularity +import scala.language.experimental.tracked import scala.language.future import collection.mutable diff --git a/tests/pos/infer-tracked-parsercombinators-givens.scala b/tests/pos/infer-tracked-parsercombinators-givens.scala index 209bbcc67493..3a66ea717892 100644 --- a/tests/pos/infer-tracked-parsercombinators-givens.scala +++ b/tests/pos/infer-tracked-parsercombinators-givens.scala @@ -1,4 +1,4 @@ -import scala.language.experimental.modularity +import scala.language.experimental.tracked import scala.language.future import collection.mutable diff --git a/tests/pos/infer-tracked-vector.scala b/tests/pos/infer-tracked-vector.scala index e748dc9cbe8e..c952c37bf1e0 100644 --- a/tests/pos/infer-tracked-vector.scala +++ b/tests/pos/infer-tracked-vector.scala @@ -1,4 +1,4 @@ -import scala.language.experimental.modularity +import scala.language.experimental.tracked import scala.language.future object typeparams: diff --git a/tests/pos/infer-tracked.scala b/tests/pos/infer-tracked.scala index 496508ffdc6c..80626ab74267 100644 --- a/tests/pos/infer-tracked.scala +++ b/tests/pos/infer-tracked.scala @@ -1,4 +1,4 @@ -import scala.language.experimental.modularity +import scala.language.experimental.tracked import scala.language.future abstract class C: