From 4f488ddd16dc83f568115460c5ccb14453b05f69 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Thu, 10 Oct 2019 13:21:26 +0300 Subject: [PATCH] Remove lazy values with dummy post compute lambdas --- .../descriptors/ClassResolutionScopesSupport.kt | 2 +- .../org/jetbrains/kotlin/types/DeferredType.java | 4 +--- .../kotlin/storage/LockBasedStorageManager.java | 15 +++++++++++++++ .../kotlin/storage/ObservableStorageManager.kt | 4 ++++ .../jetbrains/kotlin/storage/StorageManager.kt | 2 ++ 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/ClassResolutionScopesSupport.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/ClassResolutionScopesSupport.kt index d264eafbbd7..9cf63411e38 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/ClassResolutionScopesSupport.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/ClassResolutionScopesSupport.kt @@ -134,7 +134,7 @@ class ClassResolutionScopesSupport( } private fun StorageManager.createLazyValue(onRecursion: ((Boolean) -> T), compute: () -> T) = - createLazyValueWithPostCompute(compute, onRecursion, {}) + createLazyValue(compute, onRecursion) companion object { private val createErrorLexicalScope: (Boolean) -> LexicalScope = { ErrorLexicalScope() } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/DeferredType.java b/compiler/frontend/src/org/jetbrains/kotlin/types/DeferredType.java index 0c06987bcfe..dc32b87255d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/DeferredType.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/DeferredType.java @@ -52,9 +52,7 @@ public class DeferredType extends WrappedType { @NotNull BindingTrace trace, @NotNull Function0 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; } diff --git a/core/util.runtime/src/org/jetbrains/kotlin/storage/LockBasedStorageManager.java b/core/util.runtime/src/org/jetbrains/kotlin/storage/LockBasedStorageManager.java index f4274c98b67..5ed0bf28ada 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/storage/LockBasedStorageManager.java +++ b/core/util.runtime/src/org/jetbrains/kotlin/storage/LockBasedStorageManager.java @@ -133,6 +133,21 @@ public class LockBasedStorageManager implements StorageManager { return new LockBasedNotNullLazyValue(this, computable); } + @NotNull + @Override + public NotNullLazyValue createLazyValue( + @NotNull Function0 computable, + @NotNull final Function1 onRecursiveCall + ) { + return new LockBasedNotNullLazyValue(this, computable) { + @NotNull + @Override + protected RecursionDetectedResult recursionDetected(boolean firstTime) { + return RecursionDetectedResult.value(onRecursiveCall.invoke(firstTime)); + } + }; + } + @NotNull @Override public NotNullLazyValue createRecursionTolerantLazyValue( diff --git a/core/util.runtime/src/org/jetbrains/kotlin/storage/ObservableStorageManager.kt b/core/util.runtime/src/org/jetbrains/kotlin/storage/ObservableStorageManager.kt index b8bd4d134b4..24cf4933923 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/storage/ObservableStorageManager.kt +++ b/core/util.runtime/src/org/jetbrains/kotlin/storage/ObservableStorageManager.kt @@ -50,6 +50,10 @@ abstract class ObservableStorageManager(private val delegate: StorageManager) : return delegate.createLazyValue(computable.observable) } + override fun createLazyValue(computable: () -> T, onRecursiveCall: (Boolean) -> T): NotNullLazyValue { + return delegate.createLazyValue(computable.observable, onRecursiveCall) + } + override fun createRecursionTolerantLazyValue(computable: () -> T, onRecursiveCall: T): NotNullLazyValue { return delegate.createRecursionTolerantLazyValue(computable.observable, onRecursiveCall) } diff --git a/core/util.runtime/src/org/jetbrains/kotlin/storage/StorageManager.kt b/core/util.runtime/src/org/jetbrains/kotlin/storage/StorageManager.kt index 4aa74b688d4..83e8f11d6eb 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/storage/StorageManager.kt +++ b/core/util.runtime/src/org/jetbrains/kotlin/storage/StorageManager.kt @@ -40,6 +40,8 @@ interface StorageManager { fun createLazyValue(computable: () -> T): NotNullLazyValue + fun createLazyValue(computable: () -> T, onRecursiveCall: (Boolean) -> T): NotNullLazyValue + fun createRecursionTolerantLazyValue(computable: () -> T, onRecursiveCall: T): NotNullLazyValue /**