Last active
August 27, 2021 01:21
-
-
Save retronym/2cfd59578e64a8132286dca166611d1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object FindCollectionReturningHofs extends App { | |
import scala.tools.nsc._ | |
val global = new Global(new Settings) | |
import global._ | |
import global.settings | |
settings.usejavacp.value = true | |
settings.embeddedDefaults(getClass.getClassLoader) | |
new Run() | |
val results = mutable.HashMap[Symbol, mutable.Buffer[Symbol]]() | |
def hasLambdaParam(owner: Symbol) = owner.paramLists.flatten.exists { x => | |
val paramTp = definitions.dropRepeated(x.info) | |
definitions.isFunctionType(paramTp) || definitions.isPartialFunctionType(paramTp) | |
} | |
def walk(owner: Symbol): Unit = { | |
definitions.fullyInitializeSymbol(owner) | |
if (owner.isMethod && !owner.isConstructor && !owner.isPrivate) { | |
// TODO do we have any SAM lambdas? | |
if (owner.owner.name.endsWith("Ops")) { | |
val resultType = owner.info.finalResultType.typeSymbolDirect | |
if (resultType.isTypeParameter && resultType.owner.isClass && resultType.info.isHigherKinded) { | |
if (hasLambdaParam(owner)) { | |
val base = owner.overrideChain.last | |
results.getOrElseUpdate(base, mutable.ArrayBuffer()).addOne(owner.owner) | |
} | |
} | |
} | |
} | |
if (owner.isClass) { | |
owner.info.decls.foreach(walk) | |
} | |
else if (owner.isModule) walk(owner.moduleClass) | |
} | |
walk(rootMirror.getPackage("scala.collection")) | |
val hofNames = results.keys.map(_.name).toSet | |
def walk2(owner: Symbol): Unit = { | |
definitions.fullyInitializeSymbol(owner) | |
if (owner.isMethod && !owner.isConstructor && !owner.isPrivate) { | |
// TODO do we have any SAM lambdas? | |
if (!owner.owner.name.endsWith("Ops")) { | |
if (owner.name.string_==("flatMap")) | |
getClass | |
if (hasLambdaParam(owner) && hofNames.contains(owner.name)) { | |
val base = owner.overrideChain.last | |
results.getOrElseUpdate(base, mutable.ArrayBuffer()).addOne(owner.owner) | |
} | |
} | |
} | |
if (owner.isClass) { | |
owner.info.decls.foreach(walk2) | |
} | |
else if (owner.isModule) walk2(owner.moduleClass) | |
} | |
walk2(rootMirror.getPackage("scala.collection")) | |
println(results.toSeq.sortBy(x => (x._1.name.toString, x._1.owner.baseClasses.size)).map { | |
{ | |
case (base, overrides) => | |
s"== ${base.owner.fullName} - ${base.defString} ==\n${overrides.sortBy(x => (x.baseClasses.size, x.name.toString)).map(_.fullName).mkString(" ", "\n ", "")}\n\n" | |
} | |
}.mkString("\b")) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/Users/jz/.jabba/jdk/[email protected]/Contents/Home/bin/java -javaagent:/Users/jz/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/212.5080.39/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=50684:/Users/jz/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/212.5080.39/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Users/jz/code/scala-compat/compat213/target/scala-2.13/classes:/Users/jz/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/net/java/dev/jna/jna/5.3.1/jna-5.3.1.jar:/Users/jz/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/jline/jline/3.19.0/jline-3.19.0.jar:/Users/jz/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-collection-compat_2.13/2.5.0/scala-collection-compat_2.13-2.5.0.jar:/Users/jz/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.13.6/scala-compiler-2.13.6.jar:/Users/jz/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.6/scala-library-2.13.6.jar:/Users/jz/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.13.6/scala-reflect-2.13.6.jar demo.compat.FindCollectionReturningHofs | |
== scala.collection.IterableOnceOps - def collect[B](pf: PartialFunction[A,B]): CC[B] == | |
scala.collection.IterableOnceOps | |
scala.collection.IterableOps | |
scala.collection.Iterator | |
scala.collection.StrictOptimizedIterableOps | |
scala.collection.immutable.LazyList | |
scala.collection.immutable.Stream | |
scala.collection.immutable.List | |
== scala.collection.MapOps - def collect[K2, V2](pf: PartialFunction[(K, V),(K2, V2)]): CC[K2,V2] == | |
scala.collection.MapOps | |
scala.collection.StrictOptimizedMapOps | |
scala.collection.immutable.TreeSeqMap | |
== scala.collection.SortedSetOps - def collect[B](pf: PartialFunction[A,B])(implicit ev: Ordering[B]): CC[B] == | |
scala.collection.SortedSetOps | |
scala.collection.StrictOptimizedSortedSetOps | |
scala.collection.immutable.BitSet | |
scala.collection.mutable.BitSet | |
== scala.collection.SortedMapOps - def collect[K2, V2](pf: PartialFunction[(K, V),(K2, V2)])(implicit ordering: Ordering[K2]): CC[K2,V2] == | |
scala.collection.SortedMapOps | |
scala.collection.StrictOptimizedSortedMapOps | |
== scala.collection.BitSetOps - def collect(pf: PartialFunction[Int,Int]): C == | |
scala.collection.immutable.BitSet | |
scala.collection.mutable.BitSet | |
== scala.collection.immutable.LongMap - def collect[V2](pf: PartialFunction[(scala.collection.immutable.LongMapUtils.Long, T),(scala.collection.immutable.LongMapUtils.Long, V2)]): scala.collection.immutable.LongMap[V2] == | |
scala.collection.immutable.LongMap | |
== scala.collection.immutable.IntMap - def collect[V2](pf: PartialFunction[(scala.collection.immutable.IntMapUtils.Int, T),(scala.collection.immutable.IntMapUtils.Int, V2)]): scala.collection.immutable.IntMap[V2] == | |
scala.collection.immutable.IntMap | |
== scala.collection.mutable.LongMap - def collect[V2](pf: PartialFunction[(Long, V),(Long, V2)]): scala.collection.mutable.LongMap[V2] == | |
scala.collection.mutable.LongMap | |
== scala.collection.mutable.AnyRefMap - def collect[K2 <: AnyRef, V2](pf: PartialFunction[(K, V),(K2, V2)])(implicit dummy: DummyImplicit): scala.collection.mutable.AnyRefMap[K2,V2] == | |
scala.collection.mutable.AnyRefMap | |
== scala.collection.mutable.CollisionProofHashMap - def collect[K2, V2](pf: PartialFunction[(K, V),(K2, V2)])(implicit ordering: Ordering[K2]): scala.collection.mutable.CollisionProofHashMap[K2,V2] == | |
scala.collection.mutable.CollisionProofHashMap | |
== scala.collection.IterableOnceOps - def flatMap[B](f: A => scala.collection.IterableOnce[B]): CC[B] == | |
scala.collection.IterableOnceOps | |
scala.collection.IterableOps | |
scala.collection.Iterator | |
scala.collection.StrictOptimizedIterableOps | |
scala.collection.immutable.LazyList | |
scala.collection.immutable.Stream | |
scala.collection.immutable.List | |
== scala.collection.StringOps.WithFilter - def flatMap[B](f: Char => scala.collection.IterableOnce[B]): IndexedSeq[B] == | |
scala.collection.StringOps.WithFilter | |
== scala.collection.LazyZip4 - def flatMap[B, C](f: (El1, El2, El3, El4) => Iterable[B])(implicit bf: scala.collection.BuildFrom[C1,B,C]): C == | |
scala.collection.LazyZip4 | |
== scala.collection.LazyZip3 - def flatMap[B, C](f: (El1, El2, El3) => Iterable[B])(implicit bf: scala.collection.BuildFrom[C1,B,C]): C == | |
scala.collection.LazyZip3 | |
== scala.collection.IterableOnceExtensionMethods - def flatMap[B](f: A => scala.collection.IterableOnce[B]): scala.collection.IterableOnce[B] == | |
scala.collection.IterableOnceExtensionMethods | |
== scala.collection.StringOps.WithFilter - def flatMap(f: Char => String): String == | |
scala.collection.StringOps.WithFilter | |
== scala.collection.LazyZip2 - def flatMap[B, C](f: (El1, El2) => Iterable[B])(implicit bf: scala.collection.BuildFrom[C1,B,C]): C == | |
scala.collection.LazyZip2 | |
== scala.collection.ArrayOps.WithFilter - def flatMap[BS, B](f: A => BS)(implicit asIterable: BS => Iterable[B], implicit m: scala.reflect.ClassTag[B]): Array[B] == | |
scala.collection.ArrayOps.WithFilter | |
== scala.collection.ArrayOps.WithFilter - def flatMap[B](f: A => scala.collection.IterableOnce[B])(implicit evidence$2: scala.reflect.ClassTag[B]): Array[B] == | |
scala.collection.ArrayOps.WithFilter | |
== scala.collection.WithFilter - def flatMap[B](f: A => scala.collection.IterableOnce[B]): CC[B] == | |
scala.collection.WithFilter | |
scala.collection.IterableOps.WithFilter | |
scala.collection.immutable.LazyList.WithFilter | |
scala.collection.immutable.Stream.WithFilter | |
== scala.collection.MapOps.WithFilter - def flatMap[K2, V2](f: ((K, V)) => scala.collection.IterableOnce[(K2, V2)]): CC[K2,V2] == | |
scala.collection.MapOps.WithFilter | |
== scala.collection.SortedSetOps.WithFilter - def flatMap[B](f: A => scala.collection.IterableOnce[B])(implicit evidence$2: Ordering[B]): CC[B] == | |
scala.collection.SortedSetOps.WithFilter | |
== scala.collection.SortedMapOps.WithFilter - def flatMap[K2, V2](f: ((K, V)) => scala.collection.IterableOnce[(K2, V2)])(implicit evidence$2: Ordering[K2]): CC[K2,V2] == | |
scala.collection.SortedMapOps.WithFilter | |
== scala.collection.MapOps - def flatMap[K2, V2](f: ((K, V)) => scala.collection.IterableOnce[(K2, V2)]): CC[K2,V2] == | |
scala.collection.MapOps | |
scala.collection.StrictOptimizedMapOps | |
scala.collection.immutable.TreeSeqMap | |
== scala.collection.SortedSetOps - def flatMap[B](f: A => scala.collection.IterableOnce[B])(implicit ev: Ordering[B]): CC[B] == | |
scala.collection.SortedSetOps | |
scala.collection.StrictOptimizedSortedSetOps | |
scala.collection.immutable.BitSet | |
scala.collection.mutable.BitSet | |
== scala.collection.SortedMapOps - def flatMap[K2, V2](f: ((K, V)) => scala.collection.IterableOnce[(K2, V2)])(implicit ordering: Ordering[K2]): CC[K2,V2] == | |
scala.collection.SortedMapOps | |
scala.collection.StrictOptimizedSortedMapOps | |
== scala.collection.BitSetOps - def flatMap(f: Int => scala.collection.IterableOnce[Int]): C == | |
scala.collection.immutable.BitSet | |
scala.collection.mutable.BitSet | |
== scala.collection.immutable.IntMap - def flatMap[V2](f: ((scala.collection.immutable.IntMapUtils.Int, T)) => scala.collection.IterableOnce[(scala.collection.immutable.IntMapUtils.Int, V2)]): scala.collection.immutable.IntMap[V2] == | |
scala.collection.immutable.IntMap | |
== scala.collection.immutable.LongMap - def flatMap[V2](f: ((scala.collection.immutable.LongMapUtils.Long, T)) => scala.collection.IterableOnce[(scala.collection.immutable.LongMapUtils.Long, V2)]): scala.collection.immutable.LongMap[V2] == | |
scala.collection.immutable.LongMap | |
== scala.collection.mutable.CollisionProofHashMap - def flatMap[K2, V2](f: ((K, V)) => scala.collection.IterableOnce[(K2, V2)])(implicit ordering: Ordering[K2]): scala.collection.mutable.CollisionProofHashMap[K2,V2] == | |
scala.collection.mutable.CollisionProofHashMap | |
== scala.collection.mutable.LongMap - def flatMap[V2](f: ((Long, V)) => scala.collection.IterableOnce[(Long, V2)]): scala.collection.mutable.LongMap[V2] == | |
scala.collection.mutable.LongMap | |
== scala.collection.mutable.AnyRefMap - def flatMap[K2 <: AnyRef, V2](f: ((K, V)) => scala.collection.IterableOnce[(K2, V2)])(implicit dummy: DummyImplicit): scala.collection.mutable.AnyRefMap[K2,V2] == | |
scala.collection.mutable.AnyRefMap | |
== scala.collection.IterableOnceOps - def flatten[B](implicit asIterable: A => scala.collection.IterableOnce[B]): CC[B] == | |
scala.collection.IterableOnceOps | |
scala.collection.IterableOps | |
scala.collection.Iterator | |
scala.collection.StrictOptimizedIterableOps | |
scala.collection.immutable.LazyList | |
== scala.collection.IterableOnceOps - def map[B](f: A => B): CC[B] == | |
scala.collection.IterableOnceOps | |
scala.collection.IterableOps | |
scala.collection.Iterator | |
scala.collection.StrictOptimizedIterableOps | |
scala.collection.IndexedSeqOps | |
scala.collection.SeqView | |
scala.collection.IndexedSeqView | |
scala.collection.immutable.LazyList | |
scala.collection.immutable.Stream | |
scala.collection.immutable.Range | |
scala.collection.immutable.ArraySeq | |
scala.collection.immutable.List | |
scala.collection.immutable.Vector1 | |
scala.collection.immutable.Vector0 | |
scala.collection.immutable.Vector2 | |
scala.collection.immutable.Vector3 | |
scala.collection.immutable.Vector4 | |
scala.collection.immutable.Vector5 | |
scala.collection.immutable.Vector6 | |
== scala.collection.IterableOnceExtensionMethods - def map[B](f: A => B): scala.collection.IterableOnce[B] == | |
scala.collection.IterableOnceExtensionMethods | |
== scala.collection.StringOps.WithFilter - def map(f: Char => Char): String == | |
scala.collection.StringOps.WithFilter | |
== scala.collection.StringOps.WithFilter - def map[B](f: Char => B): IndexedSeq[B] == | |
scala.collection.StringOps.WithFilter | |
== scala.collection.LazyZip4 - def map[B, C](f: (El1, El2, El3, El4) => B)(implicit bf: scala.collection.BuildFrom[C1,B,C]): C == | |
scala.collection.LazyZip4 | |
== scala.collection.LazyZip3 - def map[B, C](f: (El1, El2, El3) => B)(implicit bf: scala.collection.BuildFrom[C1,B,C]): C == | |
scala.collection.LazyZip3 | |
== scala.collection.ArrayOps.WithFilter - def map[B](f: A => B)(implicit evidence$1: scala.reflect.ClassTag[B]): Array[B] == | |
scala.collection.ArrayOps.WithFilter | |
== scala.collection.LazyZip2 - def map[B, C](f: (El1, El2) => B)(implicit bf: scala.collection.BuildFrom[C1,B,C]): C == | |
scala.collection.LazyZip2 | |
== scala.collection.WithFilter - def map[B](f: A => B): CC[B] == | |
scala.collection.WithFilter | |
scala.collection.IterableOps.WithFilter | |
scala.collection.immutable.LazyList.WithFilter | |
scala.collection.immutable.Stream.WithFilter | |
== scala.collection.MapOps.WithFilter - def map[K2, V2](f: ((K, V)) => (K2, V2)): CC[K2,V2] == | |
scala.collection.MapOps.WithFilter | |
== scala.collection.SortedSetOps.WithFilter - def map[B](f: A => B)(implicit evidence$1: Ordering[B]): CC[B] == | |
scala.collection.SortedSetOps.WithFilter | |
== scala.collection.SortedMapOps.WithFilter - def map[K2, V2](f: ((K, V)) => (K2, V2))(implicit evidence$1: Ordering[K2]): CC[K2,V2] == | |
scala.collection.SortedMapOps.WithFilter | |
== scala.collection.MapOps - def map[K2, V2](f: ((K, V)) => (K2, V2)): CC[K2,V2] == | |
scala.collection.MapOps | |
scala.collection.StrictOptimizedMapOps | |
scala.collection.immutable.TreeSeqMap | |
== scala.collection.SortedSetOps - def map[B](f: A => B)(implicit ev: Ordering[B]): CC[B] == | |
scala.collection.SortedSetOps | |
scala.collection.StrictOptimizedSortedSetOps | |
scala.collection.immutable.BitSet | |
scala.collection.mutable.BitSet | |
== scala.collection.BitSetOps - def map(f: Int => Int): C == | |
scala.collection.immutable.BitSet | |
scala.collection.mutable.BitSet | |
== scala.collection.SortedMapOps - def map[K2, V2](f: ((K, V)) => (K2, V2))(implicit ordering: Ordering[K2]): CC[K2,V2] == | |
scala.collection.SortedMapOps | |
scala.collection.StrictOptimizedSortedMapOps | |
== scala.collection.immutable.LongMap - def map[V2](f: ((scala.collection.immutable.LongMapUtils.Long, T)) => (scala.collection.immutable.LongMapUtils.Long, V2)): scala.collection.immutable.LongMap[V2] == | |
scala.collection.immutable.LongMap | |
== scala.collection.immutable.IntMap - def map[V2](f: ((scala.collection.immutable.IntMapUtils.Int, T)) => (scala.collection.immutable.IntMapUtils.Int, V2)): scala.collection.immutable.IntMap[V2] == | |
scala.collection.immutable.IntMap | |
== scala.collection.mutable.CollisionProofHashMap - def map[K2, V2](f: ((K, V)) => (K2, V2))(implicit ordering: Ordering[K2]): scala.collection.mutable.CollisionProofHashMap[K2,V2] == | |
scala.collection.mutable.CollisionProofHashMap | |
== scala.collection.mutable.LongMap - def map[V2](f: ((Long, V)) => (Long, V2)): scala.collection.mutable.LongMap[V2] == | |
scala.collection.mutable.LongMap | |
== scala.collection.mutable.AnyRefMap - def map[K2 <: AnyRef, V2](f: ((K, V)) => (K2, V2))(implicit dummy: DummyImplicit): scala.collection.mutable.AnyRefMap[K2,V2] == | |
scala.collection.mutable.AnyRefMap | |
== scala.collection.SeqOps - def reverseMap[B](f: A => B): CC[B] == | |
scala.collection.SeqOps | |
== scala.collection.IterableOps - def scan[B >: A](z: B)(op: (B, B) => B): CC[B] == | |
scala.collection.IterableOps | |
== scala.collection.IterableOnceOps - def scanLeft[B](z: B)(op: (B, A) => B): CC[B] == | |
scala.collection.IterableOnceOps | |
scala.collection.IterableOps | |
scala.collection.Iterator | |
scala.collection.StrictOptimizedIterableOps | |
scala.collection.immutable.LazyList | |
scala.collection.immutable.Stream | |
== scala.collection.IterableOps - def scanRight[B](z: B)(op: (A, B) => B): CC[B] == | |
scala.collection.IterableOps | |
== scala.collection.Iterator - def scanRight[B](z: B)(op: (A, B) => B): Iterator[B] == | |
scala.collection.Iterator | |
== scala.collection.immutable.RedBlackTree - def transform[A, B, C](t: scala.collection.immutable.RedBlackTree.Tree[A,B], f: (A, B) => C): scala.collection.immutable.RedBlackTree.Tree[A,C] == | |
scala.collection.immutable.RedBlackTree | |
== scala.collection.mutable.RedBlackTree - def transform[A, B](tree: scala.collection.mutable.RedBlackTree.Tree[A,B], f: (A, B) => B): Unit == | |
scala.collection.mutable.RedBlackTree | |
== scala.collection.immutable.MapNode - def transform[W](f: (K, V) => W): scala.collection.immutable.MapNode[K,W] == | |
scala.collection.immutable.MapNode | |
scala.collection.immutable.BitmapIndexedMapNode | |
scala.collection.immutable.HashCollisionMapNode | |
== scala.collection.immutable.MapOps - def transform[W](f: (K, V) => W): CC[K,W] == | |
scala.collection.immutable.MapOps | |
scala.collection.immutable.SortedMapOps | |
scala.collection.immutable.Map.Map1 | |
scala.collection.immutable.Map.Map2 | |
scala.collection.immutable.Map.Map3 | |
scala.collection.immutable.Map.Map4 | |
scala.collection.immutable.IntMap | |
scala.collection.immutable.LongMap | |
scala.collection.immutable.HashMap | |
scala.collection.immutable.TreeMap | |
== scala.collection.IterableOps - def transpose[B](implicit asIterable: A => Iterable[B]): CC[CC[B] @scala.annotation.unchecked.uncheckedVariance] == | |
scala.collection.IterableOps | |
scala.collection.immutable.LazyList | |
== scala.collection.immutable.MapOps - def updatedWith[V1 >: V](key: K)(remappingFunction: Option[V] => Option[V1]): CC[K,V1] == | |
scala.collection.immutable.MapOps | |
scala.collection.immutable.SortedMapOps | |
scala.collection.immutable.HashMap | |
Process finished with exit code 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment