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