Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding type annotations to graph edges #1

Open
2 of 3 tasks
mikolak-net opened this issue Jan 11, 2018 · 1 comment
Open
2 of 3 tasks

Adding type annotations to graph edges #1

mikolak-net opened this issue Jan 11, 2018 · 1 comment
Assignees
Milestone

Comments

@mikolak-net
Copy link
Owner

mikolak-net commented Jan 11, 2018

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 its Shape. At least one of those would have to be an HList-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 its Inlets and Outlets, as the corresponding Lists 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.

mikolak-net added a commit that referenced this issue Jan 14, 2018
mikolak-net added a commit that referenced this issue Jan 14, 2018
mikolak-net added a commit that referenced this issue Jan 14, 2018
mikolak-net added a commit that referenced this issue Jan 18, 2018
mikolak-net added a commit that referenced this issue Jan 18, 2018
Does not compile at the moment.
@mikolak-net mikolak-net modified the milestones: v0.8, v0.9 Jan 22, 2018
@mikolak-net
Copy link
Owner Author

A partial solution (manual registration) will be available in the immediately upcoming version. Automatic derivation will come later on - see this SO question for the abstracted form of the current blocker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant