I discussed this internally but thought I’d keep e...
# arrow-meta
r
I discussed this internally but thought I’d keep everyone in the loop here too: Here is a preliminary design of what enabling QuasiQuote support over a Compiler Descriptor may look like: https://github.com/47deg/arrow-meta-prototype/compare/rr-tree-quotes-poc#diff-109f0a910d70fe85c5eea3bc6dce4775 That is the basic algebra with an embedded function that exercises the steps it takes to transforms a string into a descriptor tree then back. Supporting then an individual descriptor like ValueParameters may look like this: https://github.com/47deg/arrow-meta-prototype/compare/rr-tree-quotes-poc#diff-21516eec047a3b472606f772e9accd8d Essentially if we implement this algebra for each Declaration Descriptor that there is out there matching the different KtElements and strategies to update or create under a parent then we can support quasiquotes in Kotlin in the
syntheticResolver
. Where users do something like:
Copy code
func({
  "fun <$typeArgs> $name($params): $returnType = $body" //find
}) { fn ->
  "fun <$typeArgs> $name($params): $returnType = $body" //transform
}
In this case that would be the identity element for the
ValueParameter
declaration quote. This is in a similar way the quasiquote style syntax that scala-meta uses and much easier for most use cases to develop compiler plugins in comparison with the compiler internals, descriptor and phases we have to deal today. Say you had a use case to add logging to all functions named
foo
that return
Unit
. This will be the expression that satisfies that use case in a compiler plugin:
Copy code
func({
  "fun <$typeArgs> foo($params): Unit = $body" //find
}) { fn ->
  "fun <$typeArgs> $name($params): $returnType { 
      println("inside foo: Unit")
      return $body" 
  }
}
👏🏻 5
i
Hey @kevinmost I listened to your conversation at the kotlin podcast http://talkingkotlin.com/compiler-plugins/ and I really liked your take on compiler plugins. We’re currently working on a compiler plugin library Arrow Meta and the feature from above exactly utilises what you meant with matching on functions or any descriptors that you define and transform it the way you want.
In terms of Design we would go for the model in Scala quasiquote: https://github.com/scalameta/scalameta/blob/master/notes/quasiquotes.md
h
Hey guys, i will probably say this another few times but your effort in this area is really really awesome, so thank you much for your work! Is there a chance that you can deliver generic ide support as well for quasiquotes?? In Scala there is the presentation compiler (of which i have no knowledge about), which should be able to provide just this
❤️ 3
r
Since quasiquotes would work mostly in the synthetic Resolver we are very likely to be able to provide IDEA support out of the box for generated code
They are not exactly quasiquotes but rather context templates whose vars get replaced in transformations
And produce new descriptors and source elements that replace the ones initially discovered
arrow 1