@@ -596,19 +596,51 @@ class Definitions {
596
596
lazy val AbstractFunctionType = mkArityArray(" scala.runtime.AbstractFunction" , MaxAbstractFunctionArity , 0 )
597
597
val AbstractFunctionClassPerRun = new PerRun [Array [Symbol ]](implicit ctx => AbstractFunctionType .map(_.symbol.asClass))
598
598
def AbstractFunctionClass (n : Int )(implicit ctx : Context ) = AbstractFunctionClassPerRun ()(ctx)(n)
599
- lazy val FunctionType = mkArityArray(" scala.Function" , MaxFunctionArity , 0 )
600
- def FunctionClassPerRun = new PerRun [Array [Symbol ]](implicit ctx => FunctionType .map(_.symbol.asClass))
599
+
600
+ private lazy val functionType = mkArityArray(" scala.Function" , MaxFunctionArity , 0 )
601
+ def FunctionType (arity : Int ): TypeRef = {
602
+ if (arity <= MaxFunctionArity ) functionType(arity)
603
+ else SyntheticFunctionType (arity)
604
+ }
605
+ def FunctionClassPerRun = new PerRun [Array [Symbol ]](implicit ctx => functionType.map(_.symbol.asClass))
601
606
def FunctionClass (n : Int )(implicit ctx : Context ) = FunctionClassPerRun ()(ctx)(n)
602
607
lazy val Function0_applyR = FunctionType (0 ).symbol.requiredMethodRef(nme.apply)
603
608
def Function0_apply (implicit ctx : Context ) = Function0_applyR .symbol
604
609
610
+
611
+ private lazy val syntheticFunctionTypeMap = mutable.Map .empty[Int , TypeRef ]
612
+ private def SyntheticFunctionType (arity : Int ): TypeRef = {
613
+ assert(MaxFunctionArity < arity)
614
+ if (syntheticFunctionTypeMap.contains(arity)) syntheticFunctionTypeMap(arity)
615
+ else {
616
+ val cls = mkSyntheticFunction(arity)
617
+ syntheticCoreClasses += cls
618
+ val tpe = cls.typeRef
619
+ syntheticFunctionTypeMap.put(arity, tpe)
620
+ tpe
621
+ }
622
+ }
623
+ private def mkSyntheticFunction (i : Int ): ClassSymbol = {
624
+ val decls = newScope
625
+ val cls = newCompleteClassSymbol(ScalaPackageClass , tpnme.FunctionN (i), Trait , List (AnyRefType ), decls)
626
+ def newTypeParam (name : TypeName , flags : FlagSet , bounds : TypeBounds ) =
627
+ newSymbol(cls, name, flags | ClassTypeParamCreationFlags , bounds)
628
+
629
+ val vParamNames = (0 until i).map(j => s " i $j" .toTermName).toList
630
+ val tParamSyms = (0 until i).map(j => newTypeParam(s " T $j" .toTypeName, Contravariant , TypeBounds .empty)).toList
631
+ val returnTParamSym = newTypeParam(" R" .toTypeName, Covariant , TypeBounds .empty)
632
+ val applyMethod =
633
+ newMethod(cls, nme.apply, MethodType (vParamNames, tParamSyms.map(_.typeRef), returnTParamSym.typeRef), Deferred )
634
+
635
+ tParamSyms.foreach(decls.enter)
636
+ decls.enter(returnTParamSym)
637
+ decls.enter(applyMethod)
638
+ completeClass(cls)
639
+ }
640
+
605
641
lazy val TupleType = mkArityArray(" scala.Tuple" , MaxTupleArity , 2 )
606
642
lazy val ProductNType = mkArityArray(" scala.Product" , MaxTupleArity , 0 )
607
643
608
- private lazy val FunctionTypes : Set [TypeRef ] = FunctionType .toSet
609
- private lazy val TupleTypes : Set [TypeRef ] = TupleType .toSet
610
- private lazy val ProductTypes : Set [TypeRef ] = ProductNType .toSet
611
-
612
644
/** If `cls` is a class in the scala package, its name, otherwise EmptyTypeName */
613
645
def scalaClassName (cls : Symbol )(implicit ctx : Context ): TypeName =
614
646
if (cls.isClass && cls.owner == ScalaPackageClass ) cls.asClass.name else EmptyTypeName
@@ -753,7 +785,7 @@ class Definitions {
753
785
// ----- Initialization ---------------------------------------------------
754
786
755
787
/** Lists core classes that don't have underlying bytecode, but are synthesized on-the-fly in every reflection universe */
756
- lazy val syntheticCoreClasses = List (
788
+ private lazy val syntheticCoreClasses = mutable. ArrayBuffer [ Symbol ] (
757
789
AnyClass ,
758
790
AnyRefAlias ,
759
791
RepeatedParamClass ,
@@ -766,8 +798,10 @@ class Definitions {
766
798
EmptyPackageVal ,
767
799
OpsPackageClass )
768
800
801
+ def isSyntheticCoreClass (sym : ClassSymbol ) = syntheticCoreClasses.contains(sym)
802
+
769
803
/** Lists core methods that don't have underlying bytecode, but are synthesized on-the-fly in every reflection universe */
770
- lazy val syntheticCoreMethods = AnyMethods ++ ObjectMethods ++ List (String_+ , throwMethod)
804
+ private lazy val syntheticCoreMethods = AnyMethods ++ ObjectMethods ++ List (String_+ , throwMethod)
771
805
772
806
private [this ] var _isInitialized = false
773
807
private def isInitialized = _isInitialized
0 commit comments