Description
Summary:
Both:
- the Gremlin graph, and
- the generated diagram,
should include types as edge (transition) labels wherever possible.
Problem description:
How can't one get the types of a stage from an Akka Streams Graph
? Let me count the ways:
- obviously, it's not possible from the
Graph
itself, nor itsShape
. At least one of those would have to be anHList
-like structure for that; - it's not possible to get that information from the
Traversal
- for the exact same reason; - moreover, even given a
Stage
, one can't infer the types from itsInlet
s andOutlet
s, as the correspondingList
s are wildcard-typed.
So, the requirement is to capture every stage practically at the time of creation (at least before it passes an operation that results in type erasure) and store its associated, fully-typed Shape
, accessible by the graph generator.
Problem solution:
A possible solution would thus involve:
- a TTL/LRU/etc.-based registry mapping between stage instances and their inlet/outlet type,
- a macro/compiler plugin the would rewrite each stage creation instruction into a "wrapped" version, containing the registry store call.
- finally, and trivially, a modification to the
Traversal
parser that references said registry and matches edge labels to the corresponding types.
Regarding point 2 - in other words, we would like to automate converting this:
Source.single("0").map(_.toInt).to(Sink.seq[Int])
into this:
⇑(⇑(Source.single("0")).map(_.toInt)).to(⇑(Sink.seq[Int]))
where:
def ⇑[T <: Graph[_ <: Shape, _]: TypeTag](g: T): T = {
storeInSomeRegistry(g, typeOf[T])
g
}
Note that there will also be some typesystem deconstruction involved - for example the actual typeOf[T]
in the example above is:
akka.stream.scaladsl.Source[java.lang.String,akka.NotUsed]
akka.stream.scaladsl.Source[Int,akka.NotUsed]
akka.stream.scaladsl.Sink[Int,scala.concurrent.Future[scala.collection.immutable.Seq[Int]]]
And not e.g. Graph[SinkShape[....
.
Of course, just adding the registry and allowing users to manually insert registration invocations would be a good first step.