GSoC 2023 project overview: #79
rssh
started this conversation in
Show and tell
Replies: 1 comment
-
Finally integrated into the mainline. Schema is simplified a bit, generated code is without context parameter:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
One of the components of the dotty-cps-async is a compiler plugin, which allows the representation of monadic computations in a direct form of plain code, where monadic brackets are absent in the code. High-order functions are the natural barriers to code-level CPS transformation. When we apply cps to a lambda expression, we change its type, and therefore, it can't be an argument of the high-order functions, which accept the old type.
This is not a problem for the one-shot continuations on the platforms with continuations supports (such as JVM after JDK21 or native-i64) because we can transform the argument of the altered hight-order function to have the same shape with the help of runtime facilities. Still, we have no such facilities for platforms without continuations (such as JS or potentially scala-native on WASM) or when dealing with more sophisticated monads (such as logic search).
Currently, a developer can write their implementation of the high-order function with changed argument types (let's call this 'shifted version'), and the cps transformer will substitute the function call.
The subject of the project is to implement the generation of
shifted
variants of the high-order function in cases where this is possible (without creating the shifted version of other objects).The developer marks a high-order function by annotation, and a compiler phase generates a shifted variant of the HO function.
Example:
After processing,
I.e., in object MeasurementOps, we have a new method,
gatherStatistics$cps,
which accepts shifted functional argument.Currently, applicability is limited to a method that will invoke supplied functions. This is a partial solution, but it covers several valuable cases. Extending processing to generate shifted variables and objects can be the next step.
The basic of the main transformation is implemented by Olena and will be integrated into the one of the next version of the dotty-cps-async.
Beta Was this translation helpful? Give feedback.
All reactions