Traverse multiple store-load chains for inlined lambda parameters

When a try-catch expression is passed as an argument to the inline
lambda parameter, lambda variable on stack is spilled and restored in
several different locations (1 for try-block, 1 for each catch-blocks).
So it's possible that lambda to be invoked comes from multiple loads,
all of which should have the same "root" lambda parameter.
This commit is contained in:
Dmitry Petrov
2017-04-25 11:14:20 +03:00
parent 441be56a40
commit 08fb9c2122
12 changed files with 188 additions and 4 deletions
@@ -0,0 +1,6 @@
fun zap(s: String) = s
inline fun tryZap(string: String, fn: (String) -> String) =
fn(try { zap(string) } catch (e: Exception) { "" })
fun box(): String = tryZap("OK") { it }
@@ -0,0 +1,9 @@
fun zap(s: String) = s
inline fun tryZap(s1: String, s2: String, fn: (String, String) -> String) =
fn(
try { zap(s1) } catch (e: Exception) { "" },
try { zap(s2) } catch (e: Exception) { "" }
)
fun box(): String = tryZap("O", "K") { a, b -> a + b }
@@ -0,0 +1,9 @@
fun zap(s: String) = s
inline fun tryZap(s1: String, s2: String, fn: String.(String) -> String) =
fn(
try { zap(s1) } catch (e: Exception) { "" },
try { zap(s2) } catch (e: Exception) { "" }
)
fun box(): String = tryZap("O", "K") { this + it }
@@ -0,0 +1,6 @@
fun zap(s: String) = s
inline fun tryZap(string: String, fn: String.() -> String) =
fn(try { zap(string) } catch (e: Exception) { "" })
fun box(): String = tryZap("OK") { this }
@@ -0,0 +1,13 @@
fun zap(s: String) = s
inline fun tryZap(string: String, fn: (String) -> String) =
fn(
try {
try {
zap(string)
}
catch (e: Exception) { "" }
} catch (e: Exception) { "" }
)
fun box(): String = tryZap("OK") { it }