Skip to content

Commit

Permalink
Align nomenclature of Scala2 library compilation (#18711)
Browse files Browse the repository at this point in the history
Follow up name changes in #18615 and align with flag added in #18613.
  • Loading branch information
bishabosha committed Oct 23, 2023
2 parents d652c3e + b58f691 commit c1c2c8e
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 20 deletions.
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ object desugar {
def isNonEnumCase = !isEnumCase && (isCaseClass || isCaseObject)
val isValueClass = parents.nonEmpty && isAnyVal(parents.head)
// This is not watertight, but `extends AnyVal` will be replaced by `inline` later.
val caseClassInScala2StdLib = isCaseClass && ctx.settings.Yscala2Stdlib.value
val caseClassInScala2Library = isCaseClass && ctx.settings.YcompileScala2Library.value

val originalTparams = constr1.leadingTypeParams
val originalVparamss = asTermOnly(constr1.trailingParamss)
Expand Down Expand Up @@ -684,7 +684,7 @@ object desugar {
DefDef(name, Nil, tpt, rhs).withMods(synthetic)

def productElemMeths =
if caseClassInScala2StdLib then Nil
if caseClassInScala2Library then Nil
else
val caseParams = derivedVparamss.head.toArray
val selectorNamesInBody = normalizedBody.collect {
Expand Down Expand Up @@ -715,7 +715,7 @@ object desugar {
val copyRestParamss = derivedVparamss.tail.nestedMap(vparam =>
cpy.ValDef(vparam)(rhs = EmptyTree))
var flags = Synthetic | constr1.mods.flags & copiedAccessFlags
if ctx.settings.Yscala2Stdlib.value then flags &~= Private
if ctx.settings.YcompileScala2Library.value then flags &~= Private
DefDef(
nme.copy,
joinParams(derivedTparams, copyFirstParams :: copyRestParamss),
Expand Down Expand Up @@ -776,7 +776,7 @@ object desugar {
else {
val appMods =
var flags = Synthetic | constr1.mods.flags & copiedAccessFlags
if ctx.settings.Yscala2Stdlib.value then flags &~= Private
if ctx.settings.YcompileScala2Library.value then flags &~= Private
Modifiers(flags).withPrivateWithin(constr1.mods.privateWithin)
val appParamss =
derivedVparamss.nestedZipWithConserve(constrVparamss)((ap, cp) =>
Expand All @@ -802,7 +802,7 @@ object desugar {
val unapplyParam = makeSyntheticParameter(tpt = classTypeRef)
val unapplyRHS =
if (arity == 0) Literal(Constant(true))
else if caseClassInScala2StdLib then scala2LibCompatUnapplyRhs(unapplyParam.name)
else if caseClassInScala2Library then scala2LibCompatUnapplyRhs(unapplyParam.name)
else Ident(unapplyParam.name)
val unapplyResTp = if (arity == 0) Literal(Constant(true)) else TypeTree()

Expand Down Expand Up @@ -860,7 +860,7 @@ object desugar {
// TODO: drop this once we do not silently insert empty class parameters anymore
case paramss => paramss
}
val finalFlag = if ctx.settings.Yscala2Stdlib.value then EmptyFlags else Final
val finalFlag = if ctx.settings.YcompileScala2Library.value then EmptyFlags else Final
// implicit wrapper is typechecked in same scope as constructor, so
// we can reuse the constructor parameters; no derived params are needed.
DefDef(
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ private sealed trait YSettings:
val YfromTastyIgnoreList: Setting[List[String]] = MultiStringSetting("-Yfrom-tasty-ignore-list", "file", "List of `tasty` files in jar files that will not be loaded when using -from-tasty.")
val YnoExperimental: Setting[Boolean] = BooleanSetting("-Yno-experimental", "Disable experimental language features.")
val YlegacyLazyVals: Setting[Boolean] = BooleanSetting("-Ylegacy-lazy-vals", "Use legacy (pre 3.3.0) implementation of lazy vals.")
val Yscala2Stdlib: Setting[Boolean] = BooleanSetting("-Yscala2-stdlib", "Used when compiling the Scala 2 standard library.")
val YcompileScala2Library: Setting[Boolean] = BooleanSetting("-Ycompile-scala2-library", "Used when compiling the Scala 2 standard library.")
val YoutputOnlyTasty: Setting[Boolean] = BooleanSetting("-Youtput-only-tasty", "Used to only generate the TASTy file without the classfiles")

val YprofileEnabled: Setting[Boolean] = BooleanSetting("-Yprofile-enabled", "Enable profiling.")
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ class Definitions {
denot.sourceModule.info = denot.typeRef // we run into a cyclic reference when patching if this line is omitted
patch2(denot, patchCls)

if ctx.settings.Yscala2Stdlib.value then
if ctx.settings.YcompileScala2Library.value then
()
else if denot.name == tpnme.Predef.moduleClassName && denot.symbol == ScalaPredefModuleClass then
patchWith(ScalaPredefModuleClassPatch)
Expand Down Expand Up @@ -1769,7 +1769,7 @@ class Definitions {
|| tp.derivesFrom(defn.PolyFunctionClass) // TODO check for refinement?

private def withSpecMethods(cls: ClassSymbol, bases: List[Name], paramTypes: Set[TypeRef]) =
if !ctx.settings.Yscala2Stdlib.value then
if !ctx.settings.YcompileScala2Library.value then
for base <- bases; tp <- paramTypes do
cls.enter(newSymbol(cls, base.specializedName(List(tp)), Method, ExprType(tp)))
cls
Expand Down Expand Up @@ -1812,7 +1812,7 @@ class Definitions {
case List(x, y) => Tuple2SpecializedParamClasses().contains(x.classSymbol) && Tuple2SpecializedParamClasses().contains(y.classSymbol)
case _ => false
&& base.owner.denot.info.member(base.name.specializedName(args)).exists // when dotc compiles the stdlib there are no specialised classes
&& !ctx.settings.Yscala2Stdlib.value // We do not add the specilized TupleN methods/classes when compiling the stdlib
&& !ctx.settings.YcompileScala2Library.value // We do not add the specilized TupleN methods/classes when compiling the stdlib

def isSpecializableFunction(cls: ClassSymbol, paramTypes: List[Type], retType: Type)(using Context): Boolean =
paramTypes.length <= 2
Expand All @@ -1834,7 +1834,7 @@ class Definitions {
case _ =>
false
})
&& !ctx.settings.Yscala2Stdlib.value // We do not add the specilized FunctionN methods/classes when compiling the stdlib
&& !ctx.settings.YcompileScala2Library.value // We do not add the specilized FunctionN methods/classes when compiling the stdlib

@tu lazy val Function0SpecializedApplyNames: List[TermName] =
for r <- Function0SpecializedReturnTypes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
}

private def checkScala2Stdlib(using Context): Unit =
assert(!ctx.settings.Yscala2Stdlib.value, "No Scala 2 libraries should be unpickled under -Yscala2-stdlib")
assert(!ctx.settings.YcompileScala2Library.value, "No Scala 2 libraries should be unpickled under -Ycompile-scala2-library")

/** The `decls` scope associated with given symbol */
protected def symScope(sym: Symbol): Scope = symScopes.getOrElseUpdate(sym, newScope(0))
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>

private var compilingScala2StdLib = false
override def initContext(ctx: FreshContext): Unit =
compilingScala2StdLib = ctx.settings.Yscala2Stdlib.value(using ctx)
compilingScala2StdLib = ctx.settings.YcompileScala2Library.value(using ctx)

val superAcc: SuperAccessors = new SuperAccessors(thisPhase)
val synthMbr: SyntheticMembers = new SyntheticMembers(thisPhase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SpecializeApplyMethods extends MiniPhase with InfoTransformer {
override def description: String = SpecializeApplyMethods.description

override def isEnabled(using Context): Boolean =
!ctx.settings.scalajs.value && !ctx.settings.Yscala2Stdlib.value
!ctx.settings.scalajs.value && !ctx.settings.YcompileScala2Library.value

private def specApplySymbol(sym: Symbol, args: List[Type], ret: Type)(using Context): Symbol = {
val name = nme.apply.specializedFunction(ret, args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
case nme.productPrefix if isEnumValue => nameRef
case nme.productPrefix => ownName
case nme.productElement =>
if ctx.settings.Yscala2Stdlib.value then productElementBodyForScala2Compat(accessors.length, vrefss.head.head)
if ctx.settings.YcompileScala2Library.value then productElementBodyForScala2Compat(accessors.length, vrefss.head.head)
else productElementBody(accessors.length, vrefss.head.head)
case nme.productElementName => productElementNameBody(accessors.length, vrefss.head.head)
}
Expand Down Expand Up @@ -666,7 +666,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
val syntheticMembers = serializableObjectMethod(clazz) ::: serializableEnumValueMethod(clazz) ::: caseAndValueMethods(clazz)
checkInlining(syntheticMembers)
val impl1 = cpy.Template(impl)(body = syntheticMembers ::: impl.body)
if ctx.settings.Yscala2Stdlib.value then impl1
if ctx.settings.YcompileScala2Library.value then impl1
else addMirrorSupport(impl1)
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2749,7 +2749,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer

checkEnumParent(cls, firstParent)

if defn.ScalaValueClasses()(cls) && ctx.settings.Yscala2Stdlib.value then
if defn.ScalaValueClasses()(cls) && ctx.settings.YcompileScala2Library.value then
constr1.symbol.resetFlag(Private)

val self1 = typed(self)(using ctx.outer).asInstanceOf[ValDef] // outer context where class members are not visible
Expand Down Expand Up @@ -2789,7 +2789,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
&& !cls.isAllOf(PrivateLocal)
&& effectiveOwner.is(Trait)
&& !effectiveOwner.derivesFrom(defn.ObjectClass)
&& !ctx.settings.Yscala2Stdlib.value // FIXME?: class PermutationsItr cannot be defined in universal trait SeqOps
&& !ctx.settings.YcompileScala2Library.value // FIXME?: class PermutationsItr cannot be defined in universal trait SeqOps
then
report.error(em"$cls cannot be defined in universal $effectiveOwner", cdef.srcPos)

Expand Down
2 changes: 1 addition & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ object Build {
Seq("-sourcepath", ((Compile/sourceManaged).value / "scala-library-src").toString)
},
Compile / doc / scalacOptions += "-Ydocument-synthetic-types",
scalacOptions += "-Yscala2-stdlib",
scalacOptions += "-Ycompile-scala2-library",
scalacOptions += "-Ycheck:all",
scalacOptions -= "-Xfatal-warnings",
ivyConfigurations += SourceDeps.hide,
Expand Down
2 changes: 1 addition & 1 deletion project/TastyMiMaFilters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object TastyMiMaFilters {
// In Scala 3 these accessors are added in the `postyper` phase.
// In Scala 2 these accessors are added in the `superaccessors` phase after typer.
// Are these accessors in the Scala 2 pickles? If so, it implies that TASTy Query/MiMa is ignoring them in Scala 2 but not Scala 3.
// Otherwise, if these are not in the Scala 2 pickles, we might need to remove them when compiling with -Yscala2-stdlib
// Otherwise, if these are not in the Scala 2 pickles, we might need to remove them when compiling with -Ycompile-scala2-library
ProblemMatcher.make(ProblemKind.NewAbstractMember, "scala.collection.immutable.IndexedSeqOps.superscala$collection$immutable$IndexedSeqOps$$slice"),
ProblemMatcher.make(ProblemKind.NewAbstractMember, "scala.collection.immutable.StrictOptimizedSeqOps.superscala$collection$immutable$StrictOptimizedSeqOps$$sorted"),
ProblemMatcher.make(ProblemKind.NewAbstractMember, "scala.collection.immutable.IndexedSeq.superscala$collection$immutable$IndexedSeq$$*"/* sameElements, canEqual */),
Expand Down

0 comments on commit c1c2c8e

Please sign in to comment.