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

Effects in arguments of functions #1068

Closed
jad-hamza opened this issue May 21, 2021 · 2 comments · Fixed by #1252
Closed

Effects in arguments of functions #1068

jad-hamza opened this issue May 21, 2021 · 2 comments · Fixed by #1252

Comments

@jad-hamza
Copy link
Contributor

This example should go through but doesn't:

object ArgumentsEffects {

  def f(x1: Int, x2: Int, x3: Int): Unit = {
    require(x1 == 1)
    require(x2 == 1)
    require(x3 == 3)
  }

  def test: Unit = {
    var x = 0
    f({x += 1; x}, x, {x+= 2; x })
  }

}
// Before ImperativeCodeElimination
[ Debug  ] def test$0: Unit = {
[ Debug  ]   var (x$220: Int) @var = 0
[ Debug  ]   f$75({
[ Debug  ]     x$220 = (x$220 + 1)
[ Debug  ]     x$220
[ Debug  ]   }, x$220, {
[ Debug  ]     x$220 = (x$220 + 2)
[ Debug  ]     x$220
[ Debug  ]   })
[ Debug  ] }

// After ImperativeCodeElimination
[ Debug  ] def test$0: Unit = {
[ Debug  ]   val (x$221: Int) @var = 0
[ Debug  ]   val (x$223: Int) @var = x$221 + 1
[ Debug  ]   val tmp$15: Unit = ()
[ Debug  ]   val (x$222: Int) @var = x$223 + 2
[ Debug  ]   val tmp$14: Unit = ()
[ Debug  ]   f$75(x$223, x$222, x$222)
[ Debug  ] }
@vkuncak
Copy link
Collaborator

vkuncak commented Mar 22, 2022

Note that this works.

  def test: Unit = {
    var x = 0
    val xx1 = {x += 1; x}
    val xx2 = x
    val xx3 = {x+= 2; x }
    f(xx1, xx2, xx3)
  }

I wonder if we should not just first introduce variables for block arguments and then transform?

@samarion
Copy link
Member

Yes, great point. I was making a similar reflection in the review of #1252 because this issue is more general than function arguments.

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