Skip to content
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

Inline unapply patterns #8530

Closed
nicolasstucki opened this issue Mar 12, 2020 · 3 comments · Fixed by #8542
Closed

Inline unapply patterns #8530

nicolasstucki opened this issue Mar 12, 2020 · 3 comments · Fixed by #8542

Comments

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Mar 12, 2020

We want to be able to support the following kind of use case

object MyPattern {
  inline def unapply(x: T): Option[U] = Some(x)
}
x match 
  case MyPattern(y) => ....

where the call to MyPattern.unapply will get inline and possibly be a macro.

Technically, this would mean generating a new instance with a compatible definition of the unapply and then inline the code in it's body. The return type would be inferred from the expansion of the unapply (whiteboxity). The anonymous class could be optimized away when the pattern matching compiled to labeled blocks.

x match 
  case <new { def unapply(x: T) = MyPattern.unnaply(x) }>(y) => ....
@smarter
Copy link
Member

smarter commented Mar 12, 2020

Technically, this would mean generating a new instance with a compatible definition of the unapply and then inline the code in it's body.

Couldn't we generate a lambda that corresponds to the unapply instead ?

@smarter smarter added this to the 3.0.0-M1 milestone Mar 12, 2020
@nicolasstucki
Copy link
Contributor Author

The lambda was my first thought. But it might be hard to distinguish unapply from unapplySeq.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 13, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 13, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 13, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 13, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 13, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 13, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 13, 2020
@fhackett
Copy link
Contributor

Just a thought - if this works with inline match, it might have a really interesting interaction with #8348 .

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 14, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 14, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 14, 2020
@nicolasstucki nicolasstucki linked a pull request Mar 14, 2020 that will close this issue
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 31, 2020
odersky added a commit that referenced this issue Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants