A kotlin compiler plugin that turns an annotated K...
# compiler
o
A kotlin compiler plugin that turns an annotated Kotlin lambda into an expression tree represented by Kotlin runtime model types. https://github.com/Kronos-orm/kotlin-expr-tree-kcp
🔥 1
👀 4
s
c
Should this be integrated with the Power Assert KEEP? It can't analyse lambda contents AFAIK
s
cc\\ @bnorm
b
The problem for Power-Assert and lambdas is it needs the execution result of the lambda code, not just the expression tree. How we capture both the result of a lambda and the
Explanation
of the code within the lambda every time it is executed is complex. (And how you diagram it is another non-trivial question) Doing all of that at the call-site when calling functions that only take the lambda (potentially inlined!) is...difficult. Happy to go into further details, but don't want to distract this thread from the original post.
c
Can you clarify how this problem differs from what this plugin does? If I understand correctly, it also captures the intermediate operations within the lambda + allows to execute the lambda
b
It doesn't appear that this plugin captures the results of executing the lambda. Only the tree representation of the lambda itself (basically, an IR of the lambda). It looks like the plugin exposes "bind closure captures", which I take to be variables captured by the lambda when it is created, not expression results as part of it's execution.
c
Ohhh I see the difference now. Thanks for the clarification 🙏
b
But I could be wrong! Maybe I'm reading it incorrectly. Would definitely want to take a closer look if it is capturing expression results as part of lambda execution.
o
@bnorm Yes, your reading is correct—thanks for making that distinction. The plugin currently captures the expression structure and the values of captured variables, rather than the intermediate results produced during each invocation. For DSL parameters annotated with @ExprCapture, it also preserves an executable lambda alongside the tree, but invoking it does not record an execution trace. For example, with { user -> user.age >= minimum }, it represents the property access and comparison and binds minimum; it does not record the value of user.age or the comparison result for each call. My primary use case is inspecting and translating Kotlin expressions for query and rule DSLs. Supporting Power-Assert-style explanations would require additional execution instrumentation and a way to associate values with expressions for each invocation. There may be useful overlap in the expression representation and source mapping. I’d be interested in hearing more about those constraints if you’d like to elaborate here.
🧵 2