Repository navigation
Stop using Scala2 classfiles for parts of the standard library - #27621
SolalPirelli wants to merge 1 commit into
Conversation
| * | ||
| * @return a function `f` such that `f(x1)(x2)(x3)(x4)(x5)(x6)(x7)(x8)(x9)(x10) == apply(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10)` | ||
| */ | ||
| @annotation.unspecialized def curried: T1 => T2 => T3 => T4 => T5 => T6 => T7 => T8 => T9 => T10 => R = { |
There was a problem hiding this comment.
I removed these annotations where they had no effect, namely in classes that aren't specialized.
ec6479c to
5c884e6
Compare
| val (tmap1, params1) = (params: @unchecked) match | ||
| case ValDefs(vparams) => transformDefs(vparams) | ||
| case TypeDefs(tparams) => transformDefs(tparams) | ||
| ): @unchecked |
There was a problem hiding this comment.
This @unchecked wasn't working anymore. I suppose it's some fallout from using the Scala 3-compiled Tuple class.
| else trackedParam | ||
| if paramInfo.hasAnnotation(defn.ConsumeAnnot) then CapturingType(tp, CaptureSet.universal) | ||
| else if tp.classSymbol == symd.owner.companionClass then info.paramRefs.head // def unapply(x: C): C = x | ||
| else tp // 2.13 extractors and 0-ary extractors |
There was a problem hiding this comment.
Fix suggested by Oliver.
| val YappToMain: Setting[Boolean] = BooleanSetting(ForkSetting, "Yapp-to-main", "Rewrite `object X extends App { ... }` to an object with an explicit `main` method. Use in conjunction with --rewrite.") | ||
|
|
||
| // Temporary. Do not use outside of the stdlib. | ||
| val YcompilingStdlib: Setting[Boolean] = BooleanSetting(ForkSetting, "Ycompiling-stdlib", "Temporary. Do not use. Whether we are compiling the stdlib.") |
There was a problem hiding this comment.
Feature.shouldBehaveAsScala2 is not enough because it's dependent on the specific compilation unit; here, we want Tuple1/2 to be modified based on whether we will ourselves add the specializations or not, but their first access may be from a compilation unit that doesn't have the language.2.13 import.
| def isRechecking: Boolean = | ||
| val phaseId = ctx.phaseId | ||
| 0 <= phaseId && phaseId < 64 && (ctx.base.recheckPhaseIds & (1L << phaseId)) != 0 | ||
| 0 <= phaseId && phaseId < 64 && ctx.base.recheckPhaseIds.contains(phaseId) |
There was a problem hiding this comment.
Because this adds a couple phases, the Long encoding is no longer large enough, so this is a BitSet now.
| */ | ||
| private def mightBeDropped(sym: Symbol)(using Context) = | ||
| sym.is(Private, butNot = MethodOrLazy) && !sym.isAllOf(MutableParamAccessor) | ||
| sym.is(Private, butNot = MethodOrLazy) && !sym.isAllOf(MutableParamAccessor) && sym.targetName == sym.name |
There was a problem hiding this comment.
Don't drop a class member if it is intended to have a target name. I needed it for the manual Unit specialization of NonLocalReturnControl (see below), but this seems to make sense anyway.
| // !!! | ||
| // REVIEW: why? | ||
| coord = spanCoord(t.span.endPos) | ||
| // !!! |
There was a problem hiding this comment.
This and the two instances below are odd (this is the least odd), and aren't even enough to pass all pickling tests as NonLocalReturnControl.scala has before/after-pickling diffs anyway.
Please tell me what to put here... or what else to do so pickling doesn't change their coords... I've spent too much time on this.
| * of class `clazz` are met. | ||
| */ | ||
| def checkOverride(member: Symbol, other: Symbol): Unit = | ||
| def isInlinedFromInlineTrait = other.owner.isAllOf(InlineTrait) && member.is(Synthetic) |
There was a problem hiding this comment.
It generally seems better to not depend specifically on inline traits here anyway and just relax checks for synthetic members in general.
| "apply$mcIII$sp", | ||
| "apply"), | ||
| s"Apply methods were not in the expected order: $apps" | ||
| s"Apply methods were not the expected ones: $apps" |
There was a problem hiding this comment.
I'm not sure this test has much value now. MiMa will tell us if something is wrong anyway. Should we delete it?
| @@ -0,0 +1,195 @@ | |||
| /* | |||
There was a problem hiding this comment.
Copied from the Scala.js repo, except for the two .asInstanceOf[Object] casts added as required by explicit nulls.
| @@ -0,0 +1,95 @@ | |||
| /* | |||
There was a problem hiding this comment.
Copied from the Scala.js repo, with an added nowarn on line 17.
| * @constructor Create a new tuple with 1 elements. | ||
| * @param _1 Element 1 of this Tuple1 | ||
| */ | ||
| @SerialVersionUID(-2392256924707456902L) |
There was a problem hiding this comment.
One of the community-build projects tests that Tuple2's serialization doesn't change, so I had to add a SerialVersionUID to it anyway, and I figured I might as well add the one for Tuple1.
| // The private `Sorting.mergeSort` function has a different implementation detail | ||
| ProblemFilters.exclude[DirectMissingMethodProblem]("scala.util.Sorting.scala$util$Sorting$$mergeSort$default$5"), | ||
| // https://github.com/scala/scala3/pull/26100 (it was a private object anyway) | ||
| ProblemFilters.exclude[MissingClassProblem]("scala.collection.immutable.LazyList$MidEvaluation$"), |
There was a problem hiding this comment.
I'm unsure why this is only appearing now since LazyList wasn't a class we copied from Scala2.
| == | ||
| andThen | ||
| apply | ||
| apply$mcDD$sp |
There was a problem hiding this comment.
This check output also contains the fake $asInstanceOf$ and $isInstanceOf$ so I think having these as well is fine.
| // scalajs: --skip | ||
| // (uses reflection) | ||
|
|
||
| class C extends Function1[Int, Int]: |
There was a problem hiding this comment.
As suggested by Hamza, a test to ensure inheriting from a Function is still fine.
5c884e6 to
0ff5047
Compare
0ff5047 to
4f99f95
Compare
There was a problem hiding this comment.
This is an old project intended for 2.12 and 2.11. It stops compiling with this PR because the better generic signatures introduced in 3.10 are actually used in every classfile now, and that causes compile-time errors from incorrect casts. It will still work at runtime anyway. Lukas and Piotr agreed we don't need to keep it in community-build.
Fixes #27307
After this PR, bootstrapped compilation no longer uses Scala 2 compiler outputs.
Once this is ingested for the compiler used in nonbootstrapped compilation, we'll be able to remove the corresponding infrastructure.
Have you relied on LLM-based tools in this contribution?
Somewhat, to understand both codebases. I wrote the code myself.
How was the solution tested?
Covered by MiMa + existing standard library tests.
I did not add tests specifically for this because there is no other specification than "whatever makes MiMa happy". Scala2 specialization is known to have rough edges.