Skip to content

Remove PickledQuote and TastyString from library #10262

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

Merged

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Nov 10, 2020

Remove PickledQuote and TastyString from the library and encode the pickled quotes with an efficient interface and code generation.

def unpickleExpr[T](pickled: String | List[String], typeHole: (Int, Seq[Any]) => Type[?], termHole: (Int, Seq[Any], QuoteContext) => Expr[?]): scala.quoted.Expr[T]
def unpickleType[T <: AnyKind](pickled: String | List[String], typeHole: (Int, Seq[Any]) => Type[?], termHole: (Int, Seq[Any], QuoteContext) => Expr[?]): scala.quoted.Type[T]
  • pickled can take a String or List[String]s if it needs more than one string. In practice, we never have more than one string.
  • Split typeHole/termHole to type them more precisely
  • Uncurry arguments of typeHole/termHole to generate fewer closures. This also helps with beta-reduction of closures with the generated code of typeHole/termHole at each call site.

Part of #10222

@nicolasstucki nicolasstucki force-pushed the remove-pickled-quotes-from-library branch from 00ea969 to 0e9298c Compare November 10, 2020 13:29
@nicolasstucki nicolasstucki marked this pull request as ready for review November 10, 2020 13:30
@nicolasstucki nicolasstucki force-pushed the remove-pickled-quotes-from-library branch from 0e9298c to 8c3178b Compare November 10, 2020 14:42
@nicolasstucki
Copy link
Contributor Author

test performance with #quotes please

@nicolasstucki
Copy link
Contributor Author

For the following quote

'{ val y: T = $x; y }

We used to generate

x$2.asInstanceOf[scala.internal.quoted.QuoteContextInternal].unpickleExpr[
        evidence$1$_$1
      ](
        scala.internal.quoted.PickledQuote.make(
          scala.collection.immutable.Nil.::[String](
            
              "XKGrH5iAAJe0vOuFlwAAl2DupbEpAAGeAYRBU1RzAYF5AYEkAYxldmlkZW5jZSQxJF8Kg4KBgwGDQW55AYVzY2FsYQGMcXVvdGVUeXBlVGFnAYtDb21waWxlVGltZReBiAGIaW50ZXJuYWwCgoaKAYZxdW90ZWQCgouMAYY8aW5pdD4Cgo2IF4GPAoKQhz+CjpEBg0ZvbwGHPGVtcHR5PgGJUG9zaXRpb25zAYlGb28uc2NhbGGAwZO/jLaMkoqENIw1mIGKgTOKk4X/g4IzioOghKSM/4WAdYU2hv+DgTOgF62OdYdQdYk2jYiFcJJVM6xvk3WTUDeUlaKGAOcA+oSWA9B98Ki4fsP6hJ+H+4CXhIWAkYB/r4eGgJSB"
            
          )
        , 
          scala.collection.immutable.Nil.::[Seq[Any] => Any](
            {
              def $anonfun$3(x$0: Seq[Any]): (x$2.Nested) ?=> quoted.Expr[T] = 
                {
                  def $anonfun(using evidence$2: x$2.Nested): quoted.Expr[T] = x
                  closure($anonfun)
                }
              closure($anonfun$3)
            }
          ).::[Seq[Any] => Any](
            {
              def $anonfun$2(x$0: Seq[Any]): quoted.Type[T] = evidence$1
              closure($anonfun$2)
            }
          ).::[Seq[Any] => Any](
            {
              def $anonfun$1(x$0: Seq[Any]): quoted.Type[T] = evidence$1
              closure($anonfun$1)
            }
          )
        )
      )

Now we generate

x$2.asInstanceOf[scala.internal.quoted.QuoteContextInternal].unpickleExpr[
        evidence$1$_$1
      ](
        
          "XKGrH5iAAJe0vOuFlwAAl2DupbEpAAGeAYRBU1RzAYF5AYEkAYxldmlkZW5jZSQxJF8Kg4KBgwGDQW55AYVzY2FsYQGMcXVvdGVUeXBlVGFnAYtDb21waWxlVGltZReBiAGIaW50ZXJuYWwCgoaKAYZxdW90ZWQCgouMAYY8aW5pdD4Cgo2IF4GPAoKQhz+CjpEBg0ZvbwGHPGVtcHR5PgGJUG9zaXRpb25zAYlGb28uc2NhbGGAwZO/jLaMkoqENIw1mIGKgTOKk4X/g4IzioOghKSM/4WAdYU2hv+DgTOgF62OdYdQdYk2jYiFcJJVM6xvk3WTUDeUlaKGAOcA+oSWA9B98Ki4fsP6hJ+H+4CXhIWAkYB/r4eGgJSB"
        
      , 
        {
          def $anonfun(x$0: Int, x$1: Seq[Any]): scala.quoted.Type[<?>] = 
            x$0:(x$0 : Int) @unchecked match 
              {
                case 0 => evidence$1
                case 1 => evidence$1 // TODO optimization oporunity (deduplicate arguments)
              }
          closure($anonfun)
        }
      , 
        {
          def $anonfun(x$0: Int, x$1: Seq[Any], x$2: scala.quoted.QuoteContext)
            : 
          scala.quoted.Expr[Any] = 
            x$0:(x$0 : Int) @unchecked match 
              {
                case 2 => 
                  val evidence$2: x$2.Nested = x$2.asInstanceOf[x$2.Nested]
                  x
              }
          closure($anonfun)
        }
      )

We removed the creation of all the :: list objects and only instantiate two functions (0 if there are no splices, 1 if there are only type or expr splices).

@liufengyun
Copy link
Contributor

test performance with #quotes please

@dottybot
Copy link
Member

performance test scheduled: 6 job(s) in queue, 1 running.

@liufengyun
Copy link
Contributor

@nicolasstucki Need to rebase in order for benchmark test to succeed.

This way we could generate somthing that is not a Seq, possibly a closure with a switch on the index.
Most pickled quotes fit in a single string. We avoid the creation of the list for single string by typing as `String | List[String]`.
This allows us to generate code without nested closures.
@nicolasstucki nicolasstucki force-pushed the remove-pickled-quotes-from-library branch from 8c3178b to 2a65e96 Compare November 10, 2020 15:47
@nicolasstucki
Copy link
Contributor Author

test performance with #quotes please

@dottybot
Copy link
Member

performance test scheduled: 8 job(s) in queue, 1 running.

Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@dottybot
Copy link
Member

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/10262/ to see the changes.

Benchmarks is based on merging with master (4411811)

@nicolasstucki nicolasstucki merged commit 1154889 into scala:master Nov 10, 2020
@nicolasstucki nicolasstucki deleted the remove-pickled-quotes-from-library branch November 10, 2020 21:09
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
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

Successfully merging this pull request may close these issues.

4 participants