Skip to content

Convert List.apply into :: chains #18567

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

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ abstract class AccessProxies {
def addAccessorDefs(cls: Symbol, body: List[Tree])(using Context): List[Tree] = {
val accDefs = accessorDefs(cls).toList
transforms.println(i"add accessors for $cls: $accDefs%, %")
if (accDefs.isEmpty) body else body ++ accDefs
if (accDefs.isEmpty) body else body ::: accDefs
}

trait Insert {
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/BetaReduce.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ object BetaReduce:
case _ => None
tree match
case Apply(Select(fn, nme.apply), args) if defn.isFunctionNType(fn.tpe) =>
recur(fn, List(args)) match
recur(fn, args :: Nil) match
case Some(reduced) =>
seq(bindingsBuf.result(), reduced).withSpan(tree.span)
case None =>
tree
case Apply(TypeApply(Select(fn, nme.apply), targs), args) if fn.tpe.typeSymbol eq dotc.core.Symbols.defn.PolyFunctionClass =>
recur(fn, List(targs, args)) match
recur(fn, targs :: args :: Nil) match
case Some(reduced) =>
seq(bindingsBuf.result(), reduced).withSpan(tree.span)
case None =>
Expand Down
20 changes: 14 additions & 6 deletions compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
Expand Up @@ -561,11 +561,19 @@ object CheckUnused:
else
Nil
val warnings =
List(sortedImp, sortedLocalDefs, sortedExplicitParams, sortedImplicitParams,
sortedPrivateDefs, sortedPatVars, unsetLocalDefs, unsetPrivateDefs).flatten.sortBy { s =>
val pos = s.pos.sourcePos
(pos.line, pos.column)
}
val unsorted = sortedImp :::
sortedLocalDefs :::
sortedExplicitParams :::
sortedImplicitParams :::
sortedPrivateDefs :::
sortedPatVars :::
unsetLocalDefs :::
unsetPrivateDefs

unsorted.sortBy { s =>
val pos = s.pos.sourcePos
(pos.line, pos.column)
}
UnusedResult(warnings.toSet)
end getUnused
//============================ HELPERS ====================================
Expand Down Expand Up @@ -705,7 +713,7 @@ object CheckUnused:
sym.everySymbol.exists(usedDef.apply)

private def everySymbol(using Context): List[Symbol] =
List(sym, sym.companionClass, sym.companionModule, sym.moduleClass).filter(_.exists)
(sym :: sym.companionClass :: sym.companionModule :: sym.moduleClass :: Nil).filter(_.exists)

/** A function is overriden. Either has `override flags` or parent has a matching member (type and name) */
private def isOverriden(using Context): Boolean =
Expand Down
16 changes: 8 additions & 8 deletions compiler/src/dotty/tools/dotc/transform/CompleteJavaEnums.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class CompleteJavaEnums extends MiniPhase with InfoTransformer { thisPhase =>
tp.derivedLambdaType(resType = addConstrParams(restpe))
case _ =>
tp.derivedLambdaType(
paramNames = tp.paramNames ++ List(nameParamName, ordinalParamName),
paramInfos = tp.paramInfos ++ List(defn.StringType, defn.IntType))
paramNames = tp.paramNames ::: (nameParamName :: ordinalParamName :: Nil),
paramInfos = tp.paramInfos ::: (defn.StringType :: defn.IntType :: Nil))
}
}

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

/** Add arguments `args` to the parent constructor application in `parents` that invokes
Expand All @@ -81,7 +81,7 @@ class CompleteJavaEnums extends MiniPhase with InfoTransformer { thisPhase =>
case app @ Apply(fn, args0) if fn.symbol.owner == targetCls =>
if args0.nonEmpty && targetCls == defn.JavaEnumClass then
report.error(em"the constructor of java.lang.Enum cannot be called explicitly", app.sourcePos)
cpy.Apply(app)(fn, args0 ++ args)
cpy.Apply(app)(fn, args0 ::: args)
case p => p
}

Expand All @@ -92,7 +92,7 @@ class CompleteJavaEnums extends MiniPhase with InfoTransformer { thisPhase =>
val tree1 = cpy.DefDef(tree)(
paramss = tree.paramss.init
:+ (tree.paramss.last.asInstanceOf[List[ValDef]]
++ addedParams(sym, isLocal=false, Param)))
::: addedParams(sym, isLocal=false, Param)))
sym.setParamssFromDefs(tree1.paramss)
tree1
else tree
Expand Down Expand Up @@ -167,15 +167,15 @@ class CompleteJavaEnums extends MiniPhase with InfoTransformer { thisPhase =>
val addedForwarders = addedEnumForwarders(cls)
cpy.Template(templ)(
parents = addEnumConstrArgs(defn.JavaEnumClass, templ.parents, addedSyms.map(ref)),
body = params ++ addedDefs ++ addedForwarders ++ rest)
body = params ::: addedDefs ::: addedForwarders ::: rest)
else if isJavaEnumValueImpl(cls) then
def creatorParamRef(name: TermName) =
ref(cls.owner.paramSymss.head.find(_.name == name).get)
val args =
if cls.owner.isAllOf(EnumCase) then
List(Literal(Constant(cls.owner.name.toString)), Literal(Constant(ordinalFor(cls.owner))))
Literal(Constant(cls.owner.name.toString)) :: Literal(Constant(ordinalFor(cls.owner))) :: Nil
else
List(creatorParamRef(nme.nameDollar), creatorParamRef(nme.ordinalDollar_))
creatorParamRef(nme.nameDollar) :: creatorParamRef(nme.ordinalDollar_) :: Nil
cpy.Template(templ)(
parents = addEnumConstrArgs(cls.owner.owner.linkedClass, templ.parents, args),
)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -859,9 +859,9 @@ object Erasure {
case Block(stats, expr) =>
cpy.Block(fun1)(stats, app(expr))
case Apply(fun2, SeqLiteral(prevArgs, argTpt) :: _) if bunchArgs =>
mkApply(fun2, JavaSeqLiteral(prevArgs ++ args1, argTpt) :: Nil)
mkApply(fun2, JavaSeqLiteral(prevArgs ::: args1, argTpt) :: Nil)
case Apply(fun2, prevArgs) =>
mkApply(fun2, prevArgs ++ args1)
mkApply(fun2, prevArgs ::: args1)
case _ if bunchArgs =>
mkApply(fun1, JavaSeqLiteral(args1, TypeTree(defn.ObjectType)) :: Nil)
case _ =>
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/transform/ExpandSAMs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class ExpandSAMs extends MiniPhase:
val tpe1 = collectAndStripRefinements(tpe)
val Seq(samDenot) = tpe1.possibleSamMethods
cpy.Block(tree)(stats,
AnonClass(List(tpe1),
List(samDenot.symbol.asTerm.name -> fn.symbol.asTerm),
AnonClass(tpe1 :: Nil,
samDenot.symbol.asTerm.name -> fn.symbol.asTerm :: Nil,
refinements.toList
)
)
Expand Down Expand Up @@ -134,9 +134,9 @@ class ExpandSAMs extends MiniPhase:
val pfRHS = partialFunRHS(anon.rhs)
val anonSym = anon.symbol
val anonTpe = anon.tpe.widen
val parents = List(
defn.AbstractPartialFunctionClass.typeRef.appliedTo(anonTpe.firstParamTypes.head, anonTpe.resultType),
defn.SerializableType)
val parents =
defn.AbstractPartialFunctionClass.typeRef.appliedTo(anonTpe.firstParamTypes.head, anonTpe.resultType) ::
defn.SerializableType :: Nil

AnonClass(anonSym.owner, parents, tree.span) { pfSym =>
def overrideSym(sym: Symbol) = sym.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ class ExtensionMethods extends MiniPhase with DenotTransformer with FullParamete
val underlying = valueErasure(underlyingOfValueClass(valueClass))
val evt = ErasedValueType(valueClass.typeRef, underlying)
val u2evtSym = newSymbol(moduleSym, nme.U2EVT, Synthetic | Method,
MethodType(List(nme.x_0), List(underlying), evt))
MethodType(nme.x_0 :: Nil, underlying :: Nil, evt))
val evt2uSym = newSymbol(moduleSym, nme.EVT2U, Synthetic | Method,
MethodType(List(nme.x_0), List(evt), underlying))
MethodType(nme.x_0 :: Nil, evt :: Nil, underlying))
enterInModuleClass(u2evtSym)
enterInModuleClass(evt2uSym)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ trait FullParameterization {

info match {
case info: PolyType =>
PolyType(info.paramNames ++ ctnames)(
PolyType(info.paramNames ::: ctnames)(
pt =>
(info.paramInfos.map(mapClassParams(_, pt).bounds) ++
(info.paramInfos.map(mapClassParams(_, pt).bounds) :::
mappedClassBounds(pt)).mapConserve(_.subst(info, pt).bounds),
pt => resultType(mapClassParams(_, pt)).subst(info, pt))
case _ =>
Expand Down Expand Up @@ -164,7 +164,7 @@ trait FullParameterization {
val base = thisArg.tpe.baseType(origClass)
assert(base.exists)
ref(rewired.termRef)
.appliedToTypeTrees(targs ++ base.argInfos.map(TypeTree(_)))
.appliedToTypeTrees(targs ::: base.argInfos.map(TypeTree(_)))
.appliedTo(thisArg)
} else EmptyTree
}
Expand Down Expand Up @@ -204,7 +204,7 @@ trait FullParameterization {

new TreeTypeMap(
typeMap = rewireType(_)
.subst(origLeadingTypeParamSyms ++ origOtherParamSyms, (trefs ++ argRefs).tpes)
.subst(origLeadingTypeParamSyms ::: origOtherParamSyms, (trefs ::: argRefs).tpes)
.substThisUnlessStatic(origClass, thisRef.tpe),
treeMap = {
case tree: This if tree.symbol == origClass => thisRef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FunctionXXLForwarders extends MiniPhase with IdentityDenotTransformer {
var idx = -1
val argss = receiver.tpe.widenDealias.paramInfoss.map(_.map { param =>
idx += 1
argsApply.appliedToTermArgs(List(Literal(Constant(idx)))).cast(param)
argsApply.appliedToTermArgs(Literal(Constant(idx)) :: Nil).cast(param)
})
ref(receiver.symbol).appliedToArgss(argss).cast(defn.ObjectType)
}
Expand All @@ -51,8 +51,8 @@ class FunctionXXLForwarders extends MiniPhase with IdentityDenotTransformer {
ddef.symbol.allOverriddenSymbols.exists(sym => defn.isXXLFunctionClass(sym.owner))
}
yield {
val xsType = defn.ArrayType.appliedTo(List(defn.ObjectType))
val methType = MethodType(List(nme.args))(_ => List(xsType), _ => defn.ObjectType)
val xsType = defn.ArrayType.appliedTo(defn.ObjectType :: Nil)
val methType = MethodType(nme.args :: Nil)(_ => xsType :: Nil, _ => defn.ObjectType)
val meth = newSymbol(ddef.symbol.owner, nme.apply, Synthetic | Method, methType)
DefDef(meth, paramss => forwarderRhs(ddef, paramss.head.head))
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/HoistSuperArgs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class HoistSuperArgs extends MiniPhase with IdentityDenotTransformer { thisPhase

/** The parameter references defined by the constructor info */
def allParamRefs(tp: Type): List[ParamRef] = tp match {
case tp: LambdaType => tp.paramRefs ++ allParamRefs(tp.resultType)
case tp: LambdaType => tp.paramRefs ::: allParamRefs(tp.resultType)
case _ => Nil
}

