Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPIKE: Replacements for scalameta-based macros #539

Closed
diesalbla opened this issue Mar 26, 2018 · 15 comments
Closed

SPIKE: Replacements for scalameta-based macros #539

diesalbla opened this issue Mar 26, 2018 · 15 comments

Comments

@diesalbla
Copy link
Contributor

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.

@fommil
Copy link
Contributor

fommil commented Mar 26, 2018

@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.

@raulraja
Copy link
Contributor

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

@fommil
Copy link
Contributor

fommil commented Mar 26, 2018

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

@fommil
Copy link
Contributor

fommil commented Mar 26, 2018

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

@raulraja
Copy link
Contributor

raulraja commented Mar 26, 2018

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._

@ngbinh
Copy link

ngbinh commented May 2, 2018

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.

@mwz
Copy link

mwz commented May 2, 2018

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

@ngbinh
Copy link

ngbinh commented May 2, 2018

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

@mwz
Copy link

mwz commented May 2, 2018

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).

@ngbinh
Copy link

ngbinh commented May 2, 2018

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

@olafurpg
Copy link

olafurpg commented May 7, 2018

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.

@soronpo
Copy link

soronpo commented May 7, 2018

@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?

@mutcianm
Copy link

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.

@olafurpg
Copy link

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

@kthompson
Copy link

Just curious if this issue is still progressing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants