Don't use builder inference if possible
The builder inference is running only if there are still uninferred type variables ^KT-48193 Fixed
This commit is contained in:
committed by
TeamCityServer
parent
3df5667a4b
commit
55811c8851
+21
@@ -0,0 +1,21 @@
|
||||
// WITH_RUNTIME
|
||||
// DONT_TARGET_EXACT_BACKEND: WASM
|
||||
// !LANGUAGE: -UseBuilderInferenceOnlyIfNeeded
|
||||
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
@OptIn(ExperimentalTypeInference::class)
|
||||
fun <K, V> buildMap(@BuilderInference builderAction: MutableMap<K, V>.() -> Unit): Map<K, V> = mapOf()
|
||||
|
||||
fun foo(): MutableMap<CharSequence, *> = mutableMapOf<CharSequence, String>()
|
||||
|
||||
fun <E> MutableMap<E, *>.swap(x: MutableMap<E, *>) {}
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
fun box(): String {
|
||||
val x: Map<in String, String> = buildMap {
|
||||
put("", "")
|
||||
swap(foo())
|
||||
} // `Map<CharSequence, String>` if we use builder inference, `Map<String, String>` if we don't
|
||||
return "OK"
|
||||
}
|
||||
Vendored
-32
@@ -28,20 +28,6 @@ fun poll01(): Flow<String> {
|
||||
}
|
||||
}
|
||||
|
||||
fun poll1(flag: Boolean): Flow<String> {
|
||||
return flow {
|
||||
val inv = if (flag) { ::bar2 } else { ::foo2 }
|
||||
inv()
|
||||
}
|
||||
}
|
||||
|
||||
fun poll11(flag: Boolean): Flow<String> {
|
||||
return flow {
|
||||
val inv = if (flag) { ::bar2 } else { ::foo2 }
|
||||
inv()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun poll21(flag: Boolean): Flow<String> {
|
||||
return flow {
|
||||
@@ -57,20 +43,6 @@ fun poll31(flag: Boolean): Flow<String> {
|
||||
}
|
||||
}
|
||||
|
||||
fun poll41(): Flow<String> {
|
||||
return flow {
|
||||
val inv = try { ::bar2 } finally { ::foo2 }
|
||||
inv()
|
||||
}
|
||||
}
|
||||
|
||||
fun poll51(): Flow<String> {
|
||||
return flow {
|
||||
val inv = try { ::bar2 } catch (e: Exception) { ::foo2 } finally { ::foo2 }
|
||||
inv()
|
||||
}
|
||||
}
|
||||
|
||||
fun poll61(): Flow<String> {
|
||||
return flow {
|
||||
val inv = ::bar2
|
||||
@@ -101,12 +73,8 @@ fun poll91(): Flow<String> {
|
||||
|
||||
fun box(): String {
|
||||
poll01()
|
||||
poll1(true)
|
||||
poll11(true)
|
||||
poll21(true)
|
||||
poll31(true)
|
||||
poll41()
|
||||
poll51()
|
||||
poll61()
|
||||
poll71()
|
||||
poll81()
|
||||
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
// DONT_TARGET_EXACT_BACKEND: WASM
|
||||
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
fun <K> FlowCollector<K>.bar(): K = null as K
|
||||
fun <K> FlowCollector<K>.foo(): K = null as K
|
||||
|
||||
fun bar2(): Int = 1
|
||||
fun foo2(): Float = 1f
|
||||
|
||||
fun <T> materialize() = null as T
|
||||
|
||||
interface FlowCollector<in T> {}
|
||||
|
||||
@Suppress("EXPERIMENTAL_API_USAGE_ERROR")
|
||||
fun <L> flow(@BuilderInference block: suspend FlowCollector<L>.() -> Unit) = Flow(block)
|
||||
|
||||
class Flow<out R>(private val block: suspend FlowCollector<R>.() -> Unit)
|
||||
|
||||
fun poll1(flag: Boolean): Flow<String> {
|
||||
return flow {
|
||||
val inv = if (flag) { ::bar2 } else { ::foo2 }
|
||||
inv()
|
||||
}
|
||||
}
|
||||
|
||||
fun poll11(flag: Boolean): Flow<String> {
|
||||
return flow {
|
||||
val inv = if (flag) { ::bar2 } else { ::foo2 }
|
||||
inv()
|
||||
}
|
||||
}
|
||||
|
||||
fun poll41(): Flow<String> {
|
||||
return flow {
|
||||
val inv = try { ::bar2 } finally { ::foo2 }
|
||||
inv()
|
||||
}
|
||||
}
|
||||
|
||||
fun poll51(): Flow<String> {
|
||||
return flow {
|
||||
val inv = try { ::bar2 } catch (e: Exception) { ::foo2 } finally { ::foo2 }
|
||||
inv()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
poll1(true)
|
||||
poll11(true)
|
||||
poll41()
|
||||
poll51()
|
||||
return "OK"
|
||||
}
|
||||
-174
@@ -1,174 +0,0 @@
|
||||
// !LANGUAGE: +UnrestrictedBuilderInference
|
||||
// WITH_RUNTIME
|
||||
// SKIP_TXT
|
||||
// DONT_TARGET_EXACT_BACKEND: WASM
|
||||
// IGNORE_LIGHT_ANALYSIS
|
||||
// IGNORE_BACKEND: JVM
|
||||
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
fun <K> FlowCollector<K>.bar(): K = null as K
|
||||
fun <K> FlowCollector<K>.foo(): K = null as K
|
||||
|
||||
fun <K> K.bar3(): K = null as K
|
||||
fun <K> K.foo3(): K = null as K
|
||||
|
||||
fun bar2(): Int = 1
|
||||
fun foo2(): Float = 1f
|
||||
|
||||
val bar4: Int
|
||||
get() = 1
|
||||
|
||||
var foo4: Float
|
||||
get() = 1f
|
||||
set(value) {}
|
||||
|
||||
val <K> FlowCollector<K>.bar5: K get() = null as K
|
||||
val <K> FlowCollector<K>.foo5: K get() = null as K
|
||||
|
||||
class Foo6
|
||||
|
||||
class Foo7<T>
|
||||
fun foo7() = null as Foo7<Int>
|
||||
|
||||
interface FlowCollector<in T> {}
|
||||
|
||||
@OptIn(ExperimentalTypeInference::class)
|
||||
fun <L> flow(@BuilderInference block: suspend FlowCollector<L>.() -> Unit) = Flow(block)
|
||||
|
||||
class Flow<out R>(private val block: suspend FlowCollector<R>.() -> Unit)
|
||||
|
||||
//fun poll1(flag: Boolean): Flow<String> {
|
||||
// return flow {
|
||||
// val inv = if (flag) { ::bar2 } else { ::foo2 }
|
||||
// inv()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//fun poll11(flag: Boolean): Flow<String> {
|
||||
// return flow {
|
||||
// val inv = if (flag) { ::bar2 } else { ::foo2 }
|
||||
// inv()
|
||||
// }
|
||||
//}
|
||||
|
||||
fun poll12(flag: Boolean): Flow<String> {
|
||||
return flow {
|
||||
val inv = if (flag) { ::bar3 } else { ::foo3 }
|
||||
inv()
|
||||
}
|
||||
}
|
||||
|
||||
//fun poll13(flag: Boolean): Flow<String> {
|
||||
// return flow {
|
||||
// val inv = if (flag) { ::bar2 } else { ::foo3 }
|
||||
// inv()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//fun poll14(flag: Boolean): Flow<String> {
|
||||
// return flow {
|
||||
// val inv = if (flag) { ::bar4 } else { ::foo4 }
|
||||
// inv()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//fun poll15(flag: Boolean): Flow<String> {
|
||||
// return flow {
|
||||
// val inv = if (flag) { ::bar5 } else { ::foo5 }
|
||||
// inv()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//fun poll16(flag: Boolean): Flow<String> {
|
||||
// return flow {
|
||||
// val inv = if (flag) { ::Foo6 } else { ::Foo6 }
|
||||
// inv()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//fun poll4(): Flow<String> {
|
||||
// return flow {
|
||||
// val inv = try { ::bar } finally { ::foo }
|
||||
// inv()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//fun poll41(): Flow<String> {
|
||||
// return flow {
|
||||
// val inv = try { ::bar2 } finally { ::foo2 }
|
||||
// inv()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//fun poll42(): Flow<String> {
|
||||
// return flow {
|
||||
// val inv = try { ::bar3 } finally { ::foo3 }
|
||||
// inv()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//fun poll43(): Flow<String> {
|
||||
// return flow {
|
||||
// val inv = try { ::bar4 } finally { ::foo4 }
|
||||
// inv()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//fun poll44(): Flow<String> {
|
||||
// return flow {
|
||||
// val inv = try { ::bar5 } finally { ::foo5 }
|
||||
// inv()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//fun poll45(): Flow<String> {
|
||||
// return flow {
|
||||
// val inv = try { ::Foo6 } finally { ::Foo6 }
|
||||
// inv()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//fun poll5(): Flow<String> {
|
||||
// return flow {
|
||||
// val inv = try { ::bar } catch (e: Exception) { ::foo } finally { ::foo }
|
||||
// inv()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//fun poll51(): Flow<String> {
|
||||
// return flow {
|
||||
// val inv = try { ::bar2 } catch (e: Exception) { ::foo2 } finally { ::foo2 }
|
||||
// inv()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//fun poll52(): Flow<String> {
|
||||
// return flow {
|
||||
// val inv = try { ::bar3 } catch (e: Exception) { ::foo3 } finally { ::foo3 }
|
||||
// inv()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//fun poll53(): Flow<String> {
|
||||
// return flow {
|
||||
// val inv = try { ::bar4 } catch (e: Exception) { ::foo4 } finally { ::foo4 }
|
||||
// inv()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//fun poll54(): Flow<String> {
|
||||
// return flow {
|
||||
// val inv = try { ::bar5 } catch (e: Exception) { ::foo5 } finally { ::foo5 }
|
||||
// inv()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//fun poll55(): Flow<String> {
|
||||
// return flow {
|
||||
// val inv = try { ::Foo6 } catch (e: Exception) { ::Foo6 } finally { ::Foo6 }
|
||||
// inv()
|
||||
// }
|
||||
//}
|
||||
|
||||
fun box() = "OK"
|
||||
-32
@@ -28,20 +28,6 @@ fun poll01(): Flow<String> {
|
||||
}
|
||||
}
|
||||
|
||||
fun poll1(flag: Boolean): Flow<String> {
|
||||
return flow {
|
||||
val inv = if (flag) { ::bar2 } else { ::foo2 }
|
||||
inv()
|
||||
}
|
||||
}
|
||||
|
||||
fun poll11(flag: Boolean): Flow<String> {
|
||||
return flow {
|
||||
val inv = if (flag) { ::bar2 } else { ::foo2 }
|
||||
inv()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun poll21(flag: Boolean): Flow<String> {
|
||||
return flow {
|
||||
@@ -57,20 +43,6 @@ fun poll31(flag: Boolean): Flow<String> {
|
||||
}
|
||||
}
|
||||
|
||||
fun poll41(): Flow<String> {
|
||||
return flow {
|
||||
val inv = try { ::bar2 } finally { ::foo2 }
|
||||
inv()
|
||||
}
|
||||
}
|
||||
|
||||
fun poll51(): Flow<String> {
|
||||
return flow {
|
||||
val inv = try { ::bar2 } catch (e: Exception) { ::foo2 } finally { ::foo2 }
|
||||
inv()
|
||||
}
|
||||
}
|
||||
|
||||
fun poll61(): Flow<String> {
|
||||
return flow {
|
||||
val inv = ::bar2
|
||||
@@ -101,12 +73,8 @@ fun poll91(): Flow<String> {
|
||||
|
||||
fun box(): String {
|
||||
poll01()
|
||||
poll1(true)
|
||||
poll11(true)
|
||||
poll21(true)
|
||||
poll31(true)
|
||||
poll41()
|
||||
poll51()
|
||||
poll61()
|
||||
poll71()
|
||||
poll81()
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// !LANGUAGE: +UnrestrictedBuilderInference
|
||||
// !LANGUAGE: +UnrestrictedBuilderInference -UseBuilderInferenceOnlyIfNeeded
|
||||
// WITH_RUNTIME
|
||||
// !DIAGNOSTICS: -EXPERIMENTAL_API_USAGE_ERROR -CAST_NEVER_SUCCEEDS
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
|
||||
Reference in New Issue
Block a user