Skip to content

Commit 45ad0a8

Browse files
committed
Convert List.apply into :: chains
1 parent a37dac6 commit 45ad0a8

24 files changed

+114
-111
lines changed

compiler/src/dotty/tools/dotc/transform/BetaReduce.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ object BetaReduce:
9191
case _ => None
9292
tree match
9393
case Apply(Select(fn, nme.apply), args) if defn.isFunctionNType(fn.tpe) =>
94-
recur(fn, List(args)) match
94+
recur(fn, args :: Nil) match
9595
case Some(reduced) =>
9696
seq(bindingsBuf.result(), reduced).withSpan(tree.span)
9797
case None =>
9898
tree
9999
case Apply(TypeApply(Select(fn, nme.apply), targs), args) if fn.tpe.typeSymbol eq dotc.core.Symbols.defn.PolyFunctionClass =>
100-
recur(fn, List(targs, args)) match
100+
recur(fn, targs :: args :: Nil) match
101101
case Some(reduced) =>
102102
seq(bindingsBuf.result(), reduced).withSpan(tree.span)
103103
case None =>

compiler/src/dotty/tools/dotc/transform/CheckUnused.scala

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,19 @@ object CheckUnused:
561561
else
562562
Nil
563563
val warnings =
564-
List(sortedImp, sortedLocalDefs, sortedExplicitParams, sortedImplicitParams,
565-
sortedPrivateDefs, sortedPatVars, unsetLocalDefs, unsetPrivateDefs).flatten.sortBy { s =>
566-
val pos = s.pos.sourcePos
567-
(pos.line, pos.column)
568-
}
564+
val unsorted = sortedImp ++
565+
sortedLocalDefs ++
566+
sortedExplicitParams ++
567+
sortedImplicitParams ++
568+
sortedPrivateDefs ++
569+
sortedPatVars ++
570+
unsetLocalDefs ++
571+
unsetPrivateDefs
572+
573+
unsorted.sortBy { s =>
574+
val pos = s.pos.sourcePos
575+
(pos.line, pos.column)
576+
}
569577
UnusedResult(warnings.toSet)
570578
end getUnused
571579
//============================ HELPERS ====================================
@@ -705,7 +713,7 @@ object CheckUnused:
705713
sym.everySymbol.exists(usedDef.apply)
706714

707715
private def everySymbol(using Context): List[Symbol] =
708-
List(sym, sym.companionClass, sym.companionModule, sym.moduleClass).filter(_.exists)
716+
(sym :: sym.companionClass :: sym.companionModule :: sym.moduleClass :: Nil).filter(_.exists)
709717

710718
/** A function is overriden. Either has `override flags` or parent has a matching member (type and name) */
711719
private def isOverriden(using Context): Boolean =

compiler/src/dotty/tools/dotc/transform/CompleteJavaEnums.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class CompleteJavaEnums extends MiniPhase with InfoTransformer { thisPhase =>
5858
tp.derivedLambdaType(resType = addConstrParams(restpe))
5959
case _ =>
6060
tp.derivedLambdaType(
61-
paramNames = tp.paramNames ++ List(nameParamName, ordinalParamName),
62-
paramInfos = tp.paramInfos ++ List(defn.StringType, defn.IntType))
61+
paramNames = tp.paramNames ++ (nameParamName :: ordinalParamName :: Nil),
62+
paramInfos = tp.paramInfos ++ (defn.StringType :: defn.IntType :: Nil))
6363
}
6464
}
6565

@@ -70,7 +70,7 @@ class CompleteJavaEnums extends MiniPhase with InfoTransformer { thisPhase =>
7070
val flags = flag | Synthetic | (if isLocal then Private | Deferred else EmptyFlags)
7171
val nameParam = newSymbol(owner, nameParamName, flags, defn.StringType, coord = owner.span)
7272
val ordinalParam = newSymbol(owner, ordinalParamName, flags, defn.IntType, coord = owner.span)
73-
List(ValDef(nameParam), ValDef(ordinalParam))
73+
ValDef(nameParam) :: ValDef(ordinalParam) :: Nil
7474
}
7575

