Remove lazy values with dummy post compute lambdas

This commit is contained in:
Nikolay Krasko
2019-10-10 13:21:26 +03:00
committed by Nikolay Krasko
parent fbde7e47e9
commit 4f488ddd16
5 changed files with 23 additions and 4 deletions
@@ -134,7 +134,7 @@ class ClassResolutionScopesSupport(
}
private fun <T : Any> StorageManager.createLazyValue(onRecursion: ((Boolean) -> T), compute: () -> T) =
createLazyValueWithPostCompute(compute, onRecursion, {})
createLazyValue(compute, onRecursion)
companion object {
private val createErrorLexicalScope: (Boolean) -> LexicalScope = { ErrorLexicalScope() }
@@ -52,9 +52,7 @@ public class DeferredType extends WrappedType {
@NotNull BindingTrace trace,
@NotNull Function0<KotlinType> compute
) {
//noinspection unchecked
DeferredType deferredType =
new DeferredType(storageManager.createLazyValueWithPostCompute(compute, RECURSION_PREVENTER, t -> null));
DeferredType deferredType = new DeferredType(storageManager.createLazyValue(compute, RECURSION_PREVENTER));
trace.record(DEFERRED_TYPE, new Box<>(deferredType));
return deferredType;
}
@@ -133,6 +133,21 @@ public class LockBasedStorageManager implements StorageManager {
return new LockBasedNotNullLazyValue<T>(this, computable);
}
@NotNull
@Override
public <T> NotNullLazyValue<T> createLazyValue(
@NotNull Function0<? extends T> computable,
@NotNull final Function1<? super Boolean, ? extends T> onRecursiveCall
) {
return new LockBasedNotNullLazyValue<T>(this, computable) {
@NotNull
@Override
protected RecursionDetectedResult<T> recursionDetected(boolean firstTime) {
return RecursionDetectedResult.value(onRecursiveCall.invoke(firstTime));
}
};
}
@NotNull
@Override
public <T> NotNullLazyValue<T> createRecursionTolerantLazyValue(
@@ -50,6 +50,10 @@ abstract class ObservableStorageManager(private val delegate: StorageManager) :
return delegate.createLazyValue(computable.observable)
}
override fun <T: Any> createLazyValue(computable: () -> T, onRecursiveCall: (Boolean) -> T): NotNullLazyValue<T> {
return delegate.createLazyValue(computable.observable, onRecursiveCall)
}
override fun <T: Any> createRecursionTolerantLazyValue(computable: () -> T, onRecursiveCall: T): NotNullLazyValue<T> {
return delegate.createRecursionTolerantLazyValue(computable.observable, onRecursiveCall)
}
@@ -40,6 +40,8 @@ interface StorageManager {
fun <T : Any> createLazyValue(computable: () -> T): NotNullLazyValue<T>
fun <T : Any> createLazyValue(computable: () -> T, onRecursiveCall: (Boolean) -> T): NotNullLazyValue<T>
fun <T : Any> createRecursionTolerantLazyValue(computable: () -> T, onRecursiveCall: T): NotNullLazyValue<T>
/**