Don't relocate temporary variable which receives property access, unless it's provable that this property don't have side effects
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
||||
package foo
|
||||
|
||||
var g: Any?
|
||||
get() {
|
||||
log("g.get")
|
||||
return null
|
||||
}
|
||||
set(v) {
|
||||
log("g.set")
|
||||
}
|
||||
|
||||
public inline fun Array<String>.boo() {
|
||||
var a = g
|
||||
for (element in this);
|
||||
}
|
||||
|
||||
public inline fun Iterable<String>.boo(i: Any?) {
|
||||
var a = i
|
||||
for (element in this);
|
||||
}
|
||||
|
||||
fun test1(f: () -> Array<String>) {
|
||||
f().boo()
|
||||
}
|
||||
|
||||
fun test2(f: () -> Iterable<String>) {
|
||||
f().boo(g)
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
test1 { log("lambda1"); arrayOf() }
|
||||
assertEquals("lambda1;g.get;", pullLog())
|
||||
|
||||
test2 { log("lambda2"); listOf() }
|
||||
assertEquals("lambda2;g.get;", pullLog())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+11
@@ -52,6 +52,13 @@ function test5() {
|
||||
return $tmp1 + $tmp2 + $tmp3;
|
||||
}
|
||||
|
||||
function test6() {
|
||||
init();
|
||||
|
||||
var $tmp = foo(1);
|
||||
return foo(2) + $tmp;
|
||||
}
|
||||
|
||||
function box() {
|
||||
var result = test1();
|
||||
if (result != 3) return "fail1a: " + result;
|
||||
@@ -73,5 +80,9 @@ function box() {
|
||||
if (result != 6) return "fail5a: " + result;
|
||||
if (log != "{1}{2}{3}{4}") return "fail5b: " + log;
|
||||
|
||||
result = test6();
|
||||
if (result != 3) return "fail6a: " + result;
|
||||
if (log != "{1}{2}") return "fail6b: " + result;
|
||||
|
||||
return "OK";
|
||||
}
|
||||
+11
@@ -59,6 +59,13 @@ function test5() {
|
||||
return $tmp1 + $tmp2 + $tmp3;
|
||||
}
|
||||
|
||||
function test6() {
|
||||
init();
|
||||
|
||||
var $tmp = foo(1);
|
||||
return foo(2) + $tmp;
|
||||
}
|
||||
|
||||
function box() {
|
||||
var result = test1();
|
||||
if (result != 3) return "fail1a: " + result;
|
||||
@@ -80,5 +87,9 @@ function box() {
|
||||
if (result != 6) return "fail5a: " + result;
|
||||
if (log != "{1}{2}{3}{4}") return "fail5b: " + log;
|
||||
|
||||
result = test6();
|
||||
if (result != 3) return "fail6a: " + result;
|
||||
if (log != "{1}{2}") return "fail6b: " + result;
|
||||
|
||||
return "OK";
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
var log = "";
|
||||
|
||||
A = {};
|
||||
Object.defineProperty(A, "x", {
|
||||
get: function() {
|
||||
log += "A.x;";
|
||||
return 23;
|
||||
}
|
||||
});
|
||||
|
||||
function b() {
|
||||
log += "b();";
|
||||
return 42;
|
||||
}
|
||||
|
||||
function box() {
|
||||
var $tmp = A.x;
|
||||
var result = b() + ";" + $tmp;
|
||||
|
||||
if (result != "42;23") return "fail1: " + result;
|
||||
if (log != "A.x;b();") return "fail2: " + log;
|
||||
|
||||
return "OK";
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
var log = "";
|
||||
|
||||
A = {};
|
||||
Object.defineProperty(A, "x", {
|
||||
get: function() {
|
||||
log += "A.x;";
|
||||
return 23;
|
||||
}
|
||||
});
|
||||
|
||||
function b() {
|
||||
log += "b();";
|
||||
return 42;
|
||||
}
|
||||
|
||||
function box() {
|
||||
var $tmp = A.x;
|
||||
var result = b() + ";" + $tmp;
|
||||
|
||||
if (result != "42;23") return "fail1: " + result;
|
||||
if (log != "A.x;b();") return "fail2: " + log;
|
||||
|
||||
return "OK";
|
||||
}
|
||||
Reference in New Issue
Block a user