Skip to content

Commit 38af9de

Browse files
authored
Add Ycheck to stdlib-bootstrapped (#18002)
Adding `-Ycheck` to stdlib-bootstrapped will tests the integrity of trees generated when compiling with the `-Yscala2-stdlib` flag.
2 parents 9f15be2 + f3f6092 commit 38af9de

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

+8-3
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,9 @@ class Definitions {
13691369
denot.sourceModule.info = denot.typeRef // we run into a cyclic reference when patching if this line is omitted
13701370
patch2(denot, patchCls)
13711371

1372-
if denot.name == tpnme.Predef.moduleClassName && denot.symbol == ScalaPredefModuleClass then
1372+
if ctx.settings.Yscala2Stdlib.value then
1373+
()
1374+
else if denot.name == tpnme.Predef.moduleClassName && denot.symbol == ScalaPredefModuleClass then
13731375
patchWith(ScalaPredefModuleClassPatch)
13741376
else if denot.name == tpnme.language.moduleClassName && denot.symbol == LanguageModuleClass then
13751377
patchWith(LanguageModuleClassPatch)
@@ -1724,8 +1726,9 @@ class Definitions {
17241726
isFunctionType(tp) || isRefinedFunctionType(tp)
17251727

17261728
private def withSpecMethods(cls: ClassSymbol, bases: List[Name], paramTypes: Set[TypeRef]) =
1727-
for base <- bases; tp <- paramTypes do
1728-
cls.enter(newSymbol(cls, base.specializedName(List(tp)), Method, ExprType(tp)))
1729+
if !ctx.settings.Yscala2Stdlib.value then
1730+
for base <- bases; tp <- paramTypes do
1731+
cls.enter(newSymbol(cls, base.specializedName(List(tp)), Method, ExprType(tp)))
17291732
cls
17301733

17311734
@tu lazy val Tuple1: ClassSymbol = withSpecMethods(requiredClass("scala.Tuple1"), List(nme._1), Tuple1SpecializedParamTypes)
@@ -1766,6 +1769,7 @@ class Definitions {
17661769
case List(x, y) => Tuple2SpecializedParamClasses().contains(x.classSymbol) && Tuple2SpecializedParamClasses().contains(y.classSymbol)
17671770
case _ => false
17681771
&& base.owner.denot.info.member(base.name.specializedName(args)).exists // when dotc compiles the stdlib there are no specialised classes
1772+
&& !ctx.settings.Yscala2Stdlib.value // We do not add the specilized TupleN methods/classes when compiling the stdlib
17691773

17701774
def isSpecializableFunction(cls: ClassSymbol, paramTypes: List[Type], retType: Type)(using Context): Boolean =
17711775
paramTypes.length <= 2
@@ -1787,6 +1791,7 @@ class Definitions {
17871791
case _ =>
17881792
false
17891793
})
1794+
&& !ctx.settings.Yscala2Stdlib.value // We do not add the specilized FunctionN methods/classes when compiling the stdlib
17901795

17911796
@tu lazy val Function0SpecializedApplyNames: collection.Set[TermName] =
17921797
for r <- Function0SpecializedReturnTypes

compiler/src/dotty/tools/dotc/transform/SpecializeApplyMethods.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class SpecializeApplyMethods extends MiniPhase with InfoTransformer {
2525
override def description: String = SpecializeApplyMethods.description
2626

2727
override def isEnabled(using Context): Boolean =
28-
!ctx.settings.scalajs.value
28+
!ctx.settings.scalajs.value && !ctx.settings.Yscala2Stdlib.value
2929

3030
private def specApplySymbol(sym: Symbol, args: List[Type], ret: Type)(using Context): Symbol = {
3131
val name = nme.apply.specializedFunction(ret, args)

compiler/src/dotty/tools/dotc/typer/Typer.scala

+1
Original file line numberDiff line numberDiff line change
@@ -2734,6 +2734,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
27342734
&& !cls.isAllOf(PrivateLocal)
27352735
&& effectiveOwner.is(Trait)
27362736
&& !effectiveOwner.derivesFrom(defn.ObjectClass)
2737+
&& !ctx.settings.Yscala2Stdlib.value // FIXME?: class PermutationsItr cannot be defined in universal trait SeqOps
27372738
then
27382739
report.error(em"$cls cannot be defined in universal $effectiveOwner", cdef.srcPos)
27392740

project/Build.scala

+1
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ object Build {
940940
},
941941
Compile / doc / scalacOptions += "-Ydocument-synthetic-types",
942942
scalacOptions += "-Yscala2-stdlib",
943+
scalacOptions += "-Ycheck:all",
943944
scalacOptions -= "-Xfatal-warnings",
944945
ivyConfigurations += SourceDeps.hide,
945946
transitiveClassifiers := Seq("sources"),

0 commit comments

Comments
 (0)