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