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

AntiAliasing does not update local aliasing information after replacement #1506

Open
mario-bucev opened this issue Mar 26, 2024 · 0 comments
Labels
aliasing Alias and effect analysis for imperative bug imperative

Comments

@mario-bucev
Copy link
Collaborator

The following snippet is incorrectly transformed by AntiAliasing after the marked line, resulting in the snippet being accepted even though it is incorrect.

object AntiAntiAliasing {
  case class Ref(var x: Int)
  case class RefRef(var lhs: Ref, var rhs: Ref)

  def replaceLhs(rr: RefRef, v: Int): Unit = {
    rr.lhs = Ref(v)
  }

  def t3(refref: RefRef): Unit = {
    val lhs = refref.lhs
    val oldLhs = lhs.x
    replaceLhs(refref, 123)
    assert(lhs.x == oldLhs)
    assert(refref.lhs.x == 123)
    refref.lhs.x = 456 // !
    assert(lhs.x == 456) // Incorrect because `lhs` and `refref.lhs` become unrelated after the call to `replaceLhs`
    assert(refref.lhs.x == 456)
  }
}

If we check the tree we have after AntiAliasing, we get (with some cleaning):

var lhs: Ref = refref.lhs
val oldLhs: Int = lhs.x
var res: (Unit, RefRef) = replaceLhs(refref, 123)
refref = RefRef(res._2.lhs, refref.rhs)
assert(lhs.x == oldLhs)
assert(refref.lhs.x == 123)
refref = RefRef(Ref(456), refref.rhs)
lhs = refref.lhs // Incorrect
assert(lhs.x == 456)
assert(refref.lhs.x == 456)

This is due to AntiAliasing not updating the aliasing information of lhs: after the call to replaceLhs, lhs is no longer aliasing refref.lhs.
Note that this is very similar to #1497 but manifesting in a different way.
Will we be able to fix AntiAliasing one day? After all, what is crooked cannot be made straight 😋

@mario-bucev mario-bucev added bug imperative aliasing Alias and effect analysis for imperative labels Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aliasing Alias and effect analysis for imperative bug imperative
Projects
None yet
Development

No branches or pull requests

1 participant