diff --git a/build.gradle.kts b/build.gradle.kts index d0c3fccb66e..8f92d5e5e6f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -327,10 +327,6 @@ extra["tasksWithWarnings"] = listOf( ":kotlin-stdlib-jdk8:compileTestKotlin", ":compiler:cli:compileKotlin", ":compiler:frontend:compileKotlin", - ":compiler:fir:tree:compileKotlin", - ":compiler:fir:resolve:compileKotlin", - ":compiler:fir:checkers:compileKotlin", - ":compiler:fir:java:compileKotlin", ":kotlin-scripting-compiler:compileKotlin", ":plugins:uast-kotlin:compileKotlin", ":plugins:uast-kotlin:compileTestKotlin", diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/FirControlFlowAnalyzer.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/FirControlFlowAnalyzer.kt index 15a55601371..3ec3775b576 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/FirControlFlowAnalyzer.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/FirControlFlowAnalyzer.kt @@ -19,11 +19,14 @@ class FirControlFlowAnalyzer(session: FirSession) { private val cfaCheckers = session.checkersComponent.declarationCheckers.controlFlowAnalyserCheckers private val variableAssignmentCheckers = session.checkersComponent.declarationCheckers.variableAssignmentCfaBasedCheckers + // Currently declaration in analyzeXXX is not used, but it may be useful in future + @Suppress("UNUSED_PARAMETER") fun analyzeClassInitializer(klass: FirClass<*>, graph: ControlFlowGraph, context: CheckerContext, reporter: DiagnosticReporter) { if (graph.owner != null) return cfaCheckers.forEach { it.analyze(graph, reporter, context) } } + @Suppress("UNUSED_PARAMETER") fun analyzeFunction(function: FirFunction<*>, graph: ControlFlowGraph, context: CheckerContext, reporter: DiagnosticReporter) { if (graph.owner != null) return @@ -32,6 +35,7 @@ class FirControlFlowAnalyzer(session: FirSession) { runAssignmentCfaCheckers(graph, reporter, context) } + @Suppress("UNUSED_PARAMETER") fun analyzePropertyInitializer(property: FirProperty, graph: ControlFlowGraph, context: CheckerContext, reporter: DiagnosticReporter) { if (graph.owner != null) return @@ -39,6 +43,7 @@ class FirControlFlowAnalyzer(session: FirSession) { runAssignmentCfaCheckers(graph, reporter, context) } + @Suppress("UNUSED_PARAMETER") fun analyzePropertyAccessor( accessor: FirPropertyAccessor, graph: ControlFlowGraph, diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOverrideChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOverrideChecker.kt index 8302f1adc3a..401a0297724 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOverrideChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOverrideChecker.kt @@ -242,6 +242,7 @@ object FirOverrideChecker : FirRegularClassChecker() { } } + @Suppress("UNUSED_PARAMETER") // TODO: delete me after implementing body private fun DiagnosticReporter.reportNothingToOverride(declaration: FirMemberDeclaration, context: CheckerContext) { // TODO: not ready yet, e.g., Collections // reportOn(declaration.source, FirErrors.NOTHING_TO_OVERRIDE, declaration, context) diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/deserialization/JvmBinaryAnnotationDeserializer.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/deserialization/JvmBinaryAnnotationDeserializer.kt index f5be29cdc0a..d132752d9a5 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/deserialization/JvmBinaryAnnotationDeserializer.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/deserialization/JvmBinaryAnnotationDeserializer.kt @@ -11,8 +11,6 @@ import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.deserialization.AbstractAnnotationDeserializer import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.builder.buildAnnotationCall -import org.jetbrains.kotlin.fir.resolve.symbolProvider -import org.jetbrains.kotlin.fir.resolve.providers.impl.FirCompositeSymbolProvider import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass import org.jetbrains.kotlin.load.kotlin.MemberSignature @@ -52,7 +50,7 @@ class JvmBinaryAnnotationDeserializer( typeTable: TypeTable ): List { val signature = getCallableSignature(constructorProto, nameResolver, typeTable) ?: return emptyList() - return findJvmBinaryClassAndLoadMemberAnnotations(containerSource, signature) + return findJvmBinaryClassAndLoadMemberAnnotations(signature) } override fun loadFunctionAnnotations( @@ -62,7 +60,7 @@ class JvmBinaryAnnotationDeserializer( typeTable: TypeTable ): List { val signature = getCallableSignature(functionProto, nameResolver, typeTable) ?: return emptyList() - return findJvmBinaryClassAndLoadMemberAnnotations(containerSource, signature) + return findJvmBinaryClassAndLoadMemberAnnotations(signature) } override fun loadPropertyAnnotations( @@ -72,7 +70,7 @@ class JvmBinaryAnnotationDeserializer( typeTable: TypeTable ): List { val signature = getPropertySignature(propertyProto, nameResolver, typeTable, synthetic = true) ?: return emptyList() - return findJvmBinaryClassAndLoadMemberAnnotations(containerSource, signature).map { + return findJvmBinaryClassAndLoadMemberAnnotations(signature).map { buildAnnotationCall { annotationTypeRef = it.annotationTypeRef argumentList = it.argumentList @@ -95,7 +93,7 @@ class JvmBinaryAnnotationDeserializer( if (signature.isDelegated) { return emptyList() } - return findJvmBinaryClassAndLoadMemberAnnotations(containerSource, signature).map { + return findJvmBinaryClassAndLoadMemberAnnotations(signature).map { buildAnnotationCall { annotationTypeRef = it.annotationTypeRef argumentList = it.argumentList @@ -115,7 +113,7 @@ class JvmBinaryAnnotationDeserializer( if (!signature.isDelegated) { return emptyList() } - return findJvmBinaryClassAndLoadMemberAnnotations(containerSource, signature).map { + return findJvmBinaryClassAndLoadMemberAnnotations(signature).map { buildAnnotationCall { annotationTypeRef = it.annotationTypeRef argumentList = it.argumentList @@ -133,7 +131,7 @@ class JvmBinaryAnnotationDeserializer( getterFlags: Int ): List { val signature = getCallableSignature(propertyProto, nameResolver, typeTable, CallableKind.PROPERTY_GETTER) ?: return emptyList() - return findJvmBinaryClassAndLoadMemberAnnotations(containerSource, signature) + return findJvmBinaryClassAndLoadMemberAnnotations(signature) } override fun loadPropertySetterAnnotations( @@ -144,7 +142,7 @@ class JvmBinaryAnnotationDeserializer( setterFlags: Int ): List { val signature = getCallableSignature(propertyProto, nameResolver, typeTable, CallableKind.PROPERTY_SETTER) ?: return emptyList() - return findJvmBinaryClassAndLoadMemberAnnotations(containerSource, signature) + return findJvmBinaryClassAndLoadMemberAnnotations(signature) } override fun loadValueParameterAnnotations( @@ -160,7 +158,7 @@ class JvmBinaryAnnotationDeserializer( val methodSignature = getCallableSignature(callableProto, nameResolver, typeTable, kind) ?: return emptyList() val index = parameterIndex + computeJvmParameterIndexShift(classProto, callableProto) val paramSignature = MemberSignature.fromMethodSignatureAndParameterIndex(methodSignature, index) - return findJvmBinaryClassAndLoadMemberAnnotations(containerSource, paramSignature) + return findJvmBinaryClassAndLoadMemberAnnotations(paramSignature) } override fun loadExtensionReceiverParameterAnnotations( @@ -172,7 +170,7 @@ class JvmBinaryAnnotationDeserializer( ): List { val methodSignature = getCallableSignature(callableProto, nameResolver, typeTable, kind) ?: return emptyList() val paramSignature = MemberSignature.fromMethodSignatureAndParameterIndex(methodSignature, 0) - return findJvmBinaryClassAndLoadMemberAnnotations(containerSource, paramSignature) + return findJvmBinaryClassAndLoadMemberAnnotations(paramSignature) } private fun computeJvmParameterIndexShift(classProto: ProtoBuf.Class?, message: MessageLite): Int { @@ -255,7 +253,6 @@ class JvmBinaryAnnotationDeserializer( } private fun findJvmBinaryClassAndLoadMemberAnnotations( - containerSource: DeserializedContainerSource?, memberSignature: MemberSignature ): List { return annotationInfo.memberAnnotations[memberSignature] ?: emptyList() @@ -271,11 +268,11 @@ private fun FirSession.loadMemberAnnotations(kotlinBinaryClass: KotlinJvmBinaryC val annotationsLoader = AnnotationsLoader(this) kotlinBinaryClass.visitMembers(object : KotlinJvmBinaryClass.MemberVisitor { - override fun visitMethod(name: Name, desc: String): KotlinJvmBinaryClass.MethodAnnotationVisitor? { + override fun visitMethod(name: Name, desc: String): KotlinJvmBinaryClass.MethodAnnotationVisitor { return AnnotationVisitorForMethod(MemberSignature.fromMethodNameAndDesc(name.asString(), desc)) } - override fun visitField(name: Name, desc: String, initializer: Any?): KotlinJvmBinaryClass.AnnotationVisitor? { + override fun visitField(name: Name, desc: String, initializer: Any?): KotlinJvmBinaryClass.AnnotationVisitor { val signature = MemberSignature.fromFieldNameAndDesc(name.asString(), desc) if (initializer != null) { // TODO: load constant diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CreateFreshTypeVariableSubstitutorStage.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CreateFreshTypeVariableSubstitutorStage.kt index ae6f9936a89..d09517ee314 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CreateFreshTypeVariableSubstitutorStage.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CreateFreshTypeVariableSubstitutorStage.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.fir.resolve.calls -import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRef import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRefsOwner import org.jetbrains.kotlin.fir.renderWithType @@ -15,8 +14,8 @@ import org.jetbrains.kotlin.fir.resolve.inference.inferenceComponents import org.jetbrains.kotlin.fir.resolve.inference.model.ConeDeclaredUpperBoundConstraintPosition import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap +import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag import org.jetbrains.kotlin.fir.symbols.StandardClassIds -import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.impl.FirTypePlaceholderProjection import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation @@ -32,7 +31,7 @@ internal object CreateFreshTypeVariableSubstitutorStage : ResolutionStage() { } val csBuilder = candidate.system.getBuilder() val (substitutor, freshVariables) = - createToFreshVariableSubstitutorAndAddInitialConstraints(declaration, candidate, csBuilder, callInfo.session) + createToFreshVariableSubstitutorAndAddInitialConstraints(declaration, csBuilder) candidate.substitutor = substitutor candidate.freshVariables = freshVariables @@ -102,7 +101,7 @@ internal object CreateFreshTypeVariableSubstitutorStage : ResolutionStage() { return symbol.fir.bounds.any { val type = it.coneType type is ConeFlexibleType || with(context) { - (type.typeConstructor() as? FirTypeParameterSymbol)?.fir?.shouldBeFlexible(context) ?: false + (type.typeConstructor() as? ConeTypeParameterLookupTag)?.symbol?.fir?.shouldBeFlexible(context) ?: false } } } @@ -111,9 +110,7 @@ internal object CreateFreshTypeVariableSubstitutorStage : ResolutionStage() { private fun createToFreshVariableSubstitutorAndAddInitialConstraints( declaration: FirTypeParameterRefsOwner, - candidate: Candidate, - csBuilder: ConstraintSystemOperation, - session: FirSession + csBuilder: ConstraintSystemOperation ): Pair> { val typeParameters = declaration.typeParameters @@ -153,26 +150,5 @@ private fun createToFreshVariableSubstitutorAndAddInitialConstraints( } } -// if (candidateDescriptor is TypeAliasConstructorDescriptor) { -// val typeAliasDescriptor = candidateDescriptor.typeAliasDescriptor -// val originalTypes = typeAliasDescriptor.underlyingType.arguments.map { it.type } -// val originalTypeParameters = candidateDescriptor.underlyingConstructorDescriptor.typeParameters -// for (index in typeParameters.indices) { -// val typeParameter = typeParameters[index] -// val freshVariable = freshTypeVariables[index] -// val typeMapping = originalTypes.mapIndexedNotNull { i: Int, kotlinType: KotlinType -> -// if (kotlinType == typeParameter.defaultType) i else null -// } -// for (originalIndex in typeMapping) { -// // there can be null in case we already captured type parameter in outer class (in case of inner classes) -// // see test innerClassTypeAliasConstructor.kt -// val originalTypeParameter = originalTypeParameters.getOrNull(originalIndex) ?: continue -// val position = DeclaredUpperBoundConstraintPosition(originalTypeParameter) -// for (upperBound in originalTypeParameter.upperBounds) { -// freshVariable.addSubtypeConstraint(upperBound, position) -// } -// } -// } -// } return toFreshVariables to freshTypeVariables } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirBuilderInferenceSession.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirBuilderInferenceSession.kt index 2ac113e844a..24f1203dfa0 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirBuilderInferenceSession.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirBuilderInferenceSession.kt @@ -92,6 +92,7 @@ class FirBuilderInferenceSession( return !skipCall(call) } + @Suppress("UNUSED_PARAMETER") private fun skipCall(call: T): Boolean where T : FirResolvable, T : FirStatement { // TODO: what is FIR analog? // if (descriptor is FakeCallableDescriptorForObject) return true 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 ea7ebfaf344..e2f3f91a66d 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 @@ -198,15 +198,8 @@ fun ConeKotlinType.isKClassType(): Boolean { return classId == StandardClassIds.KClass } -fun ConeKotlinType.receiverType(expectedTypeRef: FirTypeRef?, session: FirSession): ConeKotlinType? { - if (isBuiltinFunctionalType(session) && isExtensionFunctionType(session)) { - return (this.fullyExpandedType(session).typeArguments.first() as ConeKotlinTypeProjection).type - } - return null -} - fun ConeKotlinType.receiverType(session: FirSession): ConeKotlinType? { - if (isBuiltinFunctionalType(session)) { + if (isBuiltinFunctionalType(session) && isExtensionFunctionType(session)) { return (this.fullyExpandedType(session).typeArguments.first() as ConeKotlinTypeProjection).type } return null @@ -250,7 +243,7 @@ fun extractLambdaInfoFromFunctionalType( } if (!expectedType.isBuiltinFunctionalType(session)) return null - val receiverType = argument.receiverType ?: expectedType.receiverType(expectedTypeRef, session) + val receiverType = argument.receiverType ?: expectedType.receiverType(session) val returnType = argument.returnType ?: expectedType.returnType(session) ?: return null val parameters = extractLambdaParameters(expectedType, argument, expectedType.isExtensionFunctionType(session), session) 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 93905dbcd98..cd46b7f931a 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 @@ -112,9 +112,9 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor if (property.isLocal) { prepareSignatureForBodyResolve(property) - property.transformStatus(this, property.resolveStatus(property.status).mode()) - property.getter?.let { it.transformStatus(this, it.resolveStatus(it.status).mode()) } - property.setter?.let { it.transformStatus(this, it.resolveStatus(it.status).mode()) } + property.transformStatus(this, property.resolveStatus().mode()) + property.getter?.let { it.transformStatus(this, it.resolveStatus().mode()) } + property.setter?.let { it.transformStatus(this, it.resolveStatus().mode()) } return transformLocalVariable(property) } @@ -367,7 +367,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor } } - private fun FirDeclaration.resolveStatus(status: FirDeclarationStatus, containingClass: FirClass<*>? = null): FirDeclarationStatus { + private fun FirDeclaration.resolveStatus(containingClass: FirClass<*>? = null): FirDeclarationStatus { val containingDeclaration = context.containerIfAny return statusResolver.resolveStatus( this, @@ -528,7 +528,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor if (containingDeclaration != null && containingDeclaration !is FirClass<*>) { // For class members everything should be already prepared prepareSignatureForBodyResolve(simpleFunction) - simpleFunction.transformStatus(this, simpleFunction.resolveStatus(simpleFunction.status).mode()) + simpleFunction.transformStatus(this, simpleFunction.resolveStatus().mode()) } withFullBodyResolve { diff --git a/compiler/fir/tree/build.gradle.kts b/compiler/fir/tree/build.gradle.kts index 8a6b4d3d1e1..a261ca6eb99 100644 --- a/compiler/fir/tree/build.gradle.kts +++ b/compiler/fir/tree/build.gradle.kts @@ -50,6 +50,12 @@ val compileKotlin by tasks compileKotlin.dependsOn(generateTree) +tasks.withType> { + kotlinOptions { + freeCompilerArgs += "-Xinline-classes" + } +} + if (kotlinBuildProperties.isInJpsBuildIdeaSync) { apply(plugin = "idea") idea { diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/caches/NullableMap.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/caches/NullableMap.kt index a94ccf03b4c..7dfbfb15654 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/caches/NullableMap.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/caches/NullableMap.kt @@ -33,4 +33,4 @@ internal inline class NullableMap(private val map: MutableMap