@@ -1457,116 +1457,6 @@ class Definitions {
14571457 || sym.owner == CompiletimeOpsStringModuleClass && compiletimePackageStringTypes.contains(sym.name)
14581458 )
14591459
1460- // ----- Scala-2 library patches --------------------------------------
1461-
1462- /** The `scala.runtime.stdLibPacthes` package contains objects
1463- * that contain defnitions that get added as members to standard library
1464- * objects with the same name.
1465- */
1466- @ tu lazy val StdLibPatchesPackage : TermSymbol = requiredPackage(" scala.runtime.stdLibPatches" )
1467- @ tu private lazy val ScalaPredefModuleClassPatch : Symbol = getModuleIfDefined(" scala.runtime.stdLibPatches.Predef" ).moduleClass
1468- @ tu private lazy val LanguageModuleClassPatch : Symbol = getModuleIfDefined(" scala.runtime.stdLibPatches.language" ).moduleClass
1469-
1470- /** If `sym` is a patched library class, the source file of its patch class,
1471- * otherwise `NoSource`
1472- */
1473- def patchSource (sym : Symbol )(using Context ): SourceFile =
1474- if sym == ScalaPredefModuleClass then ScalaPredefModuleClassPatch .source
1475- else if sym == LanguageModuleClass then LanguageModuleClassPatch .source
1476- else NoSource
1477-
1478- /** A finalizer that patches standard library classes.
1479- * It copies all non-private, non-synthetic definitions from `patchCls`
1480- * to `denot` while changing their owners to `denot`. Before that it deletes
1481- * any definitions of `denot` that have the same name as one of the copied
1482- * definitions.
1483- *
1484- * If an object is present in both the original class and the patch class,
1485- * it is not overwritten. Instead its members are copied recursively.
1486- *
1487- * To avpid running into cycles on bootstrap, patching happens only if `patchCls`
1488- * is read from a classfile.
1489- */
1490- def patchStdLibClass (denot : ClassDenotation )(using Context ): Unit =
1491- // Do not patch the stdlib files if we explicitly disable it
1492- // This is only to be used during the migration of the stdlib
1493- if ctx.settings.YnoStdlibPatches .value then
1494- return
1495-
1496- def patch2 (denot : ClassDenotation , patchCls : Symbol ): Unit =
1497- val scope = denot.info.decls.openForMutations
1498-
1499- def recurse (patch : Symbol ) = patch.is(Module ) && scope.lookup(patch.name).exists
1500-
1501- def makeClassSymbol (patch : Symbol , parents : List [Type ], selfInfo : TypeOrSymbol ) =
1502- newClassSymbol(
1503- owner = denot.symbol,
1504- name = patch.name.asTypeName,
1505- flags = patch.flags,
1506- // need to rebuild a fresh ClassInfo
1507- infoFn = cls => ClassInfo (
1508- prefix = denot.symbol.thisType,
1509- cls = cls,
1510- declaredParents = parents, // assume parents in patch don't refer to symbols in the patch
1511- decls = newScope,
1512- selfInfo =
1513- if patch.is(Module )
1514- then TermRef (denot.symbol.thisType, patch.name.sourceModuleName)
1515- else selfInfo // assume patch self type annotation does not refer to symbols in the patch
1516- ),
1517- privateWithin = patch.privateWithin,
1518- coord = denot.symbol.coord,
1519- compUnitInfo = denot.symbol.compilationUnitInfo
1520- )
1521-
1522- def makeNonClassSymbol (patch : Symbol ) =
1523- if patch.is(Inline ) then
1524- // Inline symbols contain trees in annotations, which is coupled
1525- // with the underlying symbol.
1526- // Changing owner for inline symbols is a simple workaround.
1527- patch.denot = patch.denot.copySymDenotation(owner = denot.symbol)
1528- patch
1529- else
1530- // change `info` which might contain reference to the patch
1531- patch.copy(
1532- owner = denot.symbol,
1533- info =
1534- if patch.is(Module )
1535- then TypeRef (denot.symbol.thisType, patch.name.moduleClassName)
1536- else patch.info // assume non-object info does not refer to symbols in the patch
1537- )
1538-
1539- if patchCls.exists then
1540- val patches = patchCls.info.decls.filter(patch =>
1541- ! patch.isConstructor && ! patch.isOneOf(PrivateOrSynthetic ))
1542- for patch <- patches if ! recurse(patch) do
1543- val e = scope.lookupEntry(patch.name)
1544- if e != null then scope.unlink(e)
1545- for patch <- patches do
1546- patch.ensureCompleted()
1547- if ! recurse(patch) then
1548- val sym =
1549- patch.info match
1550- case ClassInfo (_, _, parents, _, selfInfo) =>
1551- makeClassSymbol(patch, parents, selfInfo)
1552- case _ =>
1553- makeNonClassSymbol(patch)
1554- end match
1555- sym.annotations = patch.annotations
1556- scope.enter(sym)
1557- if patch.isClass then
1558- patch2(scope.lookup(patch.name).asClass, patch)
1559-
1560- def patchWith (patchCls : Symbol ) =
1561- denot.sourceModule.info = denot.typeRef // we run into a cyclic reference when patching if this line is omitted
1562- patch2(denot, patchCls)
1563-
1564- if denot.name == tpnme.Predef .moduleClassName && denot.symbol == ScalaPredefModuleClass then
1565- patchWith(ScalaPredefModuleClassPatch )
1566- else if denot.name == tpnme.language.moduleClassName && denot.symbol == LanguageModuleClass then
1567- patchWith(LanguageModuleClassPatch )
1568- end patchStdLibClass
1569-
15701460 // ----- Symbol sets ---------------------------------------------------
15711461
15721462 @ tu lazy val topClasses : Set [Symbol ] = Set (AnyClass , MatchableClass , ObjectClass , AnyValClass )
0 commit comments