7676
/** Add arguments `args` to the parent constructor application in `parents` that invokes
@@ -173,9 +173,9 @@ class CompleteJavaEnums extends MiniPhase with InfoTransformer { thisPhase =>
173173
ref(cls.owner.paramSymss.head.find(_.name == name).get)
174174
val args =
175175
if cls.owner.isAllOf(EnumCase) then
176-
List(Literal(Constant(cls.owner.name.toString)), Literal(Constant(ordinalFor(cls.owner))))
176+
Literal(Constant(cls.owner.name.toString)) :: Literal(Constant(ordinalFor(cls.owner))) :: Nil
177177
else
178-
List(creatorParamRef(nme.nameDollar), creatorParamRef(nme.ordinalDollar_))
178+
creatorParamRef(nme.nameDollar) :: creatorParamRef(nme.ordinalDollar_) :: Nil
179179
cpy.Template(templ)(
180180
parents = addEnumConstrArgs(cls.owner.owner.linkedClass, templ.parents, args),
181181
)

compiler/src/dotty/tools/dotc/transform/ExpandSAMs.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class ExpandSAMs extends MiniPhase:
6969
val tpe1 = collectAndStripRefinements(tpe)
7070
val Seq(samDenot) = tpe1.possibleSamMethods
7171
cpy.Block(tree)(stats,
72-
AnonClass(List(tpe1),
73-
List(samDenot.symbol.asTerm.name -> fn.symbol.asTerm),
72+
AnonClass(tpe1 :: Nil,
73+
samDenot.symbol.asTerm.name -> fn.symbol.asTerm :: Nil,
7474
refinements.toList
7575
)
7676
)
@@ -134,9 +134,9 @@ class ExpandSAMs extends MiniPhase:
134134
val pfRHS = partialFunRHS(anon.rhs)
135135
val anonSym = anon.symbol
136136
val anonTpe = anon.tpe.widen
137-
val parents = List(
138-
defn.AbstractPartialFunctionClass.typeRef.appliedTo(anonTpe.firstParamTypes.head, anonTpe.resultType),
139-
defn.SerializableType)
137+
val parents =
138+
defn.AbstractPartialFunctionClass.typeRef.appliedTo(anonTpe.firstParamTypes.head, anonTpe.resultType) ::
139+
defn.SerializableType :: Nil
140140

141141
AnonClass(anonSym.owner, parents, tree.span) { pfSym =>
142142
def overrideSym(sym: Symbol) = sym.copy(

compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ class ExtensionMethods extends MiniPhase with DenotTransformer with FullParamete
8787
val underlying = valueErasure(underlyingOfValueClass(valueClass))
8888
val evt = ErasedValueType(valueClass.typeRef, underlying)
8989
val u2evtSym = newSymbol(moduleSym, nme.U2EVT, Synthetic | Method,
90-
MethodType(List(nme.x_0), List(underlying), evt))
90+
MethodType(nme.x_0 :: Nil, underlying :: Nil, evt))
9191
val evt2uSym = newSymbol(moduleSym, nme.EVT2U, Synthetic | Method,
92-
MethodType(List(nme.x_0), List(evt), underlying))
92+
MethodType(nme.x_0 :: Nil, evt :: Nil, underlying))
9393
enterInModuleClass(u2evtSym)
9494
enterInModuleClass(evt2uSym)
9595

compiler/src/dotty/tools/dotc/transform/FunctionXXLForwarders.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class FunctionXXLForwarders extends MiniPhase with IdentityDenotTransformer {
3636
var idx = -1
3737
val argss = receiver.tpe.widenDealias.paramInfoss.map(_.map { param =>
3838
idx += 1
39-
argsApply.appliedToTermArgs(List(Literal(Constant(idx)))).cast(param)
39+
argsApply.appliedToTermArgs(Literal(Constant(idx)) :: Nil).cast(param)
4040
})
4141
ref(receiver.symbol).appliedToArgss(argss).cast(defn.ObjectType)
4242
}
@@ -51,8 +51,8 @@ class FunctionXXLForwarders extends MiniPhase with IdentityDenotTransformer {
5151
ddef.symbol.allOverriddenSymbols.exists(sym => defn.isXXLFunctionClass(sym.owner))
5252
}
5353
yield {
54-
val xsType = defn.ArrayType.appliedTo(List(defn.ObjectType))
55-
val methType = MethodType(List(nme.args))(_ => List(xsType), _ => defn.ObjectType)
54+
val xsType = defn.ArrayType.appliedTo(defn.ObjectType :: Nil)
55+
val methType = MethodType(nme.args :: Nil)(_ => xsType :: Nil, _ => defn.ObjectType)
5656
val meth = newSymbol(ddef.symbol.owner, nme.apply, Synthetic | Method, methType)
5757
DefDef(meth, paramss => forwarderRhs(ddef, paramss.head.head))
5858
}

compiler/src/dotty/tools/dotc/transform/Instrumentation.scala

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,17 @@ class Instrumentation extends MiniPhase { thisPhase =>
2727
override def isEnabled(using Context) =
2828
ctx.settings.Yinstrument.value
2929

30-
private val collectionNamesOfInterest = List(
31-
"map", "flatMap", "filter", "filterNot", "withFilter", "collect", "flatten", "foldLeft", "foldRight", "take",
32-
"reverse", "zip", "++", ":::", ":+", "distinct", "dropRight", "takeRight", "groupBy", "groupMap", "init", "inits",
33-
"interect", "mkString", "partition", "reverse_:::", "scanLeft", "scanRight",
34-
"sortBy", "sortWith", "sorted", "span", "splitAt", "takeWhile", "transpose", "unzip", "unzip3",
35-
"updated", "zipAll", "zipWithIndex",
36-
"mapConserve", "mapconserve", "filterConserve", "zipWithConserve", "mapWithIndexConserve"
37-
)
38-
39-
private val namesOfInterest = collectionNamesOfInterest ++ List(
40-
"::", "+=", "toString", "newArray", "box", "toCharArray", "termName", "typeName",
41-
"slice", "staticRef", "requiredClass")
30+
private val collectionNamesOfInterest =
31+
"map" :: "flatMap" :: "filter" :: "filterNot" :: "withFilter" :: "collect" :: "flatten" :: "foldLeft" :: "foldRight" :: "take" ::
32+
"reverse" :: "zip" :: "++" :: ":::" :: ":+" :: "distinct" :: "dropRight" :: "takeRight" :: "groupBy" :: "groupMap" :: "init" :: "inits" ::
33+
"interect" :: "mkString" :: "partition" :: "reverse_:::" :: "scanLeft" :: "scanRight" ::
34+
"sortBy" :: "sortWith" :: "sorted" :: "span" :: "splitAt" :: "takeWhile" :: "transpose" :: "unzip" :: "unzip3" ::
35+
"updated" :: "zipAll" :: "zipWithIndex" ::
36+
"mapConserve" :: "mapconserve" :: "filterConserve" :: "zipWithConserve" :: "mapWithIndexConserve" :: Nil
37+
38+
private val namesOfInterest = collectionNamesOfInterest ++ (
39+
"::" :: "+=" :: "toString" :: "newArray" :: "box" :: "toCharArray" :: "termName" :: "typeName" ::
40+
"slice" :: "staticRef" :: "requiredClass" :: Nil)
4241

4342
private var namesToRecord: Set[Name] = _
4443
private var collectionNamesToRecord: Set[Name] = _

compiler/src/dotty/tools/dotc/transform/LazyVals.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
227227
Block(stats.init, stats.last),
228228
unitLiteral
229229
)
230-
DefDef(sym.asTerm, Block(List(init), targetRef.ensureApplied))
230+
DefDef(sym.asTerm, Block(init :: Nil, targetRef.ensureApplied))
231231
}
232232

233233
/** Create thread-unsafe lazy accessor for not-nullable types equivalent to such code
@@ -249,7 +249,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
249249
Block(stats.init, stats.last),
250250
unitLiteral
251251
)
252-
DefDef(sym.asTerm, Block(List(init), targetRef.ensureApplied))
252+
DefDef(sym.asTerm, Block(init :: Nil, targetRef.ensureApplied))
253253
}
254254

255255
def transformMemberDefThreadUnsafe(x: ValOrDefDef)(using Context): Thicket = {
@@ -567,13 +567,13 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
567567
CaseDef(
568568
Bind(caseSymbol, ref(caseSymbol)),
569569
EmptyTree,
570-
Block(List(triggerRetry), Throw(ref(caseSymbol)))
570+
Block(triggerRetry :: Nil, Throw(ref(caseSymbol)))
571571
)
572572
}
573573

574574
val initialize = If(
575575
casFlag.appliedTo(thiz, offset, flagRef, computeState, fieldId),
576-
Try(compute, List(retryCase), EmptyTree),
576+
Try(compute, retryCase :: Nil, EmptyTree),
577577
unitLiteral
578578
)
579579

@@ -587,7 +587,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
587587
)
588588
)
589589

590-
val loop = WhileDo(EmptyTree, Block(List(flagDef, stateDef), condition))
590+
val loop = WhileDo(EmptyTree, Block(flagDef :: stateDef :: Nil, condition))
591591
DefDef(methodSymbol, loop)
592592
}
593593

@@ -634,7 +634,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
634634
flag = ValDef(flagSymbol, Literal(Constant(0L)))
635635
val fieldTree = thizClass.select(lazyNme.RLazyVals.getDeclaredField).appliedTo(Literal(Constant(flagName.toString)))
636636
val offsetTree = ValDef(offsetSymbol.nn, getOffsetStatic.appliedTo(fieldTree))
637-
appendOffsetDefs += (claz -> new OffsetInfo(List(offsetTree), ord))
637+
appendOffsetDefs += (claz -> new OffsetInfo(offsetTree :: Nil, ord))
638638
}
639639

640640
val containerName = LazyLocalName.fresh(x.name.asTermName)

compiler/src/dotty/tools/dotc/transform/MacroAnnotations.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ class MacroAnnotations:
3232
*/
3333
def expandAnnotations(tree: MemberDef)(using Context): List[DefTree] =
3434
if !hasMacroAnnotation(tree.symbol) then
35-
List(tree)
35+
tree :: Nil
3636
else if tree.symbol.is(Module) && !tree.symbol.isClass then
3737
// only class is transformed
38-
List(tree)
38+
tree :: Nil
3939
else if tree.symbol.isType && !tree.symbol.isClass then
4040
report.error("macro annotations are not supported on type", tree)
41-
List(tree)
41+
tree :: Nil
4242
else
4343
debug.println(i"Expanding macro annotations of:\n$tree")
4444

