Temporarily prohibit non-local returns for some stdlib functions

Make InlineUtil work with FQ names, not descriptors

 #KT-5496 Fixed
 #KT-5497 Fixed
This commit is contained in:
Alexander Udalov
2014-07-18 20:03:57 +04:00
parent 540b87a1dc
commit 70adb0f4e2
8 changed files with 96 additions and 77 deletions
+2 -1
View File
@@ -4,6 +4,7 @@ import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
import kotlin.jvm.internal.unsafe.*
import kotlin.jvm.internal.Intrinsic
import kotlin.InlineOption.ONLY_LOCAL_RETURN
/**
* This annotation indicates what exceptions should be declared by a function when compiled to a JVM method
@@ -25,7 +26,7 @@ public annotation class throws(vararg val exceptionClasses: Class<out Throwable>
[Intrinsic("kotlin.javaClass.function")] fun <reified T> javaClass() : Class<T> = null as Class<T>
public inline fun <R> synchronized(lock: Any, block: () -> R): R {
public inline fun <R> synchronized(lock: Any, [inlineOptions(ONLY_LOCAL_RETURN)] block: () -> R): R {
monitorEnter(lock)
try {
return block()
@@ -5,12 +5,13 @@ import java.util.concurrent.locks.ReadWriteLock
import java.util.concurrent.locks.ReentrantReadWriteLock
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock
import java.util.concurrent.CountDownLatch
import kotlin.InlineOption.ONLY_LOCAL_RETURN
/**
Executes given calculation under lock
Returns result of the calculation
*/
public inline fun <T> Lock.withLock(action: ()->T) : T {
public inline fun <T> Lock.withLock([inlineOptions(ONLY_LOCAL_RETURN)] action: () -> T): T {
lock()
try {
return action()
@@ -24,7 +25,7 @@ public inline fun <T> Lock.withLock(action: ()->T) : T {
Executes given calculation under read lock
Returns result of the calculation
*/
public inline fun <T> ReentrantReadWriteLock.read(action: ()->T) : T {
public inline fun <T> ReentrantReadWriteLock.read([inlineOptions(ONLY_LOCAL_RETURN)] action: () -> T): T {
val rl = readLock()
rl.lock()
try {
@@ -41,7 +42,7 @@ The method does upgrade from read to write lock if needed
If such write has been initiated by checking some condition, the condition must be rechecked inside the action to avoid possible races
Returns result of the calculation
*/
public inline fun <T> ReentrantReadWriteLock.write(action: ()->T) : T {
public inline fun <T> ReentrantReadWriteLock.write([inlineOptions(ONLY_LOCAL_RETURN)] action: () -> T): T {
val rl = readLock()
val readCount = if (getWriteHoldCount() == 0) getReadHoldCount() else 0
@@ -62,7 +63,7 @@ public inline fun <T> ReentrantReadWriteLock.write(action: ()->T) : T {
Execute given calculation and await for CountDownLatch
Returns result of the calculation
*/
fun <T> Int.latch(op: CountDownLatch.() -> T) : T {
fun <T> Int.latch(op: CountDownLatch.() -> T) : T {
val cdl = CountDownLatch(this)
val res = cdl.op()
cdl.await()
+2 -1
View File
@@ -1,9 +1,10 @@
package kotlin
import java.io.Closeable
import kotlin.InlineOption.ONLY_LOCAL_RETURN
/** Uses the given resource then closes it down correctly whether an exception is thrown or not */
public inline fun <T : Closeable, R> T.use(block: (T) -> R): R {
public inline fun <T : Closeable, R> T.use([inlineOptions(ONLY_LOCAL_RETURN)] block: (T) -> R): R {
var closed = false
try {
return block(this)
+2 -1
View File
@@ -4,6 +4,7 @@ import java.io.*
import java.nio.charset.*
import java.util.NoSuchElementException
import java.net.URL
import kotlin.InlineOption.ONLY_LOCAL_RETURN
/**
* Returns the default buffer size when working with buffered streams
@@ -198,7 +199,7 @@ public fun Writer.buffered(bufferSize: Int = defaultBufferSize): BufferedWriter
*/
public fun Reader.forEachLine(block: (String) -> Unit): Unit = useLines { lines -> lines.forEach(block) }
public inline fun <T> Reader.useLines(block: (Stream<String>) -> T): T =
public inline fun <T> Reader.useLines([inlineOptions(ONLY_LOCAL_RETURN)] block: (Stream<String>) -> T): T =
this.buffered().use { block(it.lines()) }
/**