[REPL] Fix unresolved imports caching

Before this fix, if some imports were not resolved during compilation,
this result had been saved in caches, and this import couldn't been
resolved during following compilations even if it was added to the
module dependencies. This commit adds special handling of resolution
caches for the REPL compiler.
This commit is contained in:
Ilya Muradyan
2021-03-22 14:20:36 +03:00
parent ae5fefce51
commit 14d386223b
12 changed files with 179 additions and 27 deletions
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.storage.getValue
class LazyPackageViewDescriptorImpl(
open class LazyPackageViewDescriptorImpl(
override val module: ModuleDescriptorImpl,
override val fqName: FqName,
storageManager: StorageManager
@@ -38,6 +38,7 @@ class ModuleDescriptorImpl @JvmOverloads constructor(
override val stableName: Name? = null,
) : DeclarationDescriptorImpl(Annotations.EMPTY, moduleName), ModuleDescriptor {
private val capabilities: Map<ModuleCapability<*>, Any?>
private val packageViewDescriptorFactory: PackageViewDescriptorFactory
init {
if (!moduleName.isSpecial) {
@@ -46,6 +47,7 @@ class ModuleDescriptorImpl @JvmOverloads constructor(
this.capabilities = capabilities.toMutableMap()
@OptIn(TypeRefinement::class)
this.capabilities[REFINER_CAPABILITY] = Ref(null)
packageViewDescriptorFactory = getCapability(PackageViewDescriptorFactory.CAPABILITY) ?: PackageViewDescriptorFactory.Default
}
private var dependencies: ModuleDependencies? = null
@@ -63,8 +65,8 @@ class ModuleDescriptorImpl @JvmOverloads constructor(
}
}
private val packages = storageManager.createMemoizedFunction<FqName, PackageViewDescriptor> { fqName: FqName ->
LazyPackageViewDescriptorImpl(this, fqName, storageManager)
private val packages = storageManager.createMemoizedFunction { fqName: FqName ->
packageViewDescriptorFactory.compute(this, fqName, storageManager)
}
@Deprecated("This method is not going to be supported. Please do not use it")
@@ -0,0 +1,29 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.descriptors.impl
import org.jetbrains.kotlin.descriptors.ModuleCapability
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.storage.StorageManager
interface PackageViewDescriptorFactory {
fun compute(
module: ModuleDescriptorImpl,
fqName: FqName,
storageManager: StorageManager
): PackageViewDescriptor
object Default: PackageViewDescriptorFactory {
override fun compute(module: ModuleDescriptorImpl, fqName: FqName, storageManager: StorageManager): PackageViewDescriptor {
return LazyPackageViewDescriptorImpl(module, fqName, storageManager)
}
}
companion object {
val CAPABILITY = ModuleCapability<PackageViewDescriptorFactory>("PackageViewDescriptorFactory")
}
}