Skip to content

Commit dcf6124

Browse files
committed
Make polyDefDef pass type trees instead of types
This is a first step towards passing reference trees for all parameters together.
1 parent 467a73d commit dcf6124

File tree

11 files changed

+20
-18
lines changed

11 files changed

+20
-18
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
230230
* Parameter symbols are taken from the `rawParamss` field of `sym`, or
231231
* are freshly generated if `rawParamss` is empty.
232232
*/
233-
def polyDefDef(sym: TermSymbol, rhsFn: List[Type] => List[List[Tree]] => Tree)(using Context): DefDef = {
233+
def polyDefDef(sym: TermSymbol, rhsFn: List[Tree] => List[List[Tree]] => Tree)(using Context): DefDef = {
234234

235235
val (tparams, existingParamss, mtp) = sym.info match {
236236
case tp: PolyType =>
@@ -281,7 +281,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
281281
case tp => (Nil, tp.widenExpr)
282282
}
283283
val (vparamss, rtp) = valueParamss(mtp, existingParamss)
284-
val targs = tparams map (_.typeRef)
284+
val targs = tparams.map(tparam => ref(tparam.typeRef))
285285
val argss = vparamss.nestedMap(vparam => Ident(vparam.termRef))
286286
sym.setParamss(tparams, vparamss)
287287
DefDef(sym, tparams, vparamss, rtp, rhsFn(targs)(argss))
@@ -351,7 +351,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
351351
def forwarder(fn: TermSymbol, name: TermName) = {
352352
val fwdMeth = fn.copy(cls, name, Synthetic | Method | Final).entered.asTerm
353353
if (fwdMeth.allOverriddenSymbols.exists(!_.is(Deferred))) fwdMeth.setFlag(Override)
354-
polyDefDef(fwdMeth, tprefs => prefss => ref(fn).appliedToTypes(tprefs).appliedToArgss(prefss))
354+
polyDefDef(fwdMeth, tprefs => prefss => ref(fn).appliedToTypeTrees(tprefs).appliedToArgss(prefss))
355355
}
356356
val forwarders = fns.lazyZip(methNames).map(forwarder)
357357
val cdef = ClassDef(cls, DefDef(constr), forwarders)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ abstract class AccessProxies {
4242
case info: PolyType => info.paramNames.length
4343
case _ => 0
4444
}
45-
val (accessRef, forwardedTypes, forwardedArgss) =
45+
val (accessRef, forwardedTpts, forwardedArgss) =
4646
if (passReceiverAsArg(accessor.name))
4747
(argss.head.head.select(accessed), tps.takeRight(numTypeParams), argss.tail)
4848
else
@@ -53,7 +53,7 @@ abstract class AccessProxies {
5353
forwardedArgss.nonEmpty && forwardedArgss.head.nonEmpty) // defensive conditions
5454
accessRef.becomes(forwardedArgss.head.head)
5555
else
56-
accessRef.appliedToTypes(forwardedTypes).appliedToArgss(forwardedArgss)
56+
accessRef.appliedToTypeTrees(forwardedTpts).appliedToArgss(forwardedArgss)
5757
rhs.withSpan(accessed.span)
5858
})
5959

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
228228
// form `Array[? <: SomeType]`, so we need `.argInfos` to get the `TypeBounds`.
229229
val elemtp = vararg.tpe.widen.argInfos.head
230230
ref(sym.termRef)
231-
.appliedToTypes(trefs)
231+
.appliedToTypeTrees(trefs)
232232
.appliedToArgss(init)
233233
.appliedToArgs(last :+ wrapArray(vararg, elemtp))
234234
})

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ trait FullParameterization {
204204

205205
new TreeTypeMap(
206206
typeMap = rewireType(_)
207-
.subst(origTParams ++ origVParams, trefs ++ argRefs.map(_.tpe))
207+
.subst(origTParams ++ origVParams, (trefs ++ argRefs).tpes)
208208
.substThisUnlessStatic(origClass, thisRef.tpe),
209209
treeMap = {
210210
case tree: This if tree.symbol == origClass => thisRef

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class HoistSuperArgs extends MiniPhase with IdentityDenotTransformer { thisPhase
130130
case _ if arg.existsSubTree(needsHoist) =>
131131
val superMeth = newSuperArgMethod(arg.tpe)
132132
val superArgDef = polyDefDef(superMeth, trefs => vrefss => {
133-
val paramSyms = trefs.map(_.typeSymbol) ::: vrefss.flatten.map(_.symbol)
133+
val paramSyms = trefs.map(_.tpe.typeSymbol) ::: vrefss.flatten.map(_.symbol)
134134
val tmap = new TreeTypeMap(
135135
typeMap = new TypeMap {
136136
lazy val origToParam = origParams.zip(paramSyms).toMap

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ class MixinOps(cls: ClassSymbol, thisPhase: DenotTransformer)(using Context) {
7878
final val PrivateOrAccessor: FlagSet = Private | Accessor
7979
final val PrivateOrAccessorOrDeferred: FlagSet = Private | Accessor | Deferred
8080

81-
def forwarderRhsFn(target: Symbol): List[Type] => List[List[Tree]] => Tree = {
81+
def forwarderRhsFn(target: Symbol): List[Tree] => List[List[Tree]] => Tree = {
8282
targs => vrefss =>
83-
val tapp = superRef(target).appliedToTypes(targs)
83+
val tapp = superRef(target).appliedToTypeTrees(targs)
8484
vrefss match {
8585
case Nil | List(Nil) =>
8686
// Overriding is somewhat loose about `()T` vs `=> T`, so just pick

compiler/src/dotty/tools/dotc/transform/sjs/PrepJSExports.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ object PrepJSExports {
440440
proxySym: TermSymbol, span: Span)(using Context): Tree = {
441441

442442
polyDefDef(proxySym, { targs => argss =>
443-
This(clsSym).select(trgSym).appliedToTypes(targs).appliedToArgss(argss)
443+
This(clsSym).select(trgSym).appliedToTypeTrees(targs).appliedToArgss(argss)
444444
}).withSpan(span)
445445
}
446446

compiler/src/dotty/tools/dotc/typer/Deriving.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,15 @@ trait Deriving {
271271
import tpd._
272272

273273
/** The type class instance definition with symbol `sym` */
274-
def typeclassInstance(sym: Symbol)(using Context): List[Type] => (List[List[tpd.Tree]] => tpd.Tree) = {
275-
(tparamRefs: List[Type]) => (paramRefss: List[List[tpd.Tree]]) =>
276-
val tparams = tparamRefs.map(_.typeSymbol.asType)
274+
def typeclassInstance(sym: Symbol)(using Context): List[tpd.Tree] => (List[List[tpd.Tree]] => tpd.Tree) = {
275+
(tparamRefs: List[tpd.Tree]) => (paramRefss: List[List[tpd.Tree]]) =>
276+
val tparamTypes = tparamRefs.tpes
277+
val tparams = tparamTypes.map(_.typeSymbol.asType)
277278
val params = if (paramRefss.isEmpty) Nil else paramRefss.head.map(_.symbol.asTerm)
278279
tparams.foreach(ctx.enter(_))
279280
params.foreach(ctx.enter(_))
280281
def instantiated(info: Type): Type = info match {
281-
case info: PolyType => instantiated(info.instantiate(tparamRefs))
282+
case info: PolyType => instantiated(info.instantiate(tparamTypes))
282283
case info: MethodType => info.instantiate(params.map(_.termRef))
283284
case info => info.widenExpr
284285
}

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ object Inliner {
202202
retainer.deriveTargetNameAnnotation(meth, name => BodyRetainerName(name.asTermName))
203203
polyDefDef(retainer, targs => prefss =>
204204
inlineCall(
205-
ref(meth).appliedToTypes(targs).appliedToArgss(prefss)
205+
ref(meth).appliedToTypeTrees(targs).appliedToArgss(prefss)
206206
.withSpan(mdef.rhs.span.startPos))(
207207
using ctx.withOwner(retainer)))
208208
.showing(i"retainer for $meth: $result", inlining)

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ class Namer { typer: Typer =>
10381038
import tpd._
10391039
val ref = path.select(sym.asTerm)
10401040
val ddef = tpd.polyDefDef(forwarder.asTerm, targs => prefss =>
1041-
ref.appliedToTypes(targs)
1041+
ref.appliedToTypeTrees(targs)
10421042
.appliedToArgss(adaptForwarderParams(Nil, sym.info.stripPoly, prefss))
10431043
)
10441044
if forwarder.isInlineMethod then

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
257257

258258
object DefDef extends DefDefModule:
259259
def apply(symbol: Symbol, rhsFn: List[TypeRepr] => List[List[Term]] => Option[Term]): DefDef =
260-
withDefaultPos(tpd.polyDefDef(symbol.asTerm, tparams => vparamss => yCheckedOwners(rhsFn(tparams)(vparamss), symbol).getOrElse(tpd.EmptyTree)))
260+
withDefaultPos(tpd.polyDefDef(symbol.asTerm,
261+
tparams => vparamss => yCheckedOwners(rhsFn(tparams.map(_.tpe))(vparamss), symbol).getOrElse(tpd.EmptyTree)))
261262
def copy(original: Tree)(name: String, typeParams: List[TypeDef], paramss: List[List[ValDef]], tpt: TypeTree, rhs: Option[Term]): DefDef =
262263
tpd.cpy.DefDef(original)(name.toTermName, typeParams, paramss, tpt, yCheckedOwners(rhs, original.symbol).getOrElse(tpd.EmptyTree))
263264
def unapply(ddef: DefDef): (String, List[TypeDef], List[List[ValDef]], TypeTree, Option[Term]) =

0 commit comments

Comments
 (0)