Expand Down Expand Up @@ -236,7 +236,7 @@ class HoistSuperArgs extends MiniPhase with IdentityDenotTransformer { thisPhase
cpy.TypeDef(tdef)(
rhs = cpy.Template(impl)(
parents = hoistedSuperCall :: others,
body = hoistedBody ++ staticSuperArgDefs)) ::
body = hoistedBody ::: staticSuperArgDefs)) ::
enclSuperArgDefs)
}
case _ =>
Expand Down
23 changes: 11 additions & 12 deletions compiler/src/dotty/tools/dotc/transform/Instrumentation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@ class Instrumentation extends MiniPhase { thisPhase =>
override def isEnabled(using Context) =
ctx.settings.Yinstrument.value

private val collectionNamesOfInterest = List(
"map", "flatMap", "filter", "filterNot", "withFilter", "collect", "flatten", "foldLeft", "foldRight", "take",
"reverse", "zip", "++", ":::", ":+", "distinct", "dropRight", "takeRight", "groupBy", "groupMap", "init", "inits",
"interect", "mkString", "partition", "reverse_:::", "scanLeft", "scanRight",
"sortBy", "sortWith", "sorted", "span", "splitAt", "takeWhile", "transpose", "unzip", "unzip3",
"updated", "zipAll", "zipWithIndex",
"mapConserve", "mapconserve", "filterConserve", "zipWithConserve", "mapWithIndexConserve"
)

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

private val namesOfInterest = collectionNamesOfInterest ::: (
"::" :: "+=" :: "toString" :: "newArray" :: "box" :: "toCharArray" :: "termName" :: "typeName" ::
"slice" :: "staticRef" :: "requiredClass" :: Nil)

private var namesToRecord: Set[Name] = _
private var collectionNamesToRecord: Set[Name] = _
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/transform/LambdaLift.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ object LambdaLift:
case MethodTpe(pnames, ptypes, restpe) =>
val ps = proxies(local)
MethodType(
ps.map(_.name.asTermName) ++ pnames,
ps.map(_.info) ++ ptypes,
ps.map(_.name.asTermName) ::: pnames,
ps.map(_.info) ::: ptypes,
restpe)
case info => info
}
Expand Down Expand Up @@ -169,7 +169,7 @@ object LambdaLift:

