frees-io / freestyle

A cohesive & pragmatic framework of FP centric Scala libraries

Home Page:http://frees.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SPIKE: Replacements for scalameta-based macros

diesalbla opened this issue · comments

Issue #73, carried out in PR #344, replaced the first version of @free and @module, based on the Scala Macro annotations with the macro annotations provided by the Scalameta-Paradise project. That is the basis for the current implementations of @free, @module, @tagless, as well as those macros from the freestyle-rpc project.

However, the development of macros and macro annotations in Scala Meta was closed, as explained here.

With these lessons learned, we decided to retire our efforts to build a macro system on top of Scalameta.

Recently, It has come to our attention that the earliest release of Scala, 2.12.5, can not be used with Freestyle. Thus, we need to find out a replacement for those macro annotations.

Requirements

Given that freestyle is intended to help as many Scala developers as possible, many of whom use IntelliJ-Idea, the replacement should inter-operate fairly with IDEA. In particular, spurious errors should be avoided as far as fairly possible.

Proposals

  • Compiler Plugin: one proposal would be to develop a compiler plugin. Inside the scalaz-deriving project, `@fommil has recently developed a helper class for writing code-generation annotations.

Note: this issue will be extended, as the discussion progress.

commented

@diesalbla writing a separate intellij plugin is not difficult. I did it already for @deriving and it was quite easy. JetBrains/intellij-scala#388

The code has changed a little bit since then (for the better). You can also look at simulacrum and monocle for inspiration.

Another proposal is to rely entirely in codegen since our additions are mostly implicits and companion extensions and to do that we don't need macros we can just codegen our expansion as other projects do https://github.com/olafurpg/scalameta-sbt-codegen. Codegen expansions should work fine in IDEA

commented

I'm not sure codegen works for companions... a companion must be in the same file.

commented

(unless the companion extends from some trait that you define in the codegen)

We can potentially skip companions since they are used now to add the Handler and Op dependent types but those could be just namespaced to the trait definition:

trait MyAlgebra[F[_]]
//codegen
trait MyAlgebraHandler

The other reason they are in use too is to get automatic resolution of implicit factories but those could be added to an implicits object automatically for all algebras under a package similar to how cats handles implicit traits aggregated in an all object which is also part of cats.implicits._

Is there anything we can do to help with this? We made a big bet on freestyle in our code base. Hope there is a way forward for us to update scala version. We stuck with scala 2.12.4 for now.

@ngbinh, It looks like paradise has been published for 2.12.6, see scalamacros/paradise#116.

@mwz freestyle is using https://github.com/scalameta/paradise/, a different project that has been abandoned

I think that scalameta paradise is also getting released against 2.12.6, scalameta/scalameta#1515 and https://gitter.im/scalameta/scalameta?at=5ae3661b62316e0505089ffe (they skipped a 2.12.5 release due to macro regressions).

Would be awesome if it's happening. Thanks, will be tracking that ticket

My recommendation would be to use scalamacros/paradise and implement custom support for IntelliJ. scalamacros/paradise are on track to be included by default in the Scala compiler scala/scala#6606 (no more need for addCompilerPlugin) and @mutcianm had a great presentation at ScalaSphere about how to add support for custom macros in IntelliJ, it's easier than most people think.

@mutcianm had a great presentation at ScalaSphere about how to add support for custom macros in IntelliJ, it's easier than most people think.

Is there an online link for this talk?

I don't think the recordings are available yet. Typically the talks are uploaded to YT a couple months later, so I'd expect them to be public soon.

FWIW, scalameta/paradise for 2.12.6 is on it's way to Maven Central. Note that scalameta/paradise is no longer under development and will not support 2.13, please migrate to https://docs.scala-lang.org/overviews/macros/annotations.html those macro annotations will be supported natively by the compiler in 2.13 under the scalac option -Ymacro-annotations scala/scala#6606

Just curious if this issue is still progressing.