diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index 2a5db6eebf9a..524c2ce2a3a2 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -406,7 +406,6 @@ private sealed trait YSettings: val Ylog: Setting[List[String]] = PhasesSetting(ForkSetting, "Ylog", "Log operations during") val YlogClasspath: Setting[Boolean] = BooleanSetting(ForkSetting, "Ylog-classpath", "Output information about what classpath is being applied.") val YdisableFlatCpCaching: Setting[Boolean] = BooleanSetting(ForkSetting, "YdisableFlatCpCaching", "Do not cache flat classpath representation of classpath elements from jars across compiler instances.") - val YnoStdlibPatches: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-stdlib-patches", "Do not patch stdlib files (temporary and only to be used for the stdlib migration)", false) val Yreporter: Setting[String] = StringSetting(ForkSetting, name = "Yreporter", helpArg = "", descr = "Specify a dotty.tools.dotc.reporting.Reporter", default = "dotty.tools.dotc.reporting.ConsoleReporter") diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index d2e4348c96fc..492c4987262e 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -1457,116 +1457,6 @@ class Definitions { || sym.owner == CompiletimeOpsStringModuleClass && compiletimePackageStringTypes.contains(sym.name) ) - // ----- Scala-2 library patches -------------------------------------- - - /** The `scala.runtime.stdLibPacthes` package contains objects - * that contain defnitions that get added as members to standard library - * objects with the same name. - */ - @tu lazy val StdLibPatchesPackage: TermSymbol = requiredPackage("scala.runtime.stdLibPatches") - @tu private lazy val ScalaPredefModuleClassPatch: Symbol = getModuleIfDefined("scala.runtime.stdLibPatches.Predef").moduleClass - @tu private lazy val LanguageModuleClassPatch: Symbol = getModuleIfDefined("scala.runtime.stdLibPatches.language").moduleClass - - /** If `sym` is a patched library class, the source file of its patch class, - * otherwise `NoSource` - */ - def patchSource(sym: Symbol)(using Context): SourceFile = - if sym == ScalaPredefModuleClass then ScalaPredefModuleClassPatch.source - else if sym == LanguageModuleClass then LanguageModuleClassPatch.source - else NoSource - - /** A finalizer that patches standard library classes. - * It copies all non-private, non-synthetic definitions from `patchCls` - * to `denot` while changing their owners to `denot`. Before that it deletes - * any definitions of `denot` that have the same name as one of the copied - * definitions. - * - * If an object is present in both the original class and the patch class, - * it is not overwritten. Instead its members are copied recursively. - * - * To avpid running into cycles on bootstrap, patching happens only if `patchCls` - * is read from a classfile. - */ - def patchStdLibClass(denot: ClassDenotation)(using Context): Unit = - // Do not patch the stdlib files if we explicitly disable it - // This is only to be used during the migration of the stdlib - if ctx.settings.YnoStdlibPatches.value then - return - - def patch2(denot: ClassDenotation, patchCls: Symbol): Unit = - val scope = denot.info.decls.openForMutations - - def recurse(patch: Symbol) = patch.is(Module) && scope.lookup(patch.name).exists - - def makeClassSymbol(patch: Symbol, parents: List[Type], selfInfo: TypeOrSymbol) = - newClassSymbol( - owner = denot.symbol, - name = patch.name.asTypeName, - flags = patch.flags, - // need to rebuild a fresh ClassInfo - infoFn = cls => ClassInfo( - prefix = denot.symbol.thisType, - cls = cls, - declaredParents = parents, // assume parents in patch don't refer to symbols in the patch - decls = newScope, - selfInfo = - if patch.is(Module) - then TermRef(denot.symbol.thisType, patch.name.sourceModuleName) - else selfInfo // assume patch self type annotation does not refer to symbols in the patch - ), - privateWithin = patch.privateWithin, - coord = denot.symbol.coord, - compUnitInfo = denot.symbol.compilationUnitInfo - ) - - def makeNonClassSymbol(patch: Symbol) = - if patch.is(Inline) then - // Inline symbols contain trees in annotations, which is coupled - // with the underlying symbol. - // Changing owner for inline symbols is a simple workaround. - patch.denot = patch.denot.copySymDenotation(owner = denot.symbol) - patch - else - // change `info` which might contain reference to the patch - patch.copy( - owner = denot.symbol, - info = - if patch.is(Module) - then TypeRef(denot.symbol.thisType, patch.name.moduleClassName) - else patch.info // assume non-object info does not refer to symbols in the patch - ) - - if patchCls.exists then - val patches = patchCls.info.decls.filter(patch => - !patch.isConstructor && !patch.isOneOf(PrivateOrSynthetic)) - for patch <- patches if !recurse(patch) do - val e = scope.lookupEntry(patch.name) - if e != null then scope.unlink(e) - for patch <- patches do - patch.ensureCompleted() - if !recurse(patch) then - val sym = - patch.info match - case ClassInfo(_, _, parents, _, selfInfo) => - makeClassSymbol(patch, parents, selfInfo) - case _ => - makeNonClassSymbol(patch) - end match - sym.annotations = patch.annotations - scope.enter(sym) - if patch.isClass then - patch2(scope.lookup(patch.name).asClass, patch) - - def patchWith(patchCls: Symbol) = - denot.sourceModule.info = denot.typeRef // we run into a cyclic reference when patching if this line is omitted - patch2(denot, patchCls) - - if denot.name == tpnme.Predef.moduleClassName && denot.symbol == ScalaPredefModuleClass then - patchWith(ScalaPredefModuleClassPatch) - else if denot.name == tpnme.language.moduleClassName && denot.symbol == LanguageModuleClass then - patchWith(LanguageModuleClassPatch) - end patchStdLibClass - // ----- Symbol sets --------------------------------------------------- @tu lazy val topClasses: Set[Symbol] = Set(AnyClass, MatchableClass, ObjectClass, AnyValClass) diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index f3496a8636dd..48f96dd6c72c 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -520,14 +520,12 @@ object Symbols extends SymUtils { val file = associatedFile if file != null && !file.isScalaBinary then mySource = ctx.getSource(file) - else - mySource = defn.patchSource(this) - if !mySource.exists then - val compUnitInfo = compilationUnitInfo - if compUnitInfo != null then - compUnitInfo.tastyInfo.flatMap(_.attributes.sourceFile) match - case Some(path) => mySource = ctx.getSource(path) - case _ => + else if !mySource.exists then + val compUnitInfo = compilationUnitInfo + if compUnitInfo != null then + compUnitInfo.tastyInfo.flatMap(_.attributes.sourceFile) match + case Some(path) => mySource = ctx.getSource(path) + case _ => if !mySource.exists then mySource = atPhaseNoLater(flattenPhase) { denot.topLevelClass.unforcedAnnotation(defn.SourceFileAnnot) match diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index aa1fbf371fec..aed072b322c0 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -1153,7 +1153,6 @@ class TreeUnpickler(reader: TastyReader, val stats = rdr.readIndexedStats(localDummy, end) tparams ++ vparams ++ stats }) - defn.patchStdLibClass(cls) NamerOps.addConstructorProxies(cls) NamerOps.addContextBoundCompanions(cls) setSpan(start, diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 5087044f73e8..f6a82efed005 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -128,7 +128,6 @@ object Scala2Unpickler { denot.info = tempInfo.finalized(normalizedParents) denot.ensureTypeParamsInCorrectOrder() - defn.patchStdLibClass(denot) } } diff --git a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala index d9c6da8d97eb..0b0be661d2f7 100644 --- a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -710,12 +710,6 @@ object TreeChecker { super.typedWhileDo(tree) } - override def typedPackageDef(tree: untpd.PackageDef)(using Context): Tree = - if tree.symbol == defn.StdLibPatchesPackage then - promote(tree) // don't check stdlib patches, since their symbols were highjacked by stdlib classes - else - super.typedPackageDef(tree) - override def typedQuote(tree: untpd.Quote, pt: Type)(using Context): Tree = if ctx.phase <= stagingPhase.prev then assert(tree.tags.isEmpty, i"unexpected tags in Quote before staging phase: ${tree.tags}") diff --git a/compiler/src/dotty/tools/dotc/transform/init/Util.scala b/compiler/src/dotty/tools/dotc/transform/init/Util.scala index 144abefe4116..37822b7b1772 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Util.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Util.scala @@ -117,7 +117,7 @@ object Util: } // A concrete class may not be instantiated if the self type is not satisfied - instantiable && cls.enclosingPackageClass != defn.StdLibPatchesPackage.moduleClass + instantiable /** Whether the class or its super class/trait contains any mutable fields? */ def isMutable(cls: ClassSymbol)(using Context): Boolean = diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 1207914fbcd1..9e7705c54315 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -1783,7 +1783,6 @@ class Namer { typer: Typer => cls.setStableConstructor() enterParentRefinementSyms(parentRefinements.toList) processExports(using localCtx) - defn.patchStdLibClass(cls) addConstructorProxies(cls) cleanup() } diff --git a/compiler/test/dotty/tools/vulpix/TestConfiguration.scala b/compiler/test/dotty/tools/vulpix/TestConfiguration.scala index b61368de97eb..7f3da862fb32 100644 --- a/compiler/test/dotty/tools/vulpix/TestConfiguration.scala +++ b/compiler/test/dotty/tools/vulpix/TestConfiguration.scala @@ -73,7 +73,7 @@ object TestConfiguration { val commonOptions = Array("-indent") ++ checkOptions ++ noCheckOptions ++ yCheckOptions ++ silenceOptions val noYcheckCommonOptions = Array("-indent") ++ checkOptions ++ noCheckOptions - val defaultOptions = TestFlags(basicClasspath, commonOptions) `and` "-Yno-stdlib-patches" + val defaultOptions = TestFlags(basicClasspath, commonOptions) val noYcheckOptions = TestFlags(basicClasspath, noYcheckCommonOptions) val bestEffortBaselineOptions = TestFlags(basicClasspath, noCheckOptions) val unindentOptions = TestFlags(basicClasspath, Array("-no-indent") ++ checkOptions ++ noCheckOptions ++ yCheckOptions) diff --git a/language-server/test/dotty/tools/languageserver/DefinitionTest.scala b/language-server/test/dotty/tools/languageserver/DefinitionTest.scala index 160732287004..0af7dfc7cc53 100644 --- a/language-server/test/dotty/tools/languageserver/DefinitionTest.scala +++ b/language-server/test/dotty/tools/languageserver/DefinitionTest.scala @@ -186,6 +186,7 @@ class DefinitionTest { .definition(m7 to m8, List(m3 to m4)) } + @Ignore @Test def goToParamCopyMethod: Unit = { withSources( diff --git a/library/src/scala/runtime/stdLibPatches/Predef.scala b/library/src/scala/runtime/stdLibPatches/Predef.scala index 8fb435f39801..853ac0235310 100644 --- a/library/src/scala/runtime/stdLibPatches/Predef.scala +++ b/library/src/scala/runtime/stdLibPatches/Predef.scala @@ -5,6 +5,7 @@ import scala.language.experimental.captureChecking import scala.annotation.experimental import scala.annotation.internal.RuntimeChecked +@deprecated(message = "Patches to the stdlib are not applied anymore", since = "3.8.0") object Predef: import compiletime.summonFrom diff --git a/library/src/scala/runtime/stdLibPatches/language.scala b/library/src/scala/runtime/stdLibPatches/language.scala index 34227259de0d..f2bfbd1c303c 100644 --- a/library/src/scala/runtime/stdLibPatches/language.scala +++ b/library/src/scala/runtime/stdLibPatches/language.scala @@ -6,6 +6,7 @@ import scala.annotation.compileTimeOnly /** Scala 3 additions and replacements to the `scala.language` object. */ +@deprecated(message = "Patches to the stdlib are not applied anymore", since = "3.8.0") object language: /** The experimental object contains features that have been recently added but have not diff --git a/project/Build.scala b/project/Build.scala index 66b9a9ca7e1c..437c4f379cab 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -1322,7 +1322,6 @@ object Build { Compile / unmanagedSourceDirectories += baseDirectory.value / "src-bootstrapped", // NOTE: The only difference here is that we drop `-Werror` and semanticDB for now Compile / scalacOptions := Seq("-deprecation", "-feature", "-unchecked", "-encoding", "UTF8", "-language:implicitConversions"), - Compile / scalacOptions += "-Yno-stdlib-patches", Compile / scalacOptions += "-Yexplicit-nulls", Compile / scalacOptions ++= Seq( // Needed so that the library sources are visible when `dotty.tools.dotc.core.Definitions#init` is called @@ -1455,7 +1454,6 @@ object Build { (`scala-library-bootstrapped` / Compile / unmanagedSourceDirectories).value, // NOTE: The only difference here is that we drop `-Werror` and semanticDB for now Compile / scalacOptions := Seq("-deprecation", "-feature", "-unchecked", "-encoding", "UTF8", "-language:implicitConversions", "-nowarn"), - Compile / scalacOptions += "-Yno-stdlib-patches", Compile / scalacOptions += "-Yexplicit-nulls", Compile / scalacOptions += "-scalajs", // Configure the source maps to point to GitHub for releases diff --git a/tests/neg/no-patches.check b/tests/neg/no-patches.check deleted file mode 100644 index f48e345f12d5..000000000000 --- a/tests/neg/no-patches.check +++ /dev/null @@ -1,8 +0,0 @@ --- Error: tests/neg/no-patches.scala:3:23 ------------------------------------------------------------------------------ -3 |val _ = scala.language.`3.4` // error: we do not patch `scala.language` - | ^^^^^^^^^^^^^^^^^^^^ - | `3.4` can only be used at compile time in import statements --- Error: tests/neg/no-patches.scala:4:36 ------------------------------------------------------------------------------ -4 |val _ = scala.language.experimental.modularity // error: we do not patch `scala.language.experimental` - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | `modularity` can only be used at compile time in import statements diff --git a/tests/neg/no-patches.scala b/tests/neg/no-patches.scala deleted file mode 100644 index 99ca70e568f5..000000000000 --- a/tests/neg/no-patches.scala +++ /dev/null @@ -1,4 +0,0 @@ -//> using options -Yno-stdlib-patches - -val _ = scala.language.`3.4` // error: we do not patch `scala.language` -val _ = scala.language.experimental.modularity // error: we do not patch `scala.language.experimental`