From 516623915e3293bca5757a59d4f3ca0b5e01984f Mon Sep 17 00:00:00 2001 From: Joyti Goel Date: Tue, 13 Dec 2022 15:46:38 +0100 Subject: [PATCH] final touches --- .../dotty/tools/dotc/core/Definitions.scala | 6 ++- .../dotty/tools/dotc/typer/Applications.scala | 40 ++++++------------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 9bbab14bb70c..e60a186c2682 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -466,6 +466,7 @@ class Definitions { cls.entered cls } + def AnyKindType: TypeRef = AnyKindClass.typeRef @tu lazy val andType: TypeSymbol = enterBinaryAlias(tpnme.AND, AndType(_, _)) @@ -543,6 +544,10 @@ class Definitions { List(AnyType), EmptyScope) @tu lazy val SingletonType: TypeRef = SingletonClass.typeRef + @tu lazy val IterableType: TypeRef = requiredClassRef("scala.collection.Iterable") + def IterableClass(using Context): ClassSymbol = IterableType.symbol.asClass + @tu lazy val Iterable_++ : Symbol = IterableClass.requiredMethod(nme.PLUSPLUS) + @tu lazy val CollectionSeqType: TypeRef = requiredClassRef("scala.collection.Seq") @tu lazy val SeqType: TypeRef = requiredClassRef("scala.collection.immutable.Seq") def SeqClass(using Context): ClassSymbol = SeqType.symbol.asClass @@ -551,7 +556,6 @@ class Definitions { @tu lazy val Seq_drop : Symbol = SeqClass.requiredMethod(nme.drop) @tu lazy val Seq_lengthCompare: Symbol = SeqClass.requiredMethod(nme.lengthCompare, List(IntType)) @tu lazy val Seq_length : Symbol = SeqClass.requiredMethod(nme.length) - @tu lazy val Seq_++ : Symbol = SeqClass.requiredMethod(nme.PLUSPLUS) @tu lazy val Seq_toSeq : Symbol = SeqClass.requiredMethod(nme.toSeq) @tu lazy val SeqModule: Symbol = requiredModule("scala.collection.immutable.Seq") diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index e574863ee346..be8bfc5b143d 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -382,11 +382,6 @@ trait Applications extends Compatibility { */ protected def isVarArg(arg: Arg): Boolean - /** If constructing trees, turn last `n` processed arguments into a - * `SeqLiteral` tree with element type `elemFormal`. - */ - protected def makeVarArg(n: Int, elemFormal: Type): Unit - /** If constructing trees, turn last `n` processed arguments into a * `SeqLiteral` tree with element type `elemFormal' without * */ @@ -598,11 +593,12 @@ trait Applications extends Compatibility { } } typedArgs.foreach(addArg(_, elemFormal)) + /** Iterates through all arguments and concatenates them with a single varArg SeqLiteral - * @param la: List of Arg that accumulates the Args arguments that are not varArgs up until the first varArg - * is encountered among arguments and the process is then repeated. - * @param counter: this counts how many Vararg arguments were added to the buffer which we pass as argumnent + * @param la: List of Arg that accumulates the arguments that are not varArgs up until the first varArg + is encountered among arguments, then the process is then repeated. + * @param counter: this counts how many Vararg arguments were added to the buffer which we pass as argument * to method argCombineVarArg. */ def concatVararg(listOfArgs: List[Arg], la: List[Arg], counter: Int): Unit = @@ -621,10 +617,7 @@ trait Applications extends Compatibility { addArg(typedArg(x1, seqElemFormal), seqElemFormal) concatVararg(xs, Nil, counter + 1) case Nil => - if (counter == 0) then - harmonizeSeq(listOfArgs, elemFormal) - makeVarArg(args.length, elemFormal) - else argCombineVarArg(counter, elemFormal) + argCombineVarArg(counter, elemFormal) def missingArg(n: Int): Unit = fail(MissingArgument(methodType.paramNames(n), methString)) @@ -753,7 +746,6 @@ trait Applications extends Compatibility { protected def argType(arg: Arg, formal: Type): Type def typedArg(arg: Arg, formal: Type): Arg = arg final def addArg(arg: TypedArg, formal: Type): Unit = ok = ok & argOK(arg, formal) - def makeVarArg(n: Int, elemFormal: Type): Unit = {} def makeSeqLiteral(n: Int, elemFormal: Type): Unit = {} def harmonizeSeq(arg: Arg, elemFormal: Type): Unit = {} def argCombineVarArg(n: Int, elemFormal: Type): Unit = {} @@ -807,14 +799,6 @@ trait Applications extends Compatibility { def addArg(arg: Tree, formal: Type): Unit = typedArgBuf += adapt(arg, formal.widenExpr) - - def makeVarArg(n: Int, elemFormal: Type): Unit = - val args = typedArgBuf.takeRight(n).toList - typedArgBuf.dropRightInPlace(n) - val elemtpt = TypeTree(elemFormal) - typedArgBuf += seqToRepeated(SeqLiteral(args, elemtpt)) - - def makeSeqLiteral(n: Int, elemFormal: Type): Unit = val args = typedArgBuf.takeRight(n).toList typedArgBuf.dropRightInPlace(n) @@ -827,13 +811,15 @@ trait Applications extends Compatibility { t.asInstanceOf[Typed].expr else t - val varArgTrees = typedArgBuf.takeRight(n) - typedArgBuf.dropRightInPlace(n) val repeatedarg = - seqToRepeated(varArgTrees.reduce{ - (lh, rh) => removeRepeated(lh).select(defn.Seq_++). - appliedToType(elemFormal).appliedTo(removeRepeated(rh))}) - typedArgBuf += repeatedarg + if (n == 0) then + SeqLiteral(List.empty, TypeTree(elemFormal)) + else + val varArgTrees = typedArgBuf.takeRight(n) + typedArgBuf.dropRightInPlace(n) + varArgTrees.map(x => removeRepeated(x)).reduce{ + (lh, rh) => lh.select(defn.Iterable_++).appliedToType(elemFormal).appliedTo(rh)} + typedArgBuf += seqToRepeated(repeatedarg) def harmonizeArgs(args: List[TypedArg]): List[Tree] =