@@ -63,7 +63,7 @@ class MacroAnnotations:
6363
case ex: scala.quoted.runtime.StopMacroExpansion =>
6464
if !ctx.reporter.hasErrors then
6565
report.error("Macro expansion was aborted by the macro without any errors reported. Macros should issue errors to end-users when aborting a macro expansion with StopMacroExpansion.", annot.tree)
66-
List(tree)
66+
tree :: Nil
6767
case Interpreter.MissingClassDefinedInCurrentRun(sym) =>
6868
Interpreter.suspendOnMissing(sym, annot.tree)
6969
case NonFatal(ex) =>
@@ -75,7 +75,7 @@ class MacroAnnotations:
7575
| ${stack.mkString("\n ")}
7676
|"""
7777
report.error(msg, annot.tree)
78-
List(tree)
78+
tree :: Nil
7979
case _ =>
8080
throw ex0
8181
transformedTrees.span(_.symbol != tree.symbol) match

compiler/src/dotty/tools/dotc/transform/Mixin.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase =>
273273
else if (getter.is(Lazy, butNot = Module))
274274
transformFollowing(superRef(getter).appliedToNone)
275275
else if (getter.is(Module))
276-
New(getter.info.resultType, List(This(cls)))
276+
New(getter.info.resultType, This(cls) :: Nil)
277277
else
278278
Underscore(getter.info.resultType)
279279
// transformFollowing call is needed to make memoize & lazy vals run

compiler/src/dotty/tools/dotc/transform/MixinOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class MixinOps(cls: ClassSymbol, thisPhase: DenotTransformer)(using Context) {
1414
val superCls: Symbol = cls.superClass
1515
val mixins: List[ClassSymbol] = cls.mixins
1616

17-
lazy val JUnit4Annotations: List[Symbol] = List("Test", "Ignore", "Before", "After", "BeforeClass", "AfterClass").
17+
lazy val JUnit4Annotations: List[Symbol] = ("Test" :: "Ignore" :: "Before" :: "After" :: "BeforeClass" :: "AfterClass" :: Nil).
1818
map(n => getClassIfDefined("org.junit." + n)).
1919
filter(_.exists)
2020

compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,10 +1042,9 @@ object PatternMatcher {
10421042
case _ =>
10431043
end checkSwitch
10441044

1045-
val optimizations: List[(String, Plan => Plan)] = List(
1046-
"mergeTests" -> mergeTests,
1047-
"inlineVars" -> inlineVars
1048-
)
1045+
val optimizations: List[(String, Plan => Plan)] =
1046+
"mergeTests" -> mergeTests ::
1047+
"inlineVars" -> inlineVars :: Nil
10491048

10501049
/** Translate pattern match to sequence of tests. */
10511050
def translateMatch(tree: Match): Tree = {

compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ object PickleQuotes {
235235
val typeName = body.tpe.typeSymbol.name
236236
val literalValue =
237237
if lit.const.tag == Constants.NullTag || lit.const.tag == Constants.UnitTag then Nil
238-
else List(body)
238+
else body :: Nil
239239
val constModule = lit.const.tag match
240240
case Constants.BooleanTag => defn. Quotes_reflect_BooleanConstant
241241
case Constants.ByteTag => defn. Quotes_reflect_ByteConstant
@@ -321,8 +321,8 @@ object PickleQuotes {
321321
else
322322
Lambda(
323323
MethodType(
324-
List(nme.idx, nme.contents, nme.quotes).map(name => UniqueName.fresh(name).toTermName),
325-
List(defn.IntType, defn.SeqType.appliedTo(defn.AnyType), defn.QuotesClass.typeRef),
324+
(nme.idx :: nme.contents :: nme.quotes :: Nil).map(name => UniqueName.fresh(name).toTermName),
325+
defn.IntType :: defn.SeqType.appliedTo(defn.AnyType) :: defn.QuotesClass.typeRef :: Nil,
326326
defn.QuotedExprClass.typeRef.appliedTo(defn.AnyType)),
327327
args =>
328328
val cases = holeContents.zipWithIndex.map { case (splice, idx) =>
@@ -352,8 +352,8 @@ object PickleQuotes {
352352
if quote.isTypeQuote then defn.QuoteUnpickler_unpickleTypeV2
353353
else defn.QuoteUnpickler_unpickleExprV2
354354
val unpickleArgs =
355-
if quote.isTypeQuote then List(pickledQuoteStrings, types)
356-
else List(pickledQuoteStrings, types, termHoles)
355+
if quote.isTypeQuote then pickledQuoteStrings :: types :: Nil
356+
else pickledQuoteStrings :: types :: termHoles :: Nil
357357
quotes
358358
.asInstance(defn.QuoteUnpicklerClass.typeRef)
359359
.select(unpickleMeth).appliedToType(bodyType)

compiler/src/dotty/tools/dotc/transform/SelectStatic.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class SelectStatic extends MiniPhase with IdentityDenotTransformer {
5959
val tree1 =
6060
if isStaticRef && !tree.qualifier.symbol.isAllOf(JavaModule) && !tree.qualifier.isType then
6161
if isStaticOwnerRef(tree.qualifier) then ref(sym)
62-
else Block(List(tree.qualifier), ref(sym))
62+
else Block(tree.qualifier :: Nil, ref(sym))
6363
else tree
6464

6565
normalize(tree1)

compiler/src/dotty/tools/dotc/transform/Splicing.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class Splicing extends MacroTransform:
178178
val bindingsTypes = bindings.map(_.termRef.widenTermRefExpr)
179179
val methType = MethodType(bindingsTypes, newTree.tpe)
180180
val meth = newSymbol(spliceOwner, nme.ANON_FUN, Synthetic | Method, methType)
181-
val ddef = DefDef(meth, List(bindings), newTree.tpe, newTree.changeOwner(ctx.owner, meth))
181+
val ddef = DefDef(meth, bindings :: Nil, newTree.tpe, newTree.changeOwner(ctx.owner, meth))
182182
val fnType = defn.FunctionType(bindings.size, isContextual = false).appliedTo(bindingsTypes :+ newTree.tpe)
183183
val closure = Block(ddef :: Nil, Closure(Nil, ref(meth), TypeTree(fnType)))
184184
tpd.Hole(true, holeIdx, refs, closure, tpe)
@@ -348,7 +348,7 @@ class Splicing extends MacroTransform:
348348
private def spliced(tpe: Type)(body: Context ?=> Tree)(using Context): Tree =
349349
val exprTpe = defn.QuotedExprClass.typeRef.appliedTo(tpe)
350350
val closure =
351-
val methTpe = ContextualMethodType(List(defn.QuotesClass.typeRef), exprTpe)
351+
val methTpe = ContextualMethodType(defn.QuotesClass.typeRef :: Nil, exprTpe)
352352
val meth = newSymbol(ctx.owner, nme.ANON_FUN, Synthetic | Method, methTpe)
353353
Closure(meth, argss => {
354354
withCurrentQuote(argss.head.head) {

0 commit comments

Comments
 (0)