Skip to content

Commit d64249a

Browse files
committed
Rename isContextual -> isGivenApply
Rename isContextual -> isGivenApply in Apply nodes and FunProtos
1 parent 3e0551d commit d64249a

File tree

9 files changed

+23
-26
lines changed

9 files changed

+23
-26
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,9 @@ object desugar {
503503
val nu = (makeNew(classTypeRef) /: vparamss) { (nu, vparams) =>
504504
val app = Apply(nu, vparams.map(refOfDef))
505505
vparams match {
506-
case vparam :: _ if vparam.mods.is(Given) => app.pushAttachment(ApplyGiven, ())
507-
case _ =>
506+
case vparam :: _ if vparam.mods.is(Given) => app.setGivenApply()
507+
case _ => app
508508
}
509-
app
510509
}
511510
ensureApplied(nu)
512511
//.reporting(res => i"CREATE $cdef = $res")

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,8 @@ object Trees {
436436
extends GenericApply[T] {
437437
type ThisTree[-T >: Untyped] = Apply[T]
438438

439-
def isContextual = getAttachment(untpd.ApplyGiven).nonEmpty
439+
def isGivenApply = getAttachment(untpd.ApplyGiven).nonEmpty
440+
def setGivenApply() = { pushAttachment(untpd.ApplyGiven, ()); this }
440441
}
441442

442443
/** fun[args] */

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -589,15 +589,12 @@ object Parsers {
589589
recur(first)
590590
}
591591

592-
def applyGiven(t: Tree, operand: () => Tree): Tree = {
593-
val app = atSpan(startOffset(t), in.offset) {
592+
def applyGiven(t: Tree, operand: () => Tree): Tree =
593+
atSpan(startOffset(t), in.offset) {
594594
in.nextToken()
595595
val args = if (in.token == LPAREN) parArgumentExprs() else operand() :: Nil
596596
Apply(t, args)
597-
}
598-
app.pushAttachment(ApplyGiven, ())
599-
app
600-
}
597+
}.setGivenApply()
601598

602599
/* -------- IDENTIFIERS AND LITERALS ------------------------------------------- */
603600

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
341341
optDotPrefix(tree) ~ keywordStr("this") ~ idText(tree)
342342
case Super(qual: This, mix) =>
343343
optDotPrefix(qual) ~ keywordStr("super") ~ optText(mix)("[" ~ _ ~ "]")
344-
case Apply(fun, args) =>
344+
case app @ Apply(fun, args) =>
345345
if (fun.hasType && fun.symbol == defn.throwMethod)
346346
changePrec (GlobalPrec) {
347347
keywordStr("throw ") ~ toText(args.head)
@@ -350,7 +350,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
350350
keywordStr("'{") ~ toTextGlobal(args, ", ") ~ keywordStr("}")
351351
else if (!ctx.settings.YprintDebug.value && fun.hasType && fun.symbol == defn.InternalQuoted_exprSplice)
352352
keywordStr("${") ~ toTextGlobal(args, ", ") ~ keywordStr("}")
353-
else if (tree.getAttachment(untpd.ApplyGiven).isDefined && !homogenizedView)
353+
else if (app.isGivenApply && !homogenizedView)
354354
changePrec(InfixPrec) {
355355
toTextLocal(fun) ~ " given " ~
356356
(if (args.length == 1) toTextLocal(args.head) else "(" ~ toTextGlobal(args, ", ") ~ ")")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ object Erasure {
522522
val Apply(fun, args) = tree
523523
if (fun.symbol == defn.cbnArg)
524524
typedUnadapted(args.head, pt)
525-
else typedExpr(fun, FunProto(args, pt)(this, isContextual = false)) match {
525+
else typedExpr(fun, FunProto(args, pt)(this, isGivenApply = false)) match {
526526
case fun1: Apply => // arguments passed in prototype were already passed
527527
fun1
528528
case fun1 =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
802802
def typedApply(tree: untpd.Apply, pt: Type)(implicit ctx: Context): Tree = {
803803

804804
def realApply(implicit ctx: Context): Tree = track("realApply") {
805-
val originalProto = new FunProto(tree.args, IgnoredProto(pt))(this, tree.isContextual)(argCtx(tree))
805+
val originalProto = new FunProto(tree.args, IgnoredProto(pt))(this, tree.isGivenApply)(argCtx(tree))
806806
record("typedApply")
807807
val fun1 = typedFunPart(tree.fun, originalProto)
808808

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ object EtaExpansion extends LiftImpure {
215215
var ids: List[Tree] = mt.paramNames map (name => Ident(name).withSpan(tree.span.startPos))
216216
if (mt.paramInfos.nonEmpty && mt.paramInfos.last.isRepeatedParam)
217217
ids = ids.init :+ repeated(ids.last)
218-
var body: Tree = Apply(lifted, ids)
219-
if (mt.isContextual) body.pushAttachment(ApplyGiven, ())
220-
if (!isLastApplication) body = PostfixOp(body, Ident(nme.WILDCARD))
218+
val app = Apply(lifted, ids)
219+
if (mt.isContextual) app.setGivenApply()
220+
val body = if (isLastApplication) app else PostfixOp(app, Ident(nme.WILDCARD))
221221
val fn =
222222
if (mt.isContextual) new untpd.FunctionWithMods(params, body, Modifiers(Given))
223223
else if (mt.isImplicitMethod) new untpd.FunctionWithMods(params, body, Modifiers(OldImplicit))

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ object ProtoTypes {
244244
* [](args): resultType
245245
*/
246246
case class FunProto(args: List[untpd.Tree], resType: Type)(typer: Typer,
247-
override val isContextual: Boolean, state: FunProtoState = new FunProtoState)(implicit val ctx: Context)
247+
val isGivenApply: Boolean, state: FunProtoState = new FunProtoState)(implicit val ctx: Context)
248248
extends UncachedGroundType with ApplyingProto with FunOrPolyProto {
249249
override def resultType(implicit ctx: Context): Type = resType
250250

@@ -258,7 +258,7 @@ object ProtoTypes {
258258

259259
def derivedFunProto(args: List[untpd.Tree] = this.args, resultType: Type, typer: Typer = this.typer): FunProto =
260260
if ((args eq this.args) && (resultType eq this.resultType) && (typer eq this.typer)) this
261-
else new FunProto(args, resultType)(typer, isContextual)
261+
else new FunProto(args, resultType)(typer, isGivenApply)
262262

263263
override def notApplied: Type = WildcardType
264264

@@ -342,7 +342,7 @@ object ProtoTypes {
342342
case pt: FunProto =>
343343
pt
344344
case _ =>
345-
state.tupled = new FunProto(untpd.Tuple(args) :: Nil, resultType)(typer, isContextual)
345+
state.tupled = new FunProto(untpd.Tuple(args) :: Nil, resultType)(typer, isGivenApply)
346346
tupled
347347
}
348348

@@ -377,14 +377,14 @@ object ProtoTypes {
377377

378378
override def withContext(newCtx: Context): ProtoType =
379379
if (newCtx `eq` ctx) this
380-
else new FunProto(args, resType)(typer, isContextual, state)(newCtx)
380+
else new FunProto(args, resType)(typer, isGivenApply, state)(newCtx)
381381
}
382382

383383
/** A prototype for expressions that appear in function position
384384
*
385385
* [](args): resultType, where args are known to be typed
386386
*/
387-
class FunProtoTyped(args: List[tpd.Tree], resultType: Type)(typer: Typer, isContextual: Boolean)(implicit ctx: Context) extends FunProto(args, resultType)(typer, isContextual)(ctx) {
387+
class FunProtoTyped(args: List[tpd.Tree], resultType: Type)(typer: Typer, isGivenApply: Boolean)(implicit ctx: Context) extends FunProto(args, resultType)(typer, isGivenApply)(ctx) {
388388
override def unforcedTypedArgs(implicit ctx: Context): List[tpd.Tree] = args
389389
override def withContext(ctx: Context): FunProtoTyped = this
390390
}
@@ -431,7 +431,7 @@ object ProtoTypes {
431431
}
432432

433433
class UnapplyFunProto(argType: Type, typer: Typer)(implicit ctx: Context) extends FunProto(
434-
untpd.TypedSplice(dummyTreeOfType(argType)(ctx.source))(ctx) :: Nil, WildcardType)(typer, isContextual = false)
434+
untpd.TypedSplice(dummyTreeOfType(argType)(ctx.source))(ctx) :: Nil, WildcardType)(typer, isGivenApply = false)
435435

436436
/** A prototype for expressions [] that are type-parameterized:
437437
*

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ class Typer extends Namer
912912
expr1.tpe
913913
case _ =>
914914
val protoArgs = args map (_ withType WildcardType)
915-
val callProto = FunProto(protoArgs, WildcardType)(this, isContextual = app.isContextual)
915+
val callProto = FunProto(protoArgs, WildcardType)(this, app.isGivenApply)
916916
val expr1 = typedExpr(expr, callProto)
917917
fnBody = cpy.Apply(fnBody)(untpd.TypedSplice(expr1), args)
918918
expr1.tpe
@@ -2551,7 +2551,7 @@ class Typer extends Namer
25512551
errorTree(tree, NoMatchingOverload(altDenots, pt)(err))
25522552
def hasEmptyParams(denot: SingleDenotation) = denot.info.paramInfoss == ListOfNil
25532553
pt match {
2554-
case pt: FunProto if !pt.isContextual =>
2554+
case pt: FunProto if !pt.isGivenApply =>
25552555
// insert apply or convert qualifier only for a regular application
25562556
tryInsertApplyOrImplicit(tree, pt, locked)(noMatches)
25572557
case _ =>
@@ -2687,7 +2687,7 @@ class Typer extends Namer
26872687
}
26882688
tryEither { implicit ctx =>
26892689
val app = cpy.Apply(tree)(untpd.TypedSplice(tree), namedArgs)
2690-
if (wtp.isContextual) app.pushAttachment(untpd.ApplyGiven, ())
2690+
if (wtp.isContextual) app.setGivenApply()
26912691
typr.println(i"try with default implicit args $app")
26922692
typed(app, pt, locked)
26932693
} { (_, _) =>

0 commit comments

Comments
 (0)