portals icon indicating copy to clipboard operation
portals copied to clipboard

Problems with nesting portal tasks within an Init

Open jspenger opened this issue 1 year ago • 0 comments

There is a pervasive issue with nesting portal tasks within an init. The problem is that the type of the task will be init and not one of the portal tasks (asker, replier); this is a problem as launching the tasks corretly in the runtime requires knowing this information. For this reason, there is a compilation well-formedness check that checks for this.

A better solution would be to leak the information about the nested task-type to the outer init, such that we can access this information in the compilation and the runtime dispatching.

Example:

TaskBuilder.init[Int, Nothing] {
  // initialize the aggregate
  val sum = PerTaskState[Int]("sum", 0)
  TaskBuilder
    .replier[Int, Nothing, Query, QueryReply](portal) { x =>
      sum.set(sum.get() + x) // aggregates sum
    } { case Query() =>
      reply(QueryReply(PerTaskState("sum", 0).get()))
    }
}

The example will be problematic down the line, as explained above, it will not be recognized as a replier by the dispatcher or by the compiler.

jspenger avatar Apr 07 '23 11:04 jspenger