From 3e99807436689c67c801ac6996c12762358a9fe5 Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Wed, 22 Feb 2023 12:44:46 +0000 Subject: [PATCH] Add ability to provide specific AbsentDescriptorHandler #EA-457188 Merge-request: KT-MR-8900 Merged-by: Vladimir Dolzhenko --- .../kotlin/frontend/java/di/injection.kt | 5 +- .../jvm/JvmResolverForModuleFactory.kt | 8 +- .../kotlin/analyzer/AnalyzerFacade.kt | 32 +- .../ResolverForSingleModuleProject.kt | 3 +- .../common/CommonResolverForModuleFactory.kt | 28 +- .../jetbrains/kotlin/frontend/di/injection.kt | 334 +++++++++++++++++- .../resolve/PlatformConfiguratorBase.kt | 5 +- .../resolve/lazy/AbsentDescriptorHandler.kt | 4 +- .../expressions/LocalClassifierAnalyzer.kt | 3 +- .../jetbrains/kotlin/tests/di/injection.kt | 5 +- .../FakeTopDownAnalyzerFacadeForNative.kt | 4 +- .../MultiModuleJavaAnalysisCustomTest.kt | 3 +- .../types/DefaultModalityModifiersTest.java | 3 +- .../container/PlatformSpecificExtension.kt | 5 + .../kotlin/frontend/js/di/injection.kt | 4 +- .../kotlin/backend/konan/injection.kt | 6 +- 16 files changed, 416 insertions(+), 36 deletions(-) diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/frontend/java/di/injection.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/frontend/java/di/injection.kt index 9e4bd3c9cbd..3bed0294e2e 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/frontend/java/di/injection.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/frontend/java/di/injection.kt @@ -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? = 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) } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/JvmResolverForModuleFactory.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/JvmResolverForModuleFactory.kt index 279f4176aab..25395b945c3 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/JvmResolverForModuleFactory.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/JvmResolverForModuleFactory.kt @@ -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, languageVersionSettings: LanguageVersionSettings, sealedInheritorsProvider: SealedClassInheritorsProvider, - resolveOptimizingOptions: OptimizingOptions? + resolveOptimizingOptions: OptimizingOptions?, + absentDescriptorHandlerClass: Class? ): 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( diff --git a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalyzerFacade.kt b/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalyzerFacade.kt index ddcf9afa848..b08008527ee 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalyzerFacade.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalyzerFacade.kt @@ -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 createResolverForModule( + moduleDescriptor: ModuleDescriptorImpl, + moduleContext: ModuleContext, + moduleContent: ModuleContent, + resolverForProject: ResolverForProject, + languageVersionSettings: LanguageVersionSettings, + sealedInheritorsProvider: SealedClassInheritorsProvider, + resolveOptimizingOptions: OptimizingOptions?, + absentDescriptorHandlerClass: Class? + ): 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 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 createResolverForModule( moduleDescriptor: ModuleDescriptorImpl, @@ -167,7 +194,8 @@ abstract class ResolverForModuleFactory { resolverForProject, languageVersionSettings, sealedInheritorsProvider, - null + resolveOptimizingOptions = null, + absentDescriptorHandlerClass = null ) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/ResolverForSingleModuleProject.kt b/compiler/frontend/src/org/jetbrains/kotlin/analyzer/ResolverForSingleModuleProject.kt index db221ec8ede..e122d679f39 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/ResolverForSingleModuleProject.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/analyzer/ResolverForSingleModuleProject.kt @@ -62,6 +62,7 @@ class ResolverForSingleModuleProject( this, languageVersionSettings, CliSealedClassInheritorsProvider, - null, + resolveOptimizingOptions = null, + absentDescriptorHandlerClass = null ) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/common/CommonResolverForModuleFactory.kt b/compiler/frontend/src/org/jetbrains/kotlin/analyzer/common/CommonResolverForModuleFactory.kt index 431a00a211e..114fad487de 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/common/CommonResolverForModuleFactory.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/analyzer/common/CommonResolverForModuleFactory.kt @@ -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? ): 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? ): StorageComponentContainer = createContainer("ResolveCommonCode", analyzerServices) { - configureModule(moduleContext, platform, analyzerServices, bindingTrace, languageVersionSettings) + configureModule( + moduleContext, + platform, + analyzerServices, + bindingTrace, + languageVersionSettings, + optimizingOptions = null, + absentDescriptorHandlerClass = absentDescriptorHandlerClass + ) useInstance(moduleContentScope) useInstance(declarationProviderFactory) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/frontend/di/injection.kt b/compiler/frontend/src/org/jetbrains/kotlin/frontend/di/injection.kt index b41363b1df8..a88e0e98f46 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/frontend/di/injection.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/frontend/di/injection.kt @@ -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", + 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? ) { 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() useImpl() - useImpl() 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() useImpl() - 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? ): 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) - } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt index 205e40fbd1e..421afef17cc 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt @@ -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.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() { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/AbsentDescriptorHandler.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/AbsentDescriptorHandler.kt index 7b6437cfb25..4d3b588f845 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/AbsentDescriptorHandler.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/AbsentDescriptorHandler.kt @@ -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 { fun diagnoseDescriptorNotFound(declaration: KtDeclaration): DeclarationDescriptor } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/LocalClassifierAnalyzer.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/LocalClassifierAnalyzer.kt index c557e144415..814f5342407 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/LocalClassifierAnalyzer.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/LocalClassifierAnalyzer.kt @@ -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().analyzeDeclarations( diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/tests/di/injection.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/tests/di/injection.kt index 7857063bcbe..1c5cfe0602c 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/tests/di/injection.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/tests/di/injection.kt @@ -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() useInstance(ModuleStructureOracle.SingleModule) diff --git a/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/native/FakeTopDownAnalyzerFacadeForNative.kt b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/native/FakeTopDownAnalyzerFacadeForNative.kt index 00de85dfcf9..981fcb0b380 100644 --- a/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/native/FakeTopDownAnalyzerFacadeForNative.kt +++ b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/native/FakeTopDownAnalyzerFacadeForNative.kt @@ -55,7 +55,9 @@ private fun createFakeTopDownAnalyzerForNative( NativePlatforms.unspecifiedNativePlatform, NativePlatformAnalyzerServices, bindingTrace, - languageVersionSettings + languageVersionSettings, + optimizingOptions = null, + absentDescriptorHandlerClass = null ) configureStandardResolveComponents() diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/MultiModuleJavaAnalysisCustomTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/MultiModuleJavaAnalysisCustomTest.kt index 93ffc805d89..50d0ae9752f 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/MultiModuleJavaAnalysisCustomTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/MultiModuleJavaAnalysisCustomTest.kt @@ -116,7 +116,8 @@ class MultiModuleJavaAnalysisCustomTest : KtUsefulTestCase() { this, LanguageVersionSettingsImpl.DEFAULT, CliSealedClassInheritorsProvider, - null, + resolveOptimizingOptions = null, + absentDescriptorHandlerClass = null ) } diff --git a/compiler/tests/org/jetbrains/kotlin/types/DefaultModalityModifiersTest.java b/compiler/tests/org/jetbrains/kotlin/types/DefaultModalityModifiersTest.java index 9a5aaf57fee..dddf103818a 100644 --- a/compiler/tests/org/jetbrains/kotlin/types/DefaultModalityModifiersTest.java +++ b/compiler/tests/org/jetbrains/kotlin/types/DefaultModalityModifiersTest.java @@ -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); diff --git a/core/util.runtime/src/org/jetbrains/kotlin/container/PlatformSpecificExtension.kt b/core/util.runtime/src/org/jetbrains/kotlin/container/PlatformSpecificExtension.kt index 4777398c48d..ed2177b6d76 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/container/PlatformSpecificExtension.kt +++ b/core/util.runtime/src/org/jetbrains/kotlin/container/PlatformSpecificExtension.kt @@ -48,5 +48,10 @@ abstract class PlatformExtensionsClashResolver> override fun resolveExtensionsClash(extensions: List): E = defaultValue } + + class FirstWins>(applicableTo: Class) : PlatformExtensionsClashResolver(applicableTo) { + + override fun resolveExtensionsClash(extensions: List): E = extensions.first() + } } diff --git a/js/js.frontend/src/org/jetbrains/kotlin/frontend/js/di/injection.kt b/js/js.frontend/src/org/jetbrains/kotlin/frontend/js/di/injection.kt index aa8d563fb7a..d5f6a94c84f 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/frontend/js/di/injection.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/frontend/js/di/injection.kt @@ -58,7 +58,9 @@ fun createContainerForJS( JsPlatforms.defaultJsPlatform, JsPlatformAnalyzerServices, bindingTrace, - languageVersionSettings + languageVersionSettings, + optimizingOptions = null, + absentDescriptorHandlerClass = null ) configureIncrementalCompilation(lookupTracker, expectActualTracker, inlineConstTracker, enumWhenTracker) diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/injection.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/injection.kt index 7842b0e844a..602a24bd62a 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/injection.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/injection.kt @@ -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()