Add ability to provide specific AbsentDescriptorHandler

#EA-457188

Merge-request: KT-MR-8900
Merged-by: Vladimir Dolzhenko <Vladimir.Dolzhenko@jetbrains.com>
This commit is contained in:
Vladimir Dolzhenko
2023-02-22 12:44:46 +00:00
committed by Space Team
parent 41278d0797
commit 3e99807436
16 changed files with 416 additions and 36 deletions
@@ -51,6 +51,7 @@ import org.jetbrains.kotlin.resolve.jvm.extensions.SyntheticJavaResolveExtension
import org.jetbrains.kotlin.resolve.jvm.modules.JavaModuleResolver
import org.jetbrains.kotlin.resolve.jvm.multiplatform.OptionalAnnotationPackageFragmentProvider
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformAnalyzerServices
import org.jetbrains.kotlin.resolve.lazy.AbsentDescriptorHandler
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
import org.jetbrains.kotlin.resolve.scopes.optimization.OptimizingOptions
@@ -74,10 +75,11 @@ fun createContainerForLazyResolveWithJava(
implicitsResolutionFilter: ImplicitsExtensionsResolutionFilter? = null,
sealedInheritorsProvider: SealedClassInheritorsProvider = CliSealedClassInheritorsProvider,
optimizingOptions: OptimizingOptions? = null,
absentDescriptorHandlerClass: Class<out AbsentDescriptorHandler>? = null
): StorageComponentContainer = createContainer("LazyResolveWithJava", JvmPlatformAnalyzerServices) {
configureModule(
moduleContext, jvmPlatform, JvmPlatformAnalyzerServices, bindingTrace, languageVersionSettings,
sealedInheritorsProvider, optimizingOptions
sealedInheritorsProvider, optimizingOptions, absentDescriptorHandlerClass
)
configureIncrementalCompilation(lookupTracker, expectActualTracker, inlineConstTracker, enumWhenTracker)
@@ -96,7 +98,6 @@ fun createContainerForLazyResolveWithJava(
)
targetEnvironment.configure(this)
}.apply {
initializeJavaSpecificComponents(bindingTrace)
}
@@ -19,8 +19,7 @@ package org.jetbrains.kotlin.resolve.jvm
import org.jetbrains.kotlin.analyzer.*
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltInsPackageFragmentProvider
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.container.get
import org.jetbrains.kotlin.container.tryGetService
import org.jetbrains.kotlin.container.*
import org.jetbrains.kotlin.context.ModuleContext
import org.jetbrains.kotlin.descriptors.impl.CompositePackageFragmentProvider
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
@@ -38,6 +37,7 @@ import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.resolve.SealedClassInheritorsProvider
import org.jetbrains.kotlin.resolve.TargetEnvironment
import org.jetbrains.kotlin.resolve.jvm.extensions.PackageFragmentProviderExtension
import org.jetbrains.kotlin.resolve.lazy.AbsentDescriptorHandler
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactoryService
import org.jetbrains.kotlin.resolve.scopes.optimization.OptimizingOptions
@@ -64,7 +64,8 @@ class JvmResolverForModuleFactory(
resolverForProject: ResolverForProject<M>,
languageVersionSettings: LanguageVersionSettings,
sealedInheritorsProvider: SealedClassInheritorsProvider,
resolveOptimizingOptions: OptimizingOptions?
resolveOptimizingOptions: OptimizingOptions?,
absentDescriptorHandlerClass: Class<out AbsentDescriptorHandler>?
): ResolverForModule {
val (moduleInfo, syntheticFiles, moduleContentScope) = moduleContent
val project = moduleContext.project
@@ -123,6 +124,7 @@ class JvmResolverForModuleFactory(
sealedInheritorsProvider = sealedInheritorsProvider,
useBuiltInsProvider = platformParameters.useBuiltinsProviderForModule(moduleInfo),
optimizingOptions = resolveOptimizingOptions,
absentDescriptorHandlerClass = absentDescriptorHandlerClass
)
val providersForModule = arrayListOf(
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.platform.TargetPlatformVersion
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.SealedClassInheritorsProvider
import org.jetbrains.kotlin.resolve.lazy.AbsentDescriptorHandler
import org.jetbrains.kotlin.resolve.scopes.optimization.OptimizingOptions
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.storage.getValue
@@ -128,6 +129,32 @@ interface LibraryModuleInfo : ModuleInfo {
}
abstract class ResolverForModuleFactory {
open fun <M : ModuleInfo> createResolverForModule(
moduleDescriptor: ModuleDescriptorImpl,
moduleContext: ModuleContext,
moduleContent: ModuleContent<M>,
resolverForProject: ResolverForProject<M>,
languageVersionSettings: LanguageVersionSettings,
sealedInheritorsProvider: SealedClassInheritorsProvider,
resolveOptimizingOptions: OptimizingOptions?,
absentDescriptorHandlerClass: Class<out AbsentDescriptorHandler>?
): ResolverForModule {
@Suppress("DEPRECATION")
return createResolverForModule(
moduleDescriptor,
moduleContext,
moduleContent,
resolverForProject,
languageVersionSettings,
sealedInheritorsProvider,
resolveOptimizingOptions
)
}
@Deprecated(
"Left only for compatibility, please use full version",
ReplaceWith("createResolverForModule(moduleDescriptor, moduleContext, moduleContent, resolverForProject, languageVersionSettings, sealedInheritorsProvider, null, null)")
)
open fun <M : ModuleInfo> createResolverForModule(
moduleDescriptor: ModuleDescriptorImpl,
moduleContext: ModuleContext,
@@ -150,7 +177,7 @@ abstract class ResolverForModuleFactory {
@Deprecated(
"Left only for compatibility, please use full version",
ReplaceWith("createResolverForModule(moduleDescriptor, moduleContext, moduleContent, resolverForProject, languageVersionSettings, sealedInheritorsProvider, null)")
ReplaceWith("createResolverForModule(moduleDescriptor, moduleContext, moduleContent, resolverForProject, languageVersionSettings, sealedInheritorsProvider, null, null)")
)
open fun <M : ModuleInfo> createResolverForModule(
moduleDescriptor: ModuleDescriptorImpl,
@@ -167,7 +194,8 @@ abstract class ResolverForModuleFactory {
resolverForProject,
languageVersionSettings,
sealedInheritorsProvider,
null
resolveOptimizingOptions = null,
absentDescriptorHandlerClass = null
)
}
}
@@ -62,6 +62,7 @@ class ResolverForSingleModuleProject<M : ModuleInfo>(
this,
languageVersionSettings,
CliSealedClassInheritorsProvider,
null,
resolveOptimizingOptions = null,
absentDescriptorHandlerClass = null
)
}
@@ -42,6 +42,7 @@ import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.checkers.ExpectedActualDeclarationChecker
import org.jetbrains.kotlin.resolve.extensions.AnalysisHandlerExtension
import org.jetbrains.kotlin.resolve.lazy.AbsentDescriptorHandler
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactoryService
@@ -93,6 +94,7 @@ class CommonResolverForModuleFactory(
languageVersionSettings: LanguageVersionSettings,
sealedInheritorsProvider: SealedClassInheritorsProvider,
resolveOptimizingOptions: OptimizingOptions?,
absentDescriptorHandlerClass: Class<out AbsentDescriptorHandler>?
): ResolverForModule {
val (moduleInfo, syntheticFiles, moduleContentScope) = moduleContent
val project = moduleContext.project
@@ -105,8 +107,17 @@ class CommonResolverForModuleFactory(
val metadataPartProvider = platformParameters.metadataPartProviderFactory(moduleContent)
val trace = CodeAnalyzerInitializer.getInstance(project).createTrace()
val container = createContainerToResolveCommonCode(
moduleContext, trace, declarationProviderFactory, moduleContentScope, targetEnvironment, metadataPartProvider,
languageVersionSettings, targetPlatform, CommonPlatformAnalyzerServices, shouldCheckExpectActual
moduleContext,
trace,
declarationProviderFactory,
moduleContentScope,
targetEnvironment,
metadataPartProvider,
languageVersionSettings,
targetPlatform,
CommonPlatformAnalyzerServices,
shouldCheckExpectActual,
absentDescriptorHandlerClass
)
val klibMetadataPackageFragmentProvider =
@@ -243,10 +254,19 @@ private fun createContainerToResolveCommonCode(
languageVersionSettings: LanguageVersionSettings,
platform: TargetPlatform,
analyzerServices: PlatformDependentAnalyzerServices,
shouldCheckExpectActual: Boolean
shouldCheckExpectActual: Boolean,
absentDescriptorHandlerClass: Class<out AbsentDescriptorHandler>?
): StorageComponentContainer =
createContainer("ResolveCommonCode", analyzerServices) {
configureModule(moduleContext, platform, analyzerServices, bindingTrace, languageVersionSettings)
configureModule(
moduleContext,
platform,
analyzerServices,
bindingTrace,
languageVersionSettings,
optimizingOptions = null,
absentDescriptorHandlerClass = absentDescriptorHandlerClass
)
useInstance(moduleContentScope)
useInstance(declarationProviderFactory)
@@ -18,10 +18,7 @@ package org.jetbrains.kotlin.frontend.di
import org.jetbrains.kotlin.cfg.ControlFlowInformationProvider
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.container.StorageComponentContainer
import org.jetbrains.kotlin.container.useImpl
import org.jetbrains.kotlin.container.useInstance
import org.jetbrains.kotlin.container.useInstanceIfNotNull
import org.jetbrains.kotlin.container.*
import org.jetbrains.kotlin.context.ModuleContext
import org.jetbrains.kotlin.contracts.ContractDeserializerImpl
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
@@ -54,6 +51,60 @@ import org.jetbrains.kotlin.types.expressions.LocalClassDescriptorHolder
import org.jetbrains.kotlin.types.expressions.LocalLazyDeclarationResolver
import org.jetbrains.kotlin.util.ProgressManagerBasedCancellationChecker
@Suppress("UNUSED_PARAMETER", "unused")
@Deprecated(
level = DeprecationLevel.HIDDEN,
message = "configureModule\$default provided for binary backward compatibility",
)
fun StorageComponentContainer.`configureModule$default`(
moduleContext: ModuleContext,
platform: TargetPlatform,
analyzerServices: PlatformDependentAnalyzerServices,
trace: BindingTrace,
languageVersionSettings: LanguageVersionSettings,
sealedProvider: SealedClassInheritorsProvider?,
optimizingOptions: OptimizingOptions?,
params: Int,
any: Any?
) {
configureModule(
moduleContext,
platform,
analyzerServices,
trace,
languageVersionSettings,
sealedProvider ?: CliSealedClassInheritorsProvider,
optimizingOptions,
null
)
}
@Deprecated(
level = DeprecationLevel.WARNING,
message = "consider to use configureModule with OptimizingOptions and Class<out AbsentDescriptorHandler>",
replaceWith = ReplaceWith(
"""
configureModule(
moduleContext,
platform,
analyzerServices,
trace,
languageVersionSettings,
sealedProvider,
null,
null
)"""
)
)
fun StorageComponentContainer.configureModule(
moduleContext: ModuleContext,
platform: TargetPlatform,
analyzerServices: PlatformDependentAnalyzerServices,
trace: BindingTrace,
languageVersionSettings: LanguageVersionSettings,
sealedProvider: SealedClassInheritorsProvider = CliSealedClassInheritorsProvider
) = configureModule(moduleContext, platform, analyzerServices, trace, languageVersionSettings, sealedProvider, null, null)
fun StorageComponentContainer.configureModule(
moduleContext: ModuleContext,
platform: TargetPlatform,
@@ -61,7 +112,8 @@ fun StorageComponentContainer.configureModule(
trace: BindingTrace,
languageVersionSettings: LanguageVersionSettings,
sealedProvider: SealedClassInheritorsProvider = CliSealedClassInheritorsProvider,
optimizingOptions: OptimizingOptions? = null,
optimizingOptions: OptimizingOptions?,
absentDescriptorHandlerClass: Class<out AbsentDescriptorHandler>?
) {
useInstance(sealedProvider)
useInstance(moduleContext)
@@ -74,6 +126,10 @@ fun StorageComponentContainer.configureModule(
useInstanceIfNotNull(optimizingOptions)
if (absentDescriptorHandlerClass != null) {
registerSingleton(absentDescriptorHandlerClass)
}
useInstance(platform)
useInstance(analyzerServices)
@@ -148,6 +204,25 @@ fun StorageComponentContainer.configureIncrementalCompilation(
useInstance(enumWhenTracker)
}
@Deprecated(
level = DeprecationLevel.WARNING,
message = "consider to use createContainerForBodyResolve with AbsentDescriptorHandler",
replaceWith = ReplaceWith(
"""
createContainerForBodyResolve(
moduleContext,
bindingTrace,
platform,
statementFilter,
analyzerServices,
languageVersionSettings,
moduleStructureOracle,
sealedProvider,
controlFlowInformationProviderFactory,
null
)"""
)
)
fun createContainerForBodyResolve(
moduleContext: ModuleContext,
bindingTrace: BindingTrace,
@@ -158,8 +233,37 @@ fun createContainerForBodyResolve(
moduleStructureOracle: ModuleStructureOracle,
sealedProvider: SealedClassInheritorsProvider,
controlFlowInformationProviderFactory: ControlFlowInformationProvider.Factory,
): StorageComponentContainer = createContainerForBodyResolve(
moduleContext,
bindingTrace,
platform,
statementFilter,
analyzerServices,
languageVersionSettings,
moduleStructureOracle,
sealedProvider,
controlFlowInformationProviderFactory,
null
)
fun createContainerForBodyResolve(
moduleContext: ModuleContext,
bindingTrace: BindingTrace,
platform: TargetPlatform,
statementFilter: StatementFilter,
analyzerServices: PlatformDependentAnalyzerServices,
languageVersionSettings: LanguageVersionSettings,
moduleStructureOracle: ModuleStructureOracle,
sealedProvider: SealedClassInheritorsProvider,
controlFlowInformationProviderFactory: ControlFlowInformationProvider.Factory,
absentDescriptorHandler: AbsentDescriptorHandler?
): StorageComponentContainer = createContainer("BodyResolve", analyzerServices) {
configureModule(moduleContext, platform, analyzerServices, bindingTrace, languageVersionSettings, sealedProvider)
configureModule(
moduleContext, platform, analyzerServices, bindingTrace, languageVersionSettings, sealedProvider,
optimizingOptions = null,
absentDescriptorHandlerClass = if (absentDescriptorHandler == null) BasicAbsentDescriptorHandler::class.java else null
)
useInstanceIfNotNull(absentDescriptorHandler)
useInstance(statementFilter)
@@ -172,6 +276,144 @@ fun createContainerForBodyResolve(
useInstance(InlineConstTracker.DoNothing)
}
@Suppress("UNUSED_PARAMETER", "unused")
@Deprecated(
level = DeprecationLevel.HIDDEN,
message = "createContainerForLazyBodyResolve\$default provided for binary backward compatibility",
)
fun `createContainerForLazyBodyResolve$default`(
moduleContext: ModuleContext,
kotlinCodeAnalyzer: KotlinCodeAnalyzer,
bindingTrace: BindingTrace,
platform: TargetPlatform,
bodyResolveCache: BodyResolveCache,
analyzerServices: PlatformDependentAnalyzerServices,
languageVersionSettings: LanguageVersionSettings,
moduleStructureOracle: ModuleStructureOracle,
mainFunctionDetectorFactory: MainFunctionDetector.Factory,
sealedProvider: SealedClassInheritorsProvider,
controlFlowInformationProviderFactory: ControlFlowInformationProvider.Factory,
optimizingOptions: OptimizingOptions?,
params: Int,
any: Any?
): StorageComponentContainer =
createContainerForLazyBodyResolve(
moduleContext,
kotlinCodeAnalyzer,
bindingTrace,
platform,
bodyResolveCache,
analyzerServices,
languageVersionSettings,
moduleStructureOracle,
mainFunctionDetectorFactory,
sealedProvider,
controlFlowInformationProviderFactory,
optimizingOptions,
null
)
@Deprecated(
level = DeprecationLevel.WARNING,
message = "consider to use createContainerForLazyBodyResolve with AbsentDescriptorHandler",
replaceWith = ReplaceWith(
"""
createContainerForLazyBodyResolve(
moduleContext,
kotlinCodeAnalyzer,
bindingTrace,
platform,
bodyResolveCache,
analyzerServices,
languageVersionSettings,
moduleStructureOracle,
mainFunctionDetectorFactory,
sealedProvider,
controlFlowInformationProviderFactory,
null,
null
) """
)
)
fun createContainerForLazyBodyResolve(
moduleContext: ModuleContext,
kotlinCodeAnalyzer: KotlinCodeAnalyzer,
bindingTrace: BindingTrace,
platform: TargetPlatform,
bodyResolveCache: BodyResolveCache,
analyzerServices: PlatformDependentAnalyzerServices,
languageVersionSettings: LanguageVersionSettings,
moduleStructureOracle: ModuleStructureOracle,
mainFunctionDetectorFactory: MainFunctionDetector.Factory,
sealedProvider: SealedClassInheritorsProvider,
controlFlowInformationProviderFactory: ControlFlowInformationProvider.Factory
): StorageComponentContainer = createContainerForLazyBodyResolve(
moduleContext,
kotlinCodeAnalyzer,
bindingTrace,
platform,
bodyResolveCache,
analyzerServices,
languageVersionSettings,
moduleStructureOracle,
mainFunctionDetectorFactory,
sealedProvider,
controlFlowInformationProviderFactory,
null,
null,
)
@Deprecated(
level = DeprecationLevel.WARNING,
message = "consider to use createContainerForLazyBodyResolve with AbsentDescriptorHandler",
replaceWith = ReplaceWith(
"""
createContainerForLazyBodyResolve(
moduleContext,
kotlinCodeAnalyzer,
bindingTrace,
platform,
bodyResolveCache,
analyzerServices,
languageVersionSettings,
moduleStructureOracle,
mainFunctionDetectorFactory,
sealedProvider,
controlFlowInformationProviderFactory,
optimizingOptions,
null
) """
)
)
fun createContainerForLazyBodyResolve(
moduleContext: ModuleContext,
kotlinCodeAnalyzer: KotlinCodeAnalyzer,
bindingTrace: BindingTrace,
platform: TargetPlatform,
bodyResolveCache: BodyResolveCache,
analyzerServices: PlatformDependentAnalyzerServices,
languageVersionSettings: LanguageVersionSettings,
moduleStructureOracle: ModuleStructureOracle,
mainFunctionDetectorFactory: MainFunctionDetector.Factory,
sealedProvider: SealedClassInheritorsProvider,
controlFlowInformationProviderFactory: ControlFlowInformationProvider.Factory,
optimizingOptions: OptimizingOptions?
): StorageComponentContainer = createContainerForLazyBodyResolve(
moduleContext,
kotlinCodeAnalyzer,
bindingTrace,
platform,
bodyResolveCache,
analyzerServices,
languageVersionSettings,
moduleStructureOracle,
mainFunctionDetectorFactory,
sealedProvider,
controlFlowInformationProviderFactory,
optimizingOptions,
null,
)
fun createContainerForLazyBodyResolve(
moduleContext: ModuleContext,
kotlinCodeAnalyzer: KotlinCodeAnalyzer,
@@ -184,16 +426,26 @@ fun createContainerForLazyBodyResolve(
mainFunctionDetectorFactory: MainFunctionDetector.Factory,
sealedProvider: SealedClassInheritorsProvider,
controlFlowInformationProviderFactory: ControlFlowInformationProvider.Factory,
optimizingOptions: OptimizingOptions? = null
optimizingOptions: OptimizingOptions?,
absentDescriptorHandler: AbsentDescriptorHandler?,
): StorageComponentContainer = createContainer("LazyBodyResolve", analyzerServices) {
configureModule(moduleContext, platform, analyzerServices, bindingTrace, languageVersionSettings, sealedProvider, optimizingOptions)
configureModule(
moduleContext,
platform,
analyzerServices,
bindingTrace,
languageVersionSettings,
sealedProvider,
optimizingOptions,
absentDescriptorHandlerClass = BasicAbsentDescriptorHandler::class.java.takeIf { absentDescriptorHandler == null }
)
useInstanceIfNotNull(absentDescriptorHandler)
useInstance(mainFunctionDetectorFactory)
useInstance(kotlinCodeAnalyzer)
useInstance(kotlinCodeAnalyzer.fileScopeProvider)
useInstance(bodyResolveCache)
useImpl<AnnotationResolverImpl>()
useImpl<LazyTopDownAnalyzer>()
useImpl<BasicAbsentDescriptorHandler>()
useInstance(moduleStructureOracle)
useInstance(controlFlowInformationProviderFactory)
useInstance(InlineConstTracker.DoNothing)
@@ -215,9 +467,21 @@ fun createContainerForLazyLocalClassifierAnalyzer(
localClassDescriptorHolder: LocalClassDescriptorHolder,
analyzerServices: PlatformDependentAnalyzerServices,
controlFlowInformationProviderFactory: ControlFlowInformationProvider.Factory,
absentDescriptorHandler: AbsentDescriptorHandler?
): StorageComponentContainer = createContainer("LocalClassifierAnalyzer", analyzerServices) {
configureModule(moduleContext, platform, analyzerServices, bindingTrace, languageVersionSettings)
configureModule(
moduleContext,
platform,
analyzerServices,
bindingTrace,
languageVersionSettings,
optimizingOptions = null,
absentDescriptorHandlerClass = null
)
if (absentDescriptorHandler != null) {
useInstance(absentDescriptorHandler)
}
useInstance(localClassDescriptorHolder)
useInstance(lookupTracker)
useInstance(ExpectActualTracker.DoNothing)
@@ -237,10 +501,26 @@ fun createContainerForLazyLocalClassifierAnalyzer(
useImpl<DeclarationScopeProviderForLocalClassifierAnalyzer>()
useImpl<LocalLazyDeclarationResolver>()
useInstance(statementFilter)
}
@Deprecated(
level = DeprecationLevel.WARNING,
message = "consider to use createContainerForLazyResolve with absentDescriptorHandlerClass",
replaceWith = ReplaceWith(
"""
createContainerForLazyResolve(
moduleContext,
declarationProviderFactory,
bindingTrace,
platform,
analyzerServices,
targetEnvironment,
languageVersionSettings,
null)
"""
)
)
fun createContainerForLazyResolve(
moduleContext: ModuleContext,
declarationProviderFactory: DeclarationProviderFactory,
@@ -249,15 +529,41 @@ fun createContainerForLazyResolve(
analyzerServices: PlatformDependentAnalyzerServices,
targetEnvironment: TargetEnvironment,
languageVersionSettings: LanguageVersionSettings
): StorageComponentContainer = createContainerForLazyResolve(
moduleContext,
declarationProviderFactory,
bindingTrace,
platform,
analyzerServices,
targetEnvironment,
languageVersionSettings,
null
)
fun createContainerForLazyResolve(
moduleContext: ModuleContext,
declarationProviderFactory: DeclarationProviderFactory,
bindingTrace: BindingTrace,
platform: TargetPlatform,
analyzerServices: PlatformDependentAnalyzerServices,
targetEnvironment: TargetEnvironment,
languageVersionSettings: LanguageVersionSettings,
absentDescriptorHandlerClass: Class<out AbsentDescriptorHandler>?
): StorageComponentContainer = createContainer("LazyResolve", analyzerServices) {
configureModule(moduleContext, platform, analyzerServices, bindingTrace, languageVersionSettings)
configureModule(
moduleContext,
platform,
analyzerServices,
bindingTrace,
languageVersionSettings,
optimizingOptions = null,
absentDescriptorHandlerClass = absentDescriptorHandlerClass
)
configureStandardResolveComponents()
useInstance(declarationProviderFactory)
useInstance(InlineConstTracker.DoNothing)
targetEnvironment.configure(this)
}
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.container.*
import org.jetbrains.kotlin.resolve.calls.checkers.*
import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator
import org.jetbrains.kotlin.resolve.checkers.*
import org.jetbrains.kotlin.resolve.lazy.AbsentDescriptorHandler
import org.jetbrains.kotlin.resolve.lazy.DelegationFilter
import org.jetbrains.kotlin.types.DynamicTypesSettings
@@ -94,7 +95,9 @@ private val DEFAULT_CLASH_RESOLVERS = listOf<PlatformExtensionsClashResolver<*>>
*/
PlatformExtensionsClashResolver.FallbackToDefault(TypeSpecificityComparator.NONE, TypeSpecificityComparator::class.java),
PlatformExtensionsClashResolver.FallbackToDefault(DynamicTypesSettings(), DynamicTypesSettings::class.java)
PlatformExtensionsClashResolver.FallbackToDefault(DynamicTypesSettings(), DynamicTypesSettings::class.java),
PlatformExtensionsClashResolver.FirstWins(AbsentDescriptorHandler::class.java)
)
fun StorageComponentContainer.configureDefaultCheckers() {
@@ -5,12 +5,12 @@
package org.jetbrains.kotlin.resolve.lazy
import org.jetbrains.kotlin.container.PlatformSpecificExtension
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
interface AbsentDescriptorHandler {
interface AbsentDescriptorHandler : PlatformSpecificExtension<AbsentDescriptorHandler> {
fun diagnoseDescriptorNotFound(declaration: KtDeclaration): DeclarationDescriptor
}
@@ -38,7 +38,6 @@ import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.debugText.getDebugText
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.calls.components.InferenceSession
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension
import org.jetbrains.kotlin.resolve.lazy.*
@@ -75,6 +74,7 @@ class LocalClassifierAnalyzer(
private val additionalClassPartsProvider: AdditionalClassPartsProvider,
private val sealedClassInheritorsProvider: SealedClassInheritorsProvider,
private val controlFlowInformationProviderFactory: ControlFlowInformationProvider.Factory,
private val absentDescriptorHandler: AbsentDescriptorHandler
) {
fun processClassOrObject(
scope: LexicalWritableScope?,
@@ -115,6 +115,7 @@ class LocalClassifierAnalyzer(
),
analyzerServices,
controlFlowInformationProviderFactory,
absentDescriptorHandler
)
container.get<LazyTopDownAnalyzer>().analyzeDeclarations(
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformAnalyzerServices
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
import org.jetbrains.kotlin.types.expressions.FakeCallResolver
import org.jetbrains.kotlin.incremental.components.InlineConstTracker
import org.jetbrains.kotlin.resolve.lazy.BasicAbsentDescriptorHandler
fun createContainerForTests(project: Project, module: ModuleDescriptor): ContainerForTests {
return ContainerForTests(createContainer("Tests", JvmPlatformAnalyzerServices) {
@@ -41,7 +42,9 @@ fun createContainerForTests(project: Project, module: ModuleDescriptor): Contain
JvmPlatforms.defaultJvmPlatform,
JvmPlatformAnalyzerServices,
BindingTraceContext(),
LanguageVersionSettingsImpl.DEFAULT
LanguageVersionSettingsImpl.DEFAULT,
optimizingOptions = null,
absentDescriptorHandlerClass = BasicAbsentDescriptorHandler::class.java
)
useImpl<AnnotationResolverImpl>()
useInstance(ModuleStructureOracle.SingleModule)
@@ -55,7 +55,9 @@ private fun createFakeTopDownAnalyzerForNative(
NativePlatforms.unspecifiedNativePlatform,
NativePlatformAnalyzerServices,
bindingTrace,
languageVersionSettings
languageVersionSettings,
optimizingOptions = null,
absentDescriptorHandlerClass = null
)
configureStandardResolveComponents()
@@ -116,7 +116,8 @@ class MultiModuleJavaAnalysisCustomTest : KtUsefulTestCase() {
this,
LanguageVersionSettingsImpl.DEFAULT,
CliSealedClassInheritorsProvider,
null,
resolveOptimizingOptions = null,
absentDescriptorHandlerClass = null
)
}
@@ -119,7 +119,8 @@ public class DefaultModalityModifiersTest extends KotlinTestWithEnvironment {
CommonPlatforms.INSTANCE.getDefaultCommonPlatform(),
CommonPlatformAnalyzerServices.INSTANCE,
CompilerEnvironment.INSTANCE,
LanguageVersionSettingsImpl.DEFAULT
LanguageVersionSettingsImpl.DEFAULT,
null
);
ResolveSession resolveSession = DslKt.getService(container, ResolveSession.class);
@@ -48,5 +48,10 @@ abstract class PlatformExtensionsClashResolver<E : PlatformSpecificExtension<E>>
override fun resolveExtensionsClash(extensions: List<E>): E = defaultValue
}
class FirstWins<E : PlatformSpecificExtension<E>>(applicableTo: Class<E>) : PlatformExtensionsClashResolver<E>(applicableTo) {
override fun resolveExtensionsClash(extensions: List<E>): E = extensions.first()
}
}
@@ -58,7 +58,9 @@ fun createContainerForJS(
JsPlatforms.defaultJsPlatform,
JsPlatformAnalyzerServices,
bindingTrace,
languageVersionSettings
languageVersionSettings,
optimizingOptions = null,
absentDescriptorHandlerClass = null
)
configureIncrementalCompilation(lookupTracker, expectActualTracker, inlineConstTracker, enumWhenTracker)
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.frontend.di.configureModule
import org.jetbrains.kotlin.platform.konan.NativePlatforms
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.konan.platform.NativePlatformAnalyzerServices
import org.jetbrains.kotlin.resolve.lazy.BasicAbsentDescriptorHandler
import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
@@ -29,7 +30,10 @@ fun createTopDownAnalyzerProviderForKonan(
initContainer: StorageComponentContainer.() -> Unit
): ComponentProvider {
return createContainer("TopDownAnalyzerForKonan", NativePlatformAnalyzerServices) {
configureModule(moduleContext, NativePlatforms.unspecifiedNativePlatform, NativePlatformAnalyzerServices, bindingTrace, languageVersionSettings)
configureModule(moduleContext, NativePlatforms.unspecifiedNativePlatform, NativePlatformAnalyzerServices, bindingTrace,
languageVersionSettings,
optimizingOptions = null,
absentDescriptorHandlerClass = BasicAbsentDescriptorHandler::class.java)
useInstance(declarationProviderFactory)
useImpl<AnnotationResolverImpl>()