frees-io / freestyle

A cohesive & pragmatic framework of FP centric Scala libraries
http://frees.io/
Apache License 2.0
614 stars 50 forks source link

Generate only friendly names for public exposed types generated by macro. #381

Open raulraja opened 7 years ago

raulraja commented 7 years ago

Since IDEA let's you expand and keep the expanded scalameta code we should only generate friendly names in types and type args expanded by our macros.

peterneyens commented 7 years ago

An example of the code generated by a @free algebra that is used in the tests :

{
  trait Y[FF$145[_]] extends _root_.freestyle.internal.EffectLike[FF$145] { def bar(x: Int): FS[Int] }
  @_root_.java.lang.SuppressWarnings(_root_.scala.Array("org.wartremover.warts.Any", "org.wartremover.warts.AsInstanceOf", "org.wartremover.warts.Throw")) object Y {
    sealed trait Op[_] extends _root_.scala.Product with _root_.java.io.Serializable { val FSAlgebraIndex144: _root_.scala.Int }
    final case class BarOp(x: Int) extends _root_.scala.AnyRef with Op[Int] { override val FSAlgebraIndex144: _root_.scala.Int = 0 }
    type OpTypes = _root_.iota.KCons[Op, _root_.iota.KNil]
    trait Handler[MM$151[_]] extends _root_.freestyle.FSHandler[Op, MM$151] {
      protected[this] def bar(x: Int): MM$151[Int]
      override def apply[AA$152](fa$153: Op[AA$152]): MM$151[AA$152] = ((fa$153.FSAlgebraIndex144: @_root_.scala.annotation.switch) match {
        case 0 =>
          val fresh154: BarOp = fa$153.asInstanceOf[BarOp]
          bar(fresh154.x)
        case i =>
          throw new _root_.java.lang.Exception("freestyle internal error: index " + i.toString() + " out of bounds for " + this.toString())
      }).asInstanceOf[MM$151[AA$152]]
    }
    class To[LL$147[_]](implicit ii$148: _root_.freestyle.InjK[Op, LL$147]) extends Y[LL$147] {
      private[this] val toInj149 = _root_.freestyle.FreeS.inject[Op, LL$147](ii$148)
      override def bar(x: Int): FS[Int] = toInj149(BarOp(x))
    }
    implicit def to[LL$147[_]](implicit ii$148: _root_.freestyle.InjK[Op, LL$147]): To[LL$147] = new To[LL$147]
    def apply[LL$147[_]](implicit ev$150: Y[LL$147]): Y[LL$147] = ev$150
  }
}

I don't now if IntellJ does any simplification while expanding?

I am not sure what we want to simplify? The things which make it harder to read are the fact that the types are fully qualified and that we use fresh types, but that is not really something we can change?

raulraja commented 7 years ago

We should be able to change the usage of freshtypes because non of the types we use are external to the expansion. For example if FF$145[_] is defined as just F[_] would there be any issues beside potentially shadowing?