Skip to content

Rename *ImplicitFunctionN to *ContextFunctionN #8192

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

Merged
merged 1 commit into from
Feb 4, 2020
Merged
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
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped]
def isFunctionWithUnknownParamType(tree: Tree): Boolean =
functionWithUnknownParamType(tree).isDefined

/** Is `tree` an implicit function or closure, possibly nested in a block? */
/** Is `tree` an context function or closure, possibly nested in a block? */
def isContextualClosure(tree: Tree)(implicit ctx: Context): Boolean = unsplice(tree) match {
case tree: FunctionWithMods => tree.mods.is(Given)
case Function((param: untpd.ValDef) :: _, _) => param.mods.is(Given)
Expand All @@ -307,7 +307,7 @@ trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped]
case Block(DefDef(nme.ANON_FUN, _, params :: _, _, _) :: Nil, cl: Closure) =>
params match {
case param :: _ => param.mods.is(Given)
case Nil => cl.tpt.eq(untpd.ContextualEmptyTree) || defn.isImplicitFunctionType(cl.tpt.typeOpt)
case Nil => cl.tpt.eq(untpd.ContextualEmptyTree) || defn.isContextFunctionType(cl.tpt.typeOpt)
}
case _ => false
}
Expand Down
68 changes: 34 additions & 34 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Definitions {
newClassSymbol(ScalaPackageClass, name, Artifact, completer).entered
}

/** The trait FunctionN, ImplicitFunctionN, ErasedFunctionN or ErasedImplicitFunction, for some N
/** The trait FunctionN, ContextFunctionN, ErasedFunctionN or ErasedContextFunction, for some N
* @param name The name of the trait to be created
*
* FunctionN traits follow this template:
Expand All @@ -89,9 +89,9 @@ class Definitions {
* standard library, but without `tupled` and `curried` methods and without
* a `toString`.
*
* ImplicitFunctionN traits follow this template:
* ContextFunctionN traits follow this template:
*
* trait ImplicitFunctionN[T0,...,T{N-1}, R] extends Object {
* trait ContextFunctionN[T0,...,T{N-1}, R] extends Object {
* def apply(given $x0: T0, ..., $x{N_1}: T{N-1}): R
* }
*
Expand All @@ -101,13 +101,13 @@ class Definitions {
* def apply(erased $x0: T0, ..., $x{N_1}: T{N-1}): R
* }
*
* ErasedImplicitFunctionN traits follow this template:
* ErasedContextFunctionN traits follow this template:
*
* trait ErasedImplicitFunctionN[T0,...,T{N-1}, R] extends Object {
* trait ErasedContextFunctionN[T0,...,T{N-1}, R] extends Object {
* def apply (given erased $x0: T0, ..., $x{N_1}: T{N-1}): R
* }
*
* ErasedFunctionN and ErasedImplicitFunctionN erase to Function0.
* ErasedFunctionN and ErasedContextFunctionN erase to Function0.
*/
def newFunctionNTrait(name: TypeName): ClassSymbol = {
val completer = new LazyType {
Expand All @@ -122,7 +122,7 @@ class Definitions {
val resParamRef = enterTypeParam(cls, paramNamePrefix ++ "R", Covariant, decls).typeRef
val methodType = MethodType.companion(
isJava = false,
isContextual = name.isImplicitFunction,
isContextual = name.isContextFunction,
isImplicit = false,
isErased = name.isErasedFunction)
decls.enter(newMethod(cls, nme.apply, methodType(argParamRefs, resParamRef), Deferred))
Expand All @@ -131,7 +131,7 @@ class Definitions {
}
}
val flags0 = Trait | NoInits
val flags = if (name.isImplicitFunction) flags0 | Final else flags0
val flags = if (name.isContextFunction) flags0 | Final else flags0
newClassSymbol(ScalaPackageClass, name, flags, completer)
}

Expand Down Expand Up @@ -878,7 +878,7 @@ class Definitions {
if (isFunctionClass(tsym)) {
val targs = ft.dealias.argInfos
if (targs.isEmpty) None
else Some(targs.init, targs.last, tsym.name.isImplicitFunction, tsym.name.isErasedFunction)
else Some(targs.init, targs.last, tsym.name.isContextFunction, tsym.name.isErasedFunction)
}
else None
}
Expand Down Expand Up @@ -998,9 +998,9 @@ class Definitions {

def FunctionClass(n: Int, isContextual: Boolean = false, isErased: Boolean = false)(implicit ctx: Context): Symbol =
if (isContextual && isErased)
ctx.requiredClass("scala.ErasedImplicitFunction" + n.toString)
ctx.requiredClass("scala.ErasedContextFunction" + n.toString)
else if (isContextual)
ctx.requiredClass("scala.ImplicitFunction" + n.toString)
ctx.requiredClass("scala.ContextFunction" + n.toString)
else if (isErased)
ctx.requiredClass("scala.ErasedFunction" + n.toString)
else if (n <= MaxImplementedFunctionArity)
Expand Down Expand Up @@ -1047,28 +1047,28 @@ class Definitions {
/** Is a function class.
* - FunctionXXL
* - FunctionN for N >= 0
* - ImplicitFunctionN for N >= 0
* - ContextFunctionN for N >= 0
* - ErasedFunctionN for N > 0
* - ErasedImplicitFunctionN for N > 0
* - ErasedContextFunctionN for N > 0
*/
def isFunctionClass(cls: Symbol): Boolean = scalaClassName(cls).isFunction

/** Is an implicit function class.
* - ImplicitFunctionN for N >= 0
* - ErasedImplicitFunctionN for N > 0
/** Is an context function class.
* - ContextFunctionN for N >= 0
* - ErasedContextFunctionN for N > 0
*/
def isImplicitFunctionClass(cls: Symbol): Boolean = scalaClassName(cls).isImplicitFunction
def isContextFunctionClass(cls: Symbol): Boolean = scalaClassName(cls).isContextFunction

/** Is an erased function class.
* - ErasedFunctionN for N > 0
* - ErasedImplicitFunctionN for N > 0
* - ErasedContextFunctionN for N > 0
*/
def isErasedFunctionClass(cls: Symbol): Boolean = scalaClassName(cls).isErasedFunction

/** Is either FunctionXXL or a class that will be erased to FunctionXXL
* - FunctionXXL
* - FunctionN for N >= 22
* - ImplicitFunctionN for N >= 22
* - ContextFunctionN for N >= 22
*/
def isXXLFunctionClass(cls: Symbol): Boolean = {
val name = scalaClassName(cls)
Expand All @@ -1077,9 +1077,9 @@ class Definitions {

/** Is a synthetic function class
* - FunctionN for N > 22
* - ImplicitFunctionN for N >= 0
* - ContextFunctionN for N >= 0
* - ErasedFunctionN for N > 0
* - ErasedImplicitFunctionN for N > 0
* - ErasedContextFunctionN for N > 0
*/
def isSyntheticFunctionClass(cls: Symbol): Boolean = scalaClassName(cls).isSyntheticFunction

Expand All @@ -1093,8 +1093,8 @@ class Definitions {
/** Returns the erased class of the function class `cls`
* - FunctionN for N > 22 becomes FunctionXXL
* - FunctionN for 22 > N >= 0 remains as FunctionN
* - ImplicitFunctionN for N > 22 becomes FunctionXXL
* - ImplicitFunctionN for N <= 22 becomes FunctionN
* - ContextFunctionN for N > 22 becomes FunctionXXL
* - ContextFunctionN for N <= 22 becomes FunctionN
* - ErasedFunctionN becomes Function0
* - ImplicitErasedFunctionN becomes Function0
* - anything else becomes a NoSymbol
Expand All @@ -1110,8 +1110,8 @@ class Definitions {
/** Returns the erased type of the function class `cls`
* - FunctionN for N > 22 becomes FunctionXXL
* - FunctionN for 22 > N >= 0 remains as FunctionN
* - ImplicitFunctionN for N > 22 becomes FunctionXXL
* - ImplicitFunctionN for N <= 22 becomes FunctionN
* - ContextFunctionN for N > 22 becomes FunctionXXL
* - ContextFunctionN for N <= 22 becomes FunctionN
* - ErasedFunctionN becomes Function0
* - ImplicitErasedFunctionN becomes Function0
* - anything else becomes a NoType
Expand Down Expand Up @@ -1194,7 +1194,7 @@ class Definitions {

def isProductSubType(tp: Type)(implicit ctx: Context): Boolean = tp.derivesFrom(ProductClass)

/** Is `tp` (an alias) of either a scala.FunctionN or a scala.ImplicitFunctionN
/** Is `tp` (an alias) of either a scala.FunctionN or a scala.ContextFunctionN
* instance?
*/
def isNonRefinedFunction(tp: Type)(implicit ctx: Context): Boolean = {
Expand All @@ -1203,7 +1203,7 @@ class Definitions {

arity >= 0 &&
isFunctionClass(sym) &&
tp.isRef(FunctionType(arity, sym.name.isImplicitFunction, sym.name.isErasedFunction).typeSymbol) &&
tp.isRef(FunctionType(arity, sym.name.isContextFunction, sym.name.isErasedFunction).typeSymbol) &&
!tp.isInstanceOf[RefinedType]
}

Expand Down Expand Up @@ -1251,24 +1251,24 @@ class Definitions {

def functionArity(tp: Type)(implicit ctx: Context): Int = tp.dropDependentRefinement.dealias.argInfos.length - 1

/** Return underlying immplicit function type (i.e. instance of an ImplicitFunctionN class)
/** Return underlying context function type (i.e. instance of an ContextFunctionN class)
* or NoType if none exists. The following types are considered as underlying types:
* - the alias of an alias type
* - the instance or origin of a TypeVar (i.e. the result of a stripTypeVar)
* - the upper bound of a TypeParamRef in the current constraint
*/
def asImplicitFunctionType(tp: Type)(implicit ctx: Context): Type =
def asContextFunctionType(tp: Type)(implicit ctx: Context): Type =
tp.stripTypeVar.dealias match {
case tp1: TypeParamRef if ctx.typerState.constraint.contains(tp1) =>
asImplicitFunctionType(ctx.typeComparer.bounds(tp1).hiBound)
asContextFunctionType(ctx.typeComparer.bounds(tp1).hiBound)
case tp1 =>
if (isFunctionType(tp1) && tp1.typeSymbol.name.isImplicitFunction) tp1
if (isFunctionType(tp1) && tp1.typeSymbol.name.isContextFunction) tp1
else NoType
}

/** Is `tp` an implicit function type? */
def isImplicitFunctionType(tp: Type)(implicit ctx: Context): Boolean =
asImplicitFunctionType(tp).exists
/** Is `tp` an context function type? */
def isContextFunctionType(tp: Type)(implicit ctx: Context): Boolean =
asContextFunctionType(tp).exists

def isErasedFunctionType(tp: Type)(implicit ctx: Context): Boolean =
isFunctionType(tp) && tp.dealias.typeSymbol.name.isErasedFunction
Expand Down
24 changes: 12 additions & 12 deletions compiler/src/dotty/tools/dotc/core/NameOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,38 +150,38 @@ object NameOps {

def functionArity: Int =
functionArityFor(str.Function) max
functionArityFor(str.ImplicitFunction) max {
functionArityFor(str.ContextFunction) max {
val n =
functionArityFor(str.ErasedFunction) max
functionArityFor(str.ErasedImplicitFunction)
functionArityFor(str.ErasedContextFunction)
if (n == 0) -1 else n
}

/** Is a function name, i.e one of FunctionXXL, FunctionN, ImplicitFunctionN for N >= 0 or ErasedFunctionN, ErasedImplicitFunctionN for N > 0
/** Is a function name, i.e one of FunctionXXL, FunctionN, ContextFunctionN for N >= 0 or ErasedFunctionN, ErasedContextFunctionN for N > 0
*/
def isFunction: Boolean = (name eq tpnme.FunctionXXL) || functionArity >= 0

/** Is an implicit function name, i.e one of ImplicitFunctionN for N >= 0 or ErasedImplicitFunctionN for N > 0
/** Is an context function name, i.e one of ContextFunctionN for N >= 0 or ErasedContextFunctionN for N > 0
*/
def isImplicitFunction: Boolean =
functionArityFor(str.ImplicitFunction) >= 0 ||
functionArityFor(str.ErasedImplicitFunction) > 0
def isContextFunction: Boolean =
functionArityFor(str.ContextFunction) >= 0 ||
functionArityFor(str.ErasedContextFunction) > 0

/** Is an erased function name, i.e. one of ErasedFunctionN, ErasedImplicitFunctionN for N > 0
/** Is an erased function name, i.e. one of ErasedFunctionN, ErasedContextFunctionN for N > 0
*/
def isErasedFunction: Boolean =
functionArityFor(str.ErasedFunction) > 0 ||
functionArityFor(str.ErasedImplicitFunction) > 0
functionArityFor(str.ErasedContextFunction) > 0

/** Is a synthetic function name, i.e. one of
* - FunctionN for N > 22
* - ImplicitFunctionN for N >= 0
* - ContextFunctionN for N >= 0
* - ErasedFunctionN for N > 0
* - ErasedImplicitFunctionN for N > 0
* - ErasedContextFunctionN for N > 0
*/
def isSyntheticFunction: Boolean =
functionArityFor(str.Function) > MaxImplementedFunctionArity ||
functionArityFor(str.ImplicitFunction) >= 0 ||
functionArityFor(str.ContextFunction) >= 0 ||
isErasedFunction

/** Parsed function arity for function with some specific prefix */
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/StdNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ object StdNames {

final val Function = "Function"
final val ErasedFunction = "ErasedFunction"
final val ImplicitFunction = "ImplicitFunction"
final val ErasedImplicitFunction = "ErasedImplicitFunction"
final val ContextFunction = "ContextFunction"
final val ErasedContextFunction = "ErasedContextFunction"
final val AbstractFunction = "AbstractFunction"
final val Tuple = "Tuple"
final val Product = "Product"
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
* - For a typeref scala.Any, scala.AnyVal, scala.Singleton, scala.Tuple, or scala.*: : |java.lang.Object|
* - For a typeref scala.Unit, |scala.runtime.BoxedUnit|.
* - For a typeref scala.FunctionN, where N > MaxImplementedFunctionArity, scala.FunctionXXL
* - For a typeref scala.ImplicitFunctionN, | scala.FunctionN |
* - For a typeref scala.ContextFunctionN, | scala.FunctionN |
* - For a typeref P.C where C refers to a class, <noprefix> # C.
* - For a typeref P.C where C refers to an alias type, the erasure of C's alias.
* - For a typeref P.C where C refers to an abstract type, the erasure of C's upper bound.
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4627,7 +4627,7 @@ object Types {
case et: ExprType => true
case _ => false
}
// `ImplicitFunctionN` does not have constructors
// `ContextFunctionN` does not have constructors
val ctor = tp.cls.primaryConstructor
if (!ctor.exists || zeroParams(ctor.info)) tp
else NoType
Expand Down Expand Up @@ -4657,7 +4657,7 @@ object Types {
if (absMems.size == 1)
absMems.head.info match {
case mt: MethodType if !mt.isParamDependent &&
!defn.isImplicitFunctionType(mt.resultType) =>
!defn.isContextFunctionType(mt.resultType) =>
val cls = tp.classSymbol

// Given a SAM type such as:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
case tp @ AppliedType(tycon, args) =>
val cls = tycon.typeSymbol
if (tycon.isRepeatedParam) toTextLocal(args.head) ~ "*"
else if (defn.isFunctionClass(cls)) toTextFunction(args, cls.name.isImplicitFunction, cls.name.isErasedFunction)
else if (defn.isFunctionClass(cls)) toTextFunction(args, cls.name.isContextFunction, cls.name.isErasedFunction)
else if (tp.tupleArity >= 2 && !printDebug) toTextTuple(tp.tupleElementTypes)
else if (isInfixType(tp)) {
val l :: r :: Nil = args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1191,8 +1191,8 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
def Type_isFunctionType(self: Type)(given Context): Boolean =
defn.isFunctionType(self)

def Type_isImplicitFunctionType(self: Type)(given Context): Boolean =
defn.isImplicitFunctionType(self)
def Type_isContextFunctionType(self: Type)(given Context): Boolean =
defn.isContextFunctionType(self)

def Type_isErasedFunctionType(self: Type)(given Context): Boolean =
defn.isErasedFunctionType(self)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/ExpandSAMs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ExpandSAMs extends MiniPhase {
tpt.tpe match {
case NoType =>
tree // it's a plain function
case tpe if defn.isImplicitFunctionType(tpe) =>
case tpe if defn.isContextFunctionType(tpe) =>
tree
case tpe @ SAMType(_) if tpe.isRef(defn.PartialFunctionClass) =>
val tpe1 = checkRefinements(tpe, fn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ShortcutImplicits extends MiniPhase with IdentityDenotTransformer { thisPh
/** Transform `qual.apply` occurrences according to rewrite rule (2) above */
override def transformSelect(tree: Select)(implicit ctx: Context): Tree =
if (tree.name == nme.apply &&
defn.isImplicitFunctionType(tree.qualifier.tpe.widen) &&
defn.isContextFunctionType(tree.qualifier.tpe.widen) &&
needsImplicitShortcut(tree.qualifier.symbol)) {
def directQual(tree: Tree): Tree = tree match {
case Apply(fn, args) => cpy.Apply(tree)(directQual(fn), args)
Expand Down Expand Up @@ -165,7 +165,7 @@ object ShortcutImplicits {
*/
def needsImplicitShortcut(sym: Symbol)(implicit ctx: Context): Boolean =
sym.is(Method, butNot = Accessor) &&
defn.isImplicitFunctionType(sym.info.finalResultType) &&
defn.isContextFunctionType(sym.info.finalResultType) &&
defn.functionArity(sym.info.finalResultType) > 0 &&
!sym.isAnonymousFunction &&
(specializeMonoTargets || !sym.isEffectivelyFinal || sym.allOverriddenSymbols.nonEmpty)
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ object Splicer {
}

def getDirectName(tp: Type, name: TermName): TermName = tp.widenDealias match {
case tp: AppliedType if defn.isImplicitFunctionType(tp) =>
case tp: AppliedType if defn.isContextFunctionType(tp) =>
getDirectName(tp.args.last, NameKinds.DirectMethodName(name))
case _ => name
}
Expand Down Expand Up @@ -468,8 +468,8 @@ object Splicer {
else java.lang.Class.forName(javaSig(param), false, classLoader)
}
def getExtraParams(tp: Type): List[Type] = tp.widenDealias match {
case tp: AppliedType if defn.isImplicitFunctionType(tp) =>
// Call implicit function type direct method
case tp: AppliedType if defn.isContextFunctionType(tp) =>
// Call context function type direct method
tp.args.init.map(arg => TypeErasure.erasure(arg)) ::: getExtraParams(tp.args.last)
case _ => Nil
}
Expand All @@ -496,7 +496,7 @@ object Splicer {

private object Call0 {
def unapply(arg: Tree)(implicit ctx: Context): Option[(RefTree, List[List[Tree]])] = arg match {
case Select(Call0(fn, args), nme.apply) if defn.isImplicitFunctionType(fn.tpe.widenDealias.finalResultType) =>
case Select(Call0(fn, args), nme.apply) if defn.isContextFunctionType(fn.tpe.widenDealias.finalResultType) =>
Some((fn, args))
case fn: RefTree => Some((fn, Nil))
case Apply(f @ Call0(fn, args1), args2) =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ trait Implicits { self: Typer =>
(formal, span) => implicit ctx => formal match {
case AppliedType(_, funArgs @ fun :: tupled :: Nil) =>
def functionTypeEqual(baseFun: Type, actualArgs: List[Type], actualRet: Type, expected: Type) =
expected =:= defn.FunctionOf(actualArgs, actualRet, defn.isImplicitFunctionType(baseFun), defn.isErasedFunctionType(baseFun))
expected =:= defn.FunctionOf(actualArgs, actualRet, defn.isContextFunctionType(baseFun), defn.isErasedFunctionType(baseFun))
val arity: Int =
if (defn.isErasedFunctionType(fun) || defn.isErasedFunctionType(fun)) -1 // TODO support?
else if (defn.isFunctionType(fun))
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ object ProtoTypes {
case et: ExprType =>
normalize(et.resultType, pt)
case wtp =>
val iftp = defn.asImplicitFunctionType(wtp)
val iftp = defn.asContextFunctionType(wtp)
if (iftp.exists) normalize(iftp.dropDependentRefinement.argInfos.last, pt) else tp
}
}
Expand Down
Loading