Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<class>", descr = "Specify a dotty.tools.dotc.reporting.Reporter", default = "dotty.tools.dotc.reporting.ConsoleReporter")

Expand Down
110 changes: 0 additions & 110 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 6 additions & 8 deletions compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ object Scala2Unpickler {

denot.info = tempInfo.finalized(normalizedParents)
denot.ensureTypeParamsInCorrectOrder()
defn.patchStdLibClass(denot)
}
}

Expand Down
6 changes: 0 additions & 6 deletions compiler/src/dotty/tools/dotc/transform/TreeChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/init/Util.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1783,7 +1783,6 @@ class Namer { typer: Typer =>
cls.setStableConstructor()
enterParentRefinementSyms(parentRefinements.toList)
processExports(using localCtx)
defn.patchStdLibClass(cls)
addConstructorProxies(cls)
cleanup()
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/dotty/tools/vulpix/TestConfiguration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ class DefinitionTest {
.definition(m7 to m8, List(m3 to m4))
}

@Ignore
@Test def goToParamCopyMethod: Unit = {

withSources(
Expand Down
1 change: 1 addition & 0 deletions library/src/scala/runtime/stdLibPatches/Predef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions library/src/scala/runtime/stdLibPatches/language.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions tests/neg/no-patches.check

This file was deleted.

4 changes: 0 additions & 4 deletions tests/neg/no-patches.scala

This file was deleted.

Loading