diff --git a/analysis/analysis-api-fir/build.gradle.kts b/analysis/analysis-api-fir/build.gradle.kts index 04a343b1451..f1454c7c668 100644 --- a/analysis/analysis-api-fir/build.gradle.kts +++ b/analysis/analysis-api-fir/build.gradle.kts @@ -9,6 +9,8 @@ dependencies { api(project(":compiler:fir:fir2ir")) api(project(":compiler:ir.tree")) api(project(":compiler:fir:resolve")) + api(project(":compiler:fir:providers")) + api(project(":compiler:fir:semantics")) api(project(":compiler:fir:checkers")) api(project(":compiler:fir:checkers:checkers.jvm")) api(project(":compiler:fir:java")) diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/KtSymbolByFirBuilder.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/KtSymbolByFirBuilder.kt index e175fbb740a..58d231ee104 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/KtSymbolByFirBuilder.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/KtSymbolByFirBuilder.kt @@ -28,8 +28,8 @@ import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.impl.FirFieldImpl import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty import org.jetbrains.kotlin.fir.java.declarations.FirJavaField -import org.jetbrains.kotlin.fir.resolve.calls.originalConstructorIfTypeAlias import org.jetbrains.kotlin.fir.resolve.getSymbolByLookupTag +import org.jetbrains.kotlin.fir.resolve.originalConstructorIfTypeAlias import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirAnalysisSessionComponent.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirAnalysisSessionComponent.kt index 4fa4f0c8d71..12caf876a07 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirAnalysisSessionComponent.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirAnalysisSessionComponent.kt @@ -49,7 +49,7 @@ internal interface KtFirAnalysisSessionComponent { qualifiedAccessSource: FirSourceElement?, diagnosticCache: MutableList ): KtDiagnosticWithPsi<*>? { - val firDiagnostic = toFirDiagnostics(source, qualifiedAccessSource).firstOrNull() ?: return null + val firDiagnostic = toFirDiagnostics(analysisSession.rootModuleSession, source, qualifiedAccessSource).firstOrNull() ?: return null diagnosticCache += firDiagnostic check(firDiagnostic is FirPsiDiagnostic) return firDiagnostic.asKtDiagnostic() diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirCompletionCandidateChecker.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirCompletionCandidateChecker.kt index 3852a7247a8..3a15ee823d8 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirCompletionCandidateChecker.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirCompletionCandidateChecker.kt @@ -26,7 +26,7 @@ import org.jetbrains.kotlin.fir.declarations.FirResolvePhase import org.jetbrains.kotlin.fir.declarations.FirVariable import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.resolve.calls.ImplicitReceiverValue -import org.jetbrains.kotlin.fir.resolve.inference.receiverType +import org.jetbrains.kotlin.fir.types.receiverType import org.jetbrains.kotlin.fir.types.coneType import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.KtFile diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/renderer/ConeTypeIdeRenderer.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/renderer/ConeTypeIdeRenderer.kt index ec23bc466ce..886ae2878db 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/renderer/ConeTypeIdeRenderer.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/renderer/ConeTypeIdeRenderer.kt @@ -16,7 +16,6 @@ import org.jetbrains.kotlin.fir.declarations.utils.isLocal import org.jetbrains.kotlin.fir.expressions.FirAnnotation import org.jetbrains.kotlin.fir.renderWithType import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedError -import org.jetbrains.kotlin.fir.resolve.inference.* import org.jetbrains.kotlin.fir.resolve.toFirRegularClass import org.jetbrains.kotlin.fir.resolve.toSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/scopes/KtFirPackageScope.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/scopes/KtFirPackageScope.kt index 2362a038249..6a8e10a4615 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/scopes/KtFirPackageScope.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/scopes/KtFirPackageScope.kt @@ -6,20 +6,19 @@ package org.jetbrains.kotlin.analysis.api.fir.scopes import com.intellij.openapi.project.Project -import com.intellij.psi.* +import com.intellij.psi.JavaPsiFacade import com.intellij.psi.search.GlobalSearchScope -import org.jetbrains.kotlin.analysis.providers.createDeclarationProvider -import org.jetbrains.kotlin.analysis.providers.createPackageProvider -import org.jetbrains.kotlin.fir.scopes.impl.FirPackageMemberScope -import org.jetbrains.kotlin.analysis.api.tokens.ValidityToken import org.jetbrains.kotlin.analysis.api.fir.KtSymbolByFirBuilder -import org.jetbrains.kotlin.analysis.api.fir.components.KtFirScopeProvider import org.jetbrains.kotlin.analysis.api.scopes.KtPackageScope import org.jetbrains.kotlin.analysis.api.scopes.KtScopeNameFilter import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol import org.jetbrains.kotlin.analysis.api.symbols.KtClassifierSymbol import org.jetbrains.kotlin.analysis.api.symbols.KtPackageSymbol +import org.jetbrains.kotlin.analysis.api.tokens.ValidityToken import org.jetbrains.kotlin.analysis.api.withValidityAssertion +import org.jetbrains.kotlin.analysis.providers.createDeclarationProvider +import org.jetbrains.kotlin.analysis.providers.createPackageProvider +import org.jetbrains.kotlin.fir.scopes.impl.FirPackageMemberScope import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.platform.TargetPlatform diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/KtFirOverrideInfoProvider.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/KtFirOverrideInfoProvider.kt index d33a0b1c6f5..8034894ce00 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/KtFirOverrideInfoProvider.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/KtFirOverrideInfoProvider.kt @@ -5,6 +5,13 @@ package org.jetbrains.kotlin.analysis.api.fir.symbols +import org.jetbrains.kotlin.analysis.api.components.KtOverrideInfoProvider +import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession +import org.jetbrains.kotlin.analysis.api.fir.buildSymbol +import org.jetbrains.kotlin.analysis.api.fir.components.KtFirAnalysisSessionComponent +import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol +import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol +import org.jetbrains.kotlin.analysis.api.tokens.ValidityToken import org.jetbrains.kotlin.fir.analysis.checkers.getImplementationStatus import org.jetbrains.kotlin.fir.analysis.checkers.isVisibleInClass import org.jetbrains.kotlin.fir.containingClass @@ -17,14 +24,6 @@ import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.resolve.SessionHolderImpl import org.jetbrains.kotlin.fir.resolve.toSymbol import org.jetbrains.kotlin.fir.scopes.impl.delegatedWrapperData -import org.jetbrains.kotlin.analysis.api.KtAnalysisSession -import org.jetbrains.kotlin.analysis.api.components.KtOverrideInfoProvider -import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession -import org.jetbrains.kotlin.analysis.api.fir.buildSymbol -import org.jetbrains.kotlin.analysis.api.fir.components.KtFirAnalysisSessionComponent -import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol -import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol -import org.jetbrains.kotlin.analysis.api.tokens.ValidityToken import org.jetbrains.kotlin.util.ImplementationStatus internal class KtFirOverrideInfoProvider( @@ -100,4 +99,4 @@ internal class KtFirOverrideInfoProvider( return member } -} \ No newline at end of file +} diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/types/FirKtType.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/types/FirKtType.kt index 45eee1fc563..babc26ff4e6 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/types/FirKtType.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/types/FirKtType.kt @@ -11,14 +11,13 @@ import org.jetbrains.kotlin.analysis.api.ValidityTokenOwner import org.jetbrains.kotlin.analysis.api.fir.KtSymbolByFirBuilder import org.jetbrains.kotlin.analysis.api.fir.getCandidateSymbols import org.jetbrains.kotlin.analysis.api.fir.utils.cached -import org.jetbrains.kotlin.analysis.api.fir.utils.weakRef import org.jetbrains.kotlin.analysis.api.symbols.KtClassLikeSymbol import org.jetbrains.kotlin.analysis.api.symbols.KtTypeParameterSymbol import org.jetbrains.kotlin.analysis.api.tokens.ValidityToken import org.jetbrains.kotlin.analysis.api.types.* import org.jetbrains.kotlin.analysis.api.withValidityAssertion -import org.jetbrains.kotlin.fir.resolve.inference.isSuspendFunctionType -import org.jetbrains.kotlin.fir.resolve.inference.receiverType +import org.jetbrains.kotlin.fir.types.isSuspendFunctionType +import org.jetbrains.kotlin.fir.types.receiverType import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl @@ -226,4 +225,4 @@ private fun ConeNullability.asKtNullability(): KtTypeNullability = when (this) { ConeNullability.NULLABLE -> KtTypeNullability.NULLABLE ConeNullability.UNKNOWN -> KtTypeNullability.UNKNOWN ConeNullability.NOT_NULL -> KtTypeNullability.NON_NULLABLE -} \ No newline at end of file +} diff --git a/analysis/low-level-api-fir/build.gradle.kts b/analysis/low-level-api-fir/build.gradle.kts index bd9b0408d89..853de24bd5f 100644 --- a/analysis/low-level-api-fir/build.gradle.kts +++ b/analysis/low-level-api-fir/build.gradle.kts @@ -10,6 +10,8 @@ dependencies { api(project(":compiler:fir:fir2ir:jvm-backend")) api(project(":compiler:ir.serialization.common")) api(project(":compiler:fir:resolve")) + api(project(":compiler:fir:providers")) + api(project(":compiler:fir:semantics")) api(project(":compiler:fir:checkers")) api(project(":compiler:fir:checkers:checkers.jvm")) api(project(":compiler:fir:java")) diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/api/LowLevelFirApiFacadeForResolveOnAir.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/api/LowLevelFirApiFacadeForResolveOnAir.kt index 65d4d50b127..70648ce1605 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/api/LowLevelFirApiFacadeForResolveOnAir.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/api/LowLevelFirApiFacadeForResolveOnAir.kt @@ -6,32 +6,16 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir.api import com.intellij.psi.util.PsiTreeUtil -import org.jetbrains.kotlin.fir.FirElement -import org.jetbrains.kotlin.fir.declarations.* -import org.jetbrains.kotlin.fir.expressions.FirAnnotation -import org.jetbrains.kotlin.fir.realPsi -import org.jetbrains.kotlin.fir.resolve.FirTowerDataContext -import org.jetbrains.kotlin.fir.resolve.ScopeSession -import org.jetbrains.kotlin.fir.resolve.asTowerDataElement -import org.jetbrains.kotlin.fir.resolve.transformers.FirTypeResolveTransformer -import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirTowerDataContextCollector -import org.jetbrains.kotlin.fir.scopes.createImportingScopes -import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef -import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid +import org.jetbrains.kotlin.analysis.low.level.api.fir.DeclarationCopyBuilder.withBodyFrom import org.jetbrains.kotlin.analysis.low.level.api.fir.FirModuleResolveStateDepended import org.jetbrains.kotlin.analysis.low.level.api.fir.FirModuleResolveStateImpl -import org.jetbrains.kotlin.analysis.low.level.api.fir.DeclarationCopyBuilder.withBodyFrom import org.jetbrains.kotlin.analysis.low.level.api.fir.element.builder.FileTowerProvider import org.jetbrains.kotlin.analysis.low.level.api.fir.element.builder.FirTowerContextProvider import org.jetbrains.kotlin.analysis.low.level.api.fir.element.builder.FirTowerDataContextAllElementsCollector import org.jetbrains.kotlin.analysis.low.level.api.fir.file.builder.runCustomResolveUnderLock import org.jetbrains.kotlin.analysis.low.level.api.fir.file.structure.FirElementsRecorder import org.jetbrains.kotlin.analysis.low.level.api.fir.file.structure.KtToFirMapping -import org.jetbrains.kotlin.analysis.low.level.api.fir.lazy.resolve.RawFirNonLocalDeclarationBuilder -import org.jetbrains.kotlin.analysis.low.level.api.fir.lazy.resolve.RawFirReplacement -import org.jetbrains.kotlin.analysis.low.level.api.fir.lazy.resolve.ResolveTreeBuilder -import org.jetbrains.kotlin.analysis.low.level.api.fir.lazy.resolve.buildFileFirAnnotation -import org.jetbrains.kotlin.analysis.low.level.api.fir.lazy.resolve.buildFirUserTypeRef +import org.jetbrains.kotlin.analysis.low.level.api.fir.lazy.resolve.* import org.jetbrains.kotlin.analysis.low.level.api.fir.providers.firIdeProvider import org.jetbrains.kotlin.analysis.low.level.api.fir.sessions.FirIdeSourcesSession import org.jetbrains.kotlin.analysis.low.level.api.fir.util.getElementTextInContext @@ -39,6 +23,16 @@ import org.jetbrains.kotlin.analysis.low.level.api.fir.util.originalDeclaration import org.jetbrains.kotlin.analysis.low.level.api.fir.util.parentOfType import org.jetbrains.kotlin.analysis.low.level.api.fir.util.parentsOfType import org.jetbrains.kotlin.analysis.project.structure.getKtModule +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.declarations.* +import org.jetbrains.kotlin.fir.expressions.FirAnnotation +import org.jetbrains.kotlin.fir.realPsi +import org.jetbrains.kotlin.fir.resolve.ScopeSession +import org.jetbrains.kotlin.fir.resolve.transformers.FirTypeResolveTransformer +import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirTowerDataContextCollector +import org.jetbrains.kotlin.fir.scopes.createImportingScopes +import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef +import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject import org.jetbrains.kotlin.psi.psiUtil.isAncestor diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/element/builder/FirTowerDataContextCollector.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/element/builder/FirTowerDataContextCollector.kt index 3126a761cf8..dc0f7a73bc7 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/element/builder/FirTowerDataContextCollector.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/element/builder/FirTowerDataContextCollector.kt @@ -6,13 +6,13 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir.element.builder import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.analysis.low.level.api.fir.util.originalDeclaration import org.jetbrains.kotlin.fir.declarations.FirDeclaration import org.jetbrains.kotlin.fir.declarations.FirFile +import org.jetbrains.kotlin.fir.declarations.FirTowerDataContext import org.jetbrains.kotlin.fir.expressions.FirStatement import org.jetbrains.kotlin.fir.psi -import org.jetbrains.kotlin.fir.resolve.FirTowerDataContext import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirTowerDataContextCollector -import org.jetbrains.kotlin.analysis.low.level.api.fir.util.originalDeclaration import org.jetbrains.kotlin.psi.* interface FirTowerContextProvider { diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/resolver/candidateInfoProviders.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/resolver/candidateInfoProviders.kt index b22c2d4ba0c..07f4b97c6a0 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/resolver/candidateInfoProviders.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/resolver/candidateInfoProviders.kt @@ -9,7 +9,7 @@ import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirFile import org.jetbrains.kotlin.fir.declarations.FirVariable import org.jetbrains.kotlin.fir.resolve.calls.* -import org.jetbrains.kotlin.fir.resolve.inference.receiverType +import org.jetbrains.kotlin.fir.types.receiverType import org.jetbrains.kotlin.fir.types.coneType import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind diff --git a/build.gradle.kts b/build.gradle.kts index 4341e19898a..6f4520da3b2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -202,6 +202,8 @@ val commonCompilerModules = arrayOf( val firCompilerCoreModules = arrayOf( ":compiler:fir:cones", + ":compiler:fir:providers", + ":compiler:fir:semantics", ":compiler:fir:resolve", ":compiler:fir:fir-serialization", ":compiler:fir:fir-deserialization", diff --git a/compiler/cli/build.gradle.kts b/compiler/cli/build.gradle.kts index 202b1021bbc..6f598660291 100644 --- a/compiler/cli/build.gradle.kts +++ b/compiler/cli/build.gradle.kts @@ -25,6 +25,8 @@ dependencies { api(commonDep("org.jline", "jline")) api(project(":compiler:fir:raw-fir:psi2fir")) api(project(":compiler:fir:resolve")) + api(project(":compiler:fir:providers")) + api(project(":compiler:fir:semantics")) api(project(":compiler:fir:java")) implementation(project(":compiler:fir:entrypoint")) api(project(":compiler:fir:fir2ir")) diff --git a/compiler/fir/build.gradle.kts b/compiler/fir/build.gradle.kts index 242849143a9..bbd965459a1 100644 --- a/compiler/fir/build.gradle.kts +++ b/compiler/fir/build.gradle.kts @@ -7,6 +7,8 @@ val projectsAllowedToUseFirFromSymbol = listOf( "java", "jvm", "raw-fir", + "providers", + "semantics", "resolve", "tree", "jvm-backend", diff --git a/compiler/fir/checkers/build.gradle.kts b/compiler/fir/checkers/build.gradle.kts index 62b0429c8f0..ccfd9730bd9 100644 --- a/compiler/fir/checkers/build.gradle.kts +++ b/compiler/fir/checkers/build.gradle.kts @@ -6,7 +6,8 @@ plugins { } dependencies { - api(project(":compiler:fir:resolve")) + api(project(":compiler:fir:providers")) + api(project(":compiler:fir:semantics")) implementation(project(":compiler:frontend.common-psi")) implementation(project(":compiler:psi")) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/FirCheckersResolveProcessor.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/FirCheckersResolveProcessor.kt deleted file mode 100644 index ae5f3142c02..00000000000 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/FirCheckersResolveProcessor.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2010-2020 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.fir.analysis - -import org.jetbrains.kotlin.fir.FirElement -import org.jetbrains.kotlin.fir.FirSession -import org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollector -import org.jetbrains.kotlin.fir.analysis.collectors.FirDiagnosticsCollector -import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporterFactory -import org.jetbrains.kotlin.fir.declarations.FirFile -import org.jetbrains.kotlin.fir.resolve.ScopeSession -import org.jetbrains.kotlin.fir.resolve.transformers.FirTransformerBasedResolveProcessor -import org.jetbrains.kotlin.fir.visitors.FirTransformer - -class FirCheckersResolveProcessor( - session: FirSession, - scopeSession: ScopeSession -) : FirTransformerBasedResolveProcessor(session, scopeSession) { - val diagnosticCollector: AbstractDiagnosticCollector = FirDiagnosticsCollector.create(session, scopeSession) - - override val transformer: FirTransformer = FirCheckersRunnerTransformer(diagnosticCollector) -} - -class FirCheckersRunnerTransformer(private val diagnosticCollector: AbstractDiagnosticCollector) : FirTransformer() { - override fun transformElement(element: E, data: Nothing?): E { - return element - } - - override fun transformFile(file: FirFile, data: Nothing?): FirFile { - val reporter = DiagnosticReporterFactory.createReporter() - diagnosticCollector.collectDiagnostics(file, reporter) - return file - } -} diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/FirCallsEffectAnalyzer.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/FirCallsEffectAnalyzer.kt index f7f6cdacfa3..0d761321d8a 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/FirCallsEffectAnalyzer.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/FirCallsEffectAnalyzer.kt @@ -31,7 +31,7 @@ import org.jetbrains.kotlin.fir.references.FirReference import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference import org.jetbrains.kotlin.fir.references.FirThisReference import org.jetbrains.kotlin.fir.resolve.dfa.cfg.* -import org.jetbrains.kotlin.fir.resolve.inference.isBuiltinFunctionalType +import org.jetbrains.kotlin.fir.types.isBuiltinFunctionalType import org.jetbrains.kotlin.fir.resolve.isInvoke import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/FirReturnsImpliesAnalyzer.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/FirReturnsImpliesAnalyzer.kt index c6a5044b3dd..4369f9b3fee 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/FirReturnsImpliesAnalyzer.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/FirReturnsImpliesAnalyzer.kt @@ -95,6 +95,9 @@ object FirReturnsImpliesAnalyzer : FirControlFlowChecker() { } } + // TODO: create separate variable storage and don't modify existing one + val variableStorage = dataFlowInfo.variableStorage as VariableStorageImpl + var typeStatements: TypeStatements = flow.approvedTypeStatements if (effect.value != ConeConstantReference.WILDCARD) { @@ -104,13 +107,13 @@ object FirReturnsImpliesAnalyzer : FirControlFlowChecker() { if (resultExpression is FirConstExpression<*>) { if (!resultExpression.isApplicableWith(operation)) return false } else { - val resultVar = dataFlowInfo.variableStorage.getOrCreateVariable(flow, resultExpression) + val resultVar = variableStorage.getOrCreateVariable(flow, resultExpression) typeStatements = logicSystem.approveOperationStatement(flow, OperationStatement(resultVar, operation), builtinTypes) } } val conditionStatements = effectDeclaration.condition.buildTypeStatements( - function, logicSystem, dataFlowInfo.variableStorage, flow, context + function, logicSystem, variableStorage, flow, context ) ?: return false for ((realVar, requiredTypeStatement) in conditionStatements) { @@ -153,7 +156,7 @@ object FirReturnsImpliesAnalyzer : FirControlFlowChecker() { private fun ConeBooleanExpression.buildTypeStatements( function: FirFunction, logicSystem: LogicSystem<*>, - variableStorage: VariableStorage, + variableStorage: VariableStorageImpl, flow: Flow, context: CheckerContext ): MutableTypeStatements? { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/util/LocalPropertyAndCapturedWriteCollector.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/util/LocalPropertyAndCapturedWriteCollector.kt index 6a634a9e341..4224c2f0723 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/util/LocalPropertyAndCapturedWriteCollector.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/util/LocalPropertyAndCapturedWriteCollector.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.fir.analysis.cfa.util +import org.jetbrains.kotlin.contracts.description.isInPlace import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction import org.jetbrains.kotlin.fir.declarations.FirFunction import org.jetbrains.kotlin.fir.declarations.utils.referredPropertySymbol diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirConstChecks.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirConstChecks.kt index 68f01c0d9e7..4a18a0bce3a 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirConstChecks.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirConstChecks.kt @@ -8,7 +8,6 @@ package org.jetbrains.kotlin.fir.analysis.checkers import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.fir.FirSession -import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.utils.isConst import org.jetbrains.kotlin.fir.declarations.utils.modality import org.jetbrains.kotlin.fir.expressions.* diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt index 4b63a76e8ba..3298dadf6f0 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt @@ -21,9 +21,11 @@ import org.jetbrains.kotlin.fir.expressions.FirFunctionCall import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment import org.jetbrains.kotlin.fir.expressions.impl.FirEmptyExpressionBlock import org.jetbrains.kotlin.fir.expressions.toResolvedCallableSymbol -import org.jetbrains.kotlin.fir.resolve.* -import org.jetbrains.kotlin.fir.resolve.inference.isBuiltinFunctionalType +import org.jetbrains.kotlin.fir.resolve.SessionHolder +import org.jetbrains.kotlin.fir.resolve.fullyExpandedType import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider +import org.jetbrains.kotlin.fir.resolve.toFirRegularClassSymbol +import org.jetbrains.kotlin.fir.resolve.toSymbol import org.jetbrains.kotlin.fir.scopes.FirTypeScope import org.jetbrains.kotlin.fir.scopes.ProcessorAction import org.jetbrains.kotlin.fir.scopes.impl.multipleDelegatesWithTheSameSignature diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirConflictsChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirConflictsChecker.kt index 07c2ffa1e4d..de1a5317449 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirConflictsChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirConflictsChecker.kt @@ -16,8 +16,8 @@ import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.impl.FirOuterClassTypeParameterRef import org.jetbrains.kotlin.fir.resolve.getContainingDeclaration import org.jetbrains.kotlin.fir.resolve.providers.firProvider -import org.jetbrains.kotlin.fir.scopes.PACKAGE_MEMBER import org.jetbrains.kotlin.fir.scopes.impl.FirPackageMemberScope +import org.jetbrains.kotlin.fir.scopes.impl.PACKAGE_MEMBER import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.SymbolInternals import org.jetbrains.kotlin.fir.symbols.ensureResolved diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInlineClassDeclarationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInlineClassDeclarationChecker.kt index 98af80eb92f..da45c73392b 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInlineClassDeclarationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInlineClassDeclarationChecker.kt @@ -17,7 +17,6 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOnWithSuppression import org.jetbrains.kotlin.fir.analysis.diagnostics.withSuppressedDiagnostics import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.utils.* -import org.jetbrains.kotlin.fir.resolve.calls.isPotentiallyArray import org.jetbrains.kotlin.fir.resolve.fullyExpandedType import org.jetbrains.kotlin.fir.resolve.lookupSuperTypes import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInlineDeclarationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInlineDeclarationChecker.kt index 94b6554426a..b5efd10d619 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInlineDeclarationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInlineDeclarationChecker.kt @@ -22,9 +22,9 @@ import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.utils.* import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.references.FirSuperReference -import org.jetbrains.kotlin.fir.resolve.inference.isBuiltinFunctionalType -import org.jetbrains.kotlin.fir.resolve.inference.isFunctionalType -import org.jetbrains.kotlin.fir.resolve.inference.isSuspendFunctionType +import org.jetbrains.kotlin.fir.types.isBuiltinFunctionalType +import org.jetbrains.kotlin.fir.types.isFunctionalType +import org.jetbrains.kotlin.fir.types.isSuspendFunctionType import org.jetbrains.kotlin.fir.resolve.toSymbol import org.jetbrains.kotlin.fir.resolve.transformers.publishedApiEffectiveVisibility import org.jetbrains.kotlin.fir.scopes.getDirectOverriddenMembers diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirKClassWithIncorrectTypeArgumentChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirKClassWithIncorrectTypeArgumentChecker.kt index 887779f664a..855811ec650 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirKClassWithIncorrectTypeArgumentChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirKClassWithIncorrectTypeArgumentChecker.kt @@ -13,7 +13,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration import org.jetbrains.kotlin.fir.declarations.FirFile import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeTypeParameterInQualifiedAccess -import org.jetbrains.kotlin.fir.resolve.inference.isKClassType +import org.jetbrains.kotlin.fir.types.isKClassType import org.jetbrains.kotlin.fir.scopes.impl.toConeType import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol import org.jetbrains.kotlin.fir.types.* diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirNotImplementedOverrideChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirNotImplementedOverrideChecker.kt index 3a2589337c7..becc0b91a8d 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirNotImplementedOverrideChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirNotImplementedOverrideChecker.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration -import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.fir.FirFakeSourceElementKind diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOuterClassArgumentsRequiredChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOuterClassArgumentsRequiredChecker.kt index fa58f064983..9691079b153 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOuterClassArgumentsRequiredChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOuterClassArgumentsRequiredChecker.kt @@ -6,9 +6,7 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext -import org.jetbrains.kotlin.fir.analysis.checkers.context.findClosest import org.jetbrains.kotlin.fir.analysis.checkers.extractArgumentTypeRefAndSource -import org.jetbrains.kotlin.fir.analysis.checkers.getContainingClassSymbol import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirPropertyTypeParametersChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirPropertyTypeParametersChecker.kt index 4c745aa96fe..1a4ae33d899 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirPropertyTypeParametersChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirPropertyTypeParametersChecker.kt @@ -10,8 +10,10 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn import org.jetbrains.kotlin.fir.declarations.FirProperty -import org.jetbrains.kotlin.fir.scopes.impl.toConeType -import org.jetbrains.kotlin.fir.types.* +import org.jetbrains.kotlin.fir.types.ConeKotlinType +import org.jetbrains.kotlin.fir.types.ConeTypeParameterType +import org.jetbrains.kotlin.fir.types.coneType +import org.jetbrains.kotlin.fir.types.type object FirPropertyTypeParametersChecker : FirPropertyChecker() { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCatchParameterChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCatchParameterChecker.kt index a928abe89c6..f1e3d893973 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCatchParameterChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCatchParameterChecker.kt @@ -12,9 +12,9 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn import org.jetbrains.kotlin.fir.expressions.FirTryExpression -import org.jetbrains.kotlin.fir.resolve.isTypeMismatchDueToNullability import org.jetbrains.kotlin.fir.types.ConeTypeParameterType import org.jetbrains.kotlin.fir.types.coneType +import org.jetbrains.kotlin.fir.types.isTypeMismatchDueToNullability import org.jetbrains.kotlin.fir.types.typeContext object FirCatchParameterChecker : FirTryExpressionChecker() { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirFunctionReturnTypeMismatchChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirFunctionReturnTypeMismatchChecker.kt index 7d99b7cc515..5f2c5196d72 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirFunctionReturnTypeMismatchChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirFunctionReturnTypeMismatchChecker.kt @@ -17,7 +17,6 @@ import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcast import org.jetbrains.kotlin.fir.expressions.FirReturnExpression import org.jetbrains.kotlin.fir.expressions.FirWhenExpression import org.jetbrains.kotlin.fir.expressions.isExhaustive -import org.jetbrains.kotlin.fir.resolve.isTypeMismatchDueToNullability import org.jetbrains.kotlin.fir.types.* object FirFunctionReturnTypeMismatchChecker : FirReturnExpressionChecker() { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirSuspendCallChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirSuspendCallChecker.kt index ae78c998849..e212a0a9271 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirSuspendCallChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirSuspendCallChecker.kt @@ -23,7 +23,7 @@ import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression import org.jetbrains.kotlin.fir.references.FirResolvedCallableReference import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference import org.jetbrains.kotlin.fir.resolve.fullyExpandedType -import org.jetbrains.kotlin.fir.resolve.inference.isSuspendFunctionType +import org.jetbrains.kotlin.fir.types.isSuspendFunctionType import org.jetbrains.kotlin.fir.resolve.toFirRegularClassSymbol import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirUpperBoundViolatedExpressionChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirUpperBoundViolatedExpressionChecker.kt index e2c229885e7..6f0fbd5301d 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirUpperBoundViolatedExpressionChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirUpperBoundViolatedExpressionChecker.kt @@ -13,8 +13,8 @@ import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression import org.jetbrains.kotlin.fir.expressions.toResolvedCallableSymbol import org.jetbrains.kotlin.fir.references.FirErrorNamedReference import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference -import org.jetbrains.kotlin.fir.resolve.calls.isTypeAliasedConstructor import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeInapplicableWrongReceiver +import org.jetbrains.kotlin.fir.resolve.isTypeAliasedConstructor import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/UnusedChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/UnusedChecker.kt index 254b3b604bf..0ba9fa907ee 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/UnusedChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/UnusedChecker.kt @@ -27,7 +27,7 @@ import org.jetbrains.kotlin.fir.expressions.FirFunctionCall import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference import org.jetbrains.kotlin.fir.resolve.dfa.cfg.* -import org.jetbrains.kotlin.fir.resolve.inference.isFunctionalType +import org.jetbrains.kotlin.fir.types.isFunctionalType import org.jetbrains.kotlin.fir.symbols.SymbolInternals import org.jetbrains.kotlin.fir.symbols.ensureResolved import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollectorVisitor.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollectorVisitor.kt index e87a9dc4dd6..ca4438ceb64 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollectorVisitor.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollectorVisitor.kt @@ -11,9 +11,7 @@ import org.jetbrains.kotlin.fir.FirFakeSourceElementKind import org.jetbrains.kotlin.fir.PrivateForInline import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext import org.jetbrains.kotlin.fir.declarations.* -import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor import org.jetbrains.kotlin.fir.expressions.* -import org.jetbrains.kotlin.fir.resolve.collectImplicitReceivers import org.jetbrains.kotlin.fir.resolve.defaultType import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt index abfc5db1c7d..7013b841eb0 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt @@ -127,7 +127,7 @@ class ErrorNodeDiagnosticCollectorComponent( // See FirForLoopChecker return } - for (coneDiagnostic in diagnostic.toFirDiagnostics(source, qualifiedAccessSource)) { + for (coneDiagnostic in diagnostic.toFirDiagnostics(session, source, qualifiedAccessSource)) { reporter.report(coneDiagnostic, context) } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt index 006325b4038..e7d3b8e3223 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.analysis.diagnostics import org.jetbrains.kotlin.KtNodeTypes import org.jetbrains.kotlin.fir.FirFakeSourceElementKind +import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.FirSourceElement import org.jetbrains.kotlin.fir.analysis.checkers.declaration.isLocalMember import org.jetbrains.kotlin.fir.analysis.getChild @@ -20,7 +21,6 @@ import org.jetbrains.kotlin.fir.resolve.inference.ConeTypeVariableForLambdaRetur import org.jetbrains.kotlin.fir.resolve.inference.model.ConeArgumentConstraintPosition import org.jetbrains.kotlin.fir.resolve.inference.model.ConeExpectedTypeConstraintPosition import org.jetbrains.kotlin.fir.resolve.inference.model.ConeLambdaArgumentConstraintPosition -import org.jetbrains.kotlin.fir.resolve.isTypeMismatchDueToNullability import org.jetbrains.kotlin.fir.symbols.impl.FirBackingFieldSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol @@ -63,13 +63,13 @@ private fun ConeDiagnostic.toFirDiagnostic( is ConeAmbiguityError -> when { applicability.isSuccess -> FirErrors.OVERLOAD_RESOLUTION_AMBIGUITY.createOn(source, this.candidates.map { it.symbol }) applicability == CandidateApplicability.UNSAFE_CALL -> { - val candidate = candidates.first { it.currentApplicability == CandidateApplicability.UNSAFE_CALL } + val candidate = candidates.first { it.applicability == CandidateApplicability.UNSAFE_CALL } val unsafeCall = candidate.diagnostics.firstIsInstance() mapUnsafeCallError(candidate, unsafeCall, source, qualifiedAccessSource) } applicability == CandidateApplicability.UNSTABLE_SMARTCAST -> { val unstableSmartcast = - this.candidates.first { it.currentApplicability == CandidateApplicability.UNSTABLE_SMARTCAST }.diagnostics.firstIsInstance() + this.candidates.first { it.applicability == CandidateApplicability.UNSTABLE_SMARTCAST }.diagnostics.firstIsInstance() FirErrors.SMARTCAST_IMPOSSIBLE.createOn( unstableSmartcast.argument.source, unstableSmartcast.targetType, @@ -115,18 +115,19 @@ private fun ConeDiagnostic.toFirDiagnostic( } fun ConeDiagnostic.toFirDiagnostics( + session: FirSession, source: FirSourceElement, qualifiedAccessSource: FirSourceElement? ): List { return when (this) { - is ConeInapplicableCandidateError -> mapInapplicableCandidateError(this, source, qualifiedAccessSource) - is ConeConstraintSystemHasContradiction -> mapSystemHasContradictionError(this, source, qualifiedAccessSource) + is ConeInapplicableCandidateError -> mapInapplicableCandidateError(session, this, source, qualifiedAccessSource) + is ConeConstraintSystemHasContradiction -> mapSystemHasContradictionError(session, this, source, qualifiedAccessSource) else -> listOfNotNull(toFirDiagnostic(source, qualifiedAccessSource)) } } private fun mapUnsafeCallError( - candidate: Candidate, + candidate: AbstractCandidate, rootCause: UnsafeCall, source: FirSourceElement, qualifiedAccessSource: FirSourceElement?, @@ -175,6 +176,7 @@ private fun mapUnsafeCallError( } private fun mapInapplicableCandidateError( + session: FirSession, diagnostic: ConeInapplicableCandidateError, source: FirSourceElement, qualifiedAccessSource: FirSourceElement?, @@ -190,7 +192,7 @@ private fun mapInapplicableCandidateError( rootCause.forbiddenNamedArgumentsTarget ) is ArgumentTypeMismatch -> { - val typeContext = diagnostic.candidate.callInfo.session.typeContext + val typeContext = session.typeContext FirErrors.ARGUMENT_TYPE_MISMATCH.createOn( rootCause.argument.source ?: source, rootCause.expectedType.removeTypeVariableTypes(typeContext), @@ -238,6 +240,7 @@ private fun mapInapplicableCandidateError( @OptIn(ExperimentalStdlibApi::class) private fun mapSystemHasContradictionError( + session: FirSession, diagnostic: ConeConstraintSystemHasContradiction, source: FirSourceElement, qualifiedAccessSource: FirSourceElement?, @@ -249,7 +252,7 @@ private fun mapSystemHasContradictionError( error.toDiagnostic( source, qualifiedAccessSource, - diagnostic.candidate.callInfo.session.typeContext, + session.typeContext, errorsToIgnore, diagnostic.candidate, ) @@ -285,7 +288,7 @@ private fun ConstraintSystemError.toDiagnostic( qualifiedAccessSource: FirSourceElement?, typeContext: ConeTypeContext, errorsToIgnore: MutableSet, - candidate: Candidate, + candidate: AbstractCandidate, ): FirDiagnostic? { return when (this) { is NewConstraintError -> { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/extensions/FirAdditionalCheckersExtension.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/extensions/FirAdditionalCheckersExtension.kt index 32eb31fb60d..5160240b623 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/extensions/FirAdditionalCheckersExtension.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/extensions/FirAdditionalCheckersExtension.kt @@ -9,11 +9,12 @@ import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.analysis.checkers.declaration.DeclarationCheckers import org.jetbrains.kotlin.fir.analysis.checkers.expression.ExpressionCheckers import org.jetbrains.kotlin.fir.analysis.checkers.type.TypeCheckers -import org.jetbrains.kotlin.fir.extensions.AbstractFirAdditionalCheckersExtension +import org.jetbrains.kotlin.fir.extensions.FirExtension import org.jetbrains.kotlin.fir.extensions.FirExtensionPointName import org.jetbrains.kotlin.fir.extensions.FirExtensionService +import kotlin.reflect.KClass -abstract class FirAdditionalCheckersExtension(session: FirSession) : AbstractFirAdditionalCheckersExtension(session) { +abstract class FirAdditionalCheckersExtension(session: FirSession) : FirExtension(session) { companion object { val NAME = FirExtensionPointName("ExtensionCheckers") } @@ -24,8 +25,13 @@ abstract class FirAdditionalCheckersExtension(session: FirSession) : AbstractFir final override val name: FirExtensionPointName get() = NAME + + fun interface Factory : FirExtension.Factory + + final override val extensionType: KClass + get() = FirAdditionalCheckersExtension::class } val FirExtensionService.additionalCheckers: List by FirExtensionService.registeredExtensions( - AbstractFirAdditionalCheckersExtension::class + FirAdditionalCheckersExtension::class ) diff --git a/compiler/fir/cones/build.gradle.kts b/compiler/fir/cones/build.gradle.kts index 694dbcc4ab0..a59f1a83d40 100644 --- a/compiler/fir/cones/build.gradle.kts +++ b/compiler/fir/cones/build.gradle.kts @@ -10,6 +10,7 @@ plugins { dependencies { api(project(":core:compiler.common")) + api(kotlinxCollectionsImmutable()) compileOnly(intellijCoreDep()) { includeJars("intellij-core") } } diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/resolve/substitution/ConeSubstitutor.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/resolve/substitution/ConeSubstitutor.kt index ff54fc50c83..c4ea15d8b80 100644 --- a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/resolve/substitution/ConeSubstitutor.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/resolve/substitution/ConeSubstitutor.kt @@ -26,4 +26,6 @@ abstract class ConeSubstitutor : TypeSubstitutorMarker { fun ConeSubstitutor.substituteOrNull(type: ConeKotlinType?): ConeKotlinType? { return type?.let { substituteOrNull(it) } -} \ No newline at end of file +} + +object NoSubstitutor : TypeSubstitutorMarker diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/util/ChainedIterator.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/util/ChainedIterator.kt similarity index 100% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/util/ChainedIterator.kt rename to compiler/fir/cones/src/org/jetbrains/kotlin/fir/util/ChainedIterator.kt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/Collections.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/util/Collections.kt similarity index 81% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/Collections.kt rename to compiler/fir/cones/src/org/jetbrains/kotlin/fir/util/Collections.kt index e37ff3ce89e..e4829751c8f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/Collections.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/util/Collections.kt @@ -1,9 +1,9 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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.fir +package org.jetbrains.kotlin.fir.util private open class FrozenReversedListReadOnly( private val delegate: List diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/util/Multimap.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/util/Multimap.kt similarity index 100% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/util/Multimap.kt rename to compiler/fir/cones/src/org/jetbrains/kotlin/fir/util/Multimap.kt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/util/PersistentMultimap.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/util/PersistentMultimap.kt similarity index 97% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/util/PersistentMultimap.kt rename to compiler/fir/cones/src/org/jetbrains/kotlin/fir/util/PersistentMultimap.kt index a38ac6bea2e..a97ffee3612 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/util/PersistentMultimap.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/util/PersistentMultimap.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/dump/build.gradle.kts b/compiler/fir/dump/build.gradle.kts index fb1ca3fece5..1f19bfa513a 100644 --- a/compiler/fir/dump/build.gradle.kts +++ b/compiler/fir/dump/build.gradle.kts @@ -13,6 +13,8 @@ dependencies { implementation(project(":core:deserialization")) implementation(project(":compiler:fir:cones")) implementation(project(":compiler:fir:tree")) + implementation(project(":compiler:fir:providers")) + implementation(project(":compiler:fir:semantics")) implementation(project(":compiler:fir:resolve")) implementation(project(":compiler:fir:java")) implementation(project(":compiler:cli")) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/extensions/FirExtensionRegistrar.kt b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/extensions/FirExtensionRegistrar.kt similarity index 90% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/extensions/FirExtensionRegistrar.kt rename to compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/extensions/FirExtensionRegistrar.kt index 2be0e11d75f..66eb9ba0efc 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/extensions/FirExtensionRegistrar.kt +++ b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/extensions/FirExtensionRegistrar.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.extensions import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.SessionConfiguration +import org.jetbrains.kotlin.fir.analysis.extensions.FirAdditionalCheckersExtension import kotlin.reflect.KClass abstract class FirExtensionRegistrar { @@ -14,7 +15,7 @@ abstract class FirExtensionRegistrar { val AVAILABLE_EXTENSIONS = listOf( FirStatusTransformerExtension::class, FirDeclarationGenerationExtension::class, - AbstractFirAdditionalCheckersExtension::class, + FirAdditionalCheckersExtension::class, FirSupertypeGenerationExtension::class, FirTypeAttributeExtension::class, ) @@ -34,10 +35,10 @@ abstract class FirExtensionRegistrar { } @JvmName("plusAdditionalCheckersExtension") - operator fun ((FirSession) -> AbstractFirAdditionalCheckersExtension).unaryPlus() { + operator fun ((FirSession) -> FirAdditionalCheckersExtension).unaryPlus() { registerExtension( - AbstractFirAdditionalCheckersExtension::class, - AbstractFirAdditionalCheckersExtension.Factory { this.invoke(it) } + FirAdditionalCheckersExtension::class, + FirAdditionalCheckersExtension.Factory { this.invoke(it) } ) } diff --git a/compiler/fir/fir-deserialization/build.gradle.kts b/compiler/fir/fir-deserialization/build.gradle.kts index 2054fcdf55a..35d33eed252 100644 --- a/compiler/fir/fir-deserialization/build.gradle.kts +++ b/compiler/fir/fir-deserialization/build.gradle.kts @@ -13,7 +13,8 @@ dependencies { api(project(":compiler:fir:cones")) api(project(":compiler:fir:tree")) - api(project(":compiler:fir:resolve")) + api(project(":compiler:fir:providers")) + api(project(":compiler:fir:semantics")) compileOnly(intellijCoreDep()) { includeJars("intellij-core", rootProject = rootProject) } } diff --git a/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/FirTypeDeserializer.kt b/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/FirTypeDeserializer.kt index e68edfa564d..df2957b3e72 100644 --- a/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/FirTypeDeserializer.kt +++ b/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/FirTypeDeserializer.kt @@ -15,7 +15,6 @@ import org.jetbrains.kotlin.fir.declarations.utils.addDefaultBoundIfNecessary import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind import org.jetbrains.kotlin.fir.resolve.toSymbol -import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.firUnsafe import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTag import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag @@ -194,7 +193,7 @@ class FirTypeDeserializer( attributes: ConeAttributes ): ConeClassLikeType { val result = - when (functionTypeConstructor.toSymbol(moduleData.session)!!.firUnsafe().typeParameters.size - arguments.size) { + when ((functionTypeConstructor.toSymbol(moduleData.session)?.fir as FirTypeParameterRefsOwner).typeParameters.size - arguments.size) { 0 -> createSuspendFunctionTypeForBasicCase(functionTypeConstructor, arguments, isNullable, attributes) 1 -> { val arity = arguments.size - 1 diff --git a/compiler/fir/fir-serialization/build.gradle.kts b/compiler/fir/fir-serialization/build.gradle.kts index 2162407cdc1..0de18093749 100644 --- a/compiler/fir/fir-serialization/build.gradle.kts +++ b/compiler/fir/fir-serialization/build.gradle.kts @@ -11,7 +11,8 @@ dependencies { api(project(":compiler:fir:cones")) api(project(":compiler:fir:tree")) - api(project(":compiler:fir:resolve")) + api(project(":compiler:fir:providers")) + api(project(":compiler:fir:semantics")) compileOnly(intellijCoreDep()) { includeJars("intellij-core", rootProject = rootProject) } } diff --git a/compiler/fir/fir-serialization/src/org/jetbrains/kotlin/fir/serialization/FirElementSerializer.kt b/compiler/fir/fir-serialization/src/org/jetbrains/kotlin/fir/serialization/FirElementSerializer.kt index 47f9f0bbbd1..7957913d371 100644 --- a/compiler/fir/fir-serialization/src/org/jetbrains/kotlin/fir/serialization/FirElementSerializer.kt +++ b/compiler/fir/fir-serialization/src/org/jetbrains/kotlin/fir/serialization/FirElementSerializer.kt @@ -26,9 +26,6 @@ import org.jetbrains.kotlin.fir.expressions.impl.FirEmptyAnnotationArgumentMappi import org.jetbrains.kotlin.fir.extensions.extensionService import org.jetbrains.kotlin.fir.extensions.typeAttributeExtensions import org.jetbrains.kotlin.fir.resolve.* -import org.jetbrains.kotlin.fir.resolve.calls.varargElementType -import org.jetbrains.kotlin.fir.resolve.inference.isSuspendFunctionType -import org.jetbrains.kotlin.fir.resolve.inference.suspendFunctionTypeToFunctionTypeWithContinuation import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider import org.jetbrains.kotlin.fir.scopes.FakeOverrideTypeCalculator import org.jetbrains.kotlin.fir.scopes.processAllFunctions diff --git a/compiler/fir/fir2ir/build.gradle.kts b/compiler/fir/fir2ir/build.gradle.kts index 2e356d45789..47ccc13f64a 100644 --- a/compiler/fir/fir2ir/build.gradle.kts +++ b/compiler/fir/fir2ir/build.gradle.kts @@ -10,6 +10,8 @@ dependencies { compileOnly(project(":core:descriptors.jvm")) compileOnly(project(":compiler:fir:cones")) compileOnly(project(":compiler:fir:resolve")) + compileOnly(project(":compiler:fir:providers")) + compileOnly(project(":compiler:fir:semantics")) compileOnly(project(":compiler:fir:tree")) compileOnly(project(":compiler:ir.tree")) compileOnly(project(":compiler:ir.psi2ir")) diff --git a/compiler/fir/fir2ir/jvm-backend/build.gradle.kts b/compiler/fir/fir2ir/jvm-backend/build.gradle.kts index 3fdfac22ece..94fea1ddedb 100644 --- a/compiler/fir/fir2ir/jvm-backend/build.gradle.kts +++ b/compiler/fir/fir2ir/jvm-backend/build.gradle.kts @@ -8,6 +8,8 @@ dependencies { compileOnly(project(":compiler:backend.common.jvm")) compileOnly(project(":compiler:fir:cones")) compileOnly(project(":compiler:fir:resolve")) + compileOnly(project(":compiler:fir:providers")) + compileOnly(project(":compiler:fir:semantics")) compileOnly(project(":compiler:fir:java")) compileOnly(project(":compiler:fir:tree")) compileOnly(project(":compiler:fir:fir2ir")) diff --git a/compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmSerializerExtension.kt b/compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmSerializerExtension.kt index fc69436bf0c..290f95f2d2c 100644 --- a/compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmSerializerExtension.kt +++ b/compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmSerializerExtension.kt @@ -19,8 +19,8 @@ import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.utils.* import org.jetbrains.kotlin.fir.expressions.FirAnnotation import org.jetbrains.kotlin.fir.render -import org.jetbrains.kotlin.fir.resolve.inference.isBuiltinFunctionalType import org.jetbrains.kotlin.fir.resolve.providers.firProvider +import org.jetbrains.kotlin.fir.types.isBuiltinFunctionalType import org.jetbrains.kotlin.fir.resolve.toFirRegularClassSymbol import org.jetbrains.kotlin.fir.serialization.FirElementSerializer import org.jetbrains.kotlin.fir.serialization.FirSerializerExtension diff --git a/compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmTypeMapper.kt b/compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmTypeMapper.kt index d2b28aacc88..59896b3c163 100644 --- a/compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmTypeMapper.kt +++ b/compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmTypeMapper.kt @@ -19,10 +19,6 @@ import org.jetbrains.kotlin.fir.declarations.utils.isInner import org.jetbrains.kotlin.fir.declarations.utils.isLocal import org.jetbrains.kotlin.fir.resolve.defaultType import org.jetbrains.kotlin.fir.resolve.fullyExpandedType -import org.jetbrains.kotlin.fir.resolve.inference.isFunctionalType -import org.jetbrains.kotlin.fir.resolve.inference.isKClassType -import org.jetbrains.kotlin.fir.resolve.inference.isKFunctionType -import org.jetbrains.kotlin.fir.resolve.inference.isSuspendFunctionType import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider import org.jetbrains.kotlin.fir.resolve.toSymbol import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt index a6f7e6c046b..5bc70d1766c 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt @@ -32,7 +32,6 @@ import org.jetbrains.kotlin.fir.references.FirThisReference import org.jetbrains.kotlin.fir.references.impl.FirPropertyFromParameterResolvedNamedReference import org.jetbrains.kotlin.fir.resolve.* import org.jetbrains.kotlin.fir.resolve.calls.FirSyntheticPropertySymbol -import org.jetbrains.kotlin.fir.resolve.calls.originalConstructorIfTypeAlias import org.jetbrains.kotlin.fir.resolve.providers.FirProvider import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider import org.jetbrains.kotlin.fir.scopes.FirTypeScope diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 83ba4c34d0e..a102e982db7 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -29,7 +29,7 @@ import org.jetbrains.kotlin.fir.lazy.Fir2IrLazyConstructor import org.jetbrains.kotlin.fir.lazy.Fir2IrLazyProperty import org.jetbrains.kotlin.fir.lazy.Fir2IrLazySimpleFunction import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference -import org.jetbrains.kotlin.fir.resolve.inference.isSuspendFunctionType +import org.jetbrains.kotlin.fir.types.isSuspendFunctionType import org.jetbrains.kotlin.fir.resolve.isKFunctionInvoke import org.jetbrains.kotlin.fir.resolve.providers.firProvider import org.jetbrains.kotlin.fir.resolve.toSymbol diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/IrBuiltInsOverFir.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/IrBuiltInsOverFir.kt index 5748d92caa4..d2c553baa6d 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/IrBuiltInsOverFir.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/IrBuiltInsOverFir.kt @@ -1063,7 +1063,7 @@ class IrBuiltInsOverFir( } - private fun findFunctions(packageName: FqName, name: Name) = + private fun findFunctions(packageName: FqName, name: Name): List = components.session.symbolProvider.getTopLevelFunctionSymbols(packageName, name).mapNotNull { firOpSymbol -> components.declarationStorage.getIrFunctionSymbol(firOpSymbol) as? IrSimpleFunctionSymbol } diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt index b98559c848e..79542563f0a 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt @@ -21,10 +21,7 @@ import org.jetbrains.kotlin.fir.references.FirResolvedCallableReference import org.jetbrains.kotlin.fir.render import org.jetbrains.kotlin.fir.resolve.calls.FirFakeArgumentForCallableReference import org.jetbrains.kotlin.fir.resolve.calls.ResolvedCallArgument -import org.jetbrains.kotlin.fir.resolve.inference.* -import org.jetbrains.kotlin.fir.types.ConeClassLikeType -import org.jetbrains.kotlin.fir.types.ConeKotlinType -import org.jetbrains.kotlin.fir.types.coneType +import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.ir.builders.declarations.UNDEFINED_PARAMETER_INDEX import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.IrBlock diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt index 11b45d2ad1e..9659c29254e 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt @@ -26,8 +26,8 @@ import org.jetbrains.kotlin.fir.resolve.FirSamResolverImpl import org.jetbrains.kotlin.fir.resolve.calls.getExpectedType import org.jetbrains.kotlin.fir.resolve.calls.isFunctional import org.jetbrains.kotlin.fir.resolve.fullyExpandedType -import org.jetbrains.kotlin.fir.resolve.inference.isBuiltinFunctionalType -import org.jetbrains.kotlin.fir.resolve.inference.isKMutableProperty +import org.jetbrains.kotlin.fir.types.isBuiltinFunctionalType +import org.jetbrains.kotlin.fir.types.isKMutableProperty import org.jetbrains.kotlin.fir.resolve.substitution.AbstractConeSubstitutor import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutorByMap diff --git a/compiler/fir/java/build.gradle.kts b/compiler/fir/java/build.gradle.kts index 9e3bb174869..a58d2550fc9 100644 --- a/compiler/fir/java/build.gradle.kts +++ b/compiler/fir/java/build.gradle.kts @@ -10,6 +10,7 @@ dependencies { api(project(":compiler:config.jvm")) api(project(":compiler:resolution.common.jvm")) api(project(":compiler:frontend.common")) +// api(project(":compiler:fir:resolve")) api(project(":compiler:fir:resolve")) api(project(":compiler:fir:checkers")) api(project(":compiler:fir:fir-deserialization")) diff --git a/compiler/fir/modularized-tests/build.gradle.kts b/compiler/fir/modularized-tests/build.gradle.kts index de6a0c08a0b..7b9096bd186 100644 --- a/compiler/fir/modularized-tests/build.gradle.kts +++ b/compiler/fir/modularized-tests/build.gradle.kts @@ -35,6 +35,8 @@ dependencies { testRuntimeOnly(project(":core:descriptors.runtime")) testApi(projectTests(":compiler:fir:analysis-tests:legacy-fir-tests")) testApi(project(":compiler:fir:resolve")) + testApi(project(":compiler:fir:providers")) + testApi(project(":compiler:fir:semantics")) testApi(project(":compiler:fir:dump")) val asyncProfilerClasspath = project.findProperty("fir.bench.async.profiler.classpath") as? String diff --git a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/FirResolveModularizedTotalKotlinTest.kt b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/FirResolveModularizedTotalKotlinTest.kt index 660a87d7db5..327b221d458 100644 --- a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/FirResolveModularizedTotalKotlinTest.kt +++ b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/FirResolveModularizedTotalKotlinTest.kt @@ -16,7 +16,9 @@ import org.jetbrains.kotlin.ObsoleteTestInfrastructure import org.jetbrains.kotlin.asJava.finder.JavaElementFinder import org.jetbrains.kotlin.cli.common.toBooleanLenient import org.jetbrains.kotlin.cli.jvm.compiler.* -import org.jetbrains.kotlin.fir.analysis.FirCheckersResolveProcessor +import org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollector +import org.jetbrains.kotlin.fir.analysis.collectors.FirDiagnosticsCollector +import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporterFactory import org.jetbrains.kotlin.fir.builder.PsiHandlingMode import org.jetbrains.kotlin.fir.builder.RawFirBuilder import org.jetbrains.kotlin.fir.declarations.FirFile @@ -25,8 +27,10 @@ import org.jetbrains.kotlin.fir.lightTree.LightTree2Fir import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.resolve.providers.firProvider import org.jetbrains.kotlin.fir.resolve.providers.impl.FirProviderImpl +import org.jetbrains.kotlin.fir.resolve.transformers.FirTransformerBasedResolveProcessor import org.jetbrains.kotlin.fir.resolve.transformers.createAllCompilerResolveProcessors import org.jetbrains.kotlin.fir.scopes.ProcessorAction +import org.jetbrains.kotlin.fir.visitors.FirTransformer import sun.management.ManagementFactoryHelper import java.io.File import java.io.FileOutputStream @@ -315,3 +319,24 @@ class FirResolveModularizedTotalKotlinTest : AbstractModularizedTest() { mxBean.dumpHeap(filePath, true) } } + +class FirCheckersResolveProcessor( + session: FirSession, + scopeSession: ScopeSession +) : FirTransformerBasedResolveProcessor(session, scopeSession) { + val diagnosticCollector: AbstractDiagnosticCollector = FirDiagnosticsCollector.create(session, scopeSession) + + override val transformer: FirTransformer = FirCheckersRunnerTransformer(diagnosticCollector) +} + +class FirCheckersRunnerTransformer(private val diagnosticCollector: AbstractDiagnosticCollector) : FirTransformer() { + override fun transformElement(element: E, data: Nothing?): E { + return element + } + + override fun transformFile(file: FirFile, data: Nothing?): FirFile { + val reporter = DiagnosticReporterFactory.createReporter() + diagnosticCollector.collectDiagnostics(file, reporter) + return file + } +} diff --git a/compiler/fir/providers/build.gradle.kts b/compiler/fir/providers/build.gradle.kts new file mode 100644 index 00000000000..177eb28ba81 --- /dev/null +++ b/compiler/fir/providers/build.gradle.kts @@ -0,0 +1,20 @@ +plugins { + kotlin("jvm") + id("jps-compatible") +} + +dependencies { + api(project(":core:compiler.common")) + api(project(":compiler:resolution.common")) + api(project(":compiler:fir:cones")) + api(project(":compiler:fir:tree")) + implementation(project(":core:util.runtime")) + + compileOnly(project(":kotlin-reflect-api")) + compileOnly(intellijCoreDep()) { includeJars("guava", rootProject = rootProject) } +} + +sourceSets { + "main" { projectDefault() } + "test" { none() } +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/CopyUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/CopyUtils.kt similarity index 96% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/CopyUtils.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/CopyUtils.kt index 12e2deabcee..8f77b730587 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/CopyUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/CopyUtils.kt @@ -1,6 +1,6 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. + * 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.fir @@ -58,7 +58,7 @@ fun FirFunctionCall.copy( return (builder as FirCallBuilder).build() as FirFunctionCall } -internal inline fun FirFunctionCall.copyAsImplicitInvokeCall( +inline fun FirFunctionCall.copyAsImplicitInvokeCall( setupCopy: FirImplicitInvokeCallBuilder.() -> Unit ): FirImplicitInvokeCall { val original = this diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirVisibilityChecker.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/FirVisibilityChecker.kt similarity index 85% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirVisibilityChecker.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/FirVisibilityChecker.kt index 9b6d780bb21..a6d79f134cf 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirVisibilityChecker.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/FirVisibilityChecker.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -12,9 +12,7 @@ import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticPropertyAccessor import org.jetbrains.kotlin.fir.declarations.utils.* import org.jetbrains.kotlin.fir.expressions.FirPropertyAccessExpression -import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment import org.jetbrains.kotlin.fir.references.FirSuperReference -import org.jetbrains.kotlin.fir.resolve.calls.Candidate import org.jetbrains.kotlin.fir.resolve.calls.ExpressionReceiverValue import org.jetbrains.kotlin.fir.resolve.calls.FirSyntheticFunctionSymbol import org.jetbrains.kotlin.fir.resolve.calls.ReceiverValue @@ -32,7 +30,6 @@ import org.jetbrains.kotlin.fir.types.typeContext import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.types.AbstractTypeChecker -import org.jetbrains.kotlin.utils.addToStdlib.safeAs abstract class FirModuleVisibilityChecker : FirSessionComponent { abstract fun isInFriendModule(declaration: T): Boolean where T : FirMemberDeclaration, T : FirDeclaration @@ -62,67 +59,6 @@ abstract class FirVisibilityChecker : FirSessionComponent { } } - private fun FirMemberDeclaration.getBackingFieldIfApplicable(): FirBackingField? { - val field = this.safeAs()?.getExplicitBackingField() - ?: return null - - // This check prevents resolving protected and - // public fields. - if ( - field.visibility == Visibilities.PrivateToThis || - field.visibility == Visibilities.Private || - field.visibility == Visibilities.Internal - ) { - return field - } - - return null - } - - fun isVisible( - declaration: FirMemberDeclaration, - candidate: Candidate - ): Boolean { - if (declaration is FirCallableDeclaration && (declaration.isIntersectionOverride || declaration.isSubstitutionOverride)) { - @Suppress("UNCHECKED_CAST") - return isVisible(declaration.originalIfFakeOverride() as FirMemberDeclaration, candidate) - } - - val callInfo = candidate.callInfo - val useSiteFile = callInfo.containingFile - val containingDeclarations = callInfo.containingDeclarations - val session = callInfo.session - - // We won't resolve into the backing field - // in the first place, if it's not accessible. - if (declaration is FirBackingField) { - return true - } - - val visible = isVisible( - declaration, - session, - useSiteFile, - containingDeclarations, - candidate.dispatchReceiverValue, - candidate.callInfo.callSite is FirVariableAssignment - ) - val backingField = declaration.getBackingFieldIfApplicable() - - if (visible && backingField != null) { - candidate.hasVisibleBackingField = isVisible( - backingField, - session, - useSiteFile, - containingDeclarations, - candidate.dispatchReceiverValue, - candidate.callInfo.callSite is FirVariableAssignment, - ) - } - - return visible - } - fun isVisible( declaration: FirMemberDeclaration, session: FirSession, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/declarations/FirAnnotationUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/FirAnnotationUtils.kt similarity index 99% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/declarations/FirAnnotationUtils.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/FirAnnotationUtils.kt index 0d3a5142088..d145be478ca 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/declarations/FirAnnotationUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/FirAnnotationUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/declarations/GeneratedDeclarationValidation.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/GeneratedDeclarationValidation.kt similarity index 97% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/declarations/GeneratedDeclarationValidation.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/GeneratedDeclarationValidation.kt index 5a0ffdbb106..56a503b3c5a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/declarations/GeneratedDeclarationValidation.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/GeneratedDeclarationValidation.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/declarations/InlineClassesUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/InlineClassesUtils.kt similarity index 100% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/declarations/InlineClassesUtils.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/InlineClassesUtils.kt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/declarations/declarationUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/declarationUtils.kt similarity index 100% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/declarations/declarationUtils.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/declarationUtils.kt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/declarations/deprecationUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/deprecationUtils.kt similarity index 100% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/declarations/deprecationUtils.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/deprecationUtils.kt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/extensions/FirDeclarationGenerationExtension.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/extensions/FirDeclarationGenerationExtension.kt similarity index 97% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/extensions/FirDeclarationGenerationExtension.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/extensions/FirDeclarationGenerationExtension.kt index 829536d12fe..ef50f29b46c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/extensions/FirDeclarationGenerationExtension.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/extensions/FirDeclarationGenerationExtension.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/LookupTagUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/LookupTagUtils.kt new file mode 100644 index 00000000000..fd36ec3137d --- /dev/null +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/LookupTagUtils.kt @@ -0,0 +1,112 @@ +/* + * 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.fir.resolve + +import org.jetbrains.kotlin.builtins.StandardNames +import org.jetbrains.kotlin.fir.FirFakeSourceElementKind +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.declarations.FirRegularClass +import org.jetbrains.kotlin.fir.declarations.FirValueParameter +import org.jetbrains.kotlin.fir.declarations.getAnnotationsByClassId +import org.jetbrains.kotlin.fir.expressions.builder.buildAnnotation +import org.jetbrains.kotlin.fir.expressions.builder.buildAnnotationArgumentMapping +import org.jetbrains.kotlin.fir.expressions.builder.buildConstExpression +import org.jetbrains.kotlin.fir.fakeElement +import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider +import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider +import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag +import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTag +import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTagWithFixedSymbol +import org.jetbrains.kotlin.fir.symbols.impl.* +import org.jetbrains.kotlin.fir.types.* +import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef +import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl +import org.jetbrains.kotlin.fir.utils.WeakPair +import org.jetbrains.kotlin.name.SpecialNames +import org.jetbrains.kotlin.name.StandardClassIds +import org.jetbrains.kotlin.types.ConstantValueKind + +fun ConeClassifierLookupTag.toSymbol(useSiteSession: FirSession): FirClassifierSymbol<*>? = + when (this) { + is ConeClassLikeLookupTag -> toSymbol(useSiteSession) + is ConeClassifierLookupTagWithFixedSymbol -> this.symbol + else -> null + } + +@OptIn(LookupTagInternals::class) +fun ConeClassLikeLookupTag.toSymbol(useSiteSession: FirSession): FirClassLikeSymbol<*>? { + if (this is ConeClassLookupTagWithFixedSymbol) { + return this.symbol + } + val firSymbolProvider = useSiteSession.symbolProvider + (this as? ConeClassLikeLookupTagImpl)?.boundSymbol?.takeIf { it.first === useSiteSession }?.let { return it.second } + + return firSymbolProvider.getClassLikeSymbolByClassId(classId).also { + (this as? ConeClassLikeLookupTagImpl)?.bindSymbolToLookupTag(useSiteSession, it) + } +} + +@OptIn(LookupTagInternals::class) +fun ConeClassLikeLookupTag.toSymbolOrError(useSiteSession: FirSession): FirClassLikeSymbol<*> = + toSymbol(useSiteSession) + ?: error("Class symbol with classId $classId was not found") + +@OptIn(LookupTagInternals::class) +fun ConeClassLikeLookupTag.toFirRegularClassSymbol(session: FirSession): FirRegularClassSymbol? = + session.symbolProvider.getSymbolByLookupTag(this) as? FirRegularClassSymbol + +@OptIn(LookupTagInternals::class) +fun ConeClassLikeLookupTagImpl.bindSymbolToLookupTag(session: FirSession, symbol: FirClassLikeSymbol<*>?) { + boundSymbol = WeakPair(session, symbol) +} + +@LookupTagInternals +fun ConeClassLikeLookupTag.toFirRegularClass(session: FirSession): FirRegularClass? = + session.symbolProvider.getSymbolByLookupTag(this)?.fir as? FirRegularClass + +fun FirSymbolProvider.getSymbolByLookupTag(lookupTag: ConeClassifierLookupTag): FirClassifierSymbol<*>? { + return lookupTag.toSymbol(session) +} + +fun FirSymbolProvider.getSymbolByLookupTag(lookupTag: ConeClassLikeLookupTag): FirClassLikeSymbol<*>? { + return lookupTag.toSymbol(session) +} + +fun ConeKotlinType.withParameterNameAnnotation(valueParameter: FirValueParameter, context: ConeTypeContext): ConeKotlinType { + if (valueParameter.name == SpecialNames.NO_NAME_PROVIDED || valueParameter.name == SpecialNames.UNDERSCORE_FOR_UNUSED_VAR) return this + // Existing @ParameterName annotation takes precedence + if (attributes.customAnnotations.getAnnotationsByClassId(StandardNames.FqNames.parameterNameClassId).isNotEmpty()) return this + + val fakeSource = valueParameter.source?.fakeElement(FirFakeSourceElementKind.ParameterNameAnnotationCall) + val parameterNameAnnotationCall = buildAnnotation { + source = fakeSource + annotationTypeRef = + buildResolvedTypeRef { + source = fakeSource + type = ConeClassLikeTypeImpl( + ConeClassLikeLookupTagImpl(StandardNames.FqNames.parameterNameClassId), + emptyArray(), + isNullable = false + ) + } + argumentMapping = buildAnnotationArgumentMapping { + mapping[StandardClassIds.Annotations.ParameterNames.parameterNameName] = + buildConstExpression(fakeSource, ConstantValueKind.String, valueParameter.name.asString(), setType = true) + } + } + val attributesWithParameterNameAnnotation = + ConeAttributes.create(listOf(CustomAnnotationTypeAttribute(listOf(parameterNameAnnotationCall)))) + return withCombinedCustomAttributesFrom(attributesWithParameterNameAnnotation, context) +} + +fun ConeKotlinType.withCombinedCustomAttributesFrom(other: ConeKotlinType, context: ConeTypeContext): ConeKotlinType = + withCombinedCustomAttributesFrom(other.attributes, context) + +private fun ConeKotlinType.withCombinedCustomAttributesFrom(other: ConeAttributes, context: ConeTypeContext): ConeKotlinType { + val customAttributesFromOther = other.custom ?: return this + val combinedConeAttributes = attributes.add(ConeAttributes.create(listOf(customAttributesFromOther))) + return withAttributes(combinedConeAttributes, context) +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt similarity index 98% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt index ea32284de1d..dfb81f5cc6a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SupertypeUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/SupertypeUtils.kt similarity index 99% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SupertypeUtils.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/SupertypeUtils.kt index d4eb7d96e3a..f08320f8362 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SupertypeUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/SupertypeUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/TypeExpansionUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/TypeExpansionUtils.kt similarity index 99% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/TypeExpansionUtils.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/TypeExpansionUtils.kt index 28976fa2a9d..f8c2f7ed8fa 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/TypeExpansionUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/TypeExpansionUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt similarity index 93% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt index 6f9f9f24302..f1ec4a38a14 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt @@ -1,6 +1,6 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. + * 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.fir.resolve.calls @@ -22,8 +22,11 @@ import org.jetbrains.kotlin.fir.scopes.FirTypeScope import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol -import org.jetbrains.kotlin.fir.types.* +import org.jetbrains.kotlin.fir.types.ConeKotlinErrorType +import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef +import org.jetbrains.kotlin.fir.types.coneType +import org.jetbrains.kotlin.fir.types.coneTypeSafe import org.jetbrains.kotlin.types.SmartcastStability interface Receiver @@ -93,7 +96,7 @@ sealed class ImplicitReceiverValue>( /* * Should be called only in ImplicitReceiverStack */ - internal fun replaceType(type: ConeKotlinType) { + fun replaceType(type: ConeKotlinType) { if (!mutable) throw IllegalStateException("Cannot mutate an immutable ImplicitReceiverValue") if (type == this.type) return this.type = type @@ -127,14 +130,14 @@ private fun receiverExpression(symbol: FirBasedSymbol<*>, type: ConeKotlinType): isImplicit = true } -class ImplicitDispatchReceiverValue internal constructor( +class ImplicitDispatchReceiverValue( boundSymbol: FirClassSymbol<*>, type: ConeKotlinType, useSiteSession: FirSession, scopeSession: ScopeSession, mutable: Boolean = true, ) : ImplicitReceiverValue>(boundSymbol, type, useSiteSession, scopeSession, mutable) { - internal constructor( + constructor( boundSymbol: FirClassSymbol<*>, useSiteSession: FirSession, scopeSession: ScopeSession ) : this( boundSymbol, boundSymbol.constructType(typeArguments = emptyArray(), isNullable = false), diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirSyntheticNamesProvider.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/FirSyntheticNamesProvider.kt similarity index 92% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirSyntheticNamesProvider.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/FirSyntheticNamesProvider.kt index 6320b301cdc..d7f54115c64 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirSyntheticNamesProvider.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/FirSyntheticNamesProvider.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt similarity index 96% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt index 0d04c23701a..e58988e3349 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt @@ -1,6 +1,6 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. + * 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.fir.resolve.calls diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/FirProvider.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/providers/FirProvider.kt similarity index 96% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/FirProvider.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/providers/FirProvider.kt index f8b4540de5d..a8587774726 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/FirProvider.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/providers/FirProvider.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/FirSymbolProvider.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/providers/FirSymbolProvider.kt similarity index 98% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/FirSymbolProvider.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/providers/FirSymbolProvider.kt index 86fb4a04452..74774a8c31d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/FirSymbolProvider.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/providers/FirSymbolProvider.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirCompositeSymbolProvider.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirCompositeSymbolProvider.kt similarity index 100% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirCompositeSymbolProvider.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirCompositeSymbolProvider.kt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirDependenciesSymbolProviderImpl.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirDependenciesSymbolProviderImpl.kt similarity index 98% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirDependenciesSymbolProviderImpl.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirDependenciesSymbolProviderImpl.kt index 8c96edff7ca..a5eed0895e9 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirDependenciesSymbolProviderImpl.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirDependenciesSymbolProviderImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt similarity index 97% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt index 9c83deabd76..e227123c925 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt @@ -1,12 +1,11 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. + * 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.fir.resolve.substitution import org.jetbrains.kotlin.fir.FirSession -import org.jetbrains.kotlin.fir.resolve.inference.inferenceComponents import org.jetbrains.kotlin.fir.resolve.withCombinedCustomAttributesFrom import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol import org.jetbrains.kotlin.fir.types.* diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/PhaseUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/transformers/PhaseUtils.kt similarity index 97% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/PhaseUtils.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/transformers/PhaseUtils.kt index b524815e4dc..aa206f0c538 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/PhaseUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/transformers/PhaseUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/FakeOverrideTypeCalculator.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/FakeOverrideTypeCalculator.kt similarity index 97% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/FakeOverrideTypeCalculator.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/FakeOverrideTypeCalculator.kt index 4ebad2bab99..a1fe50d9bf2 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/FakeOverrideTypeCalculator.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/FakeOverrideTypeCalculator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/FirKotlinScopeProvider.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/FirKotlinScopeProvider.kt similarity index 99% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/FirKotlinScopeProvider.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/FirKotlinScopeProvider.kt index 56c27ad20d6..22073e7b95a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/FirKotlinScopeProvider.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/FirKotlinScopeProvider.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/FirOverrideChecker.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/FirOverrideChecker.kt similarity index 92% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/FirOverrideChecker.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/FirOverrideChecker.kt index d4157324848..29aa64e682c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/FirOverrideChecker.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/FirOverrideChecker.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/FirTypeParameterScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/FirTypeParameterScope.kt similarity index 94% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/FirTypeParameterScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/FirTypeParameterScope.kt index 05644389e51..881c3b4621f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/FirTypeParameterScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/FirTypeParameterScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/Scopes.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/Scopes.kt new file mode 100644 index 00000000000..ee6e99086d2 --- /dev/null +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/Scopes.kt @@ -0,0 +1,17 @@ +/* + * 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.fir.scopes + +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.declarations.FirRegularClass +import org.jetbrains.kotlin.fir.resolve.ScopeSession +import org.jetbrains.kotlin.fir.resolve.toSymbol +import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag + +fun ConeClassLikeLookupTag.getNestedClassifierScope(session: FirSession, scopeSession: ScopeSession): FirContainingNamesAwareScope? { + val klass = toSymbol(session)?.fir as? FirRegularClass ?: return null + return klass.scopeProvider.getNestedClassifierScope(klass, session, scopeSession) +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/AbstractFirOverrideScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/AbstractFirOverrideScope.kt similarity index 93% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/AbstractFirOverrideScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/AbstractFirOverrideScope.kt index ddf00f9e78f..8a89e125e04 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/AbstractFirOverrideScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/AbstractFirOverrideScope.kt @@ -1,6 +1,6 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. + * 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.fir.scopes.impl diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/AbstractFirUseSiteMemberScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/AbstractFirUseSiteMemberScope.kt similarity index 98% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/AbstractFirUseSiteMemberScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/AbstractFirUseSiteMemberScope.kt index 18fad4bf5d1..c54c6b4da9d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/AbstractFirUseSiteMemberScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/AbstractFirUseSiteMemberScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/DefaultImportPriority.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/DefaultImportPriority.kt similarity index 95% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/DefaultImportPriority.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/DefaultImportPriority.kt index ba78e74292c..c0e3880abe3 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/DefaultImportPriority.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/DefaultImportPriority.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -29,4 +29,4 @@ enum class DefaultImportPriority { platformDependentAnalyzerServices: PlatformDependentAnalyzerServices?, languageVersionSettings: LanguageVersionSettings ): List? -} \ No newline at end of file +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractImportingScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractImportingScope.kt similarity index 98% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractImportingScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractImportingScope.kt index 3c82aded7ee..e4bceb157fd 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractImportingScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractImportingScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -32,7 +32,7 @@ enum class FirImportingScopeFilter { if (this == ALL) return true // TODO: also check DeprecationLevel.HIDDEN and required Kotlin version val fir = symbol.fir - if (fir !is FirMemberDeclaration) return false + if (fir !is FirMemberDeclaration) return false val isVisible = when (fir.status.visibility) { // When importing from the same module, status may be unknown because the status resolver depends on super types // to determine visibility for functions, so it may not have finished yet. Since we only care about classes, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractOverrideChecker.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractOverrideChecker.kt similarity index 95% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractOverrideChecker.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractOverrideChecker.kt index 5f829a8748c..082a56b1986 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractOverrideChecker.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractOverrideChecker.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractProviderBasedScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractProviderBasedScope.kt similarity index 93% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractProviderBasedScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractProviderBasedScope.kt index 26ec879403d..42217172525 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractProviderBasedScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractProviderBasedScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractSimpleImportingScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractSimpleImportingScope.kt similarity index 96% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractSimpleImportingScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractSimpleImportingScope.kt index a770f94bb3b..902d199062b 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractSimpleImportingScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractSimpleImportingScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractStarImportingScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractStarImportingScope.kt similarity index 96% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractStarImportingScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractStarImportingScope.kt index 1dcc48d1696..1bdc6ffee17 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractStarImportingScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractStarImportingScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassDeclaredMemberScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassDeclaredMemberScope.kt similarity index 98% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassDeclaredMemberScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassDeclaredMemberScope.kt index ee7293d49a7..91f7a8f16d7 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassDeclaredMemberScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassDeclaredMemberScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt similarity index 99% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt index 9d4282605de..0f40974a9d2 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassUseSiteMemberScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassUseSiteMemberScope.kt similarity index 97% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassUseSiteMemberScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassUseSiteMemberScope.kt index 031c31da969..ac90fcd5bc9 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassUseSiteMemberScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassUseSiteMemberScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDeclaredMemberScopeProvider.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDeclaredMemberScopeProvider.kt similarity index 98% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDeclaredMemberScopeProvider.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDeclaredMemberScopeProvider.kt index c9876620b6a..15af3c97190 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDeclaredMemberScopeProvider.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDeclaredMemberScopeProvider.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDefaultStarImportingScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDefaultStarImportingScope.kt similarity index 97% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDefaultStarImportingScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDefaultStarImportingScope.kt index 52ee5a3c84f..34a2b4e2d7f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDefaultStarImportingScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDefaultStarImportingScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDelegatedMemberScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDelegatedMemberScope.kt similarity index 99% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDelegatedMemberScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDelegatedMemberScope.kt index 5d884cc1c4d..ecb3986c25d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDelegatedMemberScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDelegatedMemberScope.kt @@ -200,7 +200,9 @@ class FirDelegatedMemberScope( private object MultipleDelegatesWithTheSameSignatureKey : FirDeclarationDataKey() -var FirCallableDeclaration.multipleDelegatesWithTheSameSignature: Boolean? by FirDeclarationDataRegistry.data(MultipleDelegatesWithTheSameSignatureKey) +var FirCallableDeclaration.multipleDelegatesWithTheSameSignature: Boolean? by FirDeclarationDataRegistry.data( + MultipleDelegatesWithTheSameSignatureKey +) val FirCallableSymbol<*>.multipleDelegatesWithTheSameSignature: Boolean? get() = fir.multipleDelegatesWithTheSameSignature diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirExplicitSimpleImportingScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirExplicitSimpleImportingScope.kt similarity index 94% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirExplicitSimpleImportingScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirExplicitSimpleImportingScope.kt index b97347a97b0..3d7c8310f59 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirExplicitSimpleImportingScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirExplicitSimpleImportingScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirExplicitStarImportingScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirExplicitStarImportingScope.kt similarity index 93% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirExplicitStarImportingScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirExplicitStarImportingScope.kt index 9f2dac50336..ec03a2178b1 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirExplicitStarImportingScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirExplicitStarImportingScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -21,4 +21,4 @@ class FirExplicitStarImportingScope( override val scopeOwnerLookupNames: List by lazy(LazyThreadSafetyMode.PUBLICATION) { starImports.mapTo(LinkedHashSet()) { it.packageFqName.asString() }.toList() } -} \ No newline at end of file +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirFakeOverrideGenerator.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirFakeOverrideGenerator.kt similarity index 99% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirFakeOverrideGenerator.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirFakeOverrideGenerator.kt index ed647fac8db..58e067174be 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirFakeOverrideGenerator.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirFakeOverrideGenerator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirGeneratedClassDeclaredMemberScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirGeneratedClassDeclaredMemberScope.kt similarity index 97% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirGeneratedClassDeclaredMemberScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirGeneratedClassDeclaredMemberScope.kt index f0c0f75a0e4..b4af62032ee 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirGeneratedClassDeclaredMemberScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirGeneratedClassDeclaredMemberScope.kt @@ -29,7 +29,10 @@ class FirGeneratedClassDeclaredMemberScope( val firClass: FirClass, needNestedClassifierScope: Boolean ) : FirClassDeclaredMemberScope() { - private val extensions: List = firClass.findGeneratedExtensions(useSiteSession) { needToGenerateAdditionalMembersInClass(it) } + private val extensions: List = firClass.findGeneratedExtensions(useSiteSession) { + needToGenerateAdditionalMembersInClass(it) + } + private val nestedClassifierScope: FirNestedClassifierScope? = runIf(needNestedClassifierScope) { useSiteSession.nestedClassifierScope(firClass) } @@ -75,7 +78,7 @@ class FirGeneratedClassDeclaredMemberScope( } else { CallableId(classId.asSingleFqName().parent(), classId.shortClassName) } - return extensions.flatMap { it.generateConstructors(callableId) }.onEach { } + return extensions.flatMap { it.generateConstructors(callableId) }.onEach { it.fir.validate() } } // ------------------------------------------ scope methods ------------------------------------------ diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirGeneratedClassNestedClassifierScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirGeneratedClassNestedClassifierScope.kt new file mode 100644 index 00000000000..cf93bbe5699 --- /dev/null +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirGeneratedClassNestedClassifierScope.kt @@ -0,0 +1,7 @@ +/* + * 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.fir.scopes.impl + diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirIntegerOperatorCall.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirIntegerOperatorCall.kt similarity index 98% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirIntegerOperatorCall.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirIntegerOperatorCall.kt index babd5e199a4..c258dd99e4d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirIntegerOperatorCall.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirIntegerOperatorCall.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirLazyNestedClassifierScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirLazyNestedClassifierScope.kt similarity index 95% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirLazyNestedClassifierScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirLazyNestedClassifierScope.kt index adb2f91332e..02b7718f7ac 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirLazyNestedClassifierScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirLazyNestedClassifierScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirLocalScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirLocalScope.kt similarity index 98% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirLocalScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirLocalScope.kt index e8127aea821..c44e8fd3622 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirLocalScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirLocalScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirMemberTypeParameterScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirMemberTypeParameterScope.kt similarity index 91% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirMemberTypeParameterScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirMemberTypeParameterScope.kt index 4fb94857fb8..c3cc544d66a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirMemberTypeParameterScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirMemberTypeParameterScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirNestedClassifierScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirNestedClassifierScope.kt similarity index 98% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirNestedClassifierScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirNestedClassifierScope.kt index 1a5891e0449..f5e21ebe12c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirNestedClassifierScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirNestedClassifierScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirNestedClassifierScopeWithSubstitution.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirNestedClassifierScopeWithSubstitution.kt similarity index 97% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirNestedClassifierScopeWithSubstitution.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirNestedClassifierScopeWithSubstitution.kt index 606958970d0..1f83b076d60 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirNestedClassifierScopeWithSubstitution.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirNestedClassifierScopeWithSubstitution.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirObjectImportedCallableScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirObjectImportedCallableScope.kt similarity index 98% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirObjectImportedCallableScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirObjectImportedCallableScope.kt index 4eeb39451d6..99919d02fe0 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirObjectImportedCallableScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirObjectImportedCallableScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirOnlyCallablesScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirOnlyCallablesScope.kt similarity index 96% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirOnlyCallablesScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirOnlyCallablesScope.kt index a0f8a8561cb..75da726bd3f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirOnlyCallablesScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirOnlyCallablesScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirOnlyClassifiersScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirOnlyClassifiersScope.kt similarity index 95% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirOnlyClassifiersScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirOnlyClassifiersScope.kt index cb650811c2c..819f6d30eff 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirOnlyClassifiersScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirOnlyClassifiersScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirPackageMemberScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirPackageMemberScope.kt similarity index 93% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirPackageMemberScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirPackageMemberScope.kt index 5ce589d3548..d12c2eab7d0 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirPackageMemberScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirPackageMemberScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.scopes.impl import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider +import org.jetbrains.kotlin.fir.resolve.scopeSessionKey import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.scopes.FirScope import org.jetbrains.kotlin.fir.symbols.impl.FirClassifierSymbol @@ -64,3 +65,5 @@ class FirPackageMemberScope( override val scopeOwnerLookupNames: List = SmartList(fqName.asString()) } + +val PACKAGE_MEMBER = scopeSessionKey() diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirScopeWithFakeOverrideTypeCalculator.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirScopeWithFakeOverrideTypeCalculator.kt similarity index 98% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirScopeWithFakeOverrideTypeCalculator.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirScopeWithFakeOverrideTypeCalculator.kt index b24de633015..5bbe97b1961 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirScopeWithFakeOverrideTypeCalculator.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirScopeWithFakeOverrideTypeCalculator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirStandardOverrideChecker.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirStandardOverrideChecker.kt similarity index 99% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirStandardOverrideChecker.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirStandardOverrideChecker.kt index ef83d3f1697..b969f881e3b 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirStandardOverrideChecker.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirStandardOverrideChecker.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirStaticScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirStaticScope.kt similarity index 96% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirStaticScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirStaticScope.kt index ff2e64ff75e..51c0a998418 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirStaticScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirStaticScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirTypeIntersectionScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirTypeIntersectionScope.kt similarity index 99% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirTypeIntersectionScope.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirTypeIntersectionScope.kt index 30f8cb45a75..0c611d62bc7 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirTypeIntersectionScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirTypeIntersectionScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -110,7 +110,11 @@ class FirTypeIntersectionScope private constructor( val (mostSpecific, scopeForMostSpecific) = selectMostSpecificMember(baseMembersForIntersection) val intersectionOverride = intersectionOverrides.getValue( mostSpecific, - FirIntersectionOverrideStorage.ContextForIntersectionOverrideConstruction(this, extractedOverrides, scopeForMostSpecific) + FirIntersectionOverrideStorage.ContextForIntersectionOverrideConstruction( + this, + extractedOverrides, + scopeForMostSpecific + ) ) overriddenSymbols[intersectionOverride.member] = extractedOverrides @Suppress("UNCHECKED_CAST") diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ArrayUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ArrayUtils.kt similarity index 80% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ArrayUtils.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ArrayUtils.kt index 3772bd706ea..9b5c6ae3d2a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ArrayUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ArrayUtils.kt @@ -1,6 +1,6 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. + * 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.fir.types @@ -43,3 +43,10 @@ fun ConeKotlinType.arrayElementType(): ConeKotlinType? { return null } + +fun ConeKotlinType.varargElementType(): ConeKotlinType { + return this.arrayElementType() ?: this +} + +fun ConeKotlinType?.isPotentiallyArray(): Boolean = + this != null && (this.arrayElementType() != null || this is ConeTypeVariableType) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeFlexibleTypeBoundsChecker.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeFlexibleTypeBoundsChecker.kt similarity index 100% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeFlexibleTypeBoundsChecker.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeFlexibleTypeBoundsChecker.kt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt similarity index 98% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt index f01c12a9b69..58217044a4a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -7,13 +7,11 @@ package org.jetbrains.kotlin.fir.types import org.jetbrains.kotlin.fir.diagnostics.ConeIntermediateDiagnostic import org.jetbrains.kotlin.fir.isPrimitiveNumberOrUnsignedNumberType -import org.jetbrains.kotlin.fir.resolve.calls.NoSubstitutor import org.jetbrains.kotlin.fir.resolve.fullyExpandedType -import org.jetbrains.kotlin.fir.resolve.inference.isBuiltinFunctionalType -import org.jetbrains.kotlin.fir.resolve.inference.isSuspendFunctionType import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor +import org.jetbrains.kotlin.fir.resolve.substitution.NoSubstitutor import org.jetbrains.kotlin.fir.resolve.substitution.createTypeSubstitutorByTypeConstructor import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag @@ -264,7 +262,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo return ConeStubTypeForBuilderInference(typeVariable, ConeNullability.create(typeVariable.defaultType().isMarkedNullable())) } - override fun createStubTypeForTypeVariablesInSubtyping(typeVariable: TypeVariableMarker): StubTypeMarker{ + override fun createStubTypeForTypeVariablesInSubtyping(typeVariable: TypeVariableMarker): StubTypeMarker { require(typeVariable is ConeTypeVariable) { "$typeVariable should subtype of ${ConeTypeVariable::class.qualifiedName}" } return ConeStubTypeForTypeVariableInSubtyping(typeVariable, ConeNullability.create(typeVariable.defaultType().isMarkedNullable())) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeNullabilityChecker.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeNullabilityChecker.kt similarity index 92% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeNullabilityChecker.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeNullabilityChecker.kt index 721f348c764..aa22f463e96 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeNullabilityChecker.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeNullabilityChecker.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeApproximator.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeTypeApproximator.kt similarity index 100% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeApproximator.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeTypeApproximator.kt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt similarity index 99% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt index 27cb9fa76e5..db727f4fa0a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -18,7 +18,6 @@ import org.jetbrains.kotlin.fir.resolve.fullyExpandedType import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap import org.jetbrains.kotlin.fir.resolve.toSymbol -import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.firUnsafe import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag import org.jetbrains.kotlin.fir.symbols.ensureResolved @@ -566,7 +565,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty if (type.argumentsCount() == 0) return LowerIfFlexible require(type is ConeKotlinType) val declaration = when (type) { - is ConeClassLikeType -> type.lookupTag.toSymbol(session)?.firUnsafe() + is ConeClassLikeType -> type.lookupTag.toSymbol(session)?.fir else -> null } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeIntersector.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeTypeIntersector.kt similarity index 98% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeIntersector.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeTypeIntersector.kt index af6609548ca..ab3f348898a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeIntersector.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeTypeIntersector.kt @@ -1,13 +1,11 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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.fir.types import org.jetbrains.kotlin.types.AbstractTypeChecker -import java.util.* -import kotlin.collections.LinkedHashSet object ConeTypeIntersector { fun intersectTypes( @@ -142,6 +140,7 @@ object ConeTypeIntersector { override fun combine(nextType: ConeKotlinType, context: ConeTypeContext): ResultNullability = nextType.resultNullability(context) }, + // example: type parameter without not-null supertype UNKNOWN { override fun combine(nextType: ConeKotlinType, context: ConeTypeContext): ResultNullability = diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypePreparator.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeTypePreparator.kt similarity index 100% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypePreparator.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeTypePreparator.kt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/FirCorrespondingSupertypesCache.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/FirCorrespondingSupertypesCache.kt similarity index 98% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/FirCorrespondingSupertypesCache.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/FirCorrespondingSupertypesCache.kt index 41844972018..aee30707906 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/FirCorrespondingSupertypesCache.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/FirCorrespondingSupertypesCache.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/InferenceUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/InferenceUtils.kt new file mode 100644 index 00000000000..b45f9102b58 --- /dev/null +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/InferenceUtils.kt @@ -0,0 +1,243 @@ +/* + * 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.fir.types + +import org.jetbrains.kotlin.builtins.functions.FunctionClassKind +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction +import org.jetbrains.kotlin.fir.declarations.FirClass +import org.jetbrains.kotlin.fir.originalForSubstitutionOverride +import org.jetbrains.kotlin.fir.resolve.ScopeSession +import org.jetbrains.kotlin.fir.resolve.fullyExpandedType +import org.jetbrains.kotlin.fir.resolve.scope +import org.jetbrains.kotlin.fir.resolve.toSymbol +import org.jetbrains.kotlin.fir.scopes.FakeOverrideTypeCalculator +import org.jetbrains.kotlin.fir.scopes.ProcessorAction +import org.jetbrains.kotlin.fir.scopes.processOverriddenFunctions +import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope +import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag +import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl +import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol +import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol +import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl +import org.jetbrains.kotlin.name.ClassId +import org.jetbrains.kotlin.name.StandardClassIds +import org.jetbrains.kotlin.types.AbstractTypeChecker +import org.jetbrains.kotlin.util.OperatorNameConventions +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.contract + +@OptIn(ExperimentalContracts::class) +private fun ConeKotlinType.classId(session: FirSession): ClassId? { + contract { + returns(true) implies (this@classId is ConeClassLikeType) + } + if (this !is ConeClassLikeType) return null + return fullyExpandedType(session).lookupTag.classId +} + +fun ConeKotlinType.isKMutableProperty(session: FirSession): Boolean { + val classId = classId(session) ?: return false + return classId.packageFqName == StandardClassIds.BASE_REFLECT_PACKAGE && + classId.shortClassName.identifier.startsWith("KMutableProperty") +} + +fun ConeKotlinType.functionClassKind(session: FirSession): FunctionClassKind? { + return classId(session)?.toFunctionClassKind() +} + +private fun ClassId.toFunctionClassKind(): FunctionClassKind? { + return FunctionClassKind.byClassNamePrefix(packageFqName, relativeClassName.asString()) +} + +// Function, SuspendFunction, KFunction, KSuspendFunction +fun ConeKotlinType.isBuiltinFunctionalType(session: FirSession): Boolean { + return functionClassKind(session) != null +} + +// Function, SuspendFunction, KFunction, KSuspendFunction +fun ConeClassLikeLookupTag.isBuiltinFunctionalType(): Boolean { + return classId.toFunctionClassKind() != null +} + +inline fun ConeKotlinType.isFunctionalType(session: FirSession, predicate: (FunctionClassKind) -> Boolean): Boolean { + val kind = functionClassKind(session) ?: return false + return predicate(kind) +} + +// Function +fun ConeKotlinType.isFunctionalType(session: FirSession): Boolean { + return isFunctionalType(session) { it == FunctionClassKind.Function } +} + +// SuspendFunction, KSuspendFunction +fun ConeKotlinType.isSuspendFunctionType(session: FirSession): Boolean { + return isFunctionalType(session) { it.isSuspendType } +} + +// KFunction, KSuspendFunction +fun ConeKotlinType.isKFunctionType(session: FirSession): Boolean { + return isFunctionalType(session) { it.isReflectType } +} + +fun ConeKotlinType.kFunctionTypeToFunctionType(session: FirSession): ConeClassLikeType { + require(this.isKFunctionType(session)) + val kind = + if (isSuspendFunctionType(session)) FunctionClassKind.SuspendFunction + else FunctionClassKind.Function + val functionalTypeId = ClassId(kind.packageFqName, kind.numberedClassName(typeArguments.size - 1)) + return ConeClassLikeTypeImpl(ConeClassLikeLookupTagImpl(functionalTypeId), typeArguments, isNullable = false) +} + +fun ConeKotlinType.suspendFunctionTypeToFunctionType(session: FirSession): ConeClassLikeType { + require(this.isSuspendFunctionType(session)) + val kind = + if (isKFunctionType(session)) FunctionClassKind.KFunction + else FunctionClassKind.Function + val functionalTypeId = ClassId(kind.packageFqName, kind.numberedClassName(typeArguments.size - 1)) + return ConeClassLikeTypeImpl(ConeClassLikeLookupTagImpl(functionalTypeId), typeArguments, isNullable = false, attributes = attributes) +} + +fun ConeKotlinType.suspendFunctionTypeToFunctionTypeWithContinuation(session: FirSession, continuationClassId: ClassId): ConeClassLikeType { + require(this.isSuspendFunctionType(session)) + val kind = + if (isKFunctionType(session)) FunctionClassKind.KFunction + else FunctionClassKind.Function + val functionalTypeId = ClassId(kind.packageFqName, kind.numberedClassName(typeArguments.size)) + return ConeClassLikeTypeImpl( + ConeClassLikeLookupTagImpl(functionalTypeId), + typeArguments = (type.typeArguments.dropLast(1) + ConeClassLikeLookupTagImpl(continuationClassId).constructClassType( + arrayOf(type.typeArguments.last()), + isNullable = false + ) + type.typeArguments.last()).toTypedArray(), + isNullable = false, + attributes = attributes + ) +} + +fun ConeKotlinType.isSubtypeOfFunctionalType(session: FirSession, expectedFunctionalType: ConeClassLikeType): Boolean { + require(expectedFunctionalType.isBuiltinFunctionalType(session)) + return AbstractTypeChecker.isSubtypeOf(session.typeContext, this, expectedFunctionalType.replaceArgumentsWithStarProjections()) +} + +fun ConeKotlinType.findSubtypeOfNonSuspendFunctionalType(session: FirSession, expectedFunctionalType: ConeClassLikeType): ConeKotlinType? { + require(expectedFunctionalType.isBuiltinFunctionalType(session) && !expectedFunctionalType.isSuspendFunctionType(session)) + return when (this) { + is ConeClassLikeType -> { + // Expect the argument type is not a suspend functional type. + if (isSuspendFunctionType(session) || !isSubtypeOfFunctionalType(session, expectedFunctionalType)) + null + else + this + } + is ConeIntersectionType -> { + if (intersectedTypes.any { it.isSuspendFunctionType(session) }) + null + else + intersectedTypes.find { it.findSubtypeOfNonSuspendFunctionalType(session, expectedFunctionalType) != null } + } + is ConeTypeParameterType -> { + val bounds = lookupTag.typeParameterSymbol.fir.bounds.map { it.coneType } + if (bounds.any { it.isSuspendFunctionType(session) }) + null + else + bounds.find { it.findSubtypeOfNonSuspendFunctionalType(session, expectedFunctionalType) != null } + } + else -> null + } +} + +fun ConeClassLikeType.findBaseInvokeSymbol(session: FirSession, scopeSession: ScopeSession): FirNamedFunctionSymbol? { + require(this.isBuiltinFunctionalType(session)) + val functionN = (lookupTag.toSymbol(session)?.fir as? FirClass) ?: return null + var baseInvokeSymbol: FirNamedFunctionSymbol? = null + functionN.unsubstitutedScope( + session, + scopeSession, + withForcedTypeCalculator = false + ).processFunctionsByName(OperatorNameConventions.INVOKE) { functionSymbol -> + baseInvokeSymbol = functionSymbol + return@processFunctionsByName + } + return baseInvokeSymbol +} + +fun ConeKotlinType.findContributedInvokeSymbol( + session: FirSession, + scopeSession: ScopeSession, + expectedFunctionalType: ConeClassLikeType, + shouldCalculateReturnTypesOfFakeOverrides: Boolean +): FirFunctionSymbol<*>? { + val baseInvokeSymbol = expectedFunctionalType.findBaseInvokeSymbol(session, scopeSession) ?: return null + + val fakeOverrideTypeCalculator = if (shouldCalculateReturnTypesOfFakeOverrides) { + FakeOverrideTypeCalculator.Forced + } else { + FakeOverrideTypeCalculator.DoNothing + } + val scope = scope(session, scopeSession, fakeOverrideTypeCalculator) ?: return null + var declaredInvoke: FirNamedFunctionSymbol? = null + scope.processFunctionsByName(OperatorNameConventions.INVOKE) { functionSymbol -> + if (functionSymbol.fir.valueParameters.size == baseInvokeSymbol.fir.valueParameters.size) { + declaredInvoke = functionSymbol + return@processFunctionsByName + } + } + + var overriddenInvoke: FirFunctionSymbol<*>? = null + if (declaredInvoke != null) { + // Make sure the user-contributed or type-substituted invoke we just found above is an override of base invoke. + scope.processOverriddenFunctions(declaredInvoke!!) { functionSymbol -> + if (functionSymbol == baseInvokeSymbol || functionSymbol.originalForSubstitutionOverride == baseInvokeSymbol) { + overriddenInvoke = functionSymbol + ProcessorAction.STOP + } else { + ProcessorAction.NEXT + } + } + } + + return if (overriddenInvoke != null) declaredInvoke else null +} + +fun ConeKotlinType.isKClassType(): Boolean { + return classId == StandardClassIds.KClass +} + +private fun ConeTypeProjection.typeOrDefault(default: ConeKotlinType): ConeKotlinType = + when (this) { + is ConeKotlinTypeProjection -> type + is ConeStarProjection -> default + } + +fun ConeKotlinType.receiverType(session: FirSession): ConeKotlinType? { + if (!isBuiltinFunctionalType(session) || !isExtensionFunctionType(session)) return null + return fullyExpandedType(session).typeArguments.first().typeOrDefault(session.builtinTypes.nothingType.type) +} + +fun ConeKotlinType.returnType(session: FirSession): ConeKotlinType { + require(this is ConeClassLikeType) + return fullyExpandedType(session).typeArguments.last().typeOrDefault(session.builtinTypes.nullableAnyType.type) +} + +fun ConeKotlinType.valueParameterTypesIncludingReceiver(session: FirSession): List { + require(this is ConeClassLikeType) + return fullyExpandedType(session).typeArguments.dropLast(1).map { it.typeOrDefault(session.builtinTypes.nothingType.type) } +} + +val FirAnonymousFunction.returnType: ConeKotlinType? get() = returnTypeRef.coneTypeSafe() +val FirAnonymousFunction.receiverType: ConeKotlinType? get() = receiverTypeRef?.coneTypeSafe() + +fun ConeTypeContext.isTypeMismatchDueToNullability( + actualType: ConeKotlinType, + expectedType: ConeKotlinType +): Boolean { + return actualType.isNullableType() && !expectedType.isNullableType() && AbstractTypeChecker.isSubtypeOf( + this, + actualType, + expectedType.withNullability(ConeNullability.NULLABLE, this) + ) +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeComponents.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeComponents.kt similarity index 100% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeComponents.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeComponents.kt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt similarity index 99% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt rename to compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt index 0cf9dd8f9b1..7d1d9feb4fc 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/build.gradle.kts b/compiler/fir/resolve/build.gradle.kts index 11326ca7eee..7ec8b7922e2 100644 --- a/compiler/fir/resolve/build.gradle.kts +++ b/compiler/fir/resolve/build.gradle.kts @@ -4,11 +4,8 @@ plugins { } dependencies { - api(project(":core:compiler.common")) - api(project(":compiler:resolution.common")) - api(project(":compiler:fir:cones")) - api(project(":compiler:fir:tree")) - api(kotlinxCollectionsImmutable()) + api(project(":compiler:fir:providers")) + api(project(":compiler:fir:semantics")) implementation(project(":core:util.runtime")) compileOnly(project(":kotlin-reflect-api")) @@ -19,13 +16,3 @@ sourceSets { "main" { projectDefault() } "test" { none() } } - -tasks { - val compileKotlin by existing(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class) { - kotlinOptions { - // Workaround for KT-48445. - languageVersion = "1.5" - apiVersion = "1.5" - } - } -} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirOverloadByLambdaReturnTypeResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirOverloadByLambdaReturnTypeResolver.kt index bda41af7db8..7f9287f3149 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirOverloadByLambdaReturnTypeResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirOverloadByLambdaReturnTypeResolver.kt @@ -13,7 +13,7 @@ import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate import org.jetbrains.kotlin.fir.resolve.inference.FirCallCompleter import org.jetbrains.kotlin.fir.resolve.inference.FirInferenceSession import org.jetbrains.kotlin.fir.resolve.inference.ResolvedLambdaAtom -import org.jetbrains.kotlin.fir.resolve.inference.isBuiltinFunctionalType +import org.jetbrains.kotlin.fir.types.isBuiltinFunctionalType import org.jetbrains.kotlin.fir.resolve.initialTypeOfCandidate import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirAbstractBodyResolveTransformer diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/QualifiedNameResolution.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/QualifiedNameResolution.kt index 16b4cf8c48f..e72d9fb4164 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/QualifiedNameResolution.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/QualifiedNameResolution.kt @@ -12,11 +12,11 @@ import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier import org.jetbrains.kotlin.fir.expressions.builder.buildResolvedQualifier import org.jetbrains.kotlin.fir.references.impl.FirSimpleNamedReference import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents +import org.jetbrains.kotlin.fir.resolve.createCurrentScopeList import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeDeprecated import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType import org.jetbrains.kotlin.fir.resolve.typeForQualifier import org.jetbrains.kotlin.fir.scopes.getSingleClassifier -import org.jetbrains.kotlin.fir.scopes.impl.createCurrentScopeList import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol import org.jetbrains.kotlin.fir.types.FirTypeProjection diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/extensions/AbstractFirAdditionalCheckersExtension.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/extensions/AbstractFirAdditionalCheckersExtension.kt deleted file mode 100644 index d587b82a590..00000000000 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/extensions/AbstractFirAdditionalCheckersExtension.kt +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2010-2020 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.fir.extensions - -import org.jetbrains.kotlin.fir.FirSession -import kotlin.reflect.KClass - -abstract class AbstractFirAdditionalCheckersExtension(session: FirSession) : FirExtension(session) { - fun interface Factory : FirExtension.Factory - - final override val extensionType: KClass - get() = AbstractFirAdditionalCheckersExtension::class -} \ No newline at end of file diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/BodyResolveComponents.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/BodyResolveComponents.kt index 2fbc7ad04a7..c981b49d909 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/BodyResolveComponents.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/BodyResolveComponents.kt @@ -5,17 +5,11 @@ package org.jetbrains.kotlin.fir.resolve -import kotlinx.collections.immutable.PersistentList -import kotlinx.collections.immutable.persistentListOf -import kotlinx.collections.immutable.toPersistentList import org.jetbrains.kotlin.fir.FirCallResolver import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess import org.jetbrains.kotlin.fir.resolve.FirTowerDataMode.* -import org.jetbrains.kotlin.fir.resolve.calls.ImplicitDispatchReceiverValue -import org.jetbrains.kotlin.fir.resolve.calls.ImplicitExtensionReceiverValue -import org.jetbrains.kotlin.fir.resolve.calls.ImplicitReceiverValue import org.jetbrains.kotlin.fir.resolve.calls.ResolutionStageRunner import org.jetbrains.kotlin.fir.resolve.dfa.FirDataFlowAnalyzer import org.jetbrains.kotlin.fir.resolve.inference.FirCallCompleter @@ -24,19 +18,10 @@ import org.jetbrains.kotlin.fir.resolve.transformers.FirSyntheticCallGenerator import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator import org.jetbrains.kotlin.fir.scopes.FirScope import org.jetbrains.kotlin.fir.scopes.impl.FirLocalScope -import org.jetbrains.kotlin.fir.scopes.impl.wrapNestedClassifierScopeWithSubstitutionForSuperType import org.jetbrains.kotlin.fir.symbols.impl.FirAnonymousFunctionSymbol -import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.FirTypeRef -import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.utils.addIfNotNull import java.util.* -interface SessionHolder { - val session: FirSession - val scopeSession: ScopeSession -} - data class SessionHolderImpl(override val session: FirSession, override val scopeSession: ScopeSession) : SessionHolder { companion object { fun createWithEmptyScopeSession(session: FirSession): SessionHolderImpl = SessionHolderImpl(session, ScopeSession()) @@ -65,99 +50,6 @@ abstract class BodyResolveComponents : SessionHolder { abstract val outerClassManager: FirOuterClassManager } -typealias FirLocalScopes = PersistentList - -class FirTowerDataContext private constructor( - val towerDataElements: PersistentList, - // These properties are effectively redundant, their content should be consistent with `towerDataElements`, - // i.e. implicitReceiverStack == towerDataElements.mapNotNull { it.receiver } - // i.e. localScopes == towerDataElements.mapNotNull { it.scope?.takeIf { it.isLocal } } - val implicitReceiverStack: PersistentImplicitReceiverStack, - val localScopes: FirLocalScopes, - val nonLocalTowerDataElements: PersistentList -) { - - constructor() : this( - persistentListOf(), - PersistentImplicitReceiverStack(), - persistentListOf(), - persistentListOf() - ) - - fun setLastLocalScope(newLastScope: FirLocalScope): FirTowerDataContext { - val oldLastScope = localScopes.last() - val indexOfLastLocalScope = towerDataElements.indexOfLast { it.scope === oldLastScope } - - return FirTowerDataContext( - towerDataElements.set(indexOfLastLocalScope, newLastScope.asTowerDataElement(isLocal = true)), - implicitReceiverStack, - localScopes.set(localScopes.lastIndex, newLastScope), - nonLocalTowerDataElements - ) - } - - fun addNonLocalTowerDataElements(newElements: List): FirTowerDataContext { - return FirTowerDataContext( - towerDataElements.addAll(newElements), - implicitReceiverStack.addAll(newElements.mapNotNull { it.implicitReceiver }), - localScopes, - nonLocalTowerDataElements.addAll(newElements) - ) - } - - fun addLocalScope(localScope: FirLocalScope): FirTowerDataContext { - return FirTowerDataContext( - towerDataElements.add(localScope.asTowerDataElement(isLocal = true)), - implicitReceiverStack, - localScopes.add(localScope), - nonLocalTowerDataElements - ) - } - - fun addReceiver(name: Name?, implicitReceiverValue: ImplicitReceiverValue<*>): FirTowerDataContext { - val element = implicitReceiverValue.asTowerDataElement() - return FirTowerDataContext( - towerDataElements.add(element), - implicitReceiverStack.add(name, implicitReceiverValue), - localScopes, - nonLocalTowerDataElements.add(element) - ) - } - - fun addNonLocalScopeIfNotNull(scope: FirScope?): FirTowerDataContext { - if (scope == null) return this - return addNonLocalScope(scope) - } - - private fun addNonLocalScope(scope: FirScope): FirTowerDataContext { - val element = scope.asTowerDataElement(isLocal = false) - return FirTowerDataContext( - towerDataElements.add(element), - implicitReceiverStack, - localScopes, - nonLocalTowerDataElements.add(element) - ) - } - - fun createSnapshot(): FirTowerDataContext { - return FirTowerDataContext( - towerDataElements.map { FirTowerDataElement(it.scope, it.implicitReceiver?.createSnapshot(), it.isLocal) }.toPersistentList(), - implicitReceiverStack.createSnapshot(), - localScopes.toPersistentList(), - nonLocalTowerDataElements.map { FirTowerDataElement(it.scope, it.implicitReceiver?.createSnapshot(), it.isLocal) } - .toPersistentList() - ) - } -} - -class FirTowerDataElement(val scope: FirScope?, val implicitReceiver: ImplicitReceiverValue<*>?, val isLocal: Boolean) - -fun ImplicitReceiverValue<*>.asTowerDataElement(): FirTowerDataElement = - FirTowerDataElement(scope = null, this, isLocal = false) - -fun FirScope.asTowerDataElement(isLocal: Boolean): FirTowerDataElement = - FirTowerDataElement(this, implicitReceiver = null, isLocal) - enum class FirTowerDataMode { MEMBER_DECLARATION, NESTED_CLASS, @@ -218,91 +110,6 @@ class FirTowerDataContextsForClassParts( // --------------------------------------- Utils --------------------------------------- -data class ImplicitReceivers( - val implicitReceiverValue: ImplicitReceiverValue<*>?, - val implicitCompanionValues: List> -) -fun SessionHolder.collectImplicitReceivers( - type: ConeKotlinType?, - owner: FirDeclaration -): ImplicitReceivers { - if (type == null) return ImplicitReceivers(null, emptyList()) - - val implicitCompanionValues = mutableListOf>() - val implicitReceiverValue = when (owner) { - is FirClass -> { - val towerElementsForClass = collectTowerDataElementsForClass(owner, type) - implicitCompanionValues.addAll(towerElementsForClass.implicitCompanionValues) - - towerElementsForClass.thisReceiver - } - is FirFunction -> { - ImplicitExtensionReceiverValue(owner.symbol, type, session, scopeSession) - } - is FirVariable -> { - ImplicitExtensionReceiverValue(owner.symbol, type, session, scopeSession) - } - else -> { - throw IllegalArgumentException("Incorrect label & receiver owner: ${owner.javaClass}") - } - } - return ImplicitReceivers(implicitReceiverValue, implicitCompanionValues) -} - -fun SessionHolder.collectTowerDataElementsForClass(owner: FirClass, defaultType: ConeKotlinType): TowerElementsForClass { - val allImplicitCompanionValues = mutableListOf>() - - val companionObject = (owner as? FirRegularClass)?.companionObject - val companionReceiver = companionObject?.let { companion -> - ImplicitDispatchReceiverValue( - companion.symbol, session, scopeSession - ) - } - allImplicitCompanionValues.addIfNotNull(companionReceiver) - - val superClassesStaticsAndCompanionReceivers = mutableListOf() - for (superType in lookupSuperTypes(owner, lookupInterfaces = false, deep = true, useSiteSession = session)) { - val expandedType = superType.fullyExpandedType(session) - val superClass = expandedType.lookupTag.toSymbol(session)?.fir as? FirRegularClass ?: continue - - superClass.staticScope(this) - ?.wrapNestedClassifierScopeWithSubstitutionForSuperType(expandedType, session) - ?.asTowerDataElement(isLocal = false) - ?.let(superClassesStaticsAndCompanionReceivers::add) - - (superClass as? FirRegularClass)?.companionObject?.let { companion -> - val superCompanionReceiver = ImplicitDispatchReceiverValue( - companion.symbol, session, scopeSession - ) - - superClassesStaticsAndCompanionReceivers += superCompanionReceiver.asTowerDataElement() - allImplicitCompanionValues += superCompanionReceiver - } - } - - val thisReceiver = ImplicitDispatchReceiverValue(owner.symbol, defaultType, session, scopeSession) - - return TowerElementsForClass( - thisReceiver, - owner.staticScope(this), - companionReceiver, - companionObject?.staticScope(this), - superClassesStaticsAndCompanionReceivers.asReversed(), - allImplicitCompanionValues.asReversed() - ) -} - -private fun FirClass.staticScope(sessionHolder: SessionHolder) = - scopeProvider.getStaticScope(this, sessionHolder.session, sessionHolder.scopeSession) - -class TowerElementsForClass( - val thisReceiver: ImplicitReceiverValue<*>, - val staticScope: FirScope?, - val companionReceiver: ImplicitReceiverValue<*>?, - val companionStaticScope: FirScope?, - // Ordered from inner scopes to outer scopes. - val superClassesStaticsAndCompanionReceivers: List, - // Ordered from inner scopes to outer scopes. - val implicitCompanionValues: List> -) +fun BodyResolveComponents.createCurrentScopeList(): List = + towerDataElements.asReversed().mapNotNull { it.scope } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/LookupTagUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/LookupTagUtils.kt deleted file mode 100644 index 38a19067d2b..00000000000 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/LookupTagUtils.kt +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2010-2020 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.fir.resolve - -import org.jetbrains.kotlin.fir.FirSession -import org.jetbrains.kotlin.fir.declarations.FirRegularClass -import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider -import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider -import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag -import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTag -import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTagWithFixedSymbol -import org.jetbrains.kotlin.fir.symbols.impl.* -import org.jetbrains.kotlin.fir.utils.WeakPair - -fun ConeClassifierLookupTag.toSymbol(useSiteSession: FirSession): FirClassifierSymbol<*>? = - when (this) { - is ConeClassLikeLookupTag -> toSymbol(useSiteSession) - is ConeClassifierLookupTagWithFixedSymbol -> this.symbol - else -> null - } - -@OptIn(LookupTagInternals::class) -fun ConeClassLikeLookupTag.toSymbol(useSiteSession: FirSession): FirClassLikeSymbol<*>? { - if (this is ConeClassLookupTagWithFixedSymbol) { - return this.symbol - } - val firSymbolProvider = useSiteSession.symbolProvider - (this as? ConeClassLikeLookupTagImpl)?.boundSymbol?.takeIf { it.first === useSiteSession }?.let { return it.second } - - return firSymbolProvider.getClassLikeSymbolByClassId(classId).also { - (this as? ConeClassLikeLookupTagImpl)?.bindSymbolToLookupTag(useSiteSession, it) - } -} - -@OptIn(LookupTagInternals::class) -fun ConeClassLikeLookupTag.toSymbolOrError(useSiteSession: FirSession): FirClassLikeSymbol<*> = - toSymbol(useSiteSession) - ?: error("Class symbol with classId $classId was not found") - -@OptIn(LookupTagInternals::class) -fun ConeClassLikeLookupTag.toFirRegularClassSymbol(session: FirSession): FirRegularClassSymbol? = - session.symbolProvider.getSymbolByLookupTag(this) as? FirRegularClassSymbol - -@OptIn(LookupTagInternals::class) -fun ConeClassLikeLookupTagImpl.bindSymbolToLookupTag(session: FirSession, symbol: FirClassLikeSymbol<*>?) { - boundSymbol = WeakPair(session, symbol) -} - -@LookupTagInternals -fun ConeClassLikeLookupTag.toFirRegularClass(session: FirSession): FirRegularClass? = - session.symbolProvider.getSymbolByLookupTag(this)?.fir as? FirRegularClass - -fun FirSymbolProvider.getSymbolByLookupTag(lookupTag: ConeClassifierLookupTag): FirClassifierSymbol<*>? { - return lookupTag.toSymbol(session) -} - -fun FirSymbolProvider.getSymbolByLookupTag(lookupTag: ConeClassLikeLookupTag): FirClassLikeSymbol<*>? { - return lookupTag.toSymbol(session) -} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt index b69502bca7e..6cc37494591 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt @@ -5,13 +5,15 @@ package org.jetbrains.kotlin.fir.resolve -import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.builtins.functions.FunctionClassKind import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.declarations.* -import org.jetbrains.kotlin.fir.declarations.utils.* +import org.jetbrains.kotlin.fir.declarations.utils.canNarrowDownGetterType +import org.jetbrains.kotlin.fir.declarations.utils.expandedConeType +import org.jetbrains.kotlin.fir.declarations.utils.isFinal +import org.jetbrains.kotlin.fir.declarations.utils.isInner import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic @@ -27,11 +29,8 @@ import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate import org.jetbrains.kotlin.fir.resolve.calls.FirPropertyWithExplicitBackingFieldResolvedNamedReference import org.jetbrains.kotlin.fir.resolve.calls.ImplicitDispatchReceiverValue import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedNameError -import org.jetbrains.kotlin.fir.resolve.inference.isBuiltinFunctionalType -import org.jetbrains.kotlin.fir.resolve.providers.getSymbolByTypeRef import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType -import org.jetbrains.kotlin.fir.resolve.transformers.firClassLike import org.jetbrains.kotlin.fir.scopes.impl.delegatedWrapperData import org.jetbrains.kotlin.fir.scopes.impl.importedFromObjectData import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol @@ -41,52 +40,16 @@ import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl -import org.jetbrains.kotlin.name.* +import org.jetbrains.kotlin.name.ClassId +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.name.StandardClassIds import org.jetbrains.kotlin.resolve.ForbiddenNamedArgumentsTarget -import org.jetbrains.kotlin.types.AbstractTypeChecker -import org.jetbrains.kotlin.types.ConstantValueKind import org.jetbrains.kotlin.types.SmartcastStability import org.jetbrains.kotlin.utils.addToStdlib.safeAs fun List.toTypeProjections(): Array = asReversed().flatMap { it.typeArgumentList.typeArguments.map { typeArgument -> typeArgument.toConeTypeProjection() } }.toTypedArray() -fun ConeKotlinType.withParameterNameAnnotation(valueParameter: FirValueParameter, context: ConeTypeContext): ConeKotlinType { - if (valueParameter.name == SpecialNames.NO_NAME_PROVIDED || valueParameter.name == SpecialNames.UNDERSCORE_FOR_UNUSED_VAR) return this - // Existing @ParameterName annotation takes precedence - if (attributes.customAnnotations.getAnnotationsByClassId(StandardNames.FqNames.parameterNameClassId).isNotEmpty()) return this - - val fakeSource = valueParameter.source?.fakeElement(FirFakeSourceElementKind.ParameterNameAnnotationCall) - val parameterNameAnnotationCall = buildAnnotation { - source = fakeSource - annotationTypeRef = - buildResolvedTypeRef { - source = fakeSource - type = ConeClassLikeTypeImpl( - ConeClassLikeLookupTagImpl(StandardNames.FqNames.parameterNameClassId), - emptyArray(), - isNullable = false - ) - } - argumentMapping = buildAnnotationArgumentMapping { - mapping[StandardClassIds.Annotations.ParameterNames.parameterNameName] = - buildConstExpression(fakeSource, ConstantValueKind.String, valueParameter.name.asString(), setType = true) - } - } - val attributesWithParameterNameAnnotation = - ConeAttributes.create(listOf(CustomAnnotationTypeAttribute(listOf(parameterNameAnnotationCall)))) - return withCombinedCustomAttributesFrom(attributesWithParameterNameAnnotation, context) -} - -fun ConeKotlinType.withCombinedCustomAttributesFrom(other: ConeKotlinType, context: ConeTypeContext): ConeKotlinType = - withCombinedCustomAttributesFrom(other.attributes, context) - -private fun ConeKotlinType.withCombinedCustomAttributesFrom(other: ConeAttributes, context: ConeTypeContext): ConeKotlinType { - val customAttributesFromOther = other.custom ?: return this - val combinedConeAttributes = attributes.add(ConeAttributes.create(listOf(customAttributesFromOther))) - return withAttributes(combinedConeAttributes, context) -} - fun FirFunction.constructFunctionalType(isSuspend: Boolean = false): ConeLookupTagBasedType { val receiverTypeRef = when (this) { is FirSimpleFunction -> receiverTypeRef @@ -378,33 +341,6 @@ fun BodyResolveComponents.transformQualifiedAccessUsingSmartcastInfo( } } -fun CallableId.isInvoke(): Boolean = - isKFunctionInvoke() - || callableName.asString() == "invoke" - && className?.asString()?.startsWith("Function") == true - && packageName == StandardClassIds.BASE_KOTLIN_PACKAGE - -fun CallableId.isKFunctionInvoke(): Boolean = - callableName.asString() == "invoke" - && className?.asString()?.startsWith("KFunction") == true - && packageName.asString() == "kotlin.reflect" - -fun CallableId.isIteratorNext(): Boolean = - callableName.asString() == "next" && className?.asString()?.endsWith("Iterator") == true - && packageName.asString() == "kotlin.collections" - -fun CallableId.isIteratorHasNext(): Boolean = - callableName.asString() == "hasNext" && className?.asString()?.endsWith("Iterator") == true - && packageName.asString() == "kotlin.collections" - -fun CallableId.isIterator(): Boolean = - callableName.asString() == "iterator" && packageName.asString() in arrayOf("kotlin.collections", "kotlin.ranges") - -fun FirAnnotation.fqName(session: FirSession): FqName? { - val symbol = session.symbolProvider.getSymbolByTypeRef(annotationTypeRef) ?: return null - return symbol.classId.asSingleFqName() -} - fun FirCheckedSafeCallSubject.propagateTypeFromOriginalReceiver(nullableReceiverExpression: FirExpression, session: FirSession) { // If the receiver expression is smartcast to `null`, it would have `Nothing?` as its type, which may not have members called by user // code. Hence, we fallback to the type before intersecting with `Nothing?`. @@ -528,32 +464,7 @@ fun FirFunction.getAsForbiddenNamedArgumentsTarget(session: FirSession): Forbidd // org.jetbrains.kotlin.fir.serialization.FirElementSerializer.constructorProto fun FirFunction.getHasStableParameterNames(session: FirSession): Boolean = getAsForbiddenNamedArgumentsTarget(session) == null -fun isValidTypeParameterFromOuterClass( - typeParameterSymbol: FirTypeParameterSymbol, - classDeclaration: FirRegularClass?, - session: FirSession -): Boolean { - if (classDeclaration == null) { - return true // Extra check is required because of classDeclaration will be resolved later - } - fun containsTypeParameter(currentClassDeclaration: FirRegularClass): Boolean { - if (currentClassDeclaration.typeParameters.any { it.symbol == typeParameterSymbol }) { - return true - } - - for (superTypeRef in currentClassDeclaration.superTypeRefs) { - val superClassFir = superTypeRef.firClassLike(session) - if (superClassFir == null || superClassFir is FirRegularClass && containsTypeParameter(superClassFir)) { - return true - } - } - - return false - } - - return containsTypeParameter(classDeclaration) -} fun FirRegularClass.getActualTypeParametersCount(session: FirSession): Int { var result = typeParameters.size @@ -569,31 +480,3 @@ fun FirRegularClass.getActualTypeParametersCount(session: FirSession): Int { return result } - -fun FirClassLikeDeclaration.getContainingDeclaration(session: FirSession): FirClassLikeDeclaration? { - if (isLocal) { - @OptIn(LookupTagInternals::class) - return (this as? FirRegularClass)?.containingClassForLocalAttr?.toFirRegularClass(session) - } else { - val classId = symbol.classId - val parentId = classId.relativeClassName.parent() - if (!parentId.isRoot) { - val containingDeclarationId = ClassId(classId.packageFqName, parentId, false) - return session.symbolProvider.getClassLikeSymbolByClassId(containingDeclarationId)?.fir - } - } - - return null -} - -fun ConeTypeContext.isTypeMismatchDueToNullability( - actualType: ConeKotlinType, - expectedType: ConeKotlinType -): Boolean { - return actualType.isNullableType() && !expectedType.isNullableType() && AbstractTypeChecker.isSubtypeOf( - this, - actualType, - expectedType.withNullability(ConeNullability.NULLABLE, this) - ) -} - diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt index 95d69e33a9d..17078da42cc 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt @@ -16,7 +16,6 @@ import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.resolve.createFunctionalType import org.jetbrains.kotlin.fir.resolve.fullyExpandedType import org.jetbrains.kotlin.fir.resolve.inference.* -import org.jetbrains.kotlin.fir.resolve.isTypeMismatchDueToNullability import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType import org.jetbrains.kotlin.fir.resolve.transformers.ensureResolvedTypeDeclaration import org.jetbrains.kotlin.fir.returnExpressions @@ -582,10 +581,6 @@ fun FirExpression.getExpectedType( } } -fun ConeKotlinType.varargElementType(): ConeKotlinType { - return this.arrayElementType() ?: this -} - /** * interface Inv * fun bar(l: Inv): Y = ... diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallInfo.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallInfo.kt new file mode 100644 index 00000000000..cb8444628cb --- /dev/null +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallInfo.kt @@ -0,0 +1,62 @@ +/* + * 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.fir.resolve.calls + +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.declarations.FirDeclaration +import org.jetbrains.kotlin.fir.declarations.FirFile +import org.jetbrains.kotlin.fir.expressions.FirArgumentList +import org.jetbrains.kotlin.fir.expressions.FirEmptyArgumentList +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirFunctionCallOrigin +import org.jetbrains.kotlin.fir.expressions.builder.buildArgumentList +import org.jetbrains.kotlin.fir.resolve.DoubleColonLHS +import org.jetbrains.kotlin.fir.types.ConeKotlinType +import org.jetbrains.kotlin.fir.types.FirTypeProjection +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder + +data class CallInfo( + override val callSite: FirElement, + val callKind: CallKind, + override val name: Name, + + override val explicitReceiver: FirExpression?, + override val argumentList: FirArgumentList, + override val isImplicitInvoke: Boolean, + + val typeArguments: List, + val session: FirSession, + override val containingFile: FirFile, + val containingDeclarations: List, + + val candidateForCommonInvokeReceiver: Candidate? = null, + + // Four properties for callable references only + val expectedType: ConeKotlinType? = null, + val outerCSBuilder: ConstraintSystemBuilder? = null, + val lhs: DoubleColonLHS? = null, + val origin: FirFunctionCallOrigin = FirFunctionCallOrigin.Regular, +) : AbstractCallInfo() { + val arguments: List get() = argumentList.arguments + + val argumentCount get() = arguments.size + + fun replaceWithVariableAccess(): CallInfo = + copy(callKind = CallKind.VariableAccess, typeArguments = emptyList(), argumentList = FirEmptyArgumentList) + + fun replaceExplicitReceiver(explicitReceiver: FirExpression?): CallInfo = + copy(explicitReceiver = explicitReceiver) + + fun withReceiverAsArgument(receiverExpression: FirExpression): CallInfo = + copy( + argumentList = buildArgumentList { + arguments += receiverExpression + arguments += argumentList.arguments + } + ) +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallableReferenceResolution.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallableReferenceResolution.kt index 3be9fcd0162..cbceabf9266 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallableReferenceResolution.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallableReferenceResolution.kt @@ -18,7 +18,7 @@ import org.jetbrains.kotlin.fir.resolve.DoubleColonLHS import org.jetbrains.kotlin.fir.resolve.createFunctionalType import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnsupportedCallableReferenceTarget import org.jetbrains.kotlin.fir.resolve.inference.extractInputOutputTypesFromCallableReferenceExpectedType -import org.jetbrains.kotlin.fir.resolve.inference.isSuspendFunctionType +import org.jetbrains.kotlin.fir.types.isSuspendFunctionType import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.visitors.FirTransformer @@ -256,9 +256,6 @@ private fun BodyResolveComponents.getCallableReferenceAdaptation( ) } -fun ConeKotlinType?.isPotentiallyArray(): Boolean = - this != null && (this.arrayElementType() != null || this is ConeTypeVariableType) - private fun varargParameterTypeByExpectedParameter( expectedParameterType: ConeKotlinType, substitutedParameter: FirValueParameter, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Candidate.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Candidate.kt index 72a734c7c2d..d2b52795da1 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Candidate.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Candidate.kt @@ -5,19 +5,10 @@ package org.jetbrains.kotlin.fir.resolve.calls -import org.jetbrains.kotlin.fir.FirElement -import org.jetbrains.kotlin.fir.FirSession -import org.jetbrains.kotlin.fir.declarations.FirDeclaration -import org.jetbrains.kotlin.fir.declarations.FirFile import org.jetbrains.kotlin.fir.declarations.FirValueParameter -import org.jetbrains.kotlin.fir.expressions.FirArgumentList -import org.jetbrains.kotlin.fir.expressions.FirEmptyArgumentList import org.jetbrains.kotlin.fir.expressions.FirExpression -import org.jetbrains.kotlin.fir.expressions.FirFunctionCallOrigin -import org.jetbrains.kotlin.fir.expressions.builder.buildArgumentList import org.jetbrains.kotlin.fir.expressions.impl.FirExpressionStub import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression -import org.jetbrains.kotlin.fir.resolve.DoubleColonLHS import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents import org.jetbrains.kotlin.fir.resolve.inference.PostponedResolvedAtom import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor @@ -25,10 +16,7 @@ import org.jetbrains.kotlin.fir.scopes.FirScope import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.ConeTypeVariable -import org.jetbrains.kotlin.fir.types.FirTypeProjection -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.calls.components.SuspendConversionStrategy -import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl @@ -36,61 +24,20 @@ import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability import org.jetbrains.kotlin.resolve.calls.tower.isSuccess -data class CallInfo( - val callSite: FirElement, - val callKind: CallKind, - val name: Name, - - val explicitReceiver: FirExpression?, - val argumentList: FirArgumentList, - val isImplicitInvoke: Boolean, - - val typeArguments: List, - val session: FirSession, - val containingFile: FirFile, - val containingDeclarations: List, - - val candidateForCommonInvokeReceiver: Candidate? = null, - - // Four properties for callable references only - val expectedType: ConeKotlinType? = null, - val outerCSBuilder: ConstraintSystemBuilder? = null, - val lhs: DoubleColonLHS? = null, - val origin: FirFunctionCallOrigin = FirFunctionCallOrigin.Regular, -) { - val arguments: List get() = argumentList.arguments - - val argumentCount get() = arguments.size - - fun replaceWithVariableAccess(): CallInfo = - copy(callKind = CallKind.VariableAccess, typeArguments = emptyList(), argumentList = FirEmptyArgumentList) - - fun replaceExplicitReceiver(explicitReceiver: FirExpression?): CallInfo = - copy(explicitReceiver = explicitReceiver) - - fun withReceiverAsArgument(receiverExpression: FirExpression): CallInfo = - copy( - argumentList = buildArgumentList { - arguments += receiverExpression - arguments += argumentList.arguments - } - ) -} - class Candidate( - val symbol: FirBasedSymbol<*>, - val dispatchReceiverValue: ReceiverValue?, - val extensionReceiverValue: ReceiverValue?, - val explicitReceiverKind: ExplicitReceiverKind, + override val symbol: FirBasedSymbol<*>, + override val dispatchReceiverValue: ReceiverValue?, + override val extensionReceiverValue: ReceiverValue?, + override val explicitReceiverKind: ExplicitReceiverKind, val constraintSystemFactory: InferenceComponents.ConstraintSystemFactory, private val baseSystem: ConstraintStorage, - val callInfo: CallInfo, + override val callInfo: CallInfo, val originScope: FirScope?, val isFromCompanionObjectTypeScope: Boolean = false -) { +) : AbstractCandidate() { var systemInitialized: Boolean = false - val system: NewConstraintSystemImpl by lazy(LazyThreadSafetyMode.NONE) { + override val system: NewConstraintSystemImpl by lazy(LazyThreadSafetyMode.NONE) { val system = constraintSystemFactory.createConstraintSystem() system.addOtherSystem(baseSystem) systemInitialized = true @@ -122,8 +69,11 @@ class Candidate( var currentApplicability = CandidateApplicability.RESOLVED private set + override val applicability: CandidateApplicability + get() = currentApplicability + private val _diagnostics: MutableList = mutableListOf() - val diagnostics: List + override val diagnostics: List get() = _diagnostics fun addDiagnostic(diagnostic: ResolutionDiagnostic) { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeOverloadConflictResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeOverloadConflictResolver.kt index 05eda341f13..0d385ee8c4a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeOverloadConflictResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeOverloadConflictResolver.kt @@ -195,8 +195,6 @@ class ConeOverloadConflictResolver( } } -object NoSubstitutor : TypeSubstitutorMarker - class ConeSimpleConstraintSystemImpl(val system: NewConstraintSystemImpl, val session: FirSession) : SimpleConstraintSystem { override fun registerTypeVariables(typeParameters: Collection): TypeSubstitutorMarker = with(context) { val csBuilder = system.getBuilder() diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConstructorProcessing.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConstructorProcessing.kt index 5c34b391bcc..7e9af153a52 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConstructorProcessing.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConstructorProcessing.kt @@ -12,12 +12,9 @@ import org.jetbrains.kotlin.fir.declarations.builder.buildConstructedClassTypePa import org.jetbrains.kotlin.fir.declarations.builder.buildConstructorCopy import org.jetbrains.kotlin.fir.declarations.utils.classId import org.jetbrains.kotlin.fir.declarations.utils.isInner -import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents -import org.jetbrains.kotlin.fir.resolve.fullyExpandedType -import org.jetbrains.kotlin.fir.resolve.scope +import org.jetbrains.kotlin.fir.resolve.* import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap -import org.jetbrains.kotlin.fir.resolve.toSymbol import org.jetbrains.kotlin.fir.symbols.ensureResolved import org.jetbrains.kotlin.fir.scopes.FakeOverrideTypeCalculator import org.jetbrains.kotlin.fir.scopes.FirScope @@ -256,10 +253,3 @@ private class TypeAliasConstructorsSubstitutingScope( } } } - -private object TypeAliasConstructorKey : FirDeclarationDataKey() - -var FirConstructor.originalConstructorIfTypeAlias: FirConstructor? by FirDeclarationDataRegistry.data(TypeAliasConstructorKey) - -val FirConstructorSymbol.isTypeAliasedConstructor: Boolean - get() = fir.originalConstructorIfTypeAlias != null diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionContext.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionContext.kt index 923c78558bd..1a1a3fdb383 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionContext.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionContext.kt @@ -11,12 +11,17 @@ import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents import org.jetbrains.kotlin.fir.resolve.inference.inferenceComponents import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.BodyResolveContext +import org.jetbrains.kotlin.fir.types.ConeInferenceContext +import org.jetbrains.kotlin.fir.types.typeContext class ResolutionContext( val session: FirSession, val bodyResolveComponents: BodyResolveComponents, val bodyResolveContext: BodyResolveContext ) { + val typeContext: ConeInferenceContext + get() = session.typeContext + val inferenceComponents: InferenceComponents get() = session.inferenceComponents diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt index af67621332d..45d9b5f56f7 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt @@ -15,7 +15,6 @@ import org.jetbrains.kotlin.fir.references.FirSuperReference import org.jetbrains.kotlin.fir.resolve.directExpansionType import org.jetbrains.kotlin.fir.resolve.fullyExpandedType import org.jetbrains.kotlin.fir.resolve.inference.* -import org.jetbrains.kotlin.fir.resolve.isTypeMismatchDueToNullability import org.jetbrains.kotlin.fir.resolve.toSymbol import org.jetbrains.kotlin.fir.scopes.FirTypeScope import org.jetbrains.kotlin.fir.scopes.FirUnstableSmartcastTypeScope diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/VisibilityUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/VisibilityUtils.kt new file mode 100644 index 00000000000..2dcf16b7bc1 --- /dev/null +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/VisibilityUtils.kt @@ -0,0 +1,79 @@ +/* + * 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.fir.resolve.calls + +import org.jetbrains.kotlin.descriptors.Visibilities +import org.jetbrains.kotlin.fir.FirVisibilityChecker +import org.jetbrains.kotlin.fir.declarations.FirBackingField +import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration +import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration +import org.jetbrains.kotlin.fir.declarations.FirProperty +import org.jetbrains.kotlin.fir.declarations.utils.getExplicitBackingField +import org.jetbrains.kotlin.fir.declarations.utils.visibility +import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment +import org.jetbrains.kotlin.fir.isIntersectionOverride +import org.jetbrains.kotlin.fir.isSubstitutionOverride +import org.jetbrains.kotlin.fir.originalIfFakeOverride + +fun FirVisibilityChecker.isVisible( + declaration: FirMemberDeclaration, + candidate: Candidate +): Boolean { + if (declaration is FirCallableDeclaration && (declaration.isIntersectionOverride || declaration.isSubstitutionOverride)) { + @Suppress("UNCHECKED_CAST") + return isVisible(declaration.originalIfFakeOverride() as FirMemberDeclaration, candidate) + } + + val callInfo = candidate.callInfo + val useSiteFile = callInfo.containingFile + val containingDeclarations = callInfo.containingDeclarations + val session = callInfo.session + + // We won't resolve into the backing field + // in the first place, if it's not accessible. + if (declaration is FirBackingField) { + return true + } + + val visible = isVisible( + declaration, + session, + useSiteFile, + containingDeclarations, + candidate.dispatchReceiverValue, + candidate.callInfo.callSite is FirVariableAssignment + ) + val backingField = declaration.getBackingFieldIfApplicable() + + if (visible && backingField != null) { + candidate.hasVisibleBackingField = isVisible( + backingField, + session, + useSiteFile, + containingDeclarations, + candidate.dispatchReceiverValue, + candidate.callInfo.callSite is FirVariableAssignment, + ) + } + + return visible +} + +private fun FirMemberDeclaration.getBackingFieldIfApplicable(): FirBackingField? { + val field = (this as? FirProperty)?.getExplicitBackingField() ?: return null + + // This check prevents resolving protected and + // public fields. + if ( + field.visibility == Visibilities.PrivateToThis || + field.visibility == Visibilities.Private || + field.visibility == Visibilities.Internal + ) { + return field + } + + return null +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolveTask.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolveTask.kt index 532da362698..64fef96ba8c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolveTask.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolveTask.kt @@ -5,14 +5,14 @@ package org.jetbrains.kotlin.fir.resolve.calls.tower -import org.jetbrains.kotlin.fir.asReversedFrozen +import org.jetbrains.kotlin.fir.util.asReversedFrozen +import org.jetbrains.kotlin.fir.declarations.FirTowerDataContext import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier import org.jetbrains.kotlin.fir.expressions.builder.buildExpressionStub import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents import org.jetbrains.kotlin.fir.resolve.DoubleColonLHS -import org.jetbrains.kotlin.fir.resolve.FirTowerDataContext import org.jetbrains.kotlin.fir.resolve.calls.* import org.jetbrains.kotlin.fir.scopes.FirScope import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef @@ -105,7 +105,7 @@ internal abstract class FirBaseTowerResolveTask( for ((depth, lexical) in towerDataElementsForName.nonLocalTowerDataElements.withIndex()) { if (!lexical.isLocal && lexical.scope != null) { - onScope(lexical.scope, parentGroup.NonLocal(depth)) + onScope(lexical.scope!!, parentGroup.NonLocal(depth)) } val receiver = lexical.implicitReceiver diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/Condition.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/Condition.kt deleted file mode 100644 index eb9faef3fbe..00000000000 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/Condition.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2010-2019 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.fir.resolve.dfa - -enum class Operation { - EqTrue, EqFalse, EqNull, NotEqNull; - - fun invert(): Operation = when (this) { - EqTrue -> EqFalse - EqFalse -> EqTrue - EqNull -> NotEqNull - NotEqNull -> EqNull - } - - override fun toString(): String = when (this) { - EqTrue -> "== True" - EqFalse -> "== False" - EqNull -> "== Null" - NotEqNull -> "!= Null" - } -} \ No newline at end of file diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt index 843e9294e4a..92d72790d5f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt @@ -37,9 +37,6 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.visibilityChecker import org.jetbrains.kotlin.fir.visitors.transformSingle -import org.jetbrains.kotlin.name.CallableId -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.StandardClassIds import org.jetbrains.kotlin.types.ConstantValueKind import org.jetbrains.kotlin.utils.addIfNotNull @@ -47,7 +44,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull class DataFlowAnalyzerContext( val graphBuilder: ControlFlowGraphBuilder, - variableStorage: VariableStorage, + variableStorage: VariableStorageImpl, flowOnNodes: MutableMap, FLOW>, val variablesForWhenConditions: MutableMap, val preliminaryLoopVisitor: PreliminaryLoopVisitor @@ -79,7 +76,7 @@ class DataFlowAnalyzerContext( companion object { fun empty(session: FirSession): DataFlowAnalyzerContext = DataFlowAnalyzerContext( - ControlFlowGraphBuilder(), VariableStorage(session), + ControlFlowGraphBuilder(), VariableStorageImpl(session), mutableMapOf(), mutableMapOf(), PreliminaryLoopVisitor() ) } @@ -91,8 +88,6 @@ abstract class FirDataFlowAnalyzer( private val context: DataFlowAnalyzerContext ) { companion object { - internal val KOTLIN_BOOLEAN_NOT = CallableId(FqName("kotlin"), FqName("Boolean"), Name.identifier("not")) - fun createFirDataFlowAnalyzer( components: FirAbstractBodyResolveTransformer.BodyResolveTransformerComponents, dataFlowAnalyzerContext: DataFlowAnalyzerContext diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt index 6ad2a95cd97..77cd7aba698 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt @@ -6,9 +6,9 @@ package org.jetbrains.kotlin.fir.resolve.dfa.cfg import org.jetbrains.kotlin.contracts.description.EventOccurrencesRange +import org.jetbrains.kotlin.contracts.description.isInPlace import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.declarations.* -import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyBackingField import org.jetbrains.kotlin.fir.declarations.utils.hasExplicitBackingField import org.jetbrains.kotlin.fir.declarations.utils.isLocal import org.jetbrains.kotlin.fir.expressions.* @@ -29,6 +29,7 @@ import kotlin.random.Random @RequiresOptIn private annotation class CfgBuilderInternals +@OptIn(CfgInternals::class) class ControlFlowGraphBuilder { @CfgBuilderInternals private val graphs: Stack = stackOf(ControlFlowGraph(null, "", ControlFlowGraph.Kind.TopLevel)) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphNodeBuilder.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphNodeBuilder.kt index 34eb5e6c0db..0e39fc41e4c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphNodeBuilder.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphNodeBuilder.kt @@ -64,11 +64,13 @@ fun ControlFlowGraphBuilder.createFieldInitializerExitNode(fir: FirField): Field fun ControlFlowGraphBuilder.createFieldInitializerEnterNode(fir: FirField): FieldInitializerEnterNode = FieldInitializerEnterNode(currentGraph, fir, levelCounter, createId()) +@OptIn(CfgInternals::class) fun ControlFlowGraphBuilder.createFunctionEnterNode(fir: FirFunction): FunctionEnterNode = FunctionEnterNode(currentGraph, fir, levelCounter, createId()).also { currentGraph.enterNode = it } +@OptIn(CfgInternals::class) fun ControlFlowGraphBuilder.createFunctionExitNode(fir: FirFunction): FunctionExitNode = FunctionExitNode(currentGraph, fir, levelCounter, createId()).also { currentGraph.exitNode = it diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/model.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/model.kt deleted file mode 100644 index 5b0435fc1bb..00000000000 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/model.kt +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright 2010-2020 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.fir.resolve.dfa - -import org.jetbrains.kotlin.fir.FirElement -import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier -import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol -import org.jetbrains.kotlin.fir.types.ConeClassErrorType -import org.jetbrains.kotlin.fir.types.ConeKotlinType -import org.jetbrains.kotlin.types.SmartcastStability -import kotlin.contracts.ExperimentalContracts -import kotlin.contracts.contract - -// --------------------------------------- Variables --------------------------------------- - -data class Identifier( - val symbol: FirBasedSymbol<*>, - val dispatchReceiver: DataFlowVariable?, - val extensionReceiver: DataFlowVariable? -) { - override fun toString(): String { - val callableId = (symbol as? FirCallableSymbol<*>)?.callableId - return "[$callableId, dispatchReceiver = $dispatchReceiver, extensionReceiver = $extensionReceiver]" - } -} - -sealed class DataFlowVariable(private val variableIndexForDebug: Int) { - final override fun toString(): String { - return "d$variableIndexForDebug" - } -} - -enum class PropertyStability(val impliedSmartcastStability: SmartcastStability?) { - // Immutable and no custom getter or local. - // Smartcast is definitely safe regardless of usage. - STABLE_VALUE(SmartcastStability.STABLE_VALUE), - - // Open or custom getter. - // Smartcast is always unsafe regardless of usage. - PROPERTY_WITH_GETTER(SmartcastStability.PROPERTY_WITH_GETTER), - - // Protected / public member value from another module. - // Smartcast is always unsafe regardless of usage. - ALIEN_PUBLIC_PROPERTY(SmartcastStability.ALIEN_PUBLIC_PROPERTY), - - // Smartcast may or may not be safe, depending on whether there are concurrent writes to this local variable. - LOCAL_VAR(null), - - // Mutable member property of a class or object. - // Smartcast is always unsafe regardless of usage. - MUTABLE_PROPERTY(SmartcastStability.MUTABLE_PROPERTY), - - // Delegated property of a class or object. - // Smartcast is always unsafe regardless of usage. - DELEGATED_PROPERTY(SmartcastStability.DELEGATED_PROPERTY), -} - -class RealVariable( - val identifier: Identifier, - val isThisReference: Boolean, - val explicitReceiverVariable: DataFlowVariable?, - variableIndexForDebug: Int, - val stability: PropertyStability, -) : DataFlowVariable(variableIndexForDebug) { - override fun equals(other: Any?): Boolean { - return this === other - } - - private val _hashCode by lazy { - 31 * identifier.hashCode() + (explicitReceiverVariable?.hashCode() ?: 0) - } - - override fun hashCode(): Int { - return _hashCode - } -} - -class RealVariableAndType(val variable: RealVariable, val originalType: ConeKotlinType?) { - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as RealVariableAndType - - if (variable != other.variable) return false - if (originalType != other.originalType) return false - - return true - } - - override fun hashCode(): Int { - var result = variable.hashCode() - result = 31 * result + originalType.hashCode() - return result - } -} - -class SyntheticVariable(val fir: FirElement, variableIndexForDebug: Int) : DataFlowVariable(variableIndexForDebug) { - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as SyntheticVariable - - return fir isEqualsTo other.fir - } - - override fun hashCode(): Int { - // hack for enums - return if (fir is FirResolvedQualifier) { - 31 * fir.packageFqName.hashCode() + fir.classId.hashCode() - } else { - fir.hashCode() - } - } -} - -private infix fun FirElement.isEqualsTo(other: FirElement): Boolean { - if (this !is FirResolvedQualifier || other !is FirResolvedQualifier) return this == other - if (packageFqName != other.packageFqName) return false - if (classId != other.classId) return false - return true -} - -// --------------------------------------- Facts --------------------------------------- - -sealed class Statement> { - abstract fun invert(): T - abstract val variable: DataFlowVariable -} - -/* - * Examples: - * d == Null - * d != Null - * d == True - * d == False - */ -data class OperationStatement(override val variable: DataFlowVariable, val operation: Operation) : Statement() { - override fun invert(): OperationStatement { - return OperationStatement(variable, operation.invert()) - } - - override fun toString(): String { - return "$variable $operation" - } -} - -abstract class TypeStatement : Statement() { - abstract override val variable: RealVariable - abstract val exactType: Set - abstract val exactNotType: Set - - abstract operator fun plus(other: TypeStatement): TypeStatement - abstract val isEmpty: Boolean - val isNotEmpty: Boolean get() = !isEmpty - - override fun toString(): String { - return "$variable: $exactType, $exactNotType" - } -} - -operator fun TypeStatement.plus(other: TypeStatement?): TypeStatement = other?.let { this + other } ?: this - -class MutableTypeStatement( - override val variable: RealVariable, - override val exactType: MutableSet = linkedSetOf(), - override val exactNotType: MutableSet = linkedSetOf() -) : TypeStatement() { - override fun plus(other: TypeStatement): MutableTypeStatement = MutableTypeStatement( - variable, - LinkedHashSet(exactType).apply { addAll(other.exactType) }, - LinkedHashSet(exactNotType).apply { addAll(other.exactNotType) } - ) - - override val isEmpty: Boolean - get() = exactType.isEmpty() && exactType.isEmpty() - - override fun invert(): MutableTypeStatement { - return MutableTypeStatement( - variable, - LinkedHashSet(exactNotType), - LinkedHashSet(exactType) - ) - } - - operator fun plusAssign(info: TypeStatement) { - exactType += info.exactType - exactNotType += info.exactNotType - } - - fun copy(): MutableTypeStatement = MutableTypeStatement(variable, LinkedHashSet(exactType), LinkedHashSet(exactNotType)) -} - -class Implication( - val condition: OperationStatement, - val effect: Statement<*> -) { - override fun toString(): String { - return "$condition -> $effect" - } -} - -fun Implication.invertCondition(): Implication = Implication(condition.invert(), effect) - -// --------------------------------------- Aliases --------------------------------------- - -typealias TypeStatements = Map -typealias MutableTypeStatements = MutableMap - -typealias MutableOperationStatements = MutableMap - -fun MutableTypeStatements.addStatement(variable: RealVariable, statement: TypeStatement) { - put(variable, statement.asMutableStatement()) { it.apply { this += statement } } -} - -fun MutableTypeStatements.mergeTypeStatements(other: TypeStatements) { - other.forEach { (variable, info) -> - addStatement(variable, info) - } -} - -// --------------------------------------- DSL --------------------------------------- - -infix fun DataFlowVariable.eq(constant: Boolean?): OperationStatement { - val condition = when (constant) { - true -> Operation.EqTrue - false -> Operation.EqFalse - null -> Operation.EqNull - } - return OperationStatement(this, condition) -} - -infix fun DataFlowVariable.notEq(constant: Boolean?): OperationStatement { - val condition = when (constant) { - true -> Operation.EqFalse - false -> Operation.EqTrue - null -> Operation.NotEqNull - } - return OperationStatement(this, condition) -} - -infix fun OperationStatement.implies(effect: Statement<*>): Implication = Implication(this, effect) - -infix fun RealVariable.typeEq(type: ConeKotlinType): TypeStatement = - if (type !is ConeClassErrorType) { - MutableTypeStatement(this, linkedSetOf().apply { this += type }, HashSet()) - } else { - MutableTypeStatement(this) - } - -infix fun RealVariable.typeNotEq(type: ConeKotlinType): TypeStatement = - if (type !is ConeClassErrorType) { - MutableTypeStatement(this, linkedSetOf(), LinkedHashSet().apply { this += type }) - } else { - MutableTypeStatement(this) - } - -// --------------------------------------- Utils --------------------------------------- - -@OptIn(ExperimentalContracts::class) -fun DataFlowVariable.isSynthetic(): Boolean { - contract { - returns(true) implies (this@isSynthetic is SyntheticVariable) - } - return this is SyntheticVariable -} - -@OptIn(ExperimentalContracts::class) -fun DataFlowVariable.isReal(): Boolean { - contract { - returns(true) implies (this@isReal is RealVariable) - } - return this is RealVariable -} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConeTypeParameterBasedTypeVariable.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConeTypeParameterBasedTypeVariable.kt deleted file mode 100644 index e8bd0739307..00000000000 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConeTypeParameterBasedTypeVariable.kt +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright 2010-2020 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.fir.resolve.inference - -import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol -import org.jetbrains.kotlin.fir.types.ConeTypeVariable - -class ConeTypeParameterBasedTypeVariable(val typeParameterSymbol: FirTypeParameterSymbol) : - ConeTypeVariable(typeParameterSymbol.name.identifier, typeParameterSymbol.toLookupTag()) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceComponents.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceComponents.kt index 3bbf7946069..c1d66060d52 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceComponents.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceComponents.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -46,4 +46,3 @@ class InferenceComponents(val session: FirSession) : FirSessionComponent { } val FirSession.inferenceComponents: InferenceComponents by FirSession.sessionComponentAccessor() - diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceUtils.kt index 7630a4eccff..e432397c705 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceUtils.kt @@ -1,238 +1,18 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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.fir.resolve.inference -import org.jetbrains.kotlin.builtins.functions.FunctionClassKind -import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction -import org.jetbrains.kotlin.fir.declarations.FirClass import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind import org.jetbrains.kotlin.fir.expressions.FirReturnExpression import org.jetbrains.kotlin.fir.expressions.impl.FirUnitExpression -import org.jetbrains.kotlin.fir.originalForSubstitutionOverride -import org.jetbrains.kotlin.fir.resolve.* +import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents import org.jetbrains.kotlin.fir.resolve.calls.Candidate -import org.jetbrains.kotlin.fir.scopes.FakeOverrideTypeCalculator -import org.jetbrains.kotlin.fir.scopes.ProcessorAction -import org.jetbrains.kotlin.fir.scopes.processOverriddenFunctions -import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope -import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag -import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl -import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol import org.jetbrains.kotlin.fir.types.* -import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl -import org.jetbrains.kotlin.name.ClassId -import org.jetbrains.kotlin.name.StandardClassIds -import org.jetbrains.kotlin.types.AbstractTypeChecker -import org.jetbrains.kotlin.util.OperatorNameConventions -import kotlin.contracts.ExperimentalContracts -import kotlin.contracts.contract - -@OptIn(ExperimentalContracts::class) -private fun ConeKotlinType.classId(session: FirSession): ClassId? { - contract { - returns(true) implies (this@classId is ConeClassLikeType) - } - if (this !is ConeClassLikeType) return null - return fullyExpandedType(session).lookupTag.classId -} - -fun ConeKotlinType.isKMutableProperty(session: FirSession): Boolean { - val classId = classId(session) ?: return false - return classId.packageFqName == StandardClassIds.BASE_REFLECT_PACKAGE && - classId.shortClassName.identifier.startsWith("KMutableProperty") -} - -fun ConeKotlinType.functionClassKind(session: FirSession): FunctionClassKind? { - return classId(session)?.toFunctionClassKind() -} - -private fun ClassId.toFunctionClassKind(): FunctionClassKind? { - return FunctionClassKind.byClassNamePrefix(packageFqName, relativeClassName.asString()) -} - -// Function, SuspendFunction, KFunction, KSuspendFunction -fun ConeKotlinType.isBuiltinFunctionalType(session: FirSession): Boolean { - return functionClassKind(session) != null -} - -// Function, SuspendFunction, KFunction, KSuspendFunction -fun ConeClassLikeLookupTag.isBuiltinFunctionalType(): Boolean { - return classId.toFunctionClassKind() != null -} - -inline fun ConeKotlinType.isFunctionalType(session: FirSession, predicate: (FunctionClassKind) -> Boolean): Boolean { - val kind = functionClassKind(session) ?: return false - return predicate(kind) -} - -// Function -fun ConeKotlinType.isFunctionalType(session: FirSession): Boolean { - return isFunctionalType(session) { it == FunctionClassKind.Function } -} - -// SuspendFunction, KSuspendFunction -fun ConeKotlinType.isSuspendFunctionType(session: FirSession): Boolean { - return isFunctionalType(session) { it.isSuspendType } -} - -// KFunction, KSuspendFunction -fun ConeKotlinType.isKFunctionType(session: FirSession): Boolean { - return isFunctionalType(session) { it.isReflectType } -} - -fun ConeKotlinType.kFunctionTypeToFunctionType(session: FirSession): ConeClassLikeType { - require(this.isKFunctionType(session)) - val kind = - if (isSuspendFunctionType(session)) FunctionClassKind.SuspendFunction - else FunctionClassKind.Function - val functionalTypeId = ClassId(kind.packageFqName, kind.numberedClassName(typeArguments.size - 1)) - return ConeClassLikeTypeImpl(ConeClassLikeLookupTagImpl(functionalTypeId), typeArguments, isNullable = false) -} - -fun ConeKotlinType.suspendFunctionTypeToFunctionType(session: FirSession): ConeClassLikeType { - require(this.isSuspendFunctionType(session)) - val kind = - if (isKFunctionType(session)) FunctionClassKind.KFunction - else FunctionClassKind.Function - val functionalTypeId = ClassId(kind.packageFqName, kind.numberedClassName(typeArguments.size - 1)) - return ConeClassLikeTypeImpl(ConeClassLikeLookupTagImpl(functionalTypeId), typeArguments, isNullable = false, attributes = attributes) -} - -fun ConeKotlinType.suspendFunctionTypeToFunctionTypeWithContinuation(session: FirSession, continuationClassId: ClassId): ConeClassLikeType { - require(this.isSuspendFunctionType(session)) - val kind = - if (isKFunctionType(session)) FunctionClassKind.KFunction - else FunctionClassKind.Function - val functionalTypeId = ClassId(kind.packageFqName, kind.numberedClassName(typeArguments.size)) - return ConeClassLikeTypeImpl( - ConeClassLikeLookupTagImpl(functionalTypeId), - typeArguments = (type.typeArguments.dropLast(1) + ConeClassLikeLookupTagImpl(continuationClassId).constructClassType( - arrayOf(type.typeArguments.last()), - isNullable = false - ) + type.typeArguments.last()).toTypedArray(), - isNullable = false, - attributes = attributes - ) -} - -fun ConeKotlinType.isSubtypeOfFunctionalType(session: FirSession, expectedFunctionalType: ConeClassLikeType): Boolean { - require(expectedFunctionalType.isBuiltinFunctionalType(session)) - return AbstractTypeChecker.isSubtypeOf(session.typeContext, this, expectedFunctionalType.replaceArgumentsWithStarProjections()) -} - -fun ConeKotlinType.findSubtypeOfNonSuspendFunctionalType(session: FirSession, expectedFunctionalType: ConeClassLikeType): ConeKotlinType? { - require(expectedFunctionalType.isBuiltinFunctionalType(session) && !expectedFunctionalType.isSuspendFunctionType(session)) - return when (this) { - is ConeClassLikeType -> { - // Expect the argument type is not a suspend functional type. - if (isSuspendFunctionType(session) || !isSubtypeOfFunctionalType(session, expectedFunctionalType)) - null - else - this - } - is ConeIntersectionType -> { - if (intersectedTypes.any { it.isSuspendFunctionType(session) }) - null - else - intersectedTypes.find { it.findSubtypeOfNonSuspendFunctionalType(session, expectedFunctionalType) != null } - } - is ConeTypeParameterType -> { - val bounds = lookupTag.typeParameterSymbol.fir.bounds.map { it.coneType } - if (bounds.any { it.isSuspendFunctionType(session) }) - null - else - bounds.find { it.findSubtypeOfNonSuspendFunctionalType(session, expectedFunctionalType) != null } - } - else -> null - } -} - -fun ConeClassLikeType.findBaseInvokeSymbol(session: FirSession, scopeSession: ScopeSession): FirNamedFunctionSymbol? { - require(this.isBuiltinFunctionalType(session)) - val functionN = (lookupTag.toSymbol(session)?.fir as? FirClass) ?: return null - var baseInvokeSymbol: FirNamedFunctionSymbol? = null - functionN.unsubstitutedScope( - session, - scopeSession, - withForcedTypeCalculator = false - ).processFunctionsByName(OperatorNameConventions.INVOKE) { functionSymbol -> - baseInvokeSymbol = functionSymbol - return@processFunctionsByName - } - return baseInvokeSymbol -} - -fun ConeKotlinType.findContributedInvokeSymbol( - session: FirSession, - scopeSession: ScopeSession, - expectedFunctionalType: ConeClassLikeType, - shouldCalculateReturnTypesOfFakeOverrides: Boolean -): FirFunctionSymbol<*>? { - val baseInvokeSymbol = expectedFunctionalType.findBaseInvokeSymbol(session, scopeSession) ?: return null - - val fakeOverrideTypeCalculator = if (shouldCalculateReturnTypesOfFakeOverrides) { - FakeOverrideTypeCalculator.Forced - } else { - FakeOverrideTypeCalculator.DoNothing - } - val scope = scope(session, scopeSession, fakeOverrideTypeCalculator) ?: return null - var declaredInvoke: FirNamedFunctionSymbol? = null - scope.processFunctionsByName(OperatorNameConventions.INVOKE) { functionSymbol -> - if (functionSymbol.fir.valueParameters.size == baseInvokeSymbol.fir.valueParameters.size) { - declaredInvoke = functionSymbol - return@processFunctionsByName - } - } - - var overriddenInvoke: FirFunctionSymbol<*>? = null - if (declaredInvoke != null) { - // Make sure the user-contributed or type-substituted invoke we just found above is an override of base invoke. - scope.processOverriddenFunctions(declaredInvoke!!) { functionSymbol -> - if (functionSymbol == baseInvokeSymbol || functionSymbol.originalForSubstitutionOverride == baseInvokeSymbol) { - overriddenInvoke = functionSymbol - ProcessorAction.STOP - } else { - ProcessorAction.NEXT - } - } - } - - return if (overriddenInvoke != null) declaredInvoke else null -} - -fun ConeKotlinType.isKClassType(): Boolean { - return classId == StandardClassIds.KClass -} - -private fun ConeTypeProjection.typeOrDefault(default: ConeKotlinType): ConeKotlinType = - when (this) { - is ConeKotlinTypeProjection -> type - is ConeStarProjection -> default - } - -fun ConeKotlinType.receiverType(session: FirSession): ConeKotlinType? { - if (!isBuiltinFunctionalType(session) || !isExtensionFunctionType(session)) return null - return fullyExpandedType(session).typeArguments.first().typeOrDefault(session.builtinTypes.nothingType.type) -} - -fun ConeKotlinType.returnType(session: FirSession): ConeKotlinType { - require(this is ConeClassLikeType) - return fullyExpandedType(session).typeArguments.last().typeOrDefault(session.builtinTypes.nullableAnyType.type) -} - -fun ConeKotlinType.valueParameterTypesIncludingReceiver(session: FirSession): List { - require(this is ConeClassLikeType) - return fullyExpandedType(session).typeArguments.dropLast(1).map { it.typeOrDefault(session.builtinTypes.nothingType.type) } -} - -val FirAnonymousFunction.returnType: ConeKotlinType? get() = returnTypeRef.coneTypeSafe() -val FirAnonymousFunction.receiverType: ConeKotlinType? get() = receiverTypeRef?.coneTypeSafe() fun extractLambdaInfoFromFunctionalType( expectedType: ConeKotlinType?, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt index f485cb6aa14..93a819fb7b1 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt @@ -15,7 +15,6 @@ import org.jetbrains.kotlin.fir.resolve.calls.CheckerSink import org.jetbrains.kotlin.fir.resolve.calls.ResolutionContext import org.jetbrains.kotlin.fir.resolve.createFunctionalType import org.jetbrains.kotlin.fir.resolve.inference.model.ConeArgumentConstraintPosition -import org.jetbrains.kotlin.fir.resolve.isTypeMismatchDueToNullability import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder import org.jetbrains.kotlin.resolve.calls.inference.addSubtypeConstraintIfCompatible diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedAtoms.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedAtoms.kt index 6bc875d65aa..a6ee1fa9b3d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedAtoms.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedAtoms.kt @@ -14,10 +14,7 @@ import org.jetbrains.kotlin.fir.expressions.FirStatement import org.jetbrains.kotlin.fir.references.FirNamedReference import org.jetbrains.kotlin.fir.resolve.DoubleColonLHS import org.jetbrains.kotlin.fir.resolve.calls.Candidate -import org.jetbrains.kotlin.fir.types.ConeKotlinType -import org.jetbrains.kotlin.fir.types.ConeTypeVariable -import org.jetbrains.kotlin.fir.types.ConeTypeVariableType -import org.jetbrains.kotlin.fir.types.FirTypeRef +import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.resolve.calls.model.LambdaWithTypeVariableAsExpectedTypeMarker import org.jetbrains.kotlin.resolve.calls.model.PostponedCallableReferenceMarker import org.jetbrains.kotlin.resolve.calls.model.PostponedResolvedAtomMarker @@ -25,9 +22,7 @@ import org.jetbrains.kotlin.types.model.KotlinTypeMarker // --------------------------- Variables --------------------------- -class ConeTypeVariableForLambdaReturnType(val argument: FirAnonymousFunction, name: String) : ConeTypeVariable(name) -class ConeTypeVariableForPostponedAtom(name: String) : ConeTypeVariable(name) -class ConeTypeVariableForLambdaParameterType(name: String, val index: Int) : ConeTypeVariable(name) + // -------------------------- Atoms -------------------------- diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt index dc0157f2788..e873ecb5719 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt @@ -24,7 +24,6 @@ import org.jetbrains.kotlin.fir.references.builder.buildResolvedNamedReference import org.jetbrains.kotlin.fir.resolve.calls.Candidate import org.jetbrains.kotlin.fir.resolve.calls.FirErrorReferenceWithCandidate import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate -import org.jetbrains.kotlin.fir.resolve.calls.varargElementType import org.jetbrains.kotlin.fir.resolve.constructFunctionalTypeRef import org.jetbrains.kotlin.fir.resolve.createFunctionalType import org.jetbrains.kotlin.fir.resolve.dfa.FirDataFlowAnalyzer @@ -32,10 +31,7 @@ import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeConstraintSystemHasContr import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeInapplicableCandidateError import org.jetbrains.kotlin.fir.resolve.diagnostics.ConePropertyAsOperator import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeTypeParameterInQualifiedAccess -import org.jetbrains.kotlin.fir.resolve.inference.ResolvedLambdaAtom -import org.jetbrains.kotlin.fir.resolve.inference.isBuiltinFunctionalType -import org.jetbrains.kotlin.fir.resolve.inference.isSuspendFunctionType -import org.jetbrains.kotlin.fir.resolve.inference.returnType +import org.jetbrains.kotlin.fir.resolve.inference.* import org.jetbrains.kotlin.fir.resolve.propagateTypeFromQualifiedAccessAfterNullCheck import org.jetbrains.kotlin.fir.resolve.providers.firProvider import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirStatusResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirStatusResolver.kt index 62bb1091f29..d207131146e 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirStatusResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirStatusResolver.kt @@ -22,7 +22,6 @@ import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.scopes.ProcessorAction import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope import org.jetbrains.kotlin.fir.symbols.ensureResolved -import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol import org.jetbrains.kotlin.fir.toEffectiveVisibility import org.jetbrains.kotlin.fir.types.ConeClassLikeType import org.jetbrains.kotlin.fir.types.coneTypeSafe @@ -327,12 +326,3 @@ private fun FirDeclaration.hasOwnBodyOrAccessorBody(): Boolean { else -> true } } - -private object PublishedApiEffectiveVisibilityKey : FirDeclarationDataKey() -var FirDeclaration.publishedApiEffectiveVisibility: EffectiveVisibility? by FirDeclarationDataRegistry.data(PublishedApiEffectiveVisibilityKey) - -inline val FirCallableSymbol<*>.publishedApiEffectiveVisibility: EffectiveVisibility? - get() { - ensureResolved(FirResolvePhase.STATUS) - return fir.publishedApiEffectiveVisibility - } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSupertypesResolution.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSupertypesResolution.kt index c5a8ab51143..ae9fa3085b6 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSupertypesResolution.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSupertypesResolution.kt @@ -18,14 +18,11 @@ import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind import org.jetbrains.kotlin.fir.expressions.FirStatement import org.jetbrains.kotlin.fir.extensions.extensionService import org.jetbrains.kotlin.fir.extensions.supertypeGenerators -import org.jetbrains.kotlin.fir.resolve.ScopeSession -import org.jetbrains.kotlin.fir.resolve.SupertypeSupplier +import org.jetbrains.kotlin.fir.resolve.* import org.jetbrains.kotlin.fir.resolve.dfa.cfg.isLocalClassOrAnonymousObject import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeTypeParameterSupertype -import org.jetbrains.kotlin.fir.resolve.lookupSuperTypes import org.jetbrains.kotlin.fir.resolve.providers.firProvider import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider -import org.jetbrains.kotlin.fir.resolve.toSymbol import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.LocalClassesNavigationInfo import org.jetbrains.kotlin.fir.scopes.FirCompositeScope import org.jetbrains.kotlin.fir.scopes.FirScope @@ -571,10 +568,6 @@ class SupertypeComputationSession { } } -internal fun FirTypeRef.firClassLike(session: FirSession): FirClassLikeDeclaration? { - val type = coneTypeSafe() ?: return null - return type.lookupTag.toSymbol(session)?.fir -} sealed class SupertypeComputationStatus { object NotComputed : SupertypeComputationStatus() diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/BodyResolveUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/BodyResolveUtils.kt index 36d0d0dab12..aef646a0711 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/BodyResolveUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/BodyResolveUtils.kt @@ -5,7 +5,8 @@ package org.jetbrains.kotlin.fir.resolve.transformers.body.resolve -import org.jetbrains.kotlin.fir.* +import org.jetbrains.kotlin.fir.FirFakeSourceElementKind +import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirValueParameter import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind @@ -13,8 +14,9 @@ import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.expressions.FirNamedArgumentExpression import org.jetbrains.kotlin.fir.expressions.builder.buildVarargArgumentsExpression +import org.jetbrains.kotlin.fir.fakeElement import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider -import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol +import org.jetbrains.kotlin.fir.resolvedTypeFromPrototype import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef @@ -22,14 +24,6 @@ import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.StandardClassIds import org.jetbrains.kotlin.types.ConstantValueKind -inline fun FirBasedSymbol<*>.firUnsafe(): T { - val fir = this.fir - require(fir is T) { - "Not an expected fir element type = ${T::class}, symbol = ${this}, fir = ${fir.renderWithType()}" - } - return fir -} - internal inline var FirExpression.resultType: FirTypeRef get() = typeRef set(type) { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirAbstractBodyResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirAbstractBodyResolveTransformer.kt index ee29e81be39..05074d9e688 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirAbstractBodyResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirAbstractBodyResolveTransformer.kt @@ -8,9 +8,7 @@ package org.jetbrains.kotlin.fir.resolve.transformers.body.resolve import org.jetbrains.kotlin.fir.FirCallResolver import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.PrivateForInline -import org.jetbrains.kotlin.fir.declarations.FirDeclaration -import org.jetbrains.kotlin.fir.declarations.FirFile -import org.jetbrains.kotlin.fir.declarations.FirResolvePhase +import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.resolve.* import org.jetbrains.kotlin.fir.resolve.calls.ResolutionContext import org.jetbrains.kotlin.fir.resolve.calls.ResolutionStageRunner diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirBodyResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirBodyResolveTransformer.kt index 519dea82fcd..00176846427 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirBodyResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirBodyResolveTransformer.kt @@ -14,13 +14,13 @@ import org.jetbrains.kotlin.fir.render import org.jetbrains.kotlin.fir.resolve.ResolutionMode import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.resolve.calls.ResolutionContext +import org.jetbrains.kotlin.fir.resolve.createCurrentScopeList import org.jetbrains.kotlin.fir.resolve.dfa.DataFlowAnalyzerContext import org.jetbrains.kotlin.fir.resolve.transformers.FirProviderInterceptor import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculatorForFullBodyResolve import org.jetbrains.kotlin.fir.resolve.transformers.ScopeClassDeclaration import org.jetbrains.kotlin.fir.scopes.FirCompositeScope -import org.jetbrains.kotlin.fir.scopes.impl.createCurrentScopeList import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.visitors.FirTransformer diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt index eb3b3f31910..41426236413 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt @@ -30,7 +30,7 @@ import org.jetbrains.kotlin.fir.resolve.dfa.unwrapSmartcastExpression import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeLocalVariableNoTypeOrInitializer import org.jetbrains.kotlin.fir.resolve.inference.ResolvedLambdaAtom import org.jetbrains.kotlin.fir.resolve.inference.extractLambdaInfoFromFunctionalType -import org.jetbrains.kotlin.fir.resolve.inference.isSuspendFunctionType +import org.jetbrains.kotlin.fir.types.isSuspendFunctionType import org.jetbrains.kotlin.fir.resolve.mode import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.resolve.transformers.* @@ -923,7 +923,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor expectedType.approximatedIfNeededOrSelf( session.typeApproximator, backingField.visibilityForApproximation(), - inferenceComponents.session.typeContext, + session.typeContext, ) ) ) @@ -948,7 +948,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor expectedType.approximatedIfNeededOrSelf( session.typeApproximator, variable.visibilityForApproximation(), - inferenceComponents.session.typeContext, + session.typeContext, ) ) ) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt index 86cfc5cab80..08304ec1746 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt @@ -31,7 +31,6 @@ import org.jetbrains.kotlin.fir.resolve.inference.FirStubInferenceSession import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.resolve.transformers.InvocationKindTransformer import org.jetbrains.kotlin.fir.resolve.transformers.StoreReceiver -import org.jetbrains.kotlin.fir.resolve.transformers.firClassLike import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirTowerDataContextCollector.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirTowerDataContextCollector.kt index 88fd3d16e43..fa34b23ffcc 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirTowerDataContextCollector.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirTowerDataContextCollector.kt @@ -7,8 +7,8 @@ package org.jetbrains.kotlin.fir.resolve.transformers.body.resolve import org.jetbrains.kotlin.fir.declarations.FirDeclaration import org.jetbrains.kotlin.fir.declarations.FirFile +import org.jetbrains.kotlin.fir.declarations.FirTowerDataContext import org.jetbrains.kotlin.fir.expressions.FirStatement -import org.jetbrains.kotlin.fir.resolve.FirTowerDataContext /** * Collector needed to collect TowerDataContext in IDE for in-air resolved fir elements. diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/LocalClassesResolution.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/LocalClassesResolution.kt index 6434f7708fc..bbb52ff9aaf 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/LocalClassesResolution.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/LocalClassesResolution.kt @@ -7,11 +7,11 @@ package org.jetbrains.kotlin.fir.resolve.transformers.body.resolve import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.resolve.ResolutionMode +import org.jetbrains.kotlin.fir.resolve.createCurrentScopeList import org.jetbrains.kotlin.fir.resolve.transformers.FirProviderInterceptor import org.jetbrains.kotlin.fir.resolve.transformers.runStatusResolveForLocalClass import org.jetbrains.kotlin.fir.resolve.transformers.runSupertypeResolvePhaseForLocalClass import org.jetbrains.kotlin.fir.resolve.transformers.runTypeResolvePhaseForLocalClass -import org.jetbrains.kotlin.fir.scopes.impl.createCurrentScopeList fun F.runAllPhasesForLocalClass( transformer: FirAbstractBodyResolveTransformer, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/Scopes.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/ImportingScopes.kt similarity index 84% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/Scopes.kt rename to compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/ImportingScopes.kt index 568e4afa593..761166f0653 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/Scopes.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/ImportingScopes.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -7,22 +7,15 @@ package org.jetbrains.kotlin.fir.scopes import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirFile -import org.jetbrains.kotlin.fir.declarations.FirRegularClass import org.jetbrains.kotlin.fir.packageFqName import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.resolve.scopeSessionKey -import org.jetbrains.kotlin.fir.resolve.toSymbol import org.jetbrains.kotlin.fir.scopes.impl.* -import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag -import org.jetbrains.kotlin.name.FqName +private val ALL_IMPORTS = scopeSessionKey() private val INVISIBLE_DEFAULT_STAR_IMPORT = scopeSessionKey() private val VISIBLE_DEFAULT_STAR_IMPORT = scopeSessionKey() private val DEFAULT_SIMPLE_IMPORT = scopeSessionKey() -val PACKAGE_MEMBER = scopeSessionKey() -private val ALL_IMPORTS = scopeSessionKey() - -private class ListStorageFirScope(val result: List) : FirScope() fun createImportingScopes( file: FirFile, @@ -74,7 +67,4 @@ private fun doCreateImportingScopes( ) } -fun ConeClassLikeLookupTag.getNestedClassifierScope(session: FirSession, scopeSession: ScopeSession): FirContainingNamesAwareScope? { - val klass = toSymbol(session)?.fir as? FirRegularClass ?: return null - return klass.scopeProvider.getNestedClassifierScope(klass, session, scopeSession) -} +private class ListStorageFirScope(val result: List) : FirScope() diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDefaultSimpleImportingScope.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDefaultSimpleImportingScope.kt index 1a06b37eb8b..0bffd149807 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDefaultSimpleImportingScope.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDefaultSimpleImportingScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirGeneratedClassNestedClassifierScope.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirGeneratedClassNestedClassifierScope.kt deleted file mode 100644 index 1aa355682a3..00000000000 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirGeneratedClassNestedClassifierScope.kt +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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.fir.scopes.impl - -import org.jetbrains.kotlin.fir.FirSession -import org.jetbrains.kotlin.fir.caches.FirCache -import org.jetbrains.kotlin.fir.caches.firCachesFactory -import org.jetbrains.kotlin.fir.declarations.FirClass -import org.jetbrains.kotlin.fir.declarations.utils.classId -import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol -import org.jetbrains.kotlin.name.Name - diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirTypeResolveScopeForBodyResolve.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirTypeResolveScopeForBodyResolve.kt deleted file mode 100644 index 017345cc288..00000000000 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirTypeResolveScopeForBodyResolve.kt +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright 2010-2019 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.fir.scopes.impl - -import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents -import org.jetbrains.kotlin.fir.scopes.FirScope - -fun BodyResolveComponents.createCurrentScopeList(): List = - towerDataElements.asReversed().mapNotNull { it.scope } diff --git a/compiler/fir/semantics/build.gradle.kts b/compiler/fir/semantics/build.gradle.kts new file mode 100644 index 00000000000..210a7e1b64f --- /dev/null +++ b/compiler/fir/semantics/build.gradle.kts @@ -0,0 +1,17 @@ +plugins { + kotlin("jvm") + id("jps-compatible") +} + +dependencies { + api(project(":compiler:fir:providers")) + implementation(project(":core:util.runtime")) + + compileOnly(project(":kotlin-reflect-api")) + compileOnly(intellijCoreDep()) { includeJars("guava", rootProject = rootProject) } +} + +sourceSets { + "main" { projectDefault() } + "test" { none() } +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/EffectiveVisibilityUtils.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/EffectiveVisibilityUtils.kt similarity index 100% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/EffectiveVisibilityUtils.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/EffectiveVisibilityUtils.kt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirLookupTrackerComponent.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/FirLookupTrackerComponent.kt similarity index 88% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirLookupTrackerComponent.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/FirLookupTrackerComponent.kt index 168418a041c..b0e8bcf2b02 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirLookupTrackerComponent.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/FirLookupTrackerComponent.kt @@ -1,11 +1,11 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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.fir -import org.jetbrains.kotlin.fir.resolve.calls.CallInfo +import org.jetbrains.kotlin.fir.resolve.calls.AbstractCallInfo import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.utils.SmartList @@ -17,7 +17,7 @@ abstract class FirLookupTrackerComponent : FirSessionComponent { abstract fun recordLookup(name: Name, inScope: String, source: FirSourceElement?, fileSource: FirSourceElement?) } -fun FirLookupTrackerComponent.recordCallLookup(callInfo: CallInfo, inType: ConeKotlinType) { +fun FirLookupTrackerComponent.recordCallLookup(callInfo: AbstractCallInfo, inType: ConeKotlinType) { if (inType.classId?.isLocal == true) return val scopes = SmartList(inType.render().replace('/', '.')) if (inType.classId?.shortClassName?.asString() == "Companion") { @@ -26,7 +26,7 @@ fun FirLookupTrackerComponent.recordCallLookup(callInfo: CallInfo, inType: ConeK recordLookup(callInfo.name, scopes, callInfo.callSite.source, callInfo.containingFile.source) } -fun FirLookupTrackerComponent.recordCallLookup(callInfo: CallInfo, inScopes: List) { +fun FirLookupTrackerComponent.recordCallLookup(callInfo: AbstractCallInfo, inScopes: List) { recordLookup(callInfo.name, inScopes, callInfo.callSite.source, callInfo.containingFile.source) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirNameConflictsTrackerComponent.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/FirNameConflictsTrackerComponent.kt similarity index 99% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirNameConflictsTrackerComponent.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/FirNameConflictsTrackerComponent.kt index 094f09eaaac..0c39a74749b 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirNameConflictsTrackerComponent.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/FirNameConflictsTrackerComponent.kt @@ -10,7 +10,6 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol import org.jetbrains.kotlin.name.ClassId abstract class FirNameConflictsTrackerComponent : FirSessionComponent { - abstract fun registerClassifierRedeclaration( classId: ClassId, newSymbol: FirClassLikeSymbol<*>, newSymbolFile: FirFile, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/SessionUtils.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/SessionUtils.kt similarity index 95% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/SessionUtils.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/SessionUtils.kt index bb34972a28d..a73f3b12042 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/SessionUtils.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/SessionUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/declarations/FirVersionRequirementsTableKey.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/declarations/FirVersionRequirementsTableKey.kt similarity index 100% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/declarations/FirVersionRequirementsTableKey.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/declarations/FirVersionRequirementsTableKey.kt diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/declarations/ImplicitReceiverUtils.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/declarations/ImplicitReceiverUtils.kt new file mode 100644 index 00000000000..a2611429fb7 --- /dev/null +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/declarations/ImplicitReceiverUtils.kt @@ -0,0 +1,201 @@ +/* + * 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.fir.declarations + +import kotlinx.collections.immutable.PersistentList +import kotlinx.collections.immutable.persistentListOf +import kotlinx.collections.immutable.toPersistentList +import org.jetbrains.kotlin.fir.resolve.* +import org.jetbrains.kotlin.fir.resolve.calls.ImplicitDispatchReceiverValue +import org.jetbrains.kotlin.fir.resolve.calls.ImplicitExtensionReceiverValue +import org.jetbrains.kotlin.fir.resolve.calls.ImplicitReceiverValue +import org.jetbrains.kotlin.fir.scopes.FirScope +import org.jetbrains.kotlin.fir.scopes.impl.FirLocalScope +import org.jetbrains.kotlin.fir.scopes.impl.wrapNestedClassifierScopeWithSubstitutionForSuperType +import org.jetbrains.kotlin.fir.types.ConeKotlinType +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.utils.addIfNotNull + +fun SessionHolder.collectImplicitReceivers( + type: ConeKotlinType?, + owner: FirDeclaration +): ImplicitReceivers { + if (type == null) return ImplicitReceivers(null, emptyList()) + + val implicitCompanionValues = mutableListOf>() + val implicitReceiverValue = when (owner) { + is FirClass -> { + val towerElementsForClass = collectTowerDataElementsForClass(owner, type) + implicitCompanionValues.addAll(towerElementsForClass.implicitCompanionValues) + + towerElementsForClass.thisReceiver + } + is FirFunction -> { + ImplicitExtensionReceiverValue(owner.symbol, type, session, scopeSession) + } + is FirVariable -> { + ImplicitExtensionReceiverValue(owner.symbol, type, session, scopeSession) + } + else -> { + throw IllegalArgumentException("Incorrect label & receiver owner: ${owner.javaClass}") + } + } + return ImplicitReceivers(implicitReceiverValue, implicitCompanionValues) +} + +data class ImplicitReceivers( + val implicitReceiverValue: ImplicitReceiverValue<*>?, + val implicitCompanionValues: List> +) + +fun SessionHolder.collectTowerDataElementsForClass(owner: FirClass, defaultType: ConeKotlinType): TowerElementsForClass { + val allImplicitCompanionValues = mutableListOf>() + + val companionObject = (owner as? FirRegularClass)?.companionObject + val companionReceiver = companionObject?.let { companion -> + ImplicitDispatchReceiverValue( + companion.symbol, session, scopeSession + ) + } + allImplicitCompanionValues.addIfNotNull(companionReceiver) + + val superClassesStaticsAndCompanionReceivers = mutableListOf() + for (superType in lookupSuperTypes(owner, lookupInterfaces = false, deep = true, useSiteSession = session)) { + val expandedType = superType.fullyExpandedType(session) + val superClass = expandedType.lookupTag.toSymbol(session)?.fir as? FirRegularClass ?: continue + + superClass.staticScope(this) + ?.wrapNestedClassifierScopeWithSubstitutionForSuperType(expandedType, session) + ?.asTowerDataElement(isLocal = false) + ?.let(superClassesStaticsAndCompanionReceivers::add) + + (superClass as? FirRegularClass)?.companionObject?.let { companion -> + val superCompanionReceiver = ImplicitDispatchReceiverValue( + companion.symbol, session, scopeSession + ) + + superClassesStaticsAndCompanionReceivers += superCompanionReceiver.asTowerDataElement() + allImplicitCompanionValues += superCompanionReceiver + } + } + + val thisReceiver = ImplicitDispatchReceiverValue(owner.symbol, defaultType, session, scopeSession) + + return TowerElementsForClass( + thisReceiver, + owner.staticScope(this), + companionReceiver, + companionObject?.staticScope(this), + superClassesStaticsAndCompanionReceivers.asReversed(), + allImplicitCompanionValues.asReversed() + ) +} + +class TowerElementsForClass( + val thisReceiver: ImplicitReceiverValue<*>, + val staticScope: FirScope?, + val companionReceiver: ImplicitReceiverValue<*>?, + val companionStaticScope: FirScope?, + // Ordered from inner scopes to outer scopes. + val superClassesStaticsAndCompanionReceivers: List, + // Ordered from inner scopes to outer scopes. + val implicitCompanionValues: List> +) + +class FirTowerDataContext private constructor( + val towerDataElements: PersistentList, + // These properties are effectively redundant, their content should be consistent with `towerDataElements`, + // i.e. implicitReceiverStack == towerDataElements.mapNotNull { it.receiver } + // i.e. localScopes == towerDataElements.mapNotNull { it.scope?.takeIf { it.isLocal } } + val implicitReceiverStack: PersistentImplicitReceiverStack, + val localScopes: FirLocalScopes, + val nonLocalTowerDataElements: PersistentList +) { + + constructor() : this( + persistentListOf(), + PersistentImplicitReceiverStack(), + persistentListOf(), + persistentListOf() + ) + + fun setLastLocalScope(newLastScope: FirLocalScope): FirTowerDataContext { + val oldLastScope = localScopes.last() + val indexOfLastLocalScope = towerDataElements.indexOfLast { it.scope === oldLastScope } + + return FirTowerDataContext( + towerDataElements.set(indexOfLastLocalScope, newLastScope.asTowerDataElement(isLocal = true)), + implicitReceiverStack, + localScopes.set(localScopes.lastIndex, newLastScope), + nonLocalTowerDataElements + ) + } + + fun addNonLocalTowerDataElements(newElements: List): FirTowerDataContext { + return FirTowerDataContext( + towerDataElements.addAll(newElements), + implicitReceiverStack.addAll(newElements.mapNotNull { it.implicitReceiver }), + localScopes, + nonLocalTowerDataElements.addAll(newElements) + ) + } + + fun addLocalScope(localScope: FirLocalScope): FirTowerDataContext { + return FirTowerDataContext( + towerDataElements.add(localScope.asTowerDataElement(isLocal = true)), + implicitReceiverStack, + localScopes.add(localScope), + nonLocalTowerDataElements + ) + } + + fun addReceiver(name: Name?, implicitReceiverValue: ImplicitReceiverValue<*>): FirTowerDataContext { + val element = implicitReceiverValue.asTowerDataElement() + return FirTowerDataContext( + towerDataElements.add(element), + implicitReceiverStack.add(name, implicitReceiverValue), + localScopes, + nonLocalTowerDataElements.add(element) + ) + } + + fun addNonLocalScopeIfNotNull(scope: FirScope?): FirTowerDataContext { + if (scope == null) return this + return addNonLocalScope(scope) + } + + private fun addNonLocalScope(scope: FirScope): FirTowerDataContext { + val element = scope.asTowerDataElement(isLocal = false) + return FirTowerDataContext( + towerDataElements.add(element), + implicitReceiverStack, + localScopes, + nonLocalTowerDataElements.add(element) + ) + } + + fun createSnapshot(): FirTowerDataContext { + return FirTowerDataContext( + towerDataElements.map { FirTowerDataElement(it.scope, it.implicitReceiver?.createSnapshot(), it.isLocal) }.toPersistentList(), + implicitReceiverStack.createSnapshot(), + localScopes.toPersistentList(), + nonLocalTowerDataElements.map { FirTowerDataElement(it.scope, it.implicitReceiver?.createSnapshot(), it.isLocal) } + .toPersistentList() + ) + } +} + +class FirTowerDataElement(val scope: FirScope?, val implicitReceiver: ImplicitReceiverValue<*>?, val isLocal: Boolean) + +fun ImplicitReceiverValue<*>.asTowerDataElement(): FirTowerDataElement = + FirTowerDataElement(scope = null, this, isLocal = false) + +fun FirScope.asTowerDataElement(isLocal: Boolean): FirTowerDataElement = + FirTowerDataElement(this, implicitReceiver = null, isLocal) + +private fun FirClass.staticScope(sessionHolder: SessionHolder) = + scopeProvider.getStaticScope(this, sessionHolder.session, sessionHolder.scopeSession) +typealias FirLocalScopes = PersistentList diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/CallableIdUtils.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/CallableIdUtils.kt new file mode 100644 index 00000000000..6ab4894cca5 --- /dev/null +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/CallableIdUtils.kt @@ -0,0 +1,42 @@ +/* + * 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.fir.resolve + +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.expressions.FirAnnotation +import org.jetbrains.kotlin.fir.resolve.providers.getSymbolByTypeRef +import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider +import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol +import org.jetbrains.kotlin.name.CallableId +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.StandardClassIds + +fun CallableId.isInvoke(): Boolean = + isKFunctionInvoke() + || callableName.asString() == "invoke" + && className?.asString()?.startsWith("Function") == true + && packageName == StandardClassIds.BASE_KOTLIN_PACKAGE + +fun CallableId.isKFunctionInvoke(): Boolean = + callableName.asString() == "invoke" + && className?.asString()?.startsWith("KFunction") == true + && packageName.asString() == "kotlin.reflect" + +fun CallableId.isIteratorNext(): Boolean = + callableName.asString() == "next" && className?.asString()?.endsWith("Iterator") == true + && packageName.asString() == "kotlin.collections" + +fun CallableId.isIteratorHasNext(): Boolean = + callableName.asString() == "hasNext" && className?.asString()?.endsWith("Iterator") == true + && packageName.asString() == "kotlin.collections" + +fun CallableId.isIterator(): Boolean = + callableName.asString() == "iterator" && packageName.asString() in arrayOf("kotlin.collections", "kotlin.ranges") + +fun FirAnnotation.fqName(session: FirSession): FqName? { + val symbol = session.symbolProvider.getSymbolByTypeRef(annotationTypeRef) ?: return null + return symbol.classId.asSingleFqName() +} diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/DeclarationUtils.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/DeclarationUtils.kt new file mode 100644 index 00000000000..a6dcc8708d0 --- /dev/null +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/DeclarationUtils.kt @@ -0,0 +1,75 @@ +/* + * 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.fir.resolve + +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.containingClassForLocalAttr +import org.jetbrains.kotlin.fir.declarations.* +import org.jetbrains.kotlin.fir.declarations.utils.isLocal +import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider +import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol +import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol +import org.jetbrains.kotlin.fir.symbols.impl.LookupTagInternals +import org.jetbrains.kotlin.fir.types.* +import org.jetbrains.kotlin.name.ClassId + +fun FirClassLikeDeclaration.getContainingDeclaration(session: FirSession): FirClassLikeDeclaration? { + if (isLocal) { + @OptIn(LookupTagInternals::class) + return (this as? FirRegularClass)?.containingClassForLocalAttr?.toFirRegularClass(session) + } else { + val classId = symbol.classId + val parentId = classId.relativeClassName.parent() + if (!parentId.isRoot) { + val containingDeclarationId = ClassId(classId.packageFqName, parentId, false) + return session.symbolProvider.getClassLikeSymbolByClassId(containingDeclarationId)?.fir + } + } + + return null +} + +fun isValidTypeParameterFromOuterClass( + typeParameterSymbol: FirTypeParameterSymbol, + classDeclaration: FirRegularClass?, + session: FirSession +): Boolean { + if (classDeclaration == null) { + return true // Extra check is required because of classDeclaration will be resolved later + } + + fun containsTypeParameter(currentClassDeclaration: FirRegularClass): Boolean { + if (currentClassDeclaration.typeParameters.any { it.symbol == typeParameterSymbol }) { + return true + } + + for (superTypeRef in currentClassDeclaration.superTypeRefs) { + val superClassFir = superTypeRef.firClassLike(session) + if (superClassFir == null || superClassFir is FirRegularClass && containsTypeParameter(superClassFir)) { + return true + } + } + + return false + } + + return containsTypeParameter(classDeclaration) +} + +fun FirTypeRef.firClassLike(session: FirSession): FirClassLikeDeclaration? { + val type = coneTypeSafe() ?: return null + return type.lookupTag.toSymbol(session)?.fir +} + +fun List.toTypeProjections(): Array = + asReversed().flatMap { it.typeArgumentList.typeArguments.map { typeArgument -> typeArgument.toConeTypeProjection() } }.toTypedArray() + +private object TypeAliasConstructorKey : FirDeclarationDataKey() + +var FirConstructor.originalConstructorIfTypeAlias: FirConstructor? by FirDeclarationDataRegistry.data(TypeAliasConstructorKey) + +val FirConstructorSymbol.isTypeAliasedConstructor: Boolean + get() = fir.originalConstructorIfTypeAlias != null diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ImplicitReceiverStack.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/ImplicitReceiverStack.kt similarity index 100% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ImplicitReceiverStack.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/ImplicitReceiverStack.kt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/PersistentImplicitReceiverStack.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/PersistentImplicitReceiverStack.kt similarity index 98% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/PersistentImplicitReceiverStack.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/PersistentImplicitReceiverStack.kt index be1b2822460..85a61a5ac3d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/PersistentImplicitReceiverStack.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/PersistentImplicitReceiverStack.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CfgUtils.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/SessionHolder.kt similarity index 52% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CfgUtils.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/SessionHolder.kt index 6035b2088e4..41ce2cae1c6 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CfgUtils.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/SessionHolder.kt @@ -3,9 +3,11 @@ * 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.fir.resolve.dfa.cfg +package org.jetbrains.kotlin.fir.resolve -import org.jetbrains.kotlin.contracts.description.EventOccurrencesRange +import org.jetbrains.kotlin.fir.FirSession -val EventOccurrencesRange?.isInPlace: Boolean - get() = this != null +interface SessionHolder { + val session: FirSession + val scopeSession: ScopeSession +} diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/AbstractCallInfo.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/AbstractCallInfo.kt new file mode 100644 index 00000000000..91ea6c85bcb --- /dev/null +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/AbstractCallInfo.kt @@ -0,0 +1,21 @@ +/* + * 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.fir.resolve.calls + +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.declarations.FirFile +import org.jetbrains.kotlin.fir.expressions.FirArgumentList +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.name.Name + +abstract class AbstractCallInfo { + abstract val callSite: FirElement + abstract val name: Name + abstract val containingFile: FirFile + abstract val isImplicitInvoke: Boolean + abstract val explicitReceiver: FirExpression? + abstract val argumentList: FirArgumentList +} diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/AbstractCandidate.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/AbstractCandidate.kt new file mode 100644 index 00000000000..64dce587ea1 --- /dev/null +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/AbstractCandidate.kt @@ -0,0 +1,22 @@ +/* + * 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.fir.resolve.calls + +import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol +import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl +import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind +import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability + +abstract class AbstractCandidate { + abstract val symbol: FirBasedSymbol<*> + abstract val dispatchReceiverValue: ReceiverValue? + abstract val extensionReceiverValue: ReceiverValue? + abstract val explicitReceiverKind: ExplicitReceiverKind + abstract val callInfo: AbstractCallInfo + abstract val diagnostics: List + abstract val system: NewConstraintSystemImpl + abstract val applicability: CandidateApplicability +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt similarity index 100% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/DfaInternals.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/DfaInternals.kt similarity index 78% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/DfaInternals.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/DfaInternals.kt index 39ef8b1f3ed..969af3d60ec 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/DfaInternals.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/DfaInternals.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/DfaVariables.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/DfaVariables.kt new file mode 100644 index 00000000000..ac1edadcfb9 --- /dev/null +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/DfaVariables.kt @@ -0,0 +1,122 @@ +/* + * 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.fir.resolve.dfa + +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier +import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol +import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol +import org.jetbrains.kotlin.fir.types.ConeKotlinType +import org.jetbrains.kotlin.types.SmartcastStability + +data class Identifier( + val symbol: FirBasedSymbol<*>, + val dispatchReceiver: DataFlowVariable?, + val extensionReceiver: DataFlowVariable? +) { + override fun toString(): String { + val callableId = (symbol as? FirCallableSymbol<*>)?.callableId + return "[$callableId, dispatchReceiver = $dispatchReceiver, extensionReceiver = $extensionReceiver]" + } +} + +sealed class DataFlowVariable(private val variableIndexForDebug: Int) { + final override fun toString(): String { + return "d$variableIndexForDebug" + } +} + +enum class PropertyStability(val impliedSmartcastStability: SmartcastStability?) { + // Immutable and no custom getter or local. + // Smartcast is definitely safe regardless of usage. + STABLE_VALUE(SmartcastStability.STABLE_VALUE), + + // Open or custom getter. + // Smartcast is always unsafe regardless of usage. + PROPERTY_WITH_GETTER(SmartcastStability.PROPERTY_WITH_GETTER), + + // Protected / public member value from another module. + // Smartcast is always unsafe regardless of usage. + ALIEN_PUBLIC_PROPERTY(SmartcastStability.ALIEN_PUBLIC_PROPERTY), + + // Smartcast may or may not be safe, depending on whether there are concurrent writes to this local variable. + LOCAL_VAR(null), + + // Mutable member property of a class or object. + // Smartcast is always unsafe regardless of usage. + MUTABLE_PROPERTY(SmartcastStability.MUTABLE_PROPERTY), + + // Delegated property of a class or object. + // Smartcast is always unsafe regardless of usage. + DELEGATED_PROPERTY(SmartcastStability.DELEGATED_PROPERTY), +} + +class RealVariable( + val identifier: Identifier, + val isThisReference: Boolean, + val explicitReceiverVariable: DataFlowVariable?, + variableIndexForDebug: Int, + val stability: PropertyStability, +) : DataFlowVariable(variableIndexForDebug) { + override fun equals(other: Any?): Boolean { + return this === other + } + + private val _hashCode by lazy { + 31 * identifier.hashCode() + (explicitReceiverVariable?.hashCode() ?: 0) + } + + override fun hashCode(): Int { + return _hashCode + } +} + +class RealVariableAndType(val variable: RealVariable, val originalType: ConeKotlinType?) { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as RealVariableAndType + + if (variable != other.variable) return false + if (originalType != other.originalType) return false + + return true + } + + override fun hashCode(): Int { + var result = variable.hashCode() + result = 31 * result + originalType.hashCode() + return result + } +} + +class SyntheticVariable(val fir: FirElement, variableIndexForDebug: Int) : DataFlowVariable(variableIndexForDebug) { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as SyntheticVariable + + return fir isEqualsTo other.fir + } + + override fun hashCode(): Int { + // hack for enums + return if (fir is FirResolvedQualifier) { + 31 * fir.packageFqName.hashCode() + fir.classId.hashCode() + } else { + fir.hashCode() + } + } +} + +private infix fun FirElement.isEqualsTo(other: FirElement): Boolean { + if (this !is FirResolvedQualifier || other !is FirResolvedQualifier) return this == other + if (packageFqName != other.packageFqName) return false + if (classId != other.classId) return false + return true +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirControlFlowGraphReferenceImpl.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/FirControlFlowGraphReferenceImpl.kt similarity index 95% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirControlFlowGraphReferenceImpl.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/FirControlFlowGraphReferenceImpl.kt index 993091577b6..959cca726ad 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirControlFlowGraphReferenceImpl.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/FirControlFlowGraphReferenceImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -31,4 +31,4 @@ val FirControlFlowGraphReference.controlFlowGraph: ControlFlowGraph? get() = (this as? FirControlFlowGraphReferenceImpl)?.controlFlowGraph val FirControlFlowGraphReference.dataFlowInfo: DataFlowInfo? - get() = (this as? FirControlFlowGraphReferenceImpl)?.dataFlowInfo \ No newline at end of file + get() = (this as? FirControlFlowGraphReferenceImpl)?.dataFlowInfo diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/Flow.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/Flow.kt new file mode 100644 index 00000000000..4cef1eceaf6 --- /dev/null +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/Flow.kt @@ -0,0 +1,21 @@ +/* + * 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.fir.resolve.dfa + +abstract class Flow { + abstract fun getTypeStatement(variable: RealVariable): TypeStatement? + abstract fun getImplications(variable: DataFlowVariable): Collection + abstract fun getVariablesInTypeStatements(): Collection + abstract fun removeOperations(variable: DataFlowVariable): Collection + + abstract val directAliasMap: Map + abstract val backwardsAliasMap: Map> + abstract val assignmentIndex: Map +} + +fun Flow.unwrapVariable(variable: RealVariable): RealVariable { + return directAliasMap[variable]?.variable ?: variable +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/LogicSystem.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/LogicSystem.kt similarity index 90% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/LogicSystem.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/LogicSystem.kt index 8646b6b11fb..501a251b0a9 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/LogicSystem.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/LogicSystem.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -10,21 +10,6 @@ import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.canBeNull import org.jetbrains.kotlin.fir.types.commonSuperTypeOrNull -abstract class Flow { - abstract fun getTypeStatement(variable: RealVariable): TypeStatement? - abstract fun getImplications(variable: DataFlowVariable): Collection - abstract fun getVariablesInTypeStatements(): Collection - abstract fun removeOperations(variable: DataFlowVariable): Collection - - abstract val directAliasMap: Map - abstract val backwardsAliasMap: Map> - abstract val assignmentIndex: Map -} - -fun Flow.unwrapVariable(variable: RealVariable): RealVariable { - return directAliasMap[variable]?.variable ?: variable -} - abstract class LogicSystem(protected val context: ConeInferenceContext) { // ------------------------------- Flow operations ------------------------------- diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/PersistentLogicSystem.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/PersistentLogicSystem.kt similarity index 99% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/PersistentLogicSystem.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/PersistentLogicSystem.kt index eef6beaafea..52035e95af2 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/PersistentLogicSystem.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/PersistentLogicSystem.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/Stack.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/Stack.kt similarity index 95% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/Stack.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/Stack.kt index 31c9d11cef7..c380fbf6838 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/Stack.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/Stack.kt @@ -1,15 +1,15 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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.fir.resolve.dfa import org.jetbrains.kotlin.fir.FirElement -import org.jetbrains.kotlin.fir.asReversedFrozen import org.jetbrains.kotlin.fir.declarations.FirDeclaration import org.jetbrains.kotlin.fir.resolve.dfa.cfg.CFGNode import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol +import org.jetbrains.kotlin.fir.util.asReversedFrozen abstract class Stack { abstract val size: Int diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorage.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorage.kt new file mode 100644 index 00000000000..c9010253e7c --- /dev/null +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorage.kt @@ -0,0 +1,16 @@ +/* + * 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.fir.resolve.dfa + +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol + +abstract class VariableStorage { + abstract fun getRealVariableWithoutUnwrappingAlias(symbol: FirBasedSymbol<*>?, fir: FirElement, flow: Flow): RealVariable? + abstract fun getRealVariable(symbol: FirBasedSymbol<*>?, fir: FirElement, flow: Flow): RealVariable? + abstract fun getSyntheticVariable(fir: FirElement): SyntheticVariable? + abstract fun getVariable(fir: FirElement, flow: Flow): DataFlowVariable? +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorage.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorageImpl.kt similarity index 93% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorage.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorageImpl.kt index aad0a84a86c..e75209143a4 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorage.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorageImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -15,7 +15,6 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor import org.jetbrains.kotlin.fir.declarations.utils.modality import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression -import org.jetbrains.kotlin.fir.originalIfFakeOverride import org.jetbrains.kotlin.fir.originalOrSelf import org.jetbrains.kotlin.fir.references.FirThisReference import org.jetbrains.kotlin.fir.resolve.fullyExpandedType @@ -28,7 +27,7 @@ import kotlin.contracts.ExperimentalContracts import kotlin.contracts.contract @OptIn(DfaInternals::class) -class VariableStorage(private val session: FirSession) { +class VariableStorageImpl(private val session: FirSession) : VariableStorage() { private var counter = 1 private val _realVariables: MutableMap = HashMap() val realVariables: Map @@ -36,7 +35,7 @@ class VariableStorage(private val session: FirSession) { private val syntheticVariables: MutableMap = HashMap() - fun clear(): VariableStorage = VariableStorage(session) + fun clear(): VariableStorageImpl = VariableStorageImpl(session) fun getOrCreateRealVariableWithoutUnwrappingAlias( flow: Flow, @@ -128,22 +127,22 @@ class VariableStorage(private val session: FirSession) { } } - fun getRealVariableWithoutUnwrappingAlias(symbol: FirBasedSymbol<*>?, fir: FirElement, flow: Flow): RealVariable? { + override fun getRealVariableWithoutUnwrappingAlias(symbol: FirBasedSymbol<*>?, fir: FirElement, flow: Flow): RealVariable? { val realFir = fir.unwrapElement() return symbol.takeIf { it.getStability(realFir) != null }?.let { _realVariables[getIdentifierBySymbol(flow, it, realFir.unwrapElement())] } } - fun getRealVariable(symbol: FirBasedSymbol<*>?, fir: FirElement, flow: Flow): RealVariable? { + override fun getRealVariable(symbol: FirBasedSymbol<*>?, fir: FirElement, flow: Flow): RealVariable? { return getRealVariableWithoutUnwrappingAlias(symbol, fir, flow)?.let { flow.unwrapVariable(it) } } - fun getSyntheticVariable(fir: FirElement): SyntheticVariable? { + override fun getSyntheticVariable(fir: FirElement): SyntheticVariable? { return syntheticVariables[fir.unwrapElement()] } - fun getVariable(fir: FirElement, flow: Flow): DataFlowVariable? { + override fun getVariable(fir: FirElement, flow: Flow): DataFlowVariable? { val realFir = fir.unwrapElement() val symbol = realFir.symbol val stability = symbol.getStability(fir) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CFGNode.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CFGNode.kt similarity index 92% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CFGNode.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CFGNode.kt index 2dcc6d524fc..49a403b066c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CFGNode.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CFGNode.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -17,9 +17,13 @@ import org.jetbrains.kotlin.fir.visitors.FirVisitor import org.jetbrains.kotlin.utils.addIfNotNull import org.jetbrains.kotlin.utils.addToStdlib.runIf +@RequiresOptIn +annotation class CfgInternals + sealed class CFGNode(val owner: ControlFlowGraph, val level: Int, private val id: Int) { companion object { - internal fun addEdge( + @CfgInternals + fun addEdge( from: CFGNode<*>, to: CFGNode<*>, kind: EdgeKind, @@ -31,7 +35,8 @@ sealed class CFGNode(val owner: ControlFlowGraph, val level: addJustKindEdge(from, to, kind, propagateDeadness, edgeExists = false, label = label) } - internal fun addJustKindEdge( + @CfgInternals + fun addJustKindEdge( from: CFGNode<*>, to: CFGNode<*>, kind: EdgeKind, @@ -78,7 +83,8 @@ sealed class CFGNode(val owner: ControlFlowGraph, val level: } } - internal fun removeAllIncomingEdges(to: CFGNode<*>) { + @CfgInternals + fun removeAllIncomingEdges(to: CFGNode<*>) { for (from in to._previousNodes) { from._followingNodes.remove(to) from._outgoingEdges.remove(to) @@ -87,7 +93,8 @@ sealed class CFGNode(val owner: ControlFlowGraph, val level: to._previousNodes.clear() } - internal fun removeAllOutgoingEdges(from: CFGNode<*>) { + @CfgInternals + fun removeAllOutgoingEdges(from: CFGNode<*>) { for (to in from._followingNodes) { to._previousNodes.remove(from) from._outgoingEdges.remove(to) @@ -118,7 +125,8 @@ sealed class CFGNode(val owner: ControlFlowGraph, val level: var isDead: Boolean = false protected set - internal fun updateDeadStatus() { + @CfgInternals + fun updateDeadStatus() { isDead = incomingEdges.size == previousNodes.size && incomingEdges.values.all { it.kind == EdgeKind.DeadForward || !it.kind.usedInCfa } @@ -162,12 +170,14 @@ sealed class CFGNodeWithCfgOwner(owner: Contro // ----------------------------------- Named function ----------------------------------- -class FunctionEnterNode(owner: ControlFlowGraph, override val fir: FirFunction, level: Int, id: Int) : CFGNode(owner, level, id), EnterNodeMarker { +class FunctionEnterNode(owner: ControlFlowGraph, override val fir: FirFunction, level: Int, id: Int) : CFGNode(owner, level, id), + EnterNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitFunctionEnterNode(this, data) } } -class FunctionExitNode(owner: ControlFlowGraph, override val fir: FirFunction, level: Int, id: Int) : CFGNode(owner, level, id), ExitNodeMarker { +class FunctionExitNode(owner: ControlFlowGraph, override val fir: FirFunction, level: Int, id: Int) : CFGNode(owner, level, id), + ExitNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitFunctionExitNode(this, data) } @@ -181,7 +191,9 @@ class LocalFunctionDeclarationNode(owner: ControlFlowGraph, override val fir: Fi // ----------------------------------- Default arguments ----------------------------------- -class EnterDefaultArgumentsNode(owner: ControlFlowGraph, override val fir: FirValueParameter, level: Int, id: Int) : CFGNodeWithCfgOwner(owner, level, id), EnterNodeMarker { +@OptIn(CfgInternals::class) +class EnterDefaultArgumentsNode(owner: ControlFlowGraph, override val fir: FirValueParameter, level: Int, id: Int) : CFGNodeWithCfgOwner(owner, level, id), + EnterNodeMarker { init { owner.enterNode = this } @@ -191,7 +203,9 @@ class EnterDefaultArgumentsNode(owner: ControlFlowGraph, override val fir: FirVa } } -class ExitDefaultArgumentsNode(owner: ControlFlowGraph, override val fir: FirValueParameter, level: Int, id: Int) : CFGNode(owner, level, id), ExitNodeMarker { +@OptIn(CfgInternals::class) +class ExitDefaultArgumentsNode(owner: ControlFlowGraph, override val fir: FirValueParameter, level: Int, id: Int) : CFGNode(owner, level, id), + ExitNodeMarker { init { owner.exitNode = this } @@ -227,7 +241,9 @@ class AnonymousFunctionExpressionExitNode(owner: ControlFlowGraph, override val // ----------------------------------- Classes ----------------------------------- -class ClassEnterNode(owner: ControlFlowGraph, override val fir: FirClass, level: Int, id: Int) : CFGNode(owner, level, id), EnterNodeMarker { +@OptIn(CfgInternals::class) +class ClassEnterNode(owner: ControlFlowGraph, override val fir: FirClass, level: Int, id: Int) : CFGNode(owner, level, id), + EnterNodeMarker { init { owner.enterNode = this } @@ -237,7 +253,9 @@ class ClassEnterNode(owner: ControlFlowGraph, override val fir: FirClass, level: } } -class ClassExitNode(owner: ControlFlowGraph, override val fir: FirClass, level: Int, id: Int) : CFGNode(owner, level, id), ExitNodeMarker { +@OptIn(CfgInternals::class) +class ClassExitNode(owner: ControlFlowGraph, override val fir: FirClass, level: Int, id: Int) : CFGNode(owner, level, id), + ExitNodeMarker { init { owner.exitNode = this } @@ -275,7 +293,9 @@ class PartOfClassInitializationNode(owner: ControlFlowGraph, override val fir: F // ----------------------------------- Property ----------------------------------- -class PropertyInitializerEnterNode(owner: ControlFlowGraph, override val fir: FirProperty, level: Int, id: Int) : CFGNode(owner, level, id), EnterNodeMarker { +@OptIn(CfgInternals::class) +class PropertyInitializerEnterNode(owner: ControlFlowGraph, override val fir: FirProperty, level: Int, id: Int) : CFGNode(owner, level, id), + EnterNodeMarker { init { owner.enterNode = this } @@ -284,7 +304,10 @@ class PropertyInitializerEnterNode(owner: ControlFlowGraph, override val fir: Fi return visitor.visitPropertyInitializerEnterNode(this, data) } } -class PropertyInitializerExitNode(owner: ControlFlowGraph, override val fir: FirProperty, level: Int, id: Int) : CFGNode(owner, level, id), ExitNodeMarker { + +@OptIn(CfgInternals::class) +class PropertyInitializerExitNode(owner: ControlFlowGraph, override val fir: FirProperty, level: Int, id: Int) : CFGNode(owner, level, id), + ExitNodeMarker { init { owner.exitNode = this } @@ -296,7 +319,9 @@ class PropertyInitializerExitNode(owner: ControlFlowGraph, override val fir: Fir // ----------------------------------- Field ----------------------------------- -class FieldInitializerEnterNode(owner: ControlFlowGraph, override val fir: FirField, level: Int, id: Int) : CFGNode(owner, level, id), EnterNodeMarker { +@OptIn(CfgInternals::class) +class FieldInitializerEnterNode(owner: ControlFlowGraph, override val fir: FirField, level: Int, id: Int) : CFGNode(owner, level, id), + EnterNodeMarker { init { owner.enterNode = this } @@ -305,7 +330,10 @@ class FieldInitializerEnterNode(owner: ControlFlowGraph, override val fir: FirFi return visitor.visitFieldInitializerEnterNode(this, data) } } -class FieldInitializerExitNode(owner: ControlFlowGraph, override val fir: FirField, level: Int, id: Int) : CFGNode(owner, level, id), ExitNodeMarker { + +@OptIn(CfgInternals::class) +class FieldInitializerExitNode(owner: ControlFlowGraph, override val fir: FirField, level: Int, id: Int) : CFGNode(owner, level, id), + ExitNodeMarker { init { owner.exitNode = this } @@ -317,7 +345,9 @@ class FieldInitializerExitNode(owner: ControlFlowGraph, override val fir: FirFie // ----------------------------------- Init ----------------------------------- -class InitBlockEnterNode(owner: ControlFlowGraph, override val fir: FirAnonymousInitializer, level: Int, id: Int) : CFGNode(owner, level, id), EnterNodeMarker { +@OptIn(CfgInternals::class) +class InitBlockEnterNode(owner: ControlFlowGraph, override val fir: FirAnonymousInitializer, level: Int, id: Int) : CFGNode(owner, level, id), + EnterNodeMarker { init { owner.enterNode = this } @@ -326,7 +356,10 @@ class InitBlockEnterNode(owner: ControlFlowGraph, override val fir: FirAnonymous return visitor.visitInitBlockEnterNode(this, data) } } -class InitBlockExitNode(owner: ControlFlowGraph, override val fir: FirAnonymousInitializer, level: Int, id: Int) : CFGNode(owner, level, id), ExitNodeMarker { + +@OptIn(CfgInternals::class) +class InitBlockExitNode(owner: ControlFlowGraph, override val fir: FirAnonymousInitializer, level: Int, id: Int) : CFGNode(owner, level, id), + ExitNodeMarker { init { owner.exitNode = this } @@ -338,12 +371,14 @@ class InitBlockExitNode(owner: ControlFlowGraph, override val fir: FirAnonymousI // ----------------------------------- Block ----------------------------------- -class BlockEnterNode(owner: ControlFlowGraph, override val fir: FirBlock, level: Int, id: Int) : CFGNode(owner, level, id), EnterNodeMarker { +class BlockEnterNode(owner: ControlFlowGraph, override val fir: FirBlock, level: Int, id: Int) : CFGNode(owner, level, id), + EnterNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitBlockEnterNode(this, data) } } -class BlockExitNode(owner: ControlFlowGraph, override val fir: FirBlock, level: Int, id: Int) : CFGNode(owner, level, id), ExitNodeMarker { +class BlockExitNode(owner: ControlFlowGraph, override val fir: FirBlock, level: Int, id: Int) : CFGNode(owner, level, id), + ExitNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitBlockExitNode(this, data) } @@ -351,22 +386,26 @@ class BlockExitNode(owner: ControlFlowGraph, override val fir: FirBlock, level: // ----------------------------------- When ----------------------------------- -class WhenEnterNode(owner: ControlFlowGraph, override val fir: FirWhenExpression, level: Int, id: Int) : CFGNode(owner, level, id), EnterNodeMarker { +class WhenEnterNode(owner: ControlFlowGraph, override val fir: FirWhenExpression, level: Int, id: Int) : CFGNode(owner, level, id), + EnterNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitWhenEnterNode(this, data) } } -class WhenExitNode(owner: ControlFlowGraph, override val fir: FirWhenExpression, level: Int, id: Int) : CFGNode(owner, level, id), ExitNodeMarker { +class WhenExitNode(owner: ControlFlowGraph, override val fir: FirWhenExpression, level: Int, id: Int) : CFGNode(owner, level, id), + ExitNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitWhenExitNode(this, data) } } -class WhenBranchConditionEnterNode(owner: ControlFlowGraph, override val fir: FirWhenBranch, level: Int, id: Int) : CFGNode(owner, level, id), EnterNodeMarker { +class WhenBranchConditionEnterNode(owner: ControlFlowGraph, override val fir: FirWhenBranch, level: Int, id: Int) : CFGNode(owner, level, id), + EnterNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitWhenBranchConditionEnterNode(this, data) } } -class WhenBranchConditionExitNode(owner: ControlFlowGraph, override val fir: FirWhenBranch, level: Int, id: Int) : CFGNode(owner, level, id), ExitNodeMarker { +class WhenBranchConditionExitNode(owner: ControlFlowGraph, override val fir: FirWhenBranch, level: Int, id: Int) : CFGNode(owner, level, id), + ExitNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitWhenBranchConditionExitNode(this, data) } @@ -393,32 +432,38 @@ class WhenSyntheticElseBranchNode(owner: ControlFlowGraph, override val fir: Fir // ----------------------------------- Loop ----------------------------------- -class LoopEnterNode(owner: ControlFlowGraph, override val fir: FirLoop, level: Int, id: Int) : CFGNode(owner, level, id), EnterNodeMarker { +class LoopEnterNode(owner: ControlFlowGraph, override val fir: FirLoop, level: Int, id: Int) : CFGNode(owner, level, id), + EnterNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitLoopEnterNode(this, data) } } -class LoopBlockEnterNode(owner: ControlFlowGraph, override val fir: FirLoop, level: Int, id: Int) : CFGNode(owner, level, id), EnterNodeMarker { +class LoopBlockEnterNode(owner: ControlFlowGraph, override val fir: FirLoop, level: Int, id: Int) : CFGNode(owner, level, id), + EnterNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitLoopBlockEnterNode(this, data) } } -class LoopBlockExitNode(owner: ControlFlowGraph, override val fir: FirLoop, level: Int, id: Int) : CFGNode(owner, level, id), ExitNodeMarker { +class LoopBlockExitNode(owner: ControlFlowGraph, override val fir: FirLoop, level: Int, id: Int) : CFGNode(owner, level, id), + ExitNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitLoopBlockExitNode(this, data) } } -class LoopConditionEnterNode(owner: ControlFlowGraph, override val fir: FirExpression, val loop: FirLoop, level: Int, id: Int) : CFGNode(owner, level, id), EnterNodeMarker { +class LoopConditionEnterNode(owner: ControlFlowGraph, override val fir: FirExpression, val loop: FirLoop, level: Int, id: Int) : CFGNode(owner, level, id), + EnterNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitLoopConditionEnterNode(this, data) } } -class LoopConditionExitNode(owner: ControlFlowGraph, override val fir: FirExpression, level: Int, id: Int) : CFGNode(owner, level, id), ExitNodeMarker { +class LoopConditionExitNode(owner: ControlFlowGraph, override val fir: FirExpression, level: Int, id: Int) : CFGNode(owner, level, id), + ExitNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitLoopConditionExitNode(this, data) } } -class LoopExitNode(owner: ControlFlowGraph, override val fir: FirLoop, level: Int, id: Int) : CFGNode(owner, level, id), ExitNodeMarker { +class LoopExitNode(owner: ControlFlowGraph, override val fir: FirLoop, level: Int, id: Int) : CFGNode(owner, level, id), + ExitNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitLoopExitNode(this, data) } @@ -426,52 +471,62 @@ class LoopExitNode(owner: ControlFlowGraph, override val fir: FirLoop, level: In // ----------------------------------- Try-catch-finally ----------------------------------- -class TryExpressionEnterNode(owner: ControlFlowGraph, override val fir: FirTryExpression, level: Int, id: Int) : CFGNode(owner, level, id), EnterNodeMarker { +class TryExpressionEnterNode(owner: ControlFlowGraph, override val fir: FirTryExpression, level: Int, id: Int) : CFGNode(owner, level, id), + EnterNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitTryExpressionEnterNode(this, data) } } -class TryMainBlockEnterNode(owner: ControlFlowGraph, override val fir: FirTryExpression, level: Int, id: Int) : CFGNode(owner, level, id), EnterNodeMarker { +class TryMainBlockEnterNode(owner: ControlFlowGraph, override val fir: FirTryExpression, level: Int, id: Int) : CFGNode(owner, level, id), + EnterNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitTryMainBlockEnterNode(this, data) } } -class TryMainBlockExitNode(owner: ControlFlowGraph, override val fir: FirTryExpression, level: Int, id: Int) : CFGNode(owner, level, id), ExitNodeMarker { +class TryMainBlockExitNode(owner: ControlFlowGraph, override val fir: FirTryExpression, level: Int, id: Int) : CFGNode(owner, level, id), + ExitNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitTryMainBlockExitNode(this, data) } } -class CatchClauseEnterNode(owner: ControlFlowGraph, override val fir: FirCatch, level: Int, id: Int) : CFGNode(owner, level, id), EnterNodeMarker { +class CatchClauseEnterNode(owner: ControlFlowGraph, override val fir: FirCatch, level: Int, id: Int) : CFGNode(owner, level, id), + EnterNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitCatchClauseEnterNode(this, data) } } -class CatchClauseExitNode(owner: ControlFlowGraph, override val fir: FirCatch, level: Int, id: Int) : CFGNode(owner, level, id), ExitNodeMarker { +class CatchClauseExitNode(owner: ControlFlowGraph, override val fir: FirCatch, level: Int, id: Int) : CFGNode(owner, level, id), + ExitNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitCatchClauseExitNode(this, data) } } -class FinallyBlockEnterNode(owner: ControlFlowGraph, override val fir: FirTryExpression, level: Int, id: Int) : CFGNode(owner, level, id), EnterNodeMarker { +class FinallyBlockEnterNode(owner: ControlFlowGraph, override val fir: FirTryExpression, level: Int, id: Int) : CFGNode(owner, level, id), + EnterNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitFinallyBlockEnterNode(this, data) } } -class FinallyBlockExitNode(owner: ControlFlowGraph, override val fir: FirTryExpression, level: Int, id: Int) : CFGNode(owner, level, id), ExitNodeMarker { +class FinallyBlockExitNode(owner: ControlFlowGraph, override val fir: FirTryExpression, level: Int, id: Int) : CFGNode(owner, level, id), + ExitNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitFinallyBlockExitNode(this, data) } } -class FinallyProxyEnterNode(owner: ControlFlowGraph, override val fir: FirTryExpression, level: Int, id: Int) : CFGNode(owner, level, id), EnterNodeMarker { +class FinallyProxyEnterNode(owner: ControlFlowGraph, override val fir: FirTryExpression, level: Int, id: Int) : CFGNode(owner, level, id), + EnterNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitFinallyProxyEnterNode(this, data) } } -class FinallyProxyExitNode(owner: ControlFlowGraph, override val fir: FirTryExpression, level: Int, id: Int) : CFGNode(owner, level, id), ExitNodeMarker { +class FinallyProxyExitNode(owner: ControlFlowGraph, override val fir: FirTryExpression, level: Int, id: Int) : CFGNode(owner, level, id), + ExitNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitFinallyProxyExitNode(this, data) } } -class TryExpressionExitNode(owner: ControlFlowGraph, override val fir: FirTryExpression, level: Int, id: Int) : CFGNode(owner, level, id), ExitNodeMarker { +class TryExpressionExitNode(owner: ControlFlowGraph, override val fir: FirTryExpression, level: Int, id: Int) : CFGNode(owner, level, id), + ExitNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitTryExpressionExitNode(this, data) } @@ -484,7 +539,8 @@ abstract class AbstractBinaryExitNode(owner: ControlFlowGraph, l val rightOperandNode: CFGNode<*> get() = previousNodes[1] } -class BinaryAndEnterNode(owner: ControlFlowGraph, override val fir: FirBinaryLogicExpression, level: Int, id: Int) : CFGNode(owner, level, id), EnterNodeMarker { +class BinaryAndEnterNode(owner: ControlFlowGraph, override val fir: FirBinaryLogicExpression, level: Int, id: Int) : CFGNode(owner, level, id), + EnterNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitBinaryAndEnterNode(this, data) } @@ -499,13 +555,15 @@ class BinaryAndEnterRightOperandNode(owner: ControlFlowGraph, override val fir: return visitor.visitBinaryAndEnterRightOperandNode(this, data) } } -class BinaryAndExitNode(owner: ControlFlowGraph, override val fir: FirBinaryLogicExpression, level: Int, id: Int) : AbstractBinaryExitNode(owner, level, id), ExitNodeMarker { +class BinaryAndExitNode(owner: ControlFlowGraph, override val fir: FirBinaryLogicExpression, level: Int, id: Int) : AbstractBinaryExitNode(owner, level, id), + ExitNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitBinaryAndExitNode(this, data) } } -class BinaryOrEnterNode(owner: ControlFlowGraph, override val fir: FirBinaryLogicExpression, level: Int, id: Int) : CFGNode(owner, level, id), EnterNodeMarker { +class BinaryOrEnterNode(owner: ControlFlowGraph, override val fir: FirBinaryLogicExpression, level: Int, id: Int) : CFGNode(owner, level, id), + EnterNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitBinaryOrEnterNode(this, data) } @@ -520,7 +578,8 @@ class BinaryOrEnterRightOperandNode(owner: ControlFlowGraph, override val fir: F return visitor.visitBinaryOrEnterRightOperandNode(this, data) } } -class BinaryOrExitNode(owner: ControlFlowGraph, override val fir: FirBinaryLogicExpression, level: Int, id: Int) : AbstractBinaryExitNode(owner, level, id), ExitNodeMarker { +class BinaryOrExitNode(owner: ControlFlowGraph, override val fir: FirBinaryLogicExpression, level: Int, id: Int) : AbstractBinaryExitNode(owner, level, id), + ExitNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitBinaryOrExitNode(this, data) } @@ -659,6 +718,7 @@ class StubNode(owner: ControlFlowGraph, level: Int, id: Int) : CFGNode( } } +@OptIn(CfgInternals::class) class ContractDescriptionEnterNode(owner: ControlFlowGraph, level: Int, id: Int) : CFGNode(owner, level, id) { init { owner.enterNode = this @@ -681,12 +741,14 @@ class VariableAssignmentNode(owner: ControlFlowGraph, override val fir: FirVaria } } -class EnterContractNode(owner: ControlFlowGraph, override val fir: FirQualifiedAccess, level: Int, id: Int) : CFGNode(owner, level, id), EnterNodeMarker { +class EnterContractNode(owner: ControlFlowGraph, override val fir: FirQualifiedAccess, level: Int, id: Int) : CFGNode(owner, level, id), + EnterNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitEnterContractNode(this, data) } } -class ExitContractNode(owner: ControlFlowGraph, override val fir: FirQualifiedAccess, level: Int, id: Int) : CFGNode(owner, level, id), ExitNodeMarker { +class ExitContractNode(owner: ControlFlowGraph, override val fir: FirQualifiedAccess, level: Int, id: Int) : CFGNode(owner, level, id), + ExitNodeMarker { override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { return visitor.visitExitContractNode(this, data) } @@ -734,7 +796,9 @@ class ElvisExitNode(owner: ControlFlowGraph, override val fir: FirElvisExpressio // ----------------------------------- Other ----------------------------------- -class AnnotationEnterNode(owner: ControlFlowGraph, override val fir: FirAnnotation, level: Int, id: Int) : CFGNode(owner, level, id), EnterNodeMarker { +@OptIn(CfgInternals::class) +class AnnotationEnterNode(owner: ControlFlowGraph, override val fir: FirAnnotation, level: Int, id: Int) : CFGNode(owner, level, id), + EnterNodeMarker { init { owner.enterNode = this } @@ -743,7 +807,10 @@ class AnnotationEnterNode(owner: ControlFlowGraph, override val fir: FirAnnotati return visitor.visitAnnotationEnterNode(this, data) } } -class AnnotationExitNode(owner: ControlFlowGraph, override val fir: FirAnnotation, level: Int, id: Int) : CFGNode(owner, level, id), ExitNodeMarker { + +@OptIn(CfgInternals::class) +class AnnotationExitNode(owner: ControlFlowGraph, override val fir: FirAnnotation, level: Int, id: Int) : CFGNode(owner, level, id), + ExitNodeMarker { init { owner.exitNode = this } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CFGNodeRenderer.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CFGNodeRenderer.kt similarity index 99% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CFGNodeRenderer.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CFGNodeRenderer.kt index 6d07e8bca0f..699178cbe49 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CFGNodeRenderer.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CFGNodeRenderer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraph.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraph.kt similarity index 95% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraph.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraph.kt index c85778d7ac6..fb7588648d6 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraph.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraph.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -19,11 +19,12 @@ class ControlFlowGraph(val declaration: FirDeclaration?, val name: String, val k _nodes.add(node) } + @set:CfgInternals lateinit var enterNode: CFGNode<*> - internal set + @set:CfgInternals lateinit var exitNode: CFGNode<*> - internal set + var owner: ControlFlowGraph? = null private set @@ -33,7 +34,8 @@ class ControlFlowGraph(val declaration: FirDeclaration?, val name: String, val k private val _subGraphs: MutableList = mutableListOf() val subGraphs: List get() = _subGraphs - internal fun complete() { + @CfgInternals + fun complete() { assertState(State.Building) state = State.Completed if (kind == Kind.Stub) return @@ -47,7 +49,8 @@ class ControlFlowGraph(val declaration: FirDeclaration?, val name: String, val k _nodes.addAll(sortedNodes) } - internal fun addSubGraph(graph: ControlFlowGraph) { + @CfgInternals + fun addSubGraph(graph: ControlFlowGraph) { assert(graph.owner == null) { "SubGraph already has owner" } @@ -55,7 +58,8 @@ class ControlFlowGraph(val declaration: FirDeclaration?, val name: String, val k _subGraphs += graph } - internal fun removeSubGraph(graph: ControlFlowGraph) { + @CfgInternals + fun removeSubGraph(graph: ControlFlowGraph) { assert(graph.owner == this) _subGraphs.remove(graph) graph.owner = null diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphVisitor.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphVisitor.kt similarity index 99% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphVisitor.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphVisitor.kt index 7353543f8d1..34497d3648c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphVisitor.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphVisitor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphVisitorVoid.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphVisitorVoid.kt similarity index 99% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphVisitorVoid.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphVisitorVoid.kt index fe9b296f1f2..dde35e8fb6a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphVisitorVoid.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphVisitorVoid.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/model.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/model.kt new file mode 100644 index 00000000000..615375ec3a5 --- /dev/null +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/model.kt @@ -0,0 +1,118 @@ +/* + * 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.fir.resolve.dfa + +import org.jetbrains.kotlin.fir.types.ConeClassErrorType +import org.jetbrains.kotlin.fir.types.ConeKotlinType +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.contract + +// --------------------------------------- Facts --------------------------------------- + +operator fun TypeStatement.plus(other: TypeStatement?): TypeStatement = other?.let { this + other } ?: this + +class MutableTypeStatement( + override val variable: RealVariable, + override val exactType: MutableSet = linkedSetOf(), + override val exactNotType: MutableSet = linkedSetOf() +) : TypeStatement() { + override fun plus(other: TypeStatement): MutableTypeStatement = MutableTypeStatement( + variable, + LinkedHashSet(exactType).apply { addAll(other.exactType) }, + LinkedHashSet(exactNotType).apply { addAll(other.exactNotType) } + ) + + override val isEmpty: Boolean + get() = exactType.isEmpty() && exactType.isEmpty() + + override fun invert(): MutableTypeStatement { + return MutableTypeStatement( + variable, + LinkedHashSet(exactNotType), + LinkedHashSet(exactType) + ) + } + + operator fun plusAssign(info: TypeStatement) { + exactType += info.exactType + exactNotType += info.exactNotType + } + + fun copy(): MutableTypeStatement = MutableTypeStatement(variable, LinkedHashSet(exactType), LinkedHashSet(exactNotType)) +} + +fun Implication.invertCondition(): Implication = Implication(condition.invert(), effect) + +// --------------------------------------- Aliases --------------------------------------- + +typealias TypeStatements = Map +typealias MutableTypeStatements = MutableMap + +typealias MutableOperationStatements = MutableMap + +fun MutableTypeStatements.addStatement(variable: RealVariable, statement: TypeStatement) { + put(variable, statement.asMutableStatement()) { it.apply { this += statement } } +} + +fun MutableTypeStatements.mergeTypeStatements(other: TypeStatements) { + other.forEach { (variable, info) -> + addStatement(variable, info) + } +} + +// --------------------------------------- DSL --------------------------------------- + +infix fun DataFlowVariable.eq(constant: Boolean?): OperationStatement { + val condition = when (constant) { + true -> Operation.EqTrue + false -> Operation.EqFalse + null -> Operation.EqNull + } + return OperationStatement(this, condition) +} + +infix fun DataFlowVariable.notEq(constant: Boolean?): OperationStatement { + val condition = when (constant) { + true -> Operation.EqFalse + false -> Operation.EqTrue + null -> Operation.NotEqNull + } + return OperationStatement(this, condition) +} + +infix fun OperationStatement.implies(effect: Statement<*>): Implication = Implication(this, effect) + +infix fun RealVariable.typeEq(type: ConeKotlinType): TypeStatement = + if (type !is ConeClassErrorType) { + MutableTypeStatement(this, linkedSetOf().apply { this += type }, HashSet()) + } else { + MutableTypeStatement(this) + } + +infix fun RealVariable.typeNotEq(type: ConeKotlinType): TypeStatement = + if (type !is ConeClassErrorType) { + MutableTypeStatement(this, linkedSetOf(), LinkedHashSet().apply { this += type }) + } else { + MutableTypeStatement(this) + } + +// --------------------------------------- Utils --------------------------------------- + +@OptIn(ExperimentalContracts::class) +fun DataFlowVariable.isSynthetic(): Boolean { + contract { + returns(true) implies (this@isSynthetic is SyntheticVariable) + } + return this is SyntheticVariable +} + +@OptIn(ExperimentalContracts::class) +fun DataFlowVariable.isReal(): Boolean { + contract { + returns(true) implies (this@isReal is RealVariable) + } + return this is RealVariable +} diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/statements.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/statements.kt new file mode 100644 index 00000000000..67d45739722 --- /dev/null +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/statements.kt @@ -0,0 +1,71 @@ +/* + * 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.fir.resolve.dfa + +import org.jetbrains.kotlin.fir.types.ConeKotlinType + +sealed class Statement> { + abstract fun invert(): T + abstract val variable: DataFlowVariable +} + +/* + * Examples: + * d == Null + * d != Null + * d == True + * d == False + */ +data class OperationStatement(override val variable: DataFlowVariable, val operation: Operation) : Statement() { + override fun invert(): OperationStatement { + return OperationStatement(variable, operation.invert()) + } + + override fun toString(): String { + return "$variable $operation" + } +} + +abstract class TypeStatement : Statement() { + abstract override val variable: RealVariable + abstract val exactType: Set + abstract val exactNotType: Set + + abstract operator fun plus(other: TypeStatement): TypeStatement + abstract val isEmpty: Boolean + val isNotEmpty: Boolean get() = !isEmpty + + override fun toString(): String { + return "$variable: $exactType, $exactNotType" + } +} + +class Implication( + val condition: OperationStatement, + val effect: Statement<*> +) { + override fun toString(): String { + return "$condition -> $effect" + } +} + +enum class Operation { + EqTrue, EqFalse, EqNull, NotEqNull; + + fun invert(): Operation = when (this) { + EqTrue -> EqFalse + EqFalse -> EqTrue + EqNull -> NotEqNull + NotEqNull -> EqNull + } + + override fun toString(): String = when (this) { + EqTrue -> "== True" + EqFalse -> "== False" + EqNull -> "== Null" + NotEqNull -> "!= Null" + } +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/util.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/util.kt similarity index 86% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/util.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/util.kt index 12c5b65b90b..c261dcb6e6d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/util.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/util.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -13,13 +13,14 @@ import org.jetbrains.kotlin.fir.declarations.FirDeclaration import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference import org.jetbrains.kotlin.fir.references.FirThisReference -import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate +import org.jetbrains.kotlin.fir.references.impl.FirSimpleNamedReference import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirAccessorSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.coneType +import org.jetbrains.kotlin.name.StandardClassIds import org.jetbrains.kotlin.utils.addToStdlib.safeAs import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind @@ -57,7 +58,7 @@ internal inline fun PersistentMap.put( } @DfaInternals -internal fun FirOperation.invert(): FirOperation = when (this) { +fun FirOperation.invert(): FirOperation = when (this) { FirOperation.EQ -> FirOperation.NOT_EQ FirOperation.NOT_EQ -> FirOperation.EQ FirOperation.IDENTITY -> FirOperation.NOT_IDENTITY @@ -66,7 +67,7 @@ internal fun FirOperation.invert(): FirOperation = when (this) { } @DfaInternals -internal fun FirOperation.isEq(): Boolean { +fun FirOperation.isEq(): Boolean { return when (this) { FirOperation.EQ, FirOperation.IDENTITY -> true FirOperation.NOT_EQ, FirOperation.NOT_IDENTITY -> false @@ -74,9 +75,9 @@ internal fun FirOperation.isEq(): Boolean { } } -internal fun FirFunctionCall.isBooleanNot(): Boolean { +fun FirFunctionCall.isBooleanNot(): Boolean { val symbol = calleeReference.safeAs()?.resolvedSymbol as? FirNamedFunctionSymbol ?: return false - return symbol.callableId == FirDataFlowAnalyzer.KOTLIN_BOOLEAN_NOT + return symbol.callableId == StandardClassIds.Callables.not } fun ConeConstantReference.toOperation(): Operation = when (this) { @@ -88,11 +89,11 @@ fun ConeConstantReference.toOperation(): Operation = when (this) { } @DfaInternals -internal val FirExpression.coneType: ConeKotlinType +val FirExpression.coneType: ConeKotlinType get() = typeRef.coneType @DfaInternals -internal val FirElement.symbol: FirBasedSymbol<*>? +val FirElement.symbol: FirBasedSymbol<*>? get() = when (this) { is FirResolvable -> symbol is FirDeclaration -> symbol @@ -109,11 +110,11 @@ internal val FirResolvable.symbol: FirBasedSymbol<*>? get() = when (val reference = calleeReference) { is FirThisReference -> reference.boundSymbol is FirResolvedNamedReference -> reference.resolvedSymbol - is FirNamedReferenceWithCandidate -> reference.candidateSymbol + is FirSimpleNamedReference -> reference.candidateSymbol else -> null } -internal fun FirExpression.unwrapSmartcastExpression(): FirExpression = +fun FirExpression.unwrapSmartcastExpression(): FirExpression = when (this) { is FirExpressionWithSmartcast -> originalExpression else -> this diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/diagnostics/FirDiagnostics.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/diagnostics/ConeDiagnostics.kt similarity index 98% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/diagnostics/FirDiagnostics.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/diagnostics/ConeDiagnostics.kt index c06c5b23899..d369ab1e752 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/diagnostics/FirDiagnostics.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/diagnostics/ConeDiagnostics.kt @@ -13,7 +13,7 @@ import org.jetbrains.kotlin.fir.declarations.FirVariable import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnosticWithSource import org.jetbrains.kotlin.fir.render -import org.jetbrains.kotlin.fir.resolve.calls.Candidate +import org.jetbrains.kotlin.fir.resolve.calls.AbstractCandidate import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.types.ConeKotlinType @@ -91,7 +91,7 @@ class ConeInapplicableWrongReceiver(override val candidateSymbols: Collection get() = candidate.symbol @@ -105,7 +105,7 @@ class ConeNoCompanionObject( } class ConeConstraintSystemHasContradiction( - val candidate: Candidate, + val candidate: AbstractCandidate, ) : ConeDiagnosticWithSingleCandidate { override val reason: String get() = "CS errors: ${describeSymbol(candidateSymbol)}" override val candidateSymbol: FirBasedSymbol<*> get() = candidate.symbol @@ -121,7 +121,7 @@ class ConeArgumentTypeMismatchCandidateError( class ConeAmbiguityError( val name: Name, val applicability: CandidateApplicability, - val candidates: Collection + val candidates: Collection ) : ConeDiagnosticWithCandidates { override val reason: String get() = "Ambiguity: $name, ${candidateSymbols.map { describeSymbol(it) }}" override val candidateSymbols: Collection> get() = candidates.map { it.symbol } diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/inference/ConeTypeVariables.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/inference/ConeTypeVariables.kt new file mode 100644 index 00000000000..80cf58f27df --- /dev/null +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/inference/ConeTypeVariables.kt @@ -0,0 +1,18 @@ +/* + * 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.fir.resolve.inference + +import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction +import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol +import org.jetbrains.kotlin.fir.types.ConeTypeVariable + +class ConeTypeVariableForPostponedAtom(name: String) : ConeTypeVariable(name) +class ConeTypeVariableForLambdaParameterType(name: String, val index: Int) : ConeTypeVariable(name) +class ConeTypeVariableForLambdaReturnType(val argument: FirAnonymousFunction, name: String) : ConeTypeVariable(name) + +class ConeTypeParameterBasedTypeVariable( + val typeParameterSymbol: FirTypeParameterSymbol +) : ConeTypeVariable(typeParameterSymbol.name.identifier, typeParameterSymbol.toLookupTag()) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/model/FirConstraintPositionAndErrors.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/inference/model/FirConstraintPositionAndErrors.kt similarity index 100% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/model/FirConstraintPositionAndErrors.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/inference/model/FirConstraintPositionAndErrors.kt diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/transformers/ReturnTypeCalculator.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/transformers/ReturnTypeCalculator.kt new file mode 100644 index 00000000000..6ad4dcc7f49 --- /dev/null +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/transformers/ReturnTypeCalculator.kt @@ -0,0 +1,18 @@ +/* + * 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.fir.resolve.transformers + +import org.jetbrains.kotlin.fir.declarations.FirTypedDeclaration +import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol +import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef + +interface ReturnTypeCalculator { + fun tryCalculateReturnType(declaration: FirTypedDeclaration): FirResolvedTypeRef + + fun tryCalculateReturnType(symbol: FirCallableSymbol<*>): FirResolvedTypeRef { + return tryCalculateReturnType(symbol.fir) + } +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/ReturnTypeCalculator.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/transformers/ReturnTypeCalculatorForFullBodyResolve.kt similarity index 77% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/ReturnTypeCalculator.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/transformers/ReturnTypeCalculatorForFullBodyResolve.kt index da1faef1f77..d0010fb60f4 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/ReturnTypeCalculator.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/transformers/ReturnTypeCalculatorForFullBodyResolve.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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. */ @@ -10,18 +10,9 @@ import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind import org.jetbrains.kotlin.fir.render import org.jetbrains.kotlin.fir.scopes.FakeOverrideTypeCalculator -import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef -interface ReturnTypeCalculator { - fun tryCalculateReturnType(declaration: FirTypedDeclaration): FirResolvedTypeRef - - fun tryCalculateReturnType(symbol: FirCallableSymbol<*>): FirResolvedTypeRef { - return tryCalculateReturnType(symbol.fir) - } -} - class ReturnTypeCalculatorForFullBodyResolve : ReturnTypeCalculator { override fun tryCalculateReturnType(declaration: FirTypedDeclaration): FirResolvedTypeRef { val returnTypeRef = declaration.returnTypeRef diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/transformers/publishedApiEffectiveVisibility.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/transformers/publishedApiEffectiveVisibility.kt new file mode 100644 index 00000000000..d4d9faa2033 --- /dev/null +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/transformers/publishedApiEffectiveVisibility.kt @@ -0,0 +1,23 @@ +/* + * 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.fir.resolve.transformers + +import org.jetbrains.kotlin.descriptors.EffectiveVisibility +import org.jetbrains.kotlin.fir.declarations.FirDeclaration +import org.jetbrains.kotlin.fir.declarations.FirDeclarationDataKey +import org.jetbrains.kotlin.fir.declarations.FirDeclarationDataRegistry +import org.jetbrains.kotlin.fir.declarations.FirResolvePhase +import org.jetbrains.kotlin.fir.symbols.ensureResolved +import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol + +private object PublishedApiEffectiveVisibilityKey : FirDeclarationDataKey() +var FirDeclaration.publishedApiEffectiveVisibility: EffectiveVisibility? by FirDeclarationDataRegistry.data(PublishedApiEffectiveVisibilityKey) + +inline val FirCallableSymbol<*>.publishedApiEffectiveVisibility: EffectiveVisibility? + get() { + ensureResolved(FirResolvePhase.STATUS) + return fir.publishedApiEffectiveVisibility + } diff --git a/compiler/tests-common/build.gradle.kts b/compiler/tests-common/build.gradle.kts index ecb9528ba14..317c730e41d 100644 --- a/compiler/tests-common/build.gradle.kts +++ b/compiler/tests-common/build.gradle.kts @@ -23,6 +23,8 @@ dependencies { testApi(project(":compiler:fir:fir-deserialization")) testApi(project(":compiler:fir:cones")) testApi(project(":compiler:fir:resolve")) + testApi(project(":compiler:fir:providers")) + testApi(project(":compiler:fir:semantics")) testApi(project(":compiler:fir:checkers")) testApi(project(":compiler:fir:checkers:checkers.jvm")) testApi(project(":compiler:fir:java")) diff --git a/compiler/visualizer/render-fir/src/org/jetbrains/kotlin/compiler/visualizer/FirVisualizer.kt b/compiler/visualizer/render-fir/src/org/jetbrains/kotlin/compiler/visualizer/FirVisualizer.kt index 04fd490d1f8..c4cf1d21b61 100644 --- a/compiler/visualizer/render-fir/src/org/jetbrains/kotlin/compiler/visualizer/FirVisualizer.kt +++ b/compiler/visualizer/render-fir/src/org/jetbrains/kotlin/compiler/visualizer/FirVisualizer.kt @@ -17,7 +17,6 @@ import org.jetbrains.kotlin.fir.references.* import org.jetbrains.kotlin.fir.resolve.defaultType import org.jetbrains.kotlin.fir.resolve.fullyExpandedType import org.jetbrains.kotlin.fir.resolve.toFirRegularClassSymbol -import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.firUnsafe import org.jetbrains.kotlin.fir.scopes.impl.delegatedWrapperData import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.* @@ -477,7 +476,7 @@ class FirVisualizer(private val firFile: FirFile) : BaseRenderer() { private fun renderConstructorSymbol(symbol: FirConstructorSymbol, data: StringBuilder) { data.append("constructor ") data.append(getSymbolId(symbol)) - renderListInTriangles(symbol.firUnsafe().typeParameters, data) + renderListInTriangles(symbol.fir.typeParameters, data) } private fun renderField(field: FirField, data: StringBuilder) { @@ -698,7 +697,7 @@ class FirVisualizer(private val firFile: FirFile) : BaseRenderer() { is FirNamedFunctionSymbol -> { renderFunctionSymbol(symbol, data) - val fir = symbol.firUnsafe() + val fir = symbol.fir visitValueParameters(fir.valueParameters, data) data.append(": ") fir.returnTypeRef.accept(this, data) diff --git a/core/compiler.common/src/org/jetbrains/kotlin/contracts/description/EventOccurrencesRange.kt b/core/compiler.common/src/org/jetbrains/kotlin/contracts/description/EventOccurrencesRange.kt index a3f36f07425..26fc5fb64c2 100644 --- a/core/compiler.common/src/org/jetbrains/kotlin/contracts/description/EventOccurrencesRange.kt +++ b/core/compiler.common/src/org/jetbrains/kotlin/contracts/description/EventOccurrencesRange.kt @@ -48,3 +48,6 @@ fun EventOccurrencesRange.isDefinitelyVisited(): Boolean = fun EventOccurrencesRange.canBeRevisited(): Boolean = this == EventOccurrencesRange.UNKNOWN || this == EventOccurrencesRange.AT_LEAST_ONCE || this == EventOccurrencesRange.MORE_THAN_ONCE + +val EventOccurrencesRange?.isInPlace: Boolean + get() = this != null diff --git a/core/compiler.common/src/org/jetbrains/kotlin/name/StandardClassIds.kt b/core/compiler.common/src/org/jetbrains/kotlin/name/StandardClassIds.kt index 6c80398ce43..97846e9a268 100644 --- a/core/compiler.common/src/org/jetbrains/kotlin/name/StandardClassIds.kt +++ b/core/compiler.common/src/org/jetbrains/kotlin/name/StandardClassIds.kt @@ -191,6 +191,8 @@ object StandardClassIds { val coroutineContext = "coroutineContext".callableId(BASE_COROUTINES_PACKAGE) val clone = "clone".callableId(Cloneable) + + val not = "not".callableId(Boolean) } } diff --git a/plugins/fir/fir-plugin-prototype/build.gradle.kts b/plugins/fir/fir-plugin-prototype/build.gradle.kts index 3817a51a741..621af7d611a 100644 --- a/plugins/fir/fir-plugin-prototype/build.gradle.kts +++ b/plugins/fir/fir-plugin-prototype/build.gradle.kts @@ -6,15 +6,15 @@ plugins { } dependencies { - api(project(":compiler:fir:cones")) - api(project(":compiler:fir:tree")) - api(project(":compiler:fir:resolve")) - api(project(":compiler:fir:checkers")) - api(project(":compiler:fir:fir2ir")) - api(project(":compiler:ir.backend.common")) - api(project(":compiler:ir.tree.impl")) - api(intellijCoreDep()) { includeJars("intellij-core") } - + compileOnly(project(":compiler:fir:cones")) + compileOnly(project(":compiler:fir:tree")) + compileOnly(project(":compiler:fir:resolve")) + compileOnly(project(":compiler:fir:checkers")) + compileOnly(project(":compiler:fir:fir2ir")) + compileOnly(project(":compiler:ir.backend.common")) + compileOnly(project(":compiler:ir.tree.impl")) + compileOnly(project(":compiler:fir:entrypoint")) + compileOnly(intellijCoreDep()) { includeJars("intellij-core") } compileOnly(project(":kotlin-reflect-api")) testApiJUnit5() @@ -23,7 +23,6 @@ dependencies { testApi(projectTests(":compiler:test-infrastructure-utils")) testApi(project(":compiler:fir:checkers")) testApi(project(":compiler:fir:checkers:checkers.jvm")) - testApi(project(":compiler:frontend")) testCompileOnly(project(":kotlin-reflect-api")) testRuntimeOnly(project(":kotlin-reflect")) @@ -31,14 +30,14 @@ dependencies { testRuntimeOnly(project(":compiler:fir:fir-serialization")) testRuntimeOnly(intellijDep()) { - includeJars("jna", rootProject = rootProject) + includeJars( + "jna", + "jdom", + "trove4j", + "intellij-deps-fastutil-8.4.1-4", + rootProject = rootProject) } - testRuntimeOnly(intellijDep()) { includeJars( - "intellij-deps-fastutil-8.4.1-4", - "trove4j", - "jdom" - ) } testRuntimeOnly(toolsJar()) } diff --git a/settings.gradle b/settings.gradle index baa62e7f04b..99c0fb25e98 100644 --- a/settings.gradle +++ b/settings.gradle @@ -297,6 +297,8 @@ include ":compiler:fir", ":compiler:fir:raw-fir:light-tree2fir", ":compiler:fir:fir2ir", ":compiler:fir:fir2ir:jvm-backend", + ":compiler:fir:providers", + ":compiler:fir:semantics", ":compiler:fir:resolve", ":compiler:fir:fir-serialization", ":compiler:fir:fir-deserialization",