-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relax fallback condition of AntiAliasing handling of Let (#1495)
- Loading branch information
1 parent
1001219
commit ba4a854
Showing
23 changed files
with
388 additions
and
102 deletions.
There are no files selected for viewing
241 changes: 151 additions & 90 deletions
241
core/src/main/scala/stainless/extraction/imperative/AntiAliasing.scala
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
frontends/benchmarks/extraction/invalid/IllegalAliasing4.check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[ Error ] IllegalAliasing4.scala:15:5: Unsupported `val` definition in AntiAliasing | ||
[ Error ] The following variables of mutable types are shared between the binding and the body: | ||
[ Error ] counter: A | ||
val b = { | ||
^^^^^^^^^... |
26 changes: 26 additions & 0 deletions
26
frontends/benchmarks/extraction/invalid/IllegalAliasing4.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
object IllegalAliasing4 { | ||
|
||
case class A(var i: BigInt) | ||
case class B(a: A) | ||
case class C(a: A, b: B) | ||
|
||
def createA(i: BigInt, counter: A): A = { | ||
counter.i += 1 | ||
A(i) | ||
} | ||
|
||
def test(n: BigInt, counter: A): Unit = { | ||
val origCount = counter.i | ||
val alias = counter | ||
val b = { | ||
if (n > 0) { | ||
createA(n, alias) | ||
B(alias) | ||
} | ||
else B(A(0)) | ||
} | ||
b.a.i += 1 | ||
assert(n <= 0 || counter.i == origCount + 2) | ||
assert(n > 0 || counter.i == origCount + 1) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
frontends/benchmarks/extraction/invalid/Initialization1.scalac.check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
frontends/benchmarks/extraction/invalid/Initialization2.scalac.check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
frontends/benchmarks/extraction/invalid/Initialization3.scalac.check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
frontends/benchmarks/extraction/invalid/Initialization4.scalac.check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
frontends/benchmarks/extraction/invalid/Initialization5.scalac.check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
[ Error ] MapAliasing1.scala:17:5: Unsupported `val` definition in AntiAliasing (couldn't compute targets and there are mutable variables shared between the binding and the body) | ||
[ Error ] MapAliasing1.scala:17:5: Unsupported `val` definition in AntiAliasing | ||
[ Error ] The following variables of mutable types are shared between the binding and the body: | ||
[ Error ] m: MutableMap[BigInt,A] | ||
val a = f(m, 123) | ||
^^^^^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
[ Error ] MapAliasing2.scala:15:5: Unsupported `val` definition in AntiAliasing (couldn't compute targets and there are mutable variables shared between the binding and the body) | ||
[ Error ] MapAliasing2.scala:15:5: Unsupported `val` definition in AntiAliasing | ||
[ Error ] The following variables of mutable types are shared between the binding and the body: | ||
[ Error ] m: MutableMap[BigInt,A] | ||
val a = f(m, 123) | ||
^^^^^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
[ Error ] i1099a.scala:9:5: Unsupported `val` definition in AntiAliasing (couldn't compute targets and there are mutable variables shared between the binding and the body) | ||
[ Error ] i1099a.scala:9:5: Unsupported `val` definition in AntiAliasing | ||
[ Error ] The following variables of mutable types are shared between the binding and the body: | ||
[ Error ] a1: A | ||
val c = C(a2) | ||
^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
[ Error ] i1099b.scala:9:5: Unsupported `val` definition in AntiAliasing (couldn't compute targets and there are mutable variables shared between the binding and the body) | ||
[ Error ] i1099b.scala:9:5: Unsupported `val` definition in AntiAliasing | ||
[ Error ] The following variables of mutable types are shared between the binding and the body: | ||
[ Error ] a1: A | ||
val c = C(a2) | ||
^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
[ Error ] i1099c.scala:19:5: Unsupported `val` definition in AntiAliasing (couldn't compute targets and there are mutable variables shared between the binding and the body) | ||
[ Error ] i1099c.scala:19:5: Unsupported `val` definition in AntiAliasing | ||
[ Error ] The following variables of mutable types are shared between the binding and the body: | ||
[ Error ] a1: A | ||
val c = C(a3) | ||
^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[ Error ] i1099d.scala:9:5: Unsupported `val` definition in AntiAliasing | ||
[ Error ] The following variables of mutable types are shared between the binding and the body: | ||
[ Error ] a0: A, a1: A | ||
val c = C(a2) | ||
^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
object i1099d { | ||
case class A(var x: Int) | ||
case class C(a: A) | ||
|
||
def f(a0: A, a1: A, cond: Boolean) = { | ||
require(a0.x == 0 && a1.x == 1) | ||
val a2 = if (cond) a0 else a1 | ||
// Illegal aliasing | ||
val c = C(a2) | ||
c.a.x += 1 | ||
val useA0 = a0 | ||
val useA1 = a1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
frontends/benchmarks/imperative/valid/TargetMutation7.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
object TargetMutation7 { | ||
|
||
case class A(var i: BigInt) | ||
case class B(var a1: A, var a2: A) | ||
case class C(var a: A, var b: B) | ||
|
||
def createA(i: BigInt, counter: A): A = { | ||
counter.i += 1 | ||
A(i) | ||
} | ||
|
||
def test1(n: BigInt, counter: A): C = { | ||
val origCount = counter.i | ||
val a0 = A(1234) | ||
val b = { | ||
if (n > 0) { | ||
val b = B(A(0), A(1)) | ||
b.a1 = createA(1, counter) | ||
b | ||
} else B(A(123), A(456)) | ||
} | ||
val a = createA(2, counter) | ||
assert(n <= 0 || counter.i == origCount + 2) | ||
assert(n > 0 || counter.i == origCount + 1) | ||
C(a, b) | ||
} | ||
|
||
def test2(n: BigInt, counter: A): Unit = { | ||
val origCount = counter.i | ||
val alias = counter | ||
val b = { | ||
if (n > 0) B(A(0), createA(n, alias)) | ||
else B(A(0), A(0)) | ||
} | ||
b.a2.i += 1 | ||
assert(n <= 0 || counter.i == origCount + 1) | ||
assert(n > 0 || counter.i == origCount) | ||
} | ||
|
||
|
||
def test3(n: BigInt, counter: A): Unit = { | ||
val origCount = counter.i | ||
val alias = counter | ||
val b = { | ||
if (n > 0) { | ||
createA(n, alias) | ||
B(A(0), alias) | ||
} | ||
else B(A(0), alias) | ||
} | ||
b.a2.i += 1 | ||
assert(n <= 0 || b.a2.i == origCount + 2) | ||
assert(n > 0 || b.a2.i == origCount + 1) | ||
} | ||
|
||
def test4(n: BigInt, counter: A): Unit = { | ||
val origCount = counter.i | ||
val alias = counter | ||
val b = { | ||
if (n > 0) { | ||
createA(n, alias) | ||
B(A(0), counter) | ||
} | ||
else B(A(0), alias) | ||
} | ||
b.a2.i += 1 | ||
assert(n <= 0 || b.a2.i == origCount + 2) | ||
assert(n > 0 || b.a2.i == origCount + 1) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
frontends/benchmarks/imperative/valid/TargetMutation8.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
object TargetMutation8 { | ||
|
||
case class A(var i: BigInt) | ||
case class B(arr: Array[A]) | ||
case class C(a: A, b: B) | ||
|
||
def createA(i: BigInt, counter: A): A = { | ||
counter.i += 1 | ||
A(i) | ||
} | ||
|
||
def test(n: BigInt, counter: A): C = { | ||
val origCount = counter.i | ||
// This triggers AntiAliasing 2nd case for Let binding of mutable types | ||
// *without* triggering EffectsChecker#check#traverser#traverse#Let | ||
// because: | ||
// -`b` is bound to a fresh expression (passes EffectsChecker#check#traverser#traverse#Let check) | ||
// -the transformation of `b` produces an expression whose target cannot be computed | ||
// -there are no sharing between the terminal variables of `b` and the rest of the body | ||
val b = { | ||
if (n > 0) { | ||
val b = B(Array.fill(5)(A(0))) | ||
b.arr(0) = createA(1, counter) | ||
b | ||
} else B(Array.fill(5)(A(0))) | ||
} | ||
val a = createA(2, counter) | ||
assert(n <= 0 || counter.i == origCount + 2) | ||
assert(n > 0 || counter.i == origCount + 1) | ||
C(a, b) | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
frontends/benchmarks/imperative/valid/TargetMutation9.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
object TargetMutation9 { | ||
|
||
case class A(var x: BigInt) | ||
case class C(a: A) | ||
case class D(c: C) | ||
|
||
def test1(n: BigInt): Unit = { | ||
val a = A(n) | ||
val c = C(a) | ||
c.a.x = 3 | ||
assert(c.a.x == 3) | ||
} | ||
|
||
def test2(n: BigInt): Unit = { | ||
val a = A(n) | ||
if (n == 0) { | ||
val c = C(a) | ||
c.a.x = 3 | ||
// `a` will be updated here by AntiAliasing (`copyEffects`) | ||
} | ||
assert(n != 0 || a.x == 3) | ||
} | ||
|
||
def test3(n: BigInt): Unit = { | ||
val a = A(n) | ||
if (n == 0) { | ||
val c = C(a) | ||
val c2 = c | ||
c2.a.x = 3 | ||
// `a` will be updated here by AntiAliasing (`copyEffects`) | ||
} | ||
assert(n != 0 || a.x == 3) | ||
} | ||
|
||
def test4(n: BigInt): Unit = { | ||
val a = A(n) | ||
if (n == 0) { | ||
val c = C(a) | ||
val d = D(c) | ||
d.c.a.x = 3 | ||
// `a` will be updated here by AntiAliasing (`copyEffects`) | ||
} | ||
assert(n != 0 || a.x == 3) | ||
} | ||
|
||
def test5(n: BigInt): Unit = { | ||
val a = A(n) | ||
if (n == 0) { | ||
val c = C(a) | ||
val d = D(c) | ||
d.c.a.x = 3 | ||
// `a` will be updated here by AntiAliasing (`copyEffects`) | ||
} | ||
a.x += 1 | ||
assert(n != 0 || a.x == 4) | ||
assert(n == 0 || a.x == n + 1) | ||
} | ||
} |