From 3b2bc49c4db75c8fe04f97e38277462c64f427d8 Mon Sep 17 00:00:00 2001 From: "Denis.Zharkov" Date: Wed, 9 Aug 2023 18:34:39 +0200 Subject: [PATCH] K2. Drop PostponedVariablesInitializerResolutionStage It would be unnecessary after PCLA approach would be implemented ^KT-59791 In progress --- .../kotlin/fir/resolve/calls/CallKind.kt | 4 -- .../fir/resolve/calls/ResolutionStages.kt | 53 ------------------- 2 files changed, 57 deletions(-) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallKind.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallKind.kt index ba95854842e..88dbaf006f3 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallKind.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallKind.kt @@ -19,7 +19,6 @@ sealed class CallKind(vararg resolutionSequence: ResolutionStage) { CheckContextReceivers, CheckDslScopeViolation, CheckLowPriorityInOverloadResolution, - PostponedVariablesInitializerResolutionStage, ProcessDynamicExtensionAnnotation, LowerPriorityIfDynamic, ConstraintSystemForks, @@ -55,7 +54,6 @@ sealed class CallKind(vararg resolutionSequence: ResolutionStage) { CheckCallModifiers, EagerResolveOfCallableReferences, CheckLowPriorityInOverloadResolution, - PostponedVariablesInitializerResolutionStage, ProcessDynamicExtensionAnnotation, LowerPriorityIfDynamic, ConstraintSystemForks, @@ -126,7 +124,6 @@ class ResolutionSequenceBuilder( var checkExtensionReceiver: Boolean = false, var checkArguments: Boolean = false, var checkLowPriorityInOverloadResolution: Boolean = false, - var initializePostponedVariables: Boolean = false, var mapTypeArguments: Boolean = false, var resolveCallableReferenceArguments: Boolean = false, var checkCallableReferenceExpectedType: Boolean = false, @@ -146,7 +143,6 @@ class ResolutionSequenceBuilder( if (checkContextReceivers) add(CheckContextReceivers) if (resolveCallableReferenceArguments) add(EagerResolveOfCallableReferences) if (checkLowPriorityInOverloadResolution) add(CheckLowPriorityInOverloadResolution) - if (initializePostponedVariables) add(PostponedVariablesInitializerResolutionStage) if (checkCallableReferenceExpectedType) add(CheckCallableReferenceExpectedType) }.toTypedArray() return CallKind.CustomForIde(*stages) 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 28746f0abf7..090769996a4 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 @@ -695,59 +695,6 @@ internal object CheckIncompatibleTypeVariableUpperBounds : ResolutionStage() { } } -internal object PostponedVariablesInitializerResolutionStage : ResolutionStage() { - override suspend fun check(candidate: Candidate, callInfo: CallInfo, sink: CheckerSink, context: ResolutionContext) { - val argumentMapping = candidate.argumentMapping ?: return - if (candidate.typeArgumentMapping is TypeArgumentMapping.Mapped) return - - val atomsToMark = mutableSetOf() - - for ((argument, parameter) in argumentMapping) { - if (!parameter.hasBuilderInferenceAnnotation(context.session)) continue - val unwrapped = argument.unwrapArgument() - if (unwrapped is FirAnonymousFunctionExpression) { - atomsToMark.add(unwrapped.anonymousFunction) - } - - // TODO (KT-63958): This is effectively dead-code, since UseBuilderInferenceOnlyIfNeeded is always enabled - val type = parameter.returnTypeRef.coneType - val receiverType = type.receiverType(callInfo.session) ?: continue - val dontUseBuilderInferenceIfPossible = - context.session.languageVersionSettings.supportsFeature(LanguageFeature.UseBuilderInferenceOnlyIfNeeded) - if (dontUseBuilderInferenceIfPossible) continue - - for (freshVariable in candidate.freshVariables) { - if (candidate.csBuilder.isPostponedTypeVariable(freshVariable)) continue - if (freshVariable !is ConeTypeParameterBasedTypeVariable) continue - val typeParameterSymbol = freshVariable.typeParameterSymbol - val typeHasVariable = receiverType.contains { - (it as? ConeTypeParameterType)?.lookupTag?.typeParameterSymbol == typeParameterSymbol - } - if (typeHasVariable) { - candidate.csBuilder.markPostponedVariable(freshVariable) - } - } - } - - candidate.postponedAtoms.forEach { postponedAtomContainer -> - when (postponedAtomContainer) { - is ResolvedLambdaAtom -> { - if (postponedAtomContainer.atom in atomsToMark) { - postponedAtomContainer.isCorrespondingParameterAnnotatedWithBuilderInference = true - } - } - is LambdaWithTypeVariableAsExpectedTypeAtom -> { - // Although, one may annotate fun foo(@BuilderInference t: T) - // it makes little sense - } - is ResolvedCallableReferenceAtom -> { - // Builder inference doesn't apply to such atoms. - } - } - } - } -} - internal object CheckCallModifiers : CheckerStage() { override suspend fun check(candidate: Candidate, callInfo: CallInfo, sink: CheckerSink, context: ResolutionContext) { if (callInfo.callSite is FirFunctionCall) {