Skip to content

Add support for inline matches with inline bindings #11598

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

Open
nicolasstucki opened this issue Mar 4, 2021 · 1 comment
Open

Add support for inline matches with inline bindings #11598

nicolasstucki opened this issue Mar 4, 2021 · 1 comment

Comments

@nicolasstucki
Copy link
Contributor

Whenever we perform an inline match we need o bind the matched expression before using it in the RHS of the pattern. This is the correct behavior.

class Foo:
  inline def f(inline x: Option[Int]) =
    inline x match
      case Some(y) => y + y
      case _ => ???

  def test: Unit =
    val a: Int = 5
    f(Some(a))
    // val y = a
    // a + a

Unfortunately, this blocks further optimizations or inline matches. We could introduce an inline bindings to allow those extracted terms to be used as they are. Just like in inline parameters. It would look like

    inline x match
      case Some(inline y) => y + y

then the result of f(Some(a)) would just be a + a.

@nicolasstucki
Copy link
Contributor Author

If I remember correctly, this is what is missing to properly handle patterns like

transparent inline def summonInlineOpt[T]: T = summonFrom {
  case t: T => Some(t)
  case _ => None
}

inline summonInlineOpt[Ordering[T]] match 
  case Some(inline t) => new TreeMap[T](using t)
  case None => new HashSet[]

@nicolasstucki nicolasstucki changed the title Should inline matches support inline bindings Add support for inline matches with inline bindings Mar 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant