Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Aldo Stracquadanio
    @Astrac
    is it possible to use macroparadise to implement a def macro?
    I mean, with the capabilities of an annotation macro, i.e. receiving a non-typechecked tree as an input
    Oron Port
    @soronpo
    Is there a way to get the number of extending classes of a sealed trait at compiler time?
    Jason Zaugg
    @retronym
    At what point during compile time? After typer it is easy, during typer it is hard to know if the list is complete yet.
    There is a mechanism to detect if you call it too early from a macro (scala/scala#5284)
    Oron Port
    @soronpo
    I'm unsure. Will it be possible to do something like:
    sealed trait Foo
    final class Bar1 extends Foo
    final class Bar2 extends Foo
    
    def numOfBars(implicit g : ExtendingCount[Foo]) : Int = g.value
    Jason Zaugg
    @retronym
    The API, is Symbol. knownDirectSubclasses
    Oron Port
    @soronpo
    Ok, I'll try it. Thanks
    I want to try and use the maximum enumeration count as a compile-time constraint on a parameter.
    Ferdinand Svehla
    @fsvehla
    Is the release for 2.12.6 planned for some time this week?
    Flavian Alexandru
    @alexflav23
    @fsvehla Sorry I replied on the wrong channel, confused notifications with one of my projects. If you got my last message I have no affiliation to the macro-paradise team and don’t know anything about their release schedule
    Bruno Bieth
    @backuitist
    Hi, does the scalamacros paradise plugin supports the meta macro annotations?
    Myroslav
    @odisseus
    Is there a distribution of paradise plugin compiled for Scala 2.13.0-M4?
    Oron Port
    @soronpo
    Paradise is built in that version and is enabled via compiler flag
    Myroslav
    @odisseus
    Thanks for clearing this! I spent quite some time thinking my compilation errors are caused by a missing JAR.
    Nick
    @GrigorievNick

    HI guys
    I try compile

          <groupId>com.github.pureconfig</groupId>
                <artifactId>pureconfig_${scala.binary.version}</artifactId>
                <version>0.11.1</version>
                <scope>test</scope>

    With maven, my IDE Idea work fine.
    But maven give me error that no implicit found.
    it look like maven di not work with macros well
    I take maven plugins confg from official site

      <plugin>
                    <groupId>net.alchim31.maven</groupId>
                    <artifactId>scala-maven-plugin</artifactId>
                    <version>4.1.1</version>
                    <executions>
                        <execution>
                            <configuration>
                                <compilerPlugins>
                                    <compilerPlugin>
                                        <groupId>org.scalamacros</groupId>
                                        <artifactId>paradise_${scala.version}</artifactId>
                                        <version>2.1.0</version>
                                    </compilerPlugin>
                                </compilerPlugins>
                                <args>
                                    <arg>-Xmacro-settings:materialize-derivations</arg>
                                    <arg>-language:experimental.macros</arg>
                                    <arg>-feature</arg>
                                </args>
                                <jvmArgs>
                                    <jvmArg>-Xms512m</jvmArg>
                                    <jvmArg>-Xmx2048m</jvmArg>
                                    <jvmArg>-Xss4m</jvmArg>
                                </jvmArgs>
                            </configuration>
                            <goals>
                                <goal>compile</goal>
                                <goal>testCompile</goal>
                            </goals>
                        </execution>
                    </executions>
    [ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:4.1.1:testCompile (default) on project af-s3-spark_2.11: Execution default of goal net.alchim31.maven:scala-maven-plugin:4.1.1:testCompile failed.: CompileFailed -> [Help 1]
    Can some on help me configure maven to support macros.

    I'am also try to add

            <dependency>
                <groupId>org.scala-lang</groupId>
                <artifactId>scala-reflect</artifactId>
                <version>${scala.version}</version>
                <scope>test</scope>
            </dependency>

    in different scopes, but this not help
    But it does not help

    tanaka takaya
    @takayahilton
    Remy Willems
    @keyboardDrummer
    Hi there, I have a question about Scala macro's. I'm using ScalaJS and am trying to replace some reflection code with macro's. In the reflection code, there was a trait Named that gave a class a name method based on reflecting on the Name of the inheriting class. Can I do something similar with macro's, where a def name method is generated for each classes that inherits from Named?
    Oron Port
    @soronpo
    I'm not sure if it can be done like that because a macro needs a context to run. You can do something like:
    abstract class Named(implicit namer : Namer) {
      val name : String = namer.value
    }
    class Foo extends Named //.name will be Foo
    class Bar extends Foo //.name will still be Foo
    @keyboardDrummer
    Remy Willems
    @keyboardDrummer
    Right, that makes sense, and I might approximate what I'm looking for with that, thanks :)
    I guess you're using implicit macro's there to instantiate Namer
    Oron Port
    @soronpo
    Yes.
    I see no way around the runtime reflection here
    If you want class Bar to get the name of Bar
    To implement it should be something directly supported by the backend.
    Remy Willems
    @keyboardDrummer
    I'll try an annotation macro @named. I have about a 1000 types inheriting from the reflection based Named so I'll be writing a bunch of annotations, but eh ^^
    Oron Port
    @soronpo
    Yes, macro annotation that builds the tree is the best way.
    Kyle Daruwalla
    @darsnack
    I have been struggling to enable macro paradise in an end-user build file. Here is the build.sbt:
    ThisBuild / autoCompilerPlugins := true
    ThisBuild / cancelable in Global := true
    
    ThisBuild / useSuperShell := false
    ThisBuild / organization := "com.github.uw-pharm"
    ThisBuild / scalaVersion := "2.12.6"
    
    addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)
    
    lazy val iterative_svd = (project in file("IterativeSVD"))
      .settings(
        name := "iterative_svd",
        resolvers += Resolver.sonatypeRepo("releases"),
        scalacOptions += "-Xprint:macroparadise",
        scalacOptions += "-Xprint:superaccessors",
        scalacOptions += "-Xplugin:paradise_*.jar",
        libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % Test,
        libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value,
        libraryDependencies += "com.github.uw-pharm" % "bitsad-libraries_2.12" % "0.6.0-SNAPSHOT"
      )
    I keep getting Enable macro paradise to expand macro annotations when I run iterative_svd/compile
    That’s the @compileTimeOnly error message I placed when I wrote the macro annotation
    I can’t figure out what I am missing
    Flavian Alexandru
    @alexflav23
    How do you enable macro annotations in Scala 2.13 builds? I have Compile / scalacOptions += "-Ymacro-annotations” set on specific sub projects where needed, but it seems to be ignored.
    Jeff May
    @jeffmay

    I am trying to write a macro that will return the fields referenced in an anonymous function:

    Something like:

    case class NamedGetter[A, B](path: String, getter: A => B)
    object NamedGetter {
      def apply[A, B](getter: A => B): NamedGetter[A, B] = macro Macros.namedGetter[A, B]
    }
    does this already exist somewhere? I see a lot Lens stuff and xenomorph / morphling. Lens don't capture the names of fields used to create those functions and xenomorph / morphling is way too detailed for my needs (I don't really need to handle all of the cases for types of classes and field types... required vs optional vs ...)
    I started writing my own macro for this, but I am kind of new at macros. I got stuck trying to get the methodName back into the reified expression. This is my hacky attempt so far:
    import scala.reflect.macros.blackbox
    
    object NamedFieldMacro {
    
      def fieldImpl[A : c.WeakTypeTag, B : c.WeakTypeTag](
        c: blackbox.Context,
      )(
        getter: c.Expr[A => B],
      ): c.Expr[NamedGetter[A, B]] = {
        import c.universe._
    
        // TODO: Use quasiquotes here
        val Function(args, body) = getter.tree
        val v @ ValDef(mods, name, tp, rhs) = args(0)
        println(name)
    
        val methodName = q"${name.toString}" // How do I "splice" this?
    
        reify {
          new NamedGetter[A, B](name.toString, getter.splice)
        }
      }
    }
    Jeff May
    @jeffmay
    Obviously this is wrong because I get the following compiler error:
    [info] /Users/jeffmay/code/oss/vapors/core/src/main/scala/com/rallyhealth/vapors/core/macros/NamedFieldMacro.scala:21:11: free term: Ident(TermName("name")) defined by fieldImpl in NamedFieldMacro.scala:16:26
    [info]     reify {
    [info]           ^
    [info] /Users/jeffmay/code/oss/vapors/core/src/main/scala/com/rallyhealth/vapors/core/macros/NamedFieldMacro.scala:21:11: free term: Ident(TermName("c")) defined by fieldImpl in NamedFieldMacro.scala:8:5
    [info]     reify {
    [info]           ^
    ...
    [error] /Users/jeffmay/code/oss/vapors/core/src/test/scala/com/rallyhealth/vapors/core/Example.scala:12:98: Macro expansion contains free term variable name defined by fieldImpl in NamedFieldMacro.scala:16:26. Have you forgotten to use splice when splicing this variable into a reifee? If you have troubles tracking free term variables, consider using -Xlog-free-terms
    [error]     val scores: NamedLens[Probs, Map[String, Double]] = NamedLens.id[Probs].fieldFrom(NamedGetter(_.scores))
    [error]
    Jeff May
    @jeffmay
    ok, a little better implementation that actually prints stuff:
    import scala.reflect.macros.blackbox
    
    object NamedFieldMacro {
      def fieldImpl[A : c.WeakTypeTag, B : c.WeakTypeTag](
        c: blackbox.Context,
      )(
        getter: c.Expr[A => B],
      ): c.Expr[NamedGetter[A, B]] = {
        import c.universe._
        println(s"SHOWING GETTER: ${show(getter)}")
        println(s"SHOWING GETTER CODE: ${showCode(getter.tree)}")
        println(s"SHOWING GETTER RAW: ${showRaw(getter)}")
        // TODO: Use quasiquotes here?
        // TODO: Handle nested fields better
        // TODO: Better error message for invalid function types
        val Function(_, Select(_, TermName(name))) = getter.tree
        println(s"METHOD: ${name}")
        val methodName = q"${name}" // How do I "splice" this?
        reify {
          new NamedGetter[A, B]("fieldName", getter.splice)
        }
      }
    }
    It prints the right method name, but I don't know how to add that to reify
    Jeff May
    @jeffmay
    actually, nvm, I figured it out. I needed
    object NamedGetterMacro {
      def fieldImpl[A : c.WeakTypeTag, B : c.WeakTypeTag](
        c: blackbox.Context,
      )(
        getter: c.Expr[A => B],
      ): c.Expr[NamedField[A, B]] = {
        import c.universe._
        val q"(..$_) => $_.${TermName(name)}" = getter.tree
        val NamedField = weakTypeOf[NamedField[A, B]]
        c.Expr[NamedField[A, B]](q"new $NamedField($name, $getter)")
      }
    }
    Jeff May
    @jeffmay
    Now I'm having trouble with type inference during implicit resolution of a NamedGetter[A, B] and need to take a slightly different approach... I want invoke the macro on the class method itself (rather than create an intermediary object of type NamedGetter[A, B] with an implicit conversion from A => B using this macro)

    I want to define a method:

    case class NamedLens[A, B](path: String, getter: A => B) {
    
      def field[C](method: B => C): NamedLens[A, C] = macro NamedLensMacros.fieldImpl[A, B, C]
    }

    But now I have a 3rd type parameter that comes from the surrounding class. How can I access the getter from this and have it match the expected type B?

    Dmytro Mitin
    @DmytroMitin
    @jeffmay probably you want q"${c.prefix}.getter"
    Jeff May
    @jeffmay
    I landed on this ugly, but simple code:
    implicit class Selector[A, B](val lens: NamedLens[A, B]) extends AnyVal {
        def select[C](getter: B => C): NamedLens[A, C] = macro NamedLensMacros.selectImpl[A, B, C]
      }
    
    // In another file
    object NamedLensMacros {
    
      def selectImpl[A : c.WeakTypeTag, B : c.WeakTypeTag, C : c.WeakTypeTag](
        c: blackbox.Context,
      )(
        getter: c.Expr[B => C],
      ): c.Expr[NamedLens[A, C]] = {
        import c.universe._
        val q"(..$_) => $_.${TermName(fieldName)}" = getter.tree
        val fieldNameExp = c.Expr[String](q"$fieldName")
        reify {
          c.prefix.splice.asInstanceOf[NamedLens.Selector[A, B]].lens.field(fieldNameExp.splice, getter.splice)
        }
      }
    }
    I might pull this stuff out into an open-source project and make some improvements on error messaging and allow selecting more types of fields. The goal would be to use this lens in a FreeApplicative to automatically generate circe Decoders
    danveer4686
    @danveer4686

    Hi Team,
    We are upgrading scala server application from scala 2.12 to 3.0.0
    Below plugin is not working with scala 3.0.0:
    addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)

    Can anyone suggest if there any plan to release this plugin compatible with scala 3.0.0?

    Georgi Krastev
    @joroKr21
    Scala 3 doesn't support macro annotations currently