Skip to content

Make quote pattern type variable order deterministic #17938

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

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Jun 7, 2023

This changes the order in which the type variables are listed in the encoded quote pattern. The order of the variables is the same as the order as they appear in the source.

Example:

import scala.quoted.*
def f(x: Expr[Any])(using Quotes) =
  x match
    case '{ type t; type u; Map[v, w]() } =>
[[syntax trees at end of                     typer]] 
package <empty> {
  import scala.quoted.*
  final lazy module val Test$package: Test$package = new Test$package()
  final module class Test$package() extends Object() {
    this: Test$package.type =>
    def f(x: scala.quoted.Expr[Any])(using x$2: scala.quoted.Quotes): Unit =
      x match 
        {
          case 
            x$2.asInstanceOf[scala.quoted.runtime.QuoteMatching].ExprMatch.
              unapply[
              scala.quoted.runtime.QuoteMatching.KCons[t @ _,
                scala.quoted.runtime.QuoteMatching.KCons[u @ _,
                  scala.quoted.runtime.QuoteMatching.KCons[v @ _,
                    scala.quoted.runtime.QuoteMatching.KCons[w @ _,
                      scala.quoted.runtime.QuoteMatching.KNil]
                  ]
                ]
              ],
              (scala.quoted.Type[t], scala.quoted.Type[u],
                scala.quoted.Type[v], scala.quoted.Type[w])
            ](
              Tuple4.unapply[scala.quoted.Type[t], scala.quoted.Type[u],
                scala.quoted.Type[v], scala.quoted.Type[w]](given t$given1 @ _,
                given u$given1 @ _, given v$given1 @ _, given w$given1 @ _)
            )(
              '{
                {
                  @patternType type t >: Nothing <: Any
                  @patternType type u >: Nothing <: Any
                  @patternType type v
                  @patternType type w
                  Map.apply[v, w]([ : (v, w)]*)
                }
              }.apply(x$2)
            )
           =>
            ()
        }
  }
}

We want all the places where t, u, v and w listed in some way to be in that same order.

@nicolasstucki nicolasstucki self-assigned this Jun 7, 2023
@nicolasstucki nicolasstucki force-pushed the make-quote-pattern-type-variable-order-deterministic branch from 46383ff to 036d130 Compare June 7, 2023 13:48
This changes the order in which the type variables are listed in the
encoded quote pattern. The order of the variables is the same as the
order as they appear in the source.
@nicolasstucki nicolasstucki force-pushed the make-quote-pattern-type-variable-order-deterministic branch from 036d130 to 2db2c11 Compare June 8, 2023 06:17
@nicolasstucki nicolasstucki marked this pull request as ready for review June 8, 2023 08:09
@nicolasstucki nicolasstucki requested a review from jchyb June 8, 2023 08:22
@nicolasstucki nicolasstucki assigned jchyb and unassigned nicolasstucki Jun 8, 2023
@nicolasstucki nicolasstucki merged commit 8cff236 into scala:main Jun 8, 2023
@nicolasstucki nicolasstucki deleted the make-quote-pattern-type-variable-order-deterministic branch June 8, 2023 11:27
Kordyjan added a commit that referenced this pull request Nov 21, 2023
#18978)

Backports #17938 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
@Kordyjan Kordyjan added this to the 3.3.2 milestone Dec 14, 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.

3 participants