8000 Optimize the number of `Transformer` instances during method expansions · Issue #17 · arainko/ducktape · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Optimize the number of Transformer instances during method expansions #17
Closed
@arainko

Description

@arainko

Pretty much the same as #16 but for via and intoVia, the generated code is kind of different due to beta-reduction of the lambda.
Example:

import io.github.arainko.ducktape.*

final case class WrappedInt(value: Int) extends AnyVal

final case class WrappedString(value: String) extends AnyVal

final case class TransformedWithSubtransformations[A](
  int: WrappedInt,
  string: WrappedString,
  list: List[WrappedInt],
  option: Option[A]
)

def method[A](option: Option[A], list: List[WrappedInt], string: WrappedString, int: WrappedInt) =
      TransformedWithSubtransformations[A](int, string, list, option)

val value = Input(1, "a", List(1, 2, 3), Some(4))

val actual = 
    DebugMacros.code {
       value.via(method[WrappedInt])
    }

The output is:

(({
 val option$proxy3: Option[WrappedInt] = 
  given_Transformer_Option_Option[Int, WrappedInt]((((from: Int) => (new WrappedInt(from): WrappedInt)): ToAnyVal[Int, WrappedInt])).transform(value.option)
val list$proxy3: List[WrappedInt] = 
  given_Transformer_SourceCollection_DestCollection[Int, WrappedInt, List, List]((((`from₂`: Int) => (new WrappedInt(`from₂`): WrappedInt)): ToAnyVal[Int, WrappedInt]), iterableFactory[WrappedInt]).transform(value.list)
val string$proxy3: WrappedString = 
  (((`from₃`: String) => (new WrappedString(`from₃`): WrappedString)): ToAnyVal[String, WrappedString]).transform(value.string)
val int$proxy3: WrappedInt = 
  (((`from₄`: Int) => (new WrappedInt(`from₄`): WrappedInt)): ToAnyVal[Int, WrappedInt]).transform(value.int)

method[WrappedInt](option$proxy3, list$proxy3, string$proxy3, int$proxy3)
}: Return): Return)

We can get rid of the Transformer.ToAnyVal, Transformer.FromAnyVal and Transformer.ForProduct instances by 'inlining' their insides, eg. for this line:

val string$proxy3: WrappedString = 
  (((`from₃`: String) => (new WrappedString(`from₃`): WrappedString)): ToAnyVal[String, WrappedString]).transform(value.string)

The rewritten version should just look like this:

val string$proxy3: WrappedString = new WrappedString(value.string)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0