Skip to content

Double eta-expansion when ascribing contextual types #6375

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

Closed
biboudis opened this issue Apr 25, 2019 · 5 comments
Closed

Double eta-expansion when ascribing contextual types #6375

biboudis opened this issue Apr 25, 2019 · 5 comments

Comments

@biboudis
Copy link
Contributor

biboudis commented Apr 25, 2019

When we use a contextual type as a return type

class Test  {
   def f(): given Int => Boolean = true
}

it η-expands once ->

def f(): ImplicitFunction1[Int, Boolean] =  {
   def $anonfun(implicit evidence$1: Int): Boolean = true
   closure($anonfun)
}

However, if we provide an explicit ascription:

class Test  {
   def f(): given Int => Boolean = true : (given Int => Boolean)
}

it expands unnecessarily twice:

def f(): ImplicitFunction1[Int, Boolean] =  {
   def $anonfun(implicit evidence$1: Int): Boolean =  (
      {
         def $anonfun(implicit evidence$2: Int): Boolean = true
         closure($anonfun)
      }:ImplicitFunction1[Int, Boolean]).apply(evidence$1)
   closure($anonfun)
}
@biboudis biboudis added this to the 0.15 Tech Preview milestone Apr 25, 2019
@biboudis biboudis self-assigned this Apr 25, 2019
@nicolasstucki
Copy link
Contributor

Note that this affects all inline methods that return a contextual function.

@anatoliykmetyuk
Copy link
Contributor

This one's moved to a new milestone for the third time already...

@biboudis
Copy link
Contributor Author

Will get back to it.

@anatoliykmetyuk
Copy link
Contributor

I'll remove it from the milestones FTTB

@anatoliykmetyuk anatoliykmetyuk removed this from the 0.18 Tech Preview milestone Aug 28, 2019
@odersky
Copy link
Contributor

odersky commented Mar 6, 2020

This is hard to avoid, since there are a number of ways how we could close over a context parameter twice. I think it's easiest to detect and drop these patterns later in a miniphase.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 8, 2020
@odersky odersky closed this as completed in 9daeaa0 Mar 8, 2020
odersky added a commit that referenced this issue Mar 8, 2020
Fix #6375: Add miniphase for simple beta reductions
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

4 participants