Skip to content

Inlining affects order of execution #13747

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
soronpo opened this issue Oct 14, 2021 · 4 comments · Fixed by #13755
Closed

Inlining affects order of execution #13747

soronpo opened this issue Oct 14, 2021 · 4 comments · Fixed by #13755
Assignees
Milestone

Comments

@soronpo
Copy link
Contributor

soronpo commented Oct 14, 2021

Not completely sure this is a bug, but to me whether a method is inlined or not should not affect the order of execution.

Compiler version

v3.1.0-RC3

Minimized code

var res = ""
trait Bar:
  def +(that: Bar): Bar = new Plus(this, that)
  inline def -(that: Bar): Bar = new Minus(this, that)

class LHS extends Bar {res += "LHS "}
class RHS extends Bar {res += "RHS "}

class Plus(lhs: Bar, rhs: Bar) extends Bar {res += "op"}
class Minus(lhs: Bar, rhs: Bar) extends Bar {res += "op"}

@main def main : Unit =
  val pls = new LHS + new RHS
  val plsRes = res
  res = ""
  val min = new LHS - new RHS
  assert(plsRes == res)

Output

assertion failed

Expectation

No failure. Inlining should not affect the execution order.

@soronpo
Copy link
Contributor Author

soronpo commented Oct 14, 2021

@nicolasstucki What do you think? Is this a bug?

@nicolasstucki nicolasstucki self-assigned this Oct 14, 2021
@odersky
Copy link
Contributor

odersky commented Oct 15, 2021

I think that's a bug. Here is the expansion if the - call:

     val min: Minus = 
          {
            val that$proxy1: RHS = new RHS()
            val Bar_this: LHS = new LHS()
            new Minus(Bar_this, that$proxy1)
          }

The definitions of that$proxy1 and Bar_this should be in the reverse order.

@soronpo
Copy link
Contributor Author

soronpo commented Oct 15, 2021

BTW, is there a reason why Bar_this is not given a $ in its name? Like Bar_this$ or Bar_this_$proxy?

@odersky
Copy link
Contributor

odersky commented Oct 15, 2021

@soronpo I think it's because the proxies should be available to meta programming and we want to avoid $ in names because that signals that the name is internal, and user programs use them without stability guarantees. But I am not sure whether meta programming actually uses these proxies.

odersky added a commit to dotty-staging/dotty that referenced this issue Oct 15, 2021
danicheg pushed a commit to danicheg/dotty that referenced this issue Oct 21, 2021
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
@Kordyjan Kordyjan added this to the 3.1.2 milestone Aug 2, 2023
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.

4 participants