From 5937ffae4d52e6fbc0c133fa00c24e90603fe0c9 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Thu, 24 Sep 2020 23:28:48 +0300 Subject: [PATCH] FIR: optimize checking if placeholder projection for raw FIR builder --- .../jetbrains/kotlin/fir/builder/RawFirBuilder.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index 92cdfe7579d..02d780e999a 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.builder import com.intellij.psi.PsiElement import com.intellij.psi.tree.IElementType +import org.jetbrains.kotlin.KtNodeTypes import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Visibilities @@ -558,7 +559,7 @@ class RawFirBuilder( } ) container.declarations.add(delegateField) - delegateNumber ++ + delegateNumber++ } } } @@ -816,7 +817,7 @@ class RawFirBuilder( ) val primaryConstructor = classOrObject.primaryConstructor - val firPrimaryConstructor = declarations.firstOrNull {it is FirConstructor} as? FirConstructor + val firPrimaryConstructor = declarations.firstOrNull { it is FirConstructor } as? FirConstructor if (primaryConstructor != null && firPrimaryConstructor != null) { primaryConstructor.valueParameters.zip( firPrimaryConstructor.valueParameters @@ -1006,7 +1007,7 @@ class RawFirBuilder( } private fun KtDeclarationWithBody.obtainContractDescription(): FirContractDescription? { - return when(val description = contractDescription) { + return when (val description = contractDescription) { null -> null else -> buildRawContractDescription { source = description.toFirSourceElement() @@ -1386,6 +1387,10 @@ class RawFirBuilder( } } + // TODO introduce placeholder projection type + private fun KtTypeProjection.isPlaceholderProjection() = + projectionKind == KtProjectionKind.NONE && (typeReference?.typeElement as? KtUserType)?.referencedName == "_" + override fun visitTypeProjection(typeProjection: KtTypeProjection, data: Unit): FirElement { val projectionKind = typeProjection.projectionKind val projectionSource = typeProjection.toFirSourceElement() @@ -1394,7 +1399,7 @@ class RawFirBuilder( source = projectionSource } } - if (projectionKind == KtProjectionKind.NONE && !stubMode && typeProjection.text == "_") { + if (typeProjection.isPlaceholderProjection()) { return FirTypePlaceholderProjection } val typeReference = typeProjection.typeReference