Skip to content

Commit 1799bf6

Browse files
committed
Rename isContextual -> isGiven/isGivenMethod
1 parent e2ed9c2 commit 1799bf6

File tree

12 files changed

+49
-49
lines changed

12 files changed

+49
-49
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,11 +1117,11 @@ object desugar {
11171117
* def $anonfun(params) = body
11181118
* Closure($anonfun)
11191119
*/
1120-
def makeClosure(params: List[ValDef], body: Tree, tpt: Tree = null, isContextual: Boolean)(implicit ctx: Context): Block =
1120+
def makeClosure(params: List[ValDef], body: Tree, tpt: Tree = null, isGiven: Boolean)(implicit ctx: Context): Block =
11211121
Block(
11221122
DefDef(nme.ANON_FUN, Nil, params :: Nil, if (tpt == null) TypeTree() else tpt, body)
11231123
.withMods(synthetic | Artifact),
1124-
Closure(Nil, Ident(nme.ANON_FUN), if (isContextual) ContextualEmptyTree else EmptyTree))
1124+
Closure(Nil, Ident(nme.ANON_FUN), if (isGiven) ContextualEmptyTree else EmptyTree))
11251125

11261126
/** If `nparams` == 1, expand partial function
11271127
*

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
231231

232232
def valueParam(name: TermName, origInfo: Type): TermSymbol = {
233233
val maybeImplicit =
234-
if (tp.isContextual) Given
234+
if (tp.isGivenMethod) Given
235235
else if (tp.isImplicitMethod) OldImplicit
236236
else EmptyFlags
237237
val maybeErased = if (tp.isErasedMethod) Erased else EmptyFlags
@@ -1111,9 +1111,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
11111111
}
11121112

11131113
def applyOverloaded(receiver: Tree, method: TermName, args: List[Tree], targs: List[Type],
1114-
expectedType: Type, isContextual: Boolean = false)(implicit ctx: Context): Tree = {
1114+
expectedType: Type, isGiven: Boolean = false)(implicit ctx: Context): Tree = {
11151115
val typer = ctx.typer
1116-
val proto = new FunProtoTyped(args, expectedType)(typer, isContextual)
1116+
val proto = new FunProtoTyped(args, expectedType)(typer, isGiven)
11171117
val denot = receiver.tpe.member(method)
11181118
assert(denot.exists, i"no member $receiver . $method, members = ${receiver.tpe.decls}")
11191119
val selected =

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class Definitions {
130130
val resParamRef = enterTypeParam(cls, paramNamePrefix ++ "R", Covariant, decls).typeRef
131131
val methodType = MethodType.companion(
132132
isJava = false,
133-
isContextual = name.isImplicitFunction,
133+
isGiven = name.isImplicitFunction,
134134
isOldImplicit = false,
135135
isErased = name.isErasedFunction)
136136
decls.enter(newMethod(cls, nme.apply, methodType(argParamRefs, resParamRef), Deferred))
@@ -907,8 +907,8 @@ class Definitions {
907907
sym.owner.linkedClass.typeRef
908908

909909
object FunctionOf {
910-
def apply(args: List[Type], resultType: Type, isContextual: Boolean = false, isErased: Boolean = false)(implicit ctx: Context): Type =
911-
FunctionType(args.length, isContextual, isErased).appliedTo(args ::: resultType :: Nil)
910+
def apply(args: List[Type], resultType: Type, isGiven: Boolean = false, isErased: Boolean = false)(implicit ctx: Context): Type =
911+
FunctionType(args.length, isGiven, isErased).appliedTo(args ::: resultType :: Nil)
912912
def unapply(ft: Type)(implicit ctx: Context): Option[(List[Type], Type, Boolean, Boolean)] = {
913913
val tsym = ft.typeSymbol
914914
if (isFunctionClass(tsym)) {
@@ -1013,10 +1013,10 @@ class Definitions {
10131013

10141014
lazy val TupleType: Array[TypeRef] = mkArityArray("scala.Tuple", MaxTupleArity, 1)
10151015

1016-
def FunctionClass(n: Int, isContextual: Boolean = false, isErased: Boolean = false)(implicit ctx: Context): Symbol =
1017-
if (isContextual && isErased)
1016+
def FunctionClass(n: Int, isGiven: Boolean = false, isErased: Boolean = false)(implicit ctx: Context): Symbol =
1017+
if (isGiven && isErased)
10181018
ctx.requiredClass("scala.ErasedImplicitFunction" + n.toString)
1019-
else if (isContextual)
1019+
else if (isGiven)
10201020
ctx.requiredClass("scala.ImplicitFunction" + n.toString)
10211021
else if (isErased)
10221022
ctx.requiredClass("scala.ErasedFunction" + n.toString)
@@ -1028,9 +1028,9 @@ class Definitions {
10281028
lazy val Function0_applyR: TermRef = ImplementedFunctionType(0).symbol.requiredMethodRef(nme.apply)
10291029
def Function0_apply(implicit ctx: Context): Symbol = Function0_applyR.symbol
10301030

1031-
def FunctionType(n: Int, isContextual: Boolean = false, isErased: Boolean = false)(implicit ctx: Context): TypeRef =
1032-
if (n <= MaxImplementedFunctionArity && (!isContextual || ctx.erasedTypes) && !isErased) ImplementedFunctionType(n)
1033-
else FunctionClass(n, isContextual, isErased).typeRef
1031+
def FunctionType(n: Int, isGiven: Boolean = false, isErased: Boolean = false)(implicit ctx: Context): TypeRef =
1032+
if (n <= MaxImplementedFunctionArity && (!isGiven || ctx.erasedTypes) && !isErased) ImplementedFunctionType(n)
1033+
else FunctionClass(n, isGiven, isErased).typeRef
10341034

10351035
/** If `cls` is a class in the scala package, its name, otherwise EmptyTypeName */
10361036
def scalaClassName(cls: Symbol)(implicit ctx: Context): TypeName =

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ object Types {
340340
def isImplicitMethod: Boolean = false
341341

342342
/** Is this a Method or PolyType which has contextual parameters as first value parameter list? */
343-
def isContextual: Boolean = false
343+
def isGivenMethod: Boolean = false
344344

345345
/** Is this a MethodType for which the parameters will not be used? */
346346
def isErasedMethod: Boolean = false
@@ -1504,15 +1504,15 @@ object Types {
15041504
def toFunctionType(dropLast: Int = 0)(implicit ctx: Context): Type = this match {
15051505
case mt: MethodType if !mt.isParamDependent =>
15061506
val formals1 = if (dropLast == 0) mt.paramInfos else mt.paramInfos dropRight dropLast
1507-
val isContextual = mt.isContextual && !ctx.erasedTypes
1507+
val isGiven = mt.isGivenMethod && !ctx.erasedTypes
15081508
val isErased = mt.isErasedMethod && !ctx.erasedTypes
15091509
val result1 = mt.nonDependentResultApprox match {
15101510
case res: MethodType => res.toFunctionType()
15111511
case res => res
15121512
}
15131513
val funType = defn.FunctionOf(
15141514
formals1 mapConserve (_.underlyingIfRepeated(mt.isJavaMethod)),
1515-
result1, isContextual, isErased)
1515+
result1, isGiven, isErased)
15161516
if (mt.isResultDependent) RefinedType(funType, nme.apply, mt)
15171517
else funType
15181518
}
@@ -3185,12 +3185,12 @@ object Types {
31853185
final override def isImplicitMethod: Boolean =
31863186
companion.eq(ImplicitMethodType) ||
31873187
companion.eq(ErasedImplicitMethodType) ||
3188-
isContextual
3188+
isGivenMethod
31893189
final override def isErasedMethod: Boolean =
31903190
companion.eq(ErasedMethodType) ||
31913191
companion.eq(ErasedImplicitMethodType) ||
31923192
companion.eq(ErasedContextualMethodType)
3193-
final override def isContextual: Boolean =
3193+
final override def isGivenMethod: Boolean =
31943194
companion.eq(ContextualMethodType) ||
31953195
companion.eq(ErasedContextualMethodType)
31963196

@@ -3285,14 +3285,14 @@ object Types {
32853285
}
32863286

32873287
object MethodType extends MethodTypeCompanion("MethodType") {
3288-
def companion(isJava: Boolean = false, isContextual: Boolean = false, isOldImplicit: Boolean = false, isErased: Boolean = false): MethodTypeCompanion = {
3288+
def companion(isJava: Boolean = false, isGiven: Boolean = false, isOldImplicit: Boolean = false, isErased: Boolean = false): MethodTypeCompanion = {
32893289
if (isJava) {
32903290
assert(!isOldImplicit)
32913291
assert(!isErased)
3292-
assert(!isContextual)
3292+
assert(!isGiven)
32933293
JavaMethodType
32943294
}
3295-
else if (isContextual)
3295+
else if (isGiven)
32963296
if (isErased) ErasedContextualMethodType else ContextualMethodType
32973297
else if (isOldImplicit)
32983298
if (isErased) ErasedImplicitMethodType else ImplicitMethodType
@@ -3384,7 +3384,7 @@ object Types {
33843384

33853385
def computeSignature(implicit ctx: Context): Signature = resultSignature
33863386

3387-
override def isContextual = resType.isContextual
3387+
override def isGivenMethod = resType.isGivenMethod
33883388
override def isImplicitMethod = resType.isImplicitMethod
33893389

33903390
/** Merge nested polytypes into one polytype. nested polytypes are normally not supported

compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,9 @@ object TastyFormat {
441441
final val MATCHtype = 190
442442
final val MATCHtpt = 191
443443

444-
def methodTypeTag(isContextual: Boolean, isOldImplicit: Boolean, isErased: Boolean): Int = {
444+
def methodTypeTag(isGiven: Boolean, isOldImplicit: Boolean, isErased: Boolean): Int = {
445445
val implicitOffset =
446-
if (isContextual) 2
446+
if (isGiven) 2
447447
else if (isOldImplicit) { assert(!isErased); 4 }
448448
else 0
449449
val erasedOffset = if (isErased) 1 else 0

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ class TreePickler(pickler: TastyPickler) {
260260
pickleMethodic(POLYtype, tpe)
261261
case tpe: MethodType if richTypes =>
262262
val tag = methodTypeTag(
263-
isContextual = tpe.isContextual,
264-
isOldImplicit = tpe.isImplicitMethod && !tpe.isContextual,
263+
isGiven = tpe.isGivenMethod,
264+
isOldImplicit = tpe.isImplicitMethod && !tpe.isGivenMethod,
265265
isErased = tpe.isErasedMethod)
266266
pickleMethodic(tag, tpe)
267267
case tpe: ParamRef =>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,10 +2222,10 @@ object Parsers {
22222222
in.nextToken()
22232223
initialMods |= Erased
22242224
}
2225-
val isContextual = initialMods.is(Given)
2225+
val isGiven = initialMods.is(Given)
22262226
newLineOptWhenFollowedBy(LPAREN)
22272227
def isParamClause: Boolean =
2228-
!isContextual || {
2228+
!isGiven || {
22292229
val lookahead = in.lookaheadScanner
22302230
lookahead.nextToken()
22312231
paramIntroTokens.contains(lookahead.token) && {
@@ -2237,7 +2237,7 @@ object Parsers {
22372237
}
22382238
}
22392239
if (in.token == LPAREN && isParamClause) {
2240-
if (ofInstance && !isContextual)
2240+
if (ofInstance && !isGiven)
22412241
syntaxError(em"parameters of instance definitions must come after `given'")
22422242
val params = paramClause(
22432243
ofClass = ofClass,
@@ -2247,7 +2247,7 @@ object Parsers {
22472247
val lastClause = params.nonEmpty && params.head.mods.flags.is(OldImplicit)
22482248
params :: (if (lastClause) Nil else recur(firstClause = false, nparams + params.length))
22492249
}
2250-
else if (isContextual) {
2250+
else if (isGiven) {
22512251
val tps = commaSeparated(() => annotType())
22522252
var counter = nparams
22532253
def nextIdx = { counter += 1; counter }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ class PlainPrinter(_ctx: Context) extends Printer {
185185
"<noprefix>"
186186
case tp: MethodType =>
187187
changePrec(GlobalPrec) {
188-
(if (tp.isContextual) " given" else "") ~
188+
(if (tp.isGivenMethod) " given" else "") ~
189189
(if (tp.isErasedMethod) " erased" else "") ~~
190-
("(" + (if (tp.isImplicitMethod && !tp.isContextual) "implicit " else "")) ~
190+
("(" + (if (tp.isImplicitMethod && !tp.isGivenMethod) "implicit " else "")) ~
191191
paramsText(tp) ~
192192
(if (tp.resultType.isInstanceOf[MethodType]) ")" else "): ") ~
193193
toText(tp.resultType)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
129129
def toTextTuple(args: List[Type]): Text =
130130
"(" ~ argsText(args) ~ ")"
131131

132-
def toTextFunction(args: List[Type], isContextual: Boolean, isErased: Boolean): Text =
132+
def toTextFunction(args: List[Type], isGiven: Boolean, isErased: Boolean): Text =
133133
changePrec(GlobalPrec) {
134134
val argStr: Text =
135135
if (args.length == 2 && !defn.isTupleType(args.head))
136136
atPrec(InfixPrec) { argText(args.head) }
137137
else
138138
toTextTuple(args.init)
139-
(keywordText("given ") provided isContextual) ~
139+
(keywordText("given ") provided isGiven) ~
140140
(keywordText("erased ") provided isErased) ~
141141
argStr ~ " => " ~ argText(args.last)
142142
}
@@ -232,7 +232,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
232232
case dummyTreeOfType(tp) :: Nil if !(tp isRef defn.NullClass) => "null: " ~ toText(tp)
233233
case _ => toTextGlobal(args, ", ")
234234
}
235-
return "[applied to " ~ (Str("given ") provided tp.isContextual) ~ (Str("erased ") provided tp.isErasedMethod) ~ "(" ~ argsText ~ ") returning " ~ toText(resultType) ~ "]"
235+
return "[applied to " ~ (Str("given ") provided tp.isGivenMethod) ~ (Str("erased ") provided tp.isErasedMethod) ~ "(" ~ argsText ~ ") returning " ~ toText(resultType) ~ "]"
236236
case IgnoredProto(ignored) =>
237237
return "?" ~ (("(ignored: " ~ toText(ignored) ~ ")") provided ctx.settings.verbose.value)
238238
case tp @ PolyProto(targs, resType) =>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,18 @@ object EtaExpansion extends LiftImpure {
208208
if (isLastApplication && mt.paramInfos.length == xarity) mt.paramInfos map (_ => TypeTree())
209209
else mt.paramInfos map TypeTree
210210
var paramFlag = Synthetic | Param
211-
if (mt.isContextual) paramFlag |= Given
211+
if (mt.isGivenMethod) paramFlag |= Given
212212
else if (mt.isImplicitMethod) paramFlag |= OldImplicit
213213
val params = (mt.paramNames, paramTypes).zipped.map((name, tpe) =>
214214
ValDef(name, tpe, EmptyTree).withFlags(paramFlag).withSpan(tree.span.startPos))
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)
218218
val app = Apply(lifted, ids)
219-
if (mt.isContextual) app.setGivenApply()
219+
if (mt.isGivenMethod) app.setGivenApply()
220220
val body = if (isLastApplication) app else PostfixOp(app, Ident(nme.WILDCARD))
221221
val fn =
222-
if (mt.isContextual) new untpd.FunctionWithMods(params, body, Modifiers(Given))
222+
if (mt.isGivenMethod) new untpd.FunctionWithMods(params, body, Modifiers(Given))
223223
else if (mt.isImplicitMethod) new untpd.FunctionWithMods(params, body, Modifiers(OldImplicit))
224224
else untpd.Function(params, body)
225225
if (defs.nonEmpty) untpd.Block(defs.toList map (untpd.TypedSplice(_)), fn) else fn

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ trait NamerContextOps { this: Context =>
134134
def methodType(typeParams: List[Symbol], valueParamss: List[List[Symbol]], resultType: Type, isJava: Boolean = false)(implicit ctx: Context): Type = {
135135
val monotpe =
136136
(valueParamss :\ resultType) { (params, resultType) =>
137-
val (isOldImplicit, isErased, isContextual) =
137+
val (isOldImplicit, isErased, isGiven) =
138138
if (params.isEmpty) (false, false, false)
139139
else (params.head is OldImplicit, params.head is Erased, params.head.is(Given))
140-
val make = MethodType.companion(isJava = isJava, isContextual = isContextual, isOldImplicit = isOldImplicit, isErased = isErased)
140+
val make = MethodType.companion(isJava = isJava, isGiven = isGiven, isOldImplicit = isOldImplicit, isErased = isErased)
141141
if (isJava)
142142
for (param <- params)
143143
if (param.info.isDirectRef(defn.ObjectClass)) param.info = defn.AnyType

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ class Typer extends Namer
810810
}
811811

812812
val funCls = defn.FunctionClass(args.length,
813-
isContextual = funFlags.is(Given), isErased = funFlags.is(Erased))
813+
isGiven = funFlags.is(Given), isErased = funFlags.is(Erased))
814814

815815
/** Typechecks dependent function type with given parameters `params` */
816816
def typedDependent(params: List[ValDef])(implicit ctx: Context): Tree = {
@@ -820,7 +820,7 @@ class Typer extends Namer
820820
params1.foreach(_.symbol.setFlag(funFlags))
821821
val resultTpt = typed(body)
822822
val companion = MethodType.companion(
823-
isContextual = funFlags.is(Given), isErased = funFlags.is(Erased))
823+
isGiven = funFlags.is(Given), isErased = funFlags.is(Erased))
824824
val mt = companion.fromSymbols(params1.map(_.symbol), resultTpt.tpe)
825825
if (mt.isParamDependent)
826826
ctx.error(i"$mt is an illegal function type because it has inter-parameter dependencies", tree.sourcePos)
@@ -847,7 +847,7 @@ class Typer extends Namer
847847
def typedFunctionValue(tree: untpd.Function, pt: Type)(implicit ctx: Context): Tree = {
848848
val untpd.Function(params: List[untpd.ValDef] @unchecked, body) = tree
849849

850-
val isContextual = tree match {
850+
val isGiven = tree match {
851851
case tree: untpd.FunctionWithMods => tree.mods.is(Given)
852852
case _ => false
853853
}
@@ -971,7 +971,7 @@ class Typer extends Namer
971971
else cpy.ValDef(param)(
972972
tpt = untpd.TypeTree(
973973
inferredParamType(param, protoFormal(i)).underlyingIfRepeated(isJava = false)))
974-
desugar.makeClosure(inferredParams, fnBody, resultTpt, isContextual)
974+
desugar.makeClosure(inferredParams, fnBody, resultTpt, isGiven)
975975
}
976976
typed(desugared, pt)
977977
}
@@ -1002,7 +1002,7 @@ class Typer extends Namer
10021002
}
10031003
else if ((tree.tpt `eq` untpd.ContextualEmptyTree) && mt.paramNames.isEmpty)
10041004
// Note implicitness of function in target type since there are no method parameters that indicate it.
1005-
TypeTree(defn.FunctionOf(Nil, mt.resType, isContextual = true, isErased = false))
1005+
TypeTree(defn.FunctionOf(Nil, mt.resType, isGiven = true, isErased = false))
10061006
else
10071007
EmptyTree
10081008
}
@@ -2589,7 +2589,7 @@ class Typer extends Namer
25892589
adapt(tree, pt.tupled, locked)
25902590
else
25912591
tree
2592-
else if (wtp.isContextual)
2592+
else if (wtp.isGivenMethod)
25932593
adaptNoArgs(wtp) // insert arguments implicitly
25942594
else if (tree.symbol.isPrimaryConstructor && tree.symbol.info.firstParamTypes.isEmpty)
25952595
readapt(tree.appliedToNone) // insert () to primary constructors
@@ -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.setGivenApply()
2690+
if (wtp.isGivenMethod) app.setGivenApply()
26912691
typr.println(i"try with default implicit args $app")
26922692
typed(app, pt, locked)
26932693
} { (_, _) =>
@@ -3113,7 +3113,7 @@ class Typer extends Namer
31133113
* Overridden in `ReTyper`, where all applications are treated the same
31143114
*/
31153115
protected def matchingApply(methType: MethodOrPoly, pt: FunProto)(implicit ctx: Context): Boolean =
3116-
methType.isContextual == pt.isGivenApply ||
3116+
methType.isGivenMethod == pt.isGivenApply ||
31173117
methType.isImplicitMethod && pt.isGivenApply // for a transition allow `with` arguments for regular implicit parameters
31183118

31193119
/** Check that `tree == x: pt` is typeable. Used when checking a pattern

0 commit comments

Comments
 (0)