def addFreeArgs(sym: Symbol, args: List[Tree])(using Context): List[Tree] =
val fvs = deps.freeVars(sym)
if fvs.nonEmpty then fvs.toList.map(proxyRef(_)) ++ args else args
if fvs.nonEmpty then fvs.toList.map(proxyRef(_)) ::: args else args

def addFreeParams(tree: Tree, proxies: List[Symbol])(using Context): Tree = proxies match {
case Nil => tree
Expand All @@ -192,12 +192,12 @@ object LambdaLift:
tree match {
case tree: DefDef =>
cpy.DefDef(tree)(
paramss = tree.termParamss.map(freeParamDefs ++ _),
paramss = tree.termParamss.map(freeParamDefs ::: _),
rhs =
if (sym.isPrimaryConstructor && !sym.owner.is(Trait)) copyParams(tree.rhs)
else tree.rhs)
case tree: Template =>
cpy.Template(tree)(body = freeParamDefs ++ tree.body)
cpy.Template(tree)(body = freeParamDefs ::: tree.body)
}
}

Expand Down
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/transform/LazyVals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
Block(stats.init, stats.last),
unitLiteral
)
DefDef(sym.asTerm, Block(List(init), targetRef.ensureApplied))
DefDef(sym.asTerm, Block(init :: Nil, targetRef.ensureApplied))
}

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

def transformMemberDefThreadUnsafe(x: ValOrDefDef)(using Context): Thicket = {
Expand Down Expand Up @@ -567,13 +567,13 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
CaseDef(
Bind(caseSymbol, ref(caseSymbol)),
EmptyTree,
Block(List(triggerRetry), Throw(ref(caseSymbol)))
Block(triggerRetry :: Nil, Throw(ref(caseSymbol)))
)
}

val initialize = If(
casFlag.appliedTo(thiz, offset, flagRef, computeState, fieldId),
Try(compute, List(retryCase), EmptyTree),
Try(compute, retryCase :: Nil, EmptyTree),
unitLiteral
)

Expand All @@ -587,7 +587,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
)
)

val loop = WhileDo(EmptyTree, Block(List(flagDef, stateDef), condition))
val loop = WhileDo(EmptyTree, Block(flagDef :: stateDef :: Nil, condition))
DefDef(methodSymbol, loop)
}

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

val containerName = LazyLocalName.fresh(x.name.asTermName)
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/transform/MacroAnnotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ class MacroAnnotations:
*/
def expandAnnotations(tree: MemberDef)(using Context): List[DefTree] =
if !hasMacroAnnotation(tree.symbol) then
List(tree)
tree :: Nil
else if tree.symbol.is(Module) && !tree.symbol.isClass then
// only class is transformed
List(tree)
tree :: Nil
else if tree.symbol.isType && !tree.symbol.isClass then
report.error("macro annotations are not supported on type", tree)
List(tree)
tree :: Nil
else
debug.println(i"Expanding macro annotations of:\n$tree")

Expand All @@ -63,7 +63,7 @@ class MacroAnnotations:
case ex: scala.quoted.runtime.StopMacroExpansion =>
if !ctx.reporter.hasErrors then
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)
List(tree)
tree :: Nil
case Interpreter.MissingClassDefinedInCurrentRun(sym) =>
Interpreter.suspendOnMissing(sym, annot.tree)
case NonFatal(ex) =>
Expand All @@ -75,7 +75,7 @@ class MacroAnnotations:
| ${stack.mkString("\n ")}
|"""
report.error(msg, annot.tree)
List(tree)
tree :: Nil
case _ =>
throw ex0
transformedTrees.span(_.symbol != tree.symbol) match
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Mixin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase =>
else if (getter.is(Lazy, butNot = Module))
transformFollowing(superRef(getter).appliedToNone)
else if (getter.is(Module))
New(getter.info.resultType, List(This(cls)))
New(getter.info.resultType, This(cls) :: Nil)
else
Underscore(getter.info.resultType)
// transformFollowing call is needed to make memoize & lazy vals run
Expand Down
Loading