Skip to content

Commit 8741bd9

Browse files
authored
Merge pull request scala#6364 from szeiger/wip/bootstrap-new-collections
Changes required to bootstrap the new collections library
2 parents f3aaecf + 7c018a0 commit 8741bd9

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

src/compiler/scala/tools/nsc/ast/TreeGen.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ abstract class TreeGen extends scala.reflect.internal.TreeGen with TreeDSL {
122122
def mkForwarder(target: Tree, vparamss: List[List[Symbol]]) =
123123
(target /: vparamss)((fn, vparams) => Apply(fn, vparams map paramToArg))
124124

125-
/** Applies a wrapArray call to an array, making it a WrappedArray.
125+
/** Applies a wrapArray call to an array, making it a WrappedArray or ImmutableArray suitable for Scala varargs.
126126
* Don't let a reference type parameter be inferred, in case it's a singleton:
127127
* apply the element type directly.
128128
*/
129-
def mkWrapArray(tree: Tree, elemtp: Type) = {
129+
def mkWrapVarargsArray(tree: Tree, elemtp: Type) = {
130130
mkMethodCall(
131-
PredefModule,
132-
wrapArrayMethodName(elemtp),
131+
getWrapVarargsArrayModule,
132+
wrapVarargsArrayMethodName(elemtp),
133133
if (isPrimitiveValueType(elemtp)) Nil else List(elemtp),
134134
List(tree)
135135
)

src/compiler/scala/tools/nsc/transform/CleanUp.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,15 +461,15 @@ abstract class CleanUp extends Statics with Transform with ast.TreeDSL {
461461
case app@Apply(TypeApply(fun, _), args) if fun.symbol == Object_synchronized =>
462462
treeCopy.Apply(app, fun, args).transform(this)
463463

464-
// Replaces `Array(Predef.wrapArray(ArrayValue(...).$asInstanceOf[...]), <tag>)`
464+
// Replaces `Array(<Predef-or-ScalaRunTime>.wrapArray(ArrayValue(...).$asInstanceOf[...]), <tag>)`
465465
// with just `ArrayValue(...).$asInstanceOf[...]`
466466
//
467467
// See scala/bug#6611; we must *only* do this for literal vararg arrays.
468468
case Apply(appMeth, List(Apply(wrapRefArrayMeth, List(arg @ StripCast(ArrayValue(_, _)))), _))
469-
if wrapRefArrayMeth.symbol == currentRun.runDefinitions.Predef_wrapRefArray && appMeth.symbol == ArrayModule_genericApply =>
469+
if wrapRefArrayMeth.symbol == currentRun.runDefinitions.wrapVarargsRefArrayMethod && appMeth.symbol == ArrayModule_genericApply =>
470470
arg.transform(this)
471471
case Apply(appMeth, List(elem0, Apply(wrapArrayMeth, List(rest @ ArrayValue(elemtpt, _)))))
472-
if wrapArrayMeth.symbol == Predef_wrapArray(elemtpt.tpe) && appMeth.symbol == ArrayModule_apply(elemtpt.tpe) =>
472+
if wrapArrayMeth.symbol == wrapVarargsArrayMethod(elemtpt.tpe) && appMeth.symbol == ArrayModule_apply(elemtpt.tpe) =>
473473
treeCopy.ArrayValue(rest, rest.elemtpt, elem0 :: rest.elems).transform(this)
474474

475475
case _ =>

src/compiler/scala/tools/nsc/transform/UnCurry.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ abstract class UnCurry extends InfoTransform
255255
if (tree.tpe <:< pt) tree
256256
else gen.mkCastArray(tree, elemtp, pt)
257257

258-
gen.mkWrapArray(adaptedTree, elemtp)
258+
gen.mkWrapVarargsArray(adaptedTree, elemtp)
259259
}
260260
}
261261
}
@@ -801,7 +801,7 @@ abstract class UnCurry extends InfoTransform
801801
if (!isRep) Ident(param)
802802
else {
803803
val parTp = elementType(ArrayClass, param.tpe)
804-
val wrap = gen.mkWrapArray(Ident(param), parTp)
804+
val wrap = gen.mkWrapVarargsArray(Ident(param), parTp)
805805
param.attachments.get[TypeParamVarargsAttachment] match {
806806
case Some(TypeParamVarargsAttachment(tp)) => gen.mkCast(wrap, seqType(tp))
807807
case _ => wrap

src/compiler/scala/tools/nsc/typechecker/RefChecks.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ abstract class RefChecks extends Transform {
197197
val params = bridge.paramss.head
198198
val elemtp = params.last.tpe.typeArgs.head
199199
val idents = params map Ident
200-
val lastarg = gen.wildcardStar(gen.mkWrapArray(idents.last, elemtp))
200+
val lastarg = gen.wildcardStar(gen.mkWrapVarargsArray(idents.last, elemtp))
201201
val body = Apply(Select(This(clazz), member), idents.init :+ lastarg)
202202

203203
localTyper typed DefDef(bridge, body)

src/reflect/scala/reflect/internal/Definitions.scala

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ package reflect
88
package internal
99

1010
import scala.language.postfixOps
11-
12-
import scala.annotation.meta
11+
import scala.annotation.{meta, migration}
1312
import scala.collection.mutable
1413
import Flags._
1514
import scala.reflect.api.{Universe => ApiUniverse}
@@ -349,12 +348,15 @@ trait Definitions extends api.StandardDefinitions {
349348
lazy val UnqualifiedOwners = UnqualifiedModules.toSet ++ UnqualifiedModules.map(_.moduleClass)
350349

351350
lazy val PredefModule = requiredModule[scala.Predef.type]
352-
def Predef_wrapArray(tp: Type) = getMemberMethod(PredefModule, wrapArrayMethodName(tp))
353351
def Predef_??? = getMemberMethod(PredefModule, nme.???)
354352
def isPredefMemberNamed(sym: Symbol, name: Name) = (
355353
(sym.name == name) && (sym.owner == PredefModule.moduleClass)
356354
)
357355

356+
// This is a not the usual lazy val to prevent it from showing up as a separate module in JavaUniverseForce.scala
357+
def getWrapVarargsArrayModule = if(isNewCollections) ScalaRunTimeModule else PredefModule
358+
def wrapVarargsArrayMethod(tp: Type) = getMemberMethod(getWrapVarargsArrayModule, wrapVarargsArrayMethodName(tp))
359+
358360
/** Specialization.
359361
*/
360362
lazy val SpecializableModule = requiredModule[Specializable]
@@ -429,20 +431,24 @@ trait Definitions extends api.StandardDefinitions {
429431
def elementType(container: Symbol, tp: Type): Type = elementExtract(container, tp)
430432

431433
// collections classes
434+
private[this] lazy val isNewCollections = getClassIfDefined("scala.collection.IterableOnce") != NoSymbol
432435
lazy val ConsClass = requiredClass[scala.collection.immutable.::[_]]
433436
lazy val IteratorClass = requiredClass[scala.collection.Iterator[_]]
434437
lazy val IterableClass = requiredClass[scala.collection.Iterable[_]]
435438
lazy val ListClass = requiredClass[scala.collection.immutable.List[_]]
436-
lazy val SeqClass = requiredClass[scala.collection.Seq[_]]
439+
@migration("SeqClass now refers to scala.collection.immutable.Seq", "2.13.0")
440+
lazy val SeqClass = if(isNewCollections) requiredClass[scala.collection.immutable.Seq[_]] else requiredClass[scala.collection.Seq[_]]
437441
lazy val JavaStringBuilderClass = requiredClass[java.lang.StringBuilder]
438442
lazy val JavaStringBufferClass = requiredClass[java.lang.StringBuffer]
439443
lazy val JavaCharSequenceClass = requiredClass[java.lang.CharSequence]
440-
lazy val TraversableClass = requiredClass[scala.collection.Traversable[_]]
444+
@deprecated("Use IterableClass instead of TraversableClass", "2.13.0")
445+
lazy val TraversableClass = if(isNewCollections) IterableClass else requiredClass[scala.collection.Traversable[_]]
441446

442447
lazy val ListModule = requiredModule[scala.collection.immutable.List.type]
443448
def List_apply = getMemberMethod(ListModule, nme.apply)
444449
lazy val NilModule = requiredModule[scala.collection.immutable.Nil.type]
445-
lazy val SeqModule = requiredModule[scala.collection.Seq.type]
450+
@migration("SeqModule now refers to scala.collection.immutable.Seq", "2.13.0")
451+
lazy val SeqModule = if(isNewCollections) requiredModule[scala.collection.immutable.Seq.type] else requiredModule[scala.collection.Seq.type]
446452

447453
// arrays and their members
448454
lazy val ArrayModule = requiredModule[scala.Array.type]
@@ -588,7 +594,7 @@ trait Definitions extends api.StandardDefinitions {
588594
def functionType(formals: List[Type], restpe: Type) = FunctionClass.specificType(formals, restpe)
589595
def abstractFunctionType(formals: List[Type], restpe: Type) = AbstractFunctionClass.specificType(formals, restpe)
590596

591-
def wrapArrayMethodName(elemtp: Type): TermName = elemtp.typeSymbol match {
597+
def wrapVarargsArrayMethodName(elemtp: Type): TermName = elemtp.typeSymbol match {
592598
case ByteClass => nme.wrapByteArray
593599
case ShortClass => nme.wrapShortArray
594600
case CharClass => nme.wrapCharArray
@@ -1494,7 +1500,6 @@ trait Definitions extends api.StandardDefinitions {
14941500
orElse getMemberMethod(PredefModule, TermName("conforms"))) // TODO: predicate on -Xsource:2.10 (for now, needed for transition from M8 -> RC1)
14951501
lazy val Predef_classOf = getMemberMethod(PredefModule, nme.classOf)
14961502
lazy val Predef_implicitly = getMemberMethod(PredefModule, nme.implicitly)
1497-
lazy val Predef_wrapRefArray = getMemberMethod(PredefModule, nme.wrapRefArray)
14981503
lazy val Predef_??? = DefinitionsClass.this.Predef_???
14991504

15001505
lazy val arrayApplyMethod = getMemberMethod(ScalaRunTimeModule, nme.array_apply)
@@ -1504,6 +1509,7 @@ trait Definitions extends api.StandardDefinitions {
15041509
lazy val ensureAccessibleMethod = getMemberMethod(ScalaRunTimeModule, nme.ensureAccessible)
15051510
lazy val arrayClassMethod = getMemberMethod(ScalaRunTimeModule, nme.arrayClass)
15061511
lazy val traversableDropMethod = getMemberMethod(ScalaRunTimeModule, nme.drop)
1512+
lazy val wrapVarargsRefArrayMethod = getMemberMethod(getWrapVarargsArrayModule, nme.wrapRefArray)
15071513

15081514
lazy val GroupOfSpecializable = getMemberClass(SpecializableModule, tpnme.Group)
15091515

0 commit comments

Comments
 (0)