Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider source code as Scala 2 under -Ycompile-scala2-library #22520

Merged
merged 4 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ class TreePickler(pickler: TastyPickler, attributes: Attributes) {
assert(isModifierTag(tag))
writeByte(tag)
}
assert(!flags.is(Scala2x))
if flags.is(Scala2x) then assert(attributes.scala2StandardLibrary)
if (flags.is(Private)) writeModTag(PRIVATE)
if (flags.is(Protected)) writeModTag(PROTECTED)
if (flags.is(Final, butNot = Module)) writeModTag(FINAL)
Expand Down
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
for publicInBinaryAnnot <- publicInBinaryAnnotOpt do sym.addAnnotation(publicInBinaryAnnot)
else
sym.keepAnnotationsCarrying(thisPhase, Set(defn.GetterMetaAnnot, defn.FieldMetaAnnot), orNoneOf = defn.NonBeanMetaAnnots)
if sym.isScala2Macro && !ctx.settings.XignoreScala2Macros.value then
if sym.isScala2Macro && !ctx.settings.XignoreScala2Macros.value &&
sym != defn.StringContext_raw &&
sym != defn.StringContext_f &&
sym != defn.StringContext_s then
if !sym.owner.unforcedDecls.exists(p => !p.isScala2Macro && p.name == sym.name && p.signature == sym.signature)
// Allow scala.reflect.materializeClassTag to be able to compile scala/reflect/package.scala
// This should be removed on Scala 3.x
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ class Namer { typer: Typer =>

tree match {
case tree: TypeDef if tree.isClassDef =>
val flags = checkFlags(tree.mods.flags)
var flags = checkFlags(tree.mods.flags)
if ctx.settings.YcompileScala2Library.value then
flags |= Scala2x
val name = checkNoConflict(tree.name, flags.is(Private), tree.span).asTypeName
val cls =
createOrRefine[ClassSymbol](tree, name, flags, ctx.owner,
Expand Down
9 changes: 0 additions & 9 deletions project/Scala2LibraryBootstrappedMiMaFilters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,8 @@ object Scala2LibraryBootstrappedMiMaFilters {
ProblemFilters.exclude[FinalMethodProblem]("scala.io.Source.NoPositioner"),
ProblemFilters.exclude[FinalMethodProblem]("scala.io.Source.RelaxedPosition"),
ProblemFilters.exclude[FinalMethodProblem]("scala.io.Source.RelaxedPositioner"),
ProblemFilters.exclude[IncompatibleResultTypeProblem]("scala.collection.immutable.SortedMapOps.coll"),
ProblemFilters.exclude[IncompatibleResultTypeProblem]("scala.collection.immutable.TreeMap.empty"),
ProblemFilters.exclude[IncompatibleResultTypeProblem]("scala.collection.immutable.TreeMap.fromSpecific"),
ProblemFilters.exclude[IncompatibleResultTypeProblem]("scala.collection.mutable.ArrayBuilder#ofUnit.addAll"),
ProblemFilters.exclude[IncompatibleResultTypeProblem]("scala.collection.mutable.TreeMap.empty"),
ProblemFilters.exclude[IncompatibleResultTypeProblem]("scala.collection.mutable.TreeMap.fromSpecific"),
ProblemFilters.exclude[IncompatibleResultTypeProblem]("scala.reflect.ManifestFactory#NothingManifest.newArray"),
ProblemFilters.exclude[IncompatibleResultTypeProblem]("scala.reflect.ManifestFactory#NullManifest.newArray"),
ProblemFilters.exclude[MissingFieldProblem]("scala.collection.ArrayOps#ReverseIterator.xs"),
ProblemFilters.exclude[MissingFieldProblem]("scala.runtime.NonLocalReturnControl.value"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.collection.immutable.SortedMapOps.coll"),
) ++
Seq( // DirectMissingMethodProblem
"scala.collection.LinearSeqIterator#LazyCell.this",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,7 @@ object TrieMap extends MapFactory[TrieMap] {

// non-final as an extension point for parallel collections
private[collection] class TrieMapIterator[K, V](var level: Int, private var ct: TrieMap[K, V], mustInit: Boolean = true) extends AbstractIterator[(K, V)] {
this:TrieMapIterator[K, V]^ =>
private val stack = new Array[Array[BasicNode]](7)
private val stackpos = new Array[Int](7)
private var depth = -1
Expand Down Expand Up @@ -1161,7 +1162,7 @@ private[collection] class TrieMapIterator[K, V](var level: Int, private var ct:
/** Returns a sequence of iterators over subsets of this iterator.
* It's used to ease the implementation of splitters for a parallel version of the TrieMap.
*/
protected def subdivide(): Seq[Iterator[(K, V)]] = if (subiter ne null) {
protected def subdivide(): Seq[Iterator[(K, V)]^{this}] = if (subiter ne null) {
// the case where an LNode is being iterated
val it = newIterator(level + 1, ct, _mustInit = false)
it.depth = -1
Expand Down
3 changes: 2 additions & 1 deletion scala2-library-cc/src/scala/collection/immutable/Range.scala
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ private class RangeIterator(
lastElement: Int,
initiallyEmpty: Boolean
) extends AbstractIterator[Int] with Serializable {
this: RangeIterator^ =>
private[this] var _hasNext: Boolean = !initiallyEmpty
private[this] var _next: Int = start
override def knownSize: Int = if (_hasNext) (lastElement - _next) / step + 1 else 0
Expand All @@ -656,7 +657,7 @@ private class RangeIterator(
value
}

override def drop(n: Int): Iterator[Int] = {
override def drop(n: Int): Iterator[Int]^{this} = {
if (n > 0) {
val longPos = _next.toLong + step * n
if (step > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import scala.collection.generic.DefaultSerializable
import scala.reflect.ClassTag
import scala.collection.immutable.Nil
import language.experimental.captureChecking
import caps.unsafe.unsafeAssumePure

/** A buffer that stores elements in an unrolled linked list.
*
Expand Down Expand Up @@ -259,13 +260,14 @@ object UnrolledBuffer extends StrictOptimizedClassTagSeqFactory[UnrolledBuffer]
/** Unrolled buffer node.
*/
class Unrolled[T: ClassTag] private[collection] (var size: Int, var array: Array[T], var next: Unrolled[T], val buff: UnrolledBuffer[T] = null) {
//this: Unrolled[T]^ =>
private[collection] def this() = this(0, new Array[T](unrolledlength), null, null)
private[collection] def this(b: UnrolledBuffer[T]) = this(0, new Array[T](unrolledlength), null, b)

private def nextlength = if (buff eq null) unrolledlength else buff.calcNextLength(array.length)

// adds and returns itself or the new unrolled if full
@tailrec final def append(elem: T): Unrolled[T] = if (size < array.length) {
@tailrec final def append(elem: T): Unrolled[T]^{this} = if (size < array.length) {
array(size) = elem
size += 1
this
Expand Down Expand Up @@ -307,21 +309,21 @@ object UnrolledBuffer extends StrictOptimizedClassTagSeqFactory[UnrolledBuffer]
if (idx < size) array(idx) else next.apply(idx - size)
@tailrec final def update(idx: Int, newelem: T): Unit =
if (idx < size) array(idx) = newelem else next.update(idx - size, newelem)
@tailrec final def locate(idx: Int): Unrolled[T] =
@tailrec final def locate(idx: Int): Unrolled[T]^{this} =
if (idx < size) this else next.locate(idx - size)
def prepend(elem: T) = if (size < array.length) {
def prepend(elem: T): Unrolled[T] = if (size < array.length) {
// shift the elements of the array right
// then insert the element
shiftright()
array(0) = elem
size += 1
this
this.unsafeAssumePure
} else {
// allocate a new node and store element
// then make it point to this
val newhead = new Unrolled[T](buff)
newhead append elem
newhead.next = this
newhead.next = this.unsafeAssumePure
newhead
}
// shifts right assuming enough space
Expand All @@ -340,7 +342,7 @@ object UnrolledBuffer extends StrictOptimizedClassTagSeqFactory[UnrolledBuffer]
val r = array(idx)
shiftleft(idx)
size -= 1
if (tryMergeWithNext()) buffer.lastPtr = this
if (tryMergeWithNext()) buffer.lastPtr = this.unsafeAssumePure
r
} else next.remove(idx - size, buffer)

Expand Down Expand Up @@ -397,7 +399,7 @@ object UnrolledBuffer extends StrictOptimizedClassTagSeqFactory[UnrolledBuffer]
curr.next = newnextnode

// try to merge the last node of this with the newnextnode and fix tail pointer if needed
if (curr.tryMergeWithNext()) buffer.lastPtr = curr
if (curr.tryMergeWithNext()) buffer.lastPtr = curr.unsafeAssumePure
else if (newnextnode.next eq null) buffer.lastPtr = newnextnode
appended
}
Expand Down
Loading