Revert "Don't memoize exceptions in built-ins resolve session"
This reverts commit 450d6cad3b. It's no longer
needed since there's no resolve session in built-ins anymore
This commit is contained in:
+1
-1
@@ -86,7 +86,7 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
||||
final PsiClassFinder psiClassFinder = injector.getPsiClassFinder();
|
||||
|
||||
// TODO: Replace with stub declaration provider
|
||||
LockBasedStorageManager storageManager = LockBasedStorageManager.create();
|
||||
LockBasedStorageManager storageManager = new LockBasedStorageManager();
|
||||
FileBasedDeclarationProviderFactory declarationProviderFactory = new FileBasedDeclarationProviderFactory(storageManager, files, new Predicate<FqName>() {
|
||||
@Override
|
||||
public boolean apply(FqName fqName) {
|
||||
|
||||
+16
-39
@@ -37,13 +37,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public class LockBasedStorageManager implements StorageManager {
|
||||
public static LockBasedStorageManager create() {
|
||||
return new LockBasedStorageManager(true);
|
||||
}
|
||||
|
||||
public static LockBasedStorageManager createWithoutExceptionMemoization() {
|
||||
return new LockBasedStorageManager(false);
|
||||
}
|
||||
|
||||
private final Object lock = new Object() {
|
||||
@Override
|
||||
@@ -52,19 +45,13 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
}
|
||||
};
|
||||
|
||||
private final boolean memoizeExceptions;
|
||||
|
||||
private LockBasedStorageManager(boolean memoizeExceptions) {
|
||||
this.memoizeExceptions = memoizeExceptions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <K, V> MemoizedFunctionToNotNull<K, V> createMemoizedFunction(
|
||||
@NotNull Function<K, V> compute, @NotNull ReferenceKind valuesReferenceKind
|
||||
) {
|
||||
ConcurrentMap<K, Object> map = createConcurrentMap(valuesReferenceKind);
|
||||
return new MapBasedMemoizedFunctionToNotNull<K, V>(lock, map, compute, memoizeExceptions);
|
||||
return new MapBasedMemoizedFunctionToNotNull<K, V>(lock, map, compute);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -73,7 +60,7 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
@NotNull Function<K, V> compute, @NotNull ReferenceKind valuesReferenceKind
|
||||
) {
|
||||
ConcurrentMap<K, Object> map = createConcurrentMap(valuesReferenceKind);
|
||||
return new MapBasedMemoizedFunction<K, V>(lock, map, compute, memoizeExceptions);
|
||||
return new MapBasedMemoizedFunction<K, V>(lock, map, compute);
|
||||
}
|
||||
|
||||
private static <K, V> ConcurrentMap<K, V> createConcurrentMap(ReferenceKind referenceKind) {
|
||||
@@ -83,13 +70,13 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
@NotNull
|
||||
@Override
|
||||
public <T> NotNullLazyValue<T> createLazyValue(@NotNull Computable<T> computable) {
|
||||
return new LockBasedNotNullLazyValue<T>(lock, computable, memoizeExceptions);
|
||||
return new LockBasedNotNullLazyValue<T>(lock, computable);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <T> NotNullLazyValue<T> createLazyValueWithPostCompute(@NotNull Computable<T> computable, @NotNull final Consumer<T> postCompute) {
|
||||
return new LockBasedNotNullLazyValue<T>(lock, computable, memoizeExceptions) {
|
||||
return new LockBasedNotNullLazyValue<T>(lock, computable) {
|
||||
@Override
|
||||
protected void postCompute(@NotNull T value) {
|
||||
postCompute.consume(value);
|
||||
@@ -100,7 +87,7 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
@NotNull
|
||||
@Override
|
||||
public <T> NullableLazyValue<T> createNullableLazyValue(@NotNull Computable<T> computable) {
|
||||
return new LockBasedLazyValue<T>(lock, computable, memoizeExceptions);
|
||||
return new LockBasedLazyValue<T>(lock, computable);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -108,7 +95,7 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
public <T> NullableLazyValue<T> createNullableLazyValueWithPostCompute(
|
||||
@NotNull Computable<T> computable, @NotNull final Consumer<T> postCompute
|
||||
) {
|
||||
return new LockBasedLazyValue<T>(lock, computable, memoizeExceptions) {
|
||||
return new LockBasedLazyValue<T>(lock, computable) {
|
||||
@Override
|
||||
protected void postCompute(@Nullable T value) {
|
||||
postCompute.consume(value);
|
||||
@@ -134,15 +121,13 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
private static class LockBasedLazyValue<T> implements NullableLazyValue<T> {
|
||||
private final Object lock;
|
||||
private final Computable<T> computable;
|
||||
private final boolean memoizeExceptions;
|
||||
|
||||
@Nullable
|
||||
private volatile Object value = null;
|
||||
|
||||
public LockBasedLazyValue(@NotNull Object lock, @NotNull Computable<T> computable, boolean memoizeExceptions) {
|
||||
public LockBasedLazyValue(@NotNull Object lock, @NotNull Computable<T> computable) {
|
||||
this.lock = lock;
|
||||
this.computable = computable;
|
||||
this.memoizeExceptions = memoizeExceptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -161,9 +146,7 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
return typedValue;
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
if (memoizeExceptions) {
|
||||
value = WrappedValues.escapeThrowable(throwable);
|
||||
}
|
||||
value = WrappedValues.escapeThrowable(throwable);
|
||||
throw ExceptionUtils.rethrow(throwable);
|
||||
}
|
||||
}
|
||||
@@ -176,8 +159,8 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
|
||||
private static class LockBasedNotNullLazyValue<T> extends LockBasedLazyValue<T> implements NotNullLazyValue<T> {
|
||||
|
||||
public LockBasedNotNullLazyValue(@NotNull Object lock, @NotNull Computable<T> computable, boolean memoizeExceptions) {
|
||||
super(lock, computable, memoizeExceptions);
|
||||
public LockBasedNotNullLazyValue(@NotNull Object lock, @NotNull Computable<T> computable) {
|
||||
super(lock, computable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -193,15 +176,11 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
private final Object lock;
|
||||
private final ConcurrentMap<K, Object> cache;
|
||||
private final Function<K, V> compute;
|
||||
private final boolean memoizeExceptions;
|
||||
|
||||
public MapBasedMemoizedFunction(
|
||||
@NotNull Object lock, @NotNull ConcurrentMap<K, Object> map,
|
||||
@NotNull Function<K, V> compute, boolean memoizeExceptions) {
|
||||
public MapBasedMemoizedFunction(@NotNull Object lock, @NotNull ConcurrentMap<K, Object> map, @NotNull Function<K, V> compute) {
|
||||
this.lock = lock;
|
||||
this.cache = map;
|
||||
this.compute = compute;
|
||||
this.memoizeExceptions = memoizeExceptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -222,10 +201,8 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
return typedValue;
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
if (memoizeExceptions) {
|
||||
Object oldValue = cache.put(input, WrappedValues.escapeThrowable(throwable));
|
||||
assert oldValue == null : "Race condition detected";
|
||||
}
|
||||
Object oldValue = cache.put(input, WrappedValues.escapeThrowable(throwable));
|
||||
assert oldValue == null : "Race condition detected";
|
||||
|
||||
throw ExceptionUtils.rethrow(throwable);
|
||||
}
|
||||
@@ -238,10 +215,9 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
public MapBasedMemoizedFunctionToNotNull(
|
||||
@NotNull Object lock,
|
||||
@NotNull ConcurrentMap<K, Object> map,
|
||||
@NotNull Function<K, V> compute,
|
||||
boolean memoizeExceptions
|
||||
@NotNull Function<K, V> compute
|
||||
) {
|
||||
super(lock, map, compute, memoizeExceptions);
|
||||
super(lock, map, compute);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -348,4 +324,5 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -238,10 +238,7 @@ public class KotlinBuiltIns {
|
||||
@NotNull
|
||||
private KotlinCodeAnalyzer createLazyResolveSession(@NotNull Project project) throws IOException {
|
||||
List<JetFile> files = loadResourcesAsJetFiles(project, LIBRARY_FILES);
|
||||
|
||||
// As builtins resolve session is never recreated, we don't want it be corrupted forever with stored exceptions
|
||||
LockBasedStorageManager storageManager = LockBasedStorageManager.createWithoutExceptionMemoization();
|
||||
|
||||
LockBasedStorageManager storageManager = new LockBasedStorageManager();
|
||||
return new ResolveSession(
|
||||
project,
|
||||
storageManager,
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ public abstract class AbstractLazyResolveDescriptorRendererTest extends KotlinTe
|
||||
|
||||
ModuleDescriptorImpl lazyModule = AnalyzerFacadeForJVM.createJavaModule("<lazy module>");
|
||||
lazyModule.setModuleConfiguration(injectorForTopDownAnalyzer.getModuleDescriptor().getModuleConfiguration());
|
||||
LockBasedStorageManager storageManager = LockBasedStorageManager.create();
|
||||
LockBasedStorageManager storageManager = new LockBasedStorageManager();
|
||||
final ResolveSession resolveSession = new ResolveSession(getProject(), storageManager, lazyModule,
|
||||
new FileBasedDeclarationProviderFactory(storageManager, files));
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ public class LazyResolveTestUtil {
|
||||
final JavaDescriptorResolver javaDescriptorResolver = injector.getJavaDescriptorResolver();
|
||||
|
||||
|
||||
LockBasedStorageManager storageManager = LockBasedStorageManager.create();
|
||||
LockBasedStorageManager storageManager = new LockBasedStorageManager();
|
||||
FileBasedDeclarationProviderFactory declarationProviderFactory = new FileBasedDeclarationProviderFactory(storageManager, files, new Predicate<FqName>() {
|
||||
@Override
|
||||
public boolean apply(FqName fqName) {
|
||||
|
||||
@@ -214,7 +214,7 @@ public class JetSourceNavigationHelper {
|
||||
}
|
||||
|
||||
Project project = decompiledDeclaration.getProject();
|
||||
LockBasedStorageManager storageManager = LockBasedStorageManager.create();
|
||||
LockBasedStorageManager storageManager = new LockBasedStorageManager();
|
||||
FileBasedDeclarationProviderFactory providerFactory = new FileBasedDeclarationProviderFactory(storageManager, getContainingFiles(candidates),
|
||||
new Predicate<FqName>() {
|
||||
@Override
|
||||
|
||||
@@ -140,7 +140,7 @@ public final class AnalyzerFacadeForJS {
|
||||
|
||||
@NotNull
|
||||
public static ResolveSession getLazyResolveSession(Collection<JetFile> files, Config config) {
|
||||
LockBasedStorageManager storageManager = LockBasedStorageManager.create();
|
||||
LockBasedStorageManager storageManager = new LockBasedStorageManager();
|
||||
FileBasedDeclarationProviderFactory declarationProviderFactory = new FileBasedDeclarationProviderFactory(
|
||||
storageManager, Config.withJsLibAdded(files, config), Predicates.<FqName>alwaysFalse());
|
||||
ModuleDescriptorImpl lazyModule = createJsModule("<lazy module>");
|
||||
|
||||
Reference in New Issue
Block a user