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