@@ -637,13 +637,9 @@ class Definitions {
637
637
FunctionType (args.length, isImplicit).appliedTo(args ::: resultType :: Nil )
638
638
def unapply (ft : Type )(implicit ctx : Context ) = {
639
639
val tsym = ft.typeSymbol
640
- val isImplicitFun = isImplicitFunctionClass(tsym)
641
- if (isImplicitFun || isFunctionClass(tsym)) {
642
- val targs = ft.argInfos
643
- val numArgs = targs.length - 1
644
- if (numArgs >= 0 && FunctionType (numArgs, isImplicitFun).symbol == tsym)
645
- Some (targs.init, targs.last, isImplicitFun)
646
- else None
640
+ if (isFunctionClass(tsym)) {
641
+ val targs = ft.dealias.argInfos
642
+ Some (targs.init, targs.last, tsym.name.isImplicitFunction)
647
643
}
648
644
else None
649
645
}
@@ -696,20 +692,17 @@ class Definitions {
696
692
lazy val TupleType = mkArityArray(" scala.Tuple" , MaxTupleArity , 2 )
697
693
lazy val ProductNType = mkArityArray(" scala.Product" , MaxTupleArity , 0 )
698
694
699
- def FunctionClass (n : Int )(implicit ctx : Context ) =
700
- if (n < MaxImplementedFunctionArity ) FunctionClassPerRun ()(ctx)(n)
695
+ def FunctionClass (n : Int , isImplicit : Boolean = false )(implicit ctx : Context ) =
696
+ if (isImplicit) ctx.requiredClass(" scala.ImplicitFunction" + n.toString)
697
+ else if (n <= MaxImplementedFunctionArity ) FunctionClassPerRun ()(ctx)(n)
701
698
else ctx.requiredClass(" scala.Function" + n.toString)
702
699
703
700
lazy val Function0_applyR = ImplementedFunctionType (0 ).symbol.requiredMethodRef(nme.apply)
704
701
def Function0_apply (implicit ctx : Context ) = Function0_applyR .symbol
705
702
706
- def ImplicitFunctionClass (n : Int )(implicit ctx : Context ) =
707
- ctx.requiredClass(" scala.ImplicitFunction" + n.toString)
708
-
709
703
def FunctionType (n : Int , isImplicit : Boolean = false )(implicit ctx : Context ): TypeRef =
710
- if (isImplicit && ! ctx.erasedTypes) ImplicitFunctionClass (n).typeRef
711
- else if (n < MaxImplementedFunctionArity ) ImplementedFunctionType (n)
712
- else FunctionClass (n).typeRef
704
+ if (n <= MaxImplementedFunctionArity && (! isImplicit || ctx.erasedTypes)) ImplementedFunctionType (n)
705
+ else FunctionClass (n, isImplicit).typeRef
713
706
714
707
private lazy val TupleTypes : Set [TypeRef ] = TupleType .toSet
715
708
private lazy val ProductTypes : Set [TypeRef ] = ProductNType .toSet
@@ -733,14 +726,61 @@ class Definitions {
733
726
def isBottomType (tp : Type ) =
734
727
tp.derivesFrom(NothingClass ) || tp.derivesFrom(NullClass )
735
728
736
- def isFunctionClass (cls : Symbol ) = isVarArityClass(cls, tpnme.Function )
737
- def isImplicitFunctionClass (cls : Symbol ) = isVarArityClass(cls, tpnme.ImplicitFunction )
738
- /** Is a class that will be erased to FunctionXXL */
739
- def isXXLFunctionClass (cls : Symbol ) = cls.name.functionArity > MaxImplementedFunctionArity
729
+ /** Is a function class.
730
+ * - FunctionN for N >= 0
731
+ * - ImplicitFunctionN for N >= 0
732
+ */
733
+ def isFunctionClass (cls : Symbol ) = scalaClassName(cls).isFunction
734
+
735
+ /** Is an implicit function class.
736
+ * - ImplicitFunctionN for N >= 0
737
+ */
738
+ def isImplicitFunctionClass (cls : Symbol ) = scalaClassName(cls).isImplicitFunction
739
+
740
+ /** Is a class that will be erased to FunctionXXL
741
+ * - FunctionN for N >= 22
742
+ * - ImplicitFunctionN for N >= 22
743
+ */
744
+ def isXXLFunctionClass (cls : Symbol ) = scalaClassName(cls).functionArity > MaxImplementedFunctionArity
745
+
746
+ /** Is a synthetic function class
747
+ * - FunctionN for N > 22
748
+ * - ImplicitFunctionN for N >= 0
749
+ */
750
+ def isSyntheticFunctionClass (cls : Symbol ) = scalaClassName(cls).isSyntheticFunction
751
+
740
752
def isAbstractFunctionClass (cls : Symbol ) = isVarArityClass(cls, tpnme.AbstractFunction )
741
753
def isTupleClass (cls : Symbol ) = isVarArityClass(cls, tpnme.Tuple )
742
754
def isProductClass (cls : Symbol ) = isVarArityClass(cls, tpnme.Product )
743
755
756
+ /** Returns the erased class of the function class `cls`
757
+ * - FunctionN for N > 22 becomes FunctionXXL
758
+ * - FunctionN for 22 > N >= 0 remains as FunctionN
759
+ * - ImplicitFunctionN for N > 22 becomes FunctionXXL
760
+ * - ImplicitFunctionN for 22 > N >= 0 becomes FunctionN
761
+ * - anything else becomes a NoSymbol
762
+ */
763
+ def erasedFunctionClass (cls : Symbol ): Symbol = {
764
+ val arity = scalaClassName(cls).functionArity
765
+ if (arity > 22 ) defn.FunctionXXLClass
766
+ else if (arity >= 0 ) defn.FunctionClass (arity)
767
+ else NoSymbol
768
+ }
769
+
770
+ /** Returns the erased type of the function class `cls`
771
+ * - FunctionN for N > 22 becomes FunctionXXL
772
+ * - FunctionN for 22 > N >= 0 remains as FunctionN
773
+ * - ImplicitFunctionN for N > 22 becomes FunctionXXL
774
+ * - ImplicitFunctionN for 22 > N >= 0 becomes FunctionN
775
+ * - anything else becomes a NoType
776
+ */
777
+ def erasedFunctionType (cls : Symbol ): Type = {
778
+ val arity = scalaClassName(cls).functionArity
779
+ if (arity > 22 ) defn.FunctionXXLType
780
+ else if (arity >= 0 ) defn.FunctionType (arity)
781
+ else NoType
782
+ }
783
+
744
784
val predefClassNames : Set [Name ] =
745
785
Set (" Predef$" , " DeprecatedPredef" , " LowPriorityImplicits" ).map(_.toTypeName)
746
786
@@ -811,16 +851,13 @@ class Definitions {
811
851
def isFunctionType (tp : Type )(implicit ctx : Context ) = {
812
852
val arity = functionArity(tp)
813
853
val sym = tp.dealias.typeSymbol
814
- arity >= 0 && (
815
- isFunctionClass(sym) && tp.isRef(FunctionType (arity, isImplicit = false ).typeSymbol) ||
816
- isImplicitFunctionClass(sym) && tp.isRef(FunctionType (arity, isImplicit = true ).typeSymbol)
817
- )
854
+ arity >= 0 && isFunctionClass(sym) && tp.isRef(FunctionType (arity, sym.name.isImplicitFunction).typeSymbol)
818
855
}
819
856
820
857
def functionArity (tp : Type )(implicit ctx : Context ) = tp.dealias.argInfos.length - 1
821
858
822
859
def isImplicitFunctionType (tp : Type )(implicit ctx : Context ) =
823
- isFunctionType(tp) && tp.dealias.typeSymbol.name.startsWith(tpnme. ImplicitFunction )
860
+ isFunctionType(tp) && tp.dealias.typeSymbol.name.isImplicitFunction
824
861
825
862
// ----- primitive value class machinery ------------------------------------------
826
863
@@ -894,9 +931,6 @@ class Definitions {
894
931
895
932
// ----- Initialization ---------------------------------------------------
896
933
897
- private def maxImplemented (name : Name ) =
898
- if (name `startsWith` tpnme.Function ) MaxImplementedFunctionArity else 0
899
-
900
934
/** Give the scala package a scope where a FunctionN trait is automatically
901
935
* added when someone looks for it.
902
936
*/
@@ -906,7 +940,7 @@ class Definitions {
906
940
val newDecls = new MutableScope (oldDecls) {
907
941
override def lookupEntry (name : Name )(implicit ctx : Context ): ScopeEntry = {
908
942
val res = super .lookupEntry(name)
909
- if (res == null && name.isTypeName && name.functionArity > maxImplemented(name) )
943
+ if (res == null && name.isTypeName && name.isSyntheticFunction )
910
944
newScopeEntry(newFunctionNTrait(name.asTypeName))
911
945
else res
912
946
}
0 commit comments