Skip to content

Commit

Permalink
Merge branch 'master' into autogen-ir-tree
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpiroman committed Oct 16, 2021
2 parents 0a1e3cc + 6b45396 commit b4dae8d
Show file tree
Hide file tree
Showing 5,463 changed files with 72,802 additions and 37,814 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
6 changes: 6 additions & 0 deletions .idea/artifacts/kotlin_test_wasm_js_1_6_255_SNAPSHOT.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/dictionaries/svyatoslav_kuzmich.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/kotlinTestDataPluginTestDataPaths.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ In the import dialog, select `use default gradle wrapper`.

To be able to run tests from IntelliJ easily, check `Delegate IDE build/run actions to Gradle` and choose `Gradle Test Runner` in the Gradle runner settings after importing the project.

At this time, you can use the latest released `1.3.x` version of the Kotlin plugin for working with the code. To make sure you have the latest version installed, use `Tools` -> `Kotlin` -> `Configure Kotlin Plugin Updates`.
At this time, you can use the latest released `1.6.x` version of the Kotlin plugin for working with the code. To make sure you have the latest version installed, use `Tools` -> `Kotlin` -> `Configure Kotlin Plugin Updates`.

For handy work with compiler tests it's recommended to use [
Kotlin Compiler Test Helper](https://plugins.jetbrains.com/plugin/17620-kotlin-compiler-test-helper)

### Dependency verification

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.lexer.KtKeywordToken
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtExpression
Expand Down Expand Up @@ -340,6 +341,7 @@ private object FirToKtConversionCreator {
FirModuleData::class,
ExpectActualCompatibility.Incompatible::class,
DeprecationInfo::class,
CallableId::class
)

private val KType.kClass: KClass<*>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ object FirIdeDeserializedDeclarationSourceProvider {
is FirClass -> provideSourceForClass(fir, project)
is FirTypeAlias -> provideSourceForTypeAlias(fir, project)
is FirConstructor -> provideSourceForConstructor(fir, project)
is FirEnumEntry -> provideSourceForEnumEntry(fir, project)
else -> null
}
}
Expand Down Expand Up @@ -97,6 +98,17 @@ object FirIdeDeserializedDeclarationSourceProvider {
return null
}

private fun provideSourceForEnumEntry(
enumEntry: FirEnumEntry,
project: Project
): PsiElement? {
val candidates = enumEntry.containingKtClass(project)?.body?.enumEntries
?.filter { it.name == enumEntry.name.asString() }
.orEmpty()

return candidates.firstOrNull(KtElement::isCompiled)
}

private fun FirDeclaration.scope(project: Project): GlobalSearchScope {
return GlobalSearchScope.allScope(project)
/* TODO:
Expand Down Expand Up @@ -125,6 +137,7 @@ object FirIdeDeserializedDeclarationSourceProvider {
private fun KtElement.isCompiled(): Boolean = containingKtFile.isCompiled

private val allowedFakeElementKinds = setOf(
FirFakeSourceElementKind.FromUseSiteTarget,
FirFakeSourceElementKind.PropertyFromParameter,
FirFakeSourceElementKind.ItLambdaParameter,
FirFakeSourceElementKind.DataClassGeneratedMembers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ internal fun FirNamedReference.getCandidateSymbols(): Collection<FirBasedSymbol<

internal fun ConeDiagnostic.getCandidateSymbols(): Collection<FirBasedSymbol<*>> =
when (this) {
is ConeHiddenCandidateError -> {
// Candidate with @Deprecated(DeprecationLevel.HIDDEN)
emptyList()
}
is ConeDiagnosticWithCandidates -> candidateSymbols
else -> emptyList()
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirClassifierSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirClassInitializerSymbol
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.types.Variance
Expand Down Expand Up @@ -68,6 +69,7 @@ internal class KtSymbolByFirBuilder private constructor(
val functionLikeBuilder = FunctionLikeSymbolBuilder()
val variableLikeBuilder = VariableLikeSymbolBuilder()
val callableBuilder = CallableSymbolBuilder()
val anonymousInitializerBuilder = AnonymousInitializerBuilder()
val typeBuilder = TypeBuilder()

constructor(
Expand Down Expand Up @@ -337,6 +339,12 @@ internal class KtSymbolByFirBuilder private constructor(
}
}

inner class AnonymousInitializerBuilder {
fun buildClassInitializer(fir: FirAnonymousInitializer): KtClassInitializerSymbol {
return symbolsCache.cache(fir) { KtFirClassInitializerSymbol(fir, resolveState, token) }
}
}

inner class TypeBuilder {
fun buildKtType(coneType: ConeKotlinType): KtType {
return typesCache.cache(coneType) {
Expand All @@ -351,6 +359,7 @@ internal class KtSymbolByFirBuilder private constructor(
is ConeIntersectionType -> KtFirIntersectionType(coneType, token, this@KtSymbolByFirBuilder)
is ConeDefinitelyNotNullType -> KtFirDefinitelyNotNullType(coneType, token, this@KtSymbolByFirBuilder)
is ConeCapturedType -> KtFirCapturedType(coneType, token)
is ConeIntegerLiteralType -> KtFirIntegerLiteralType(coneType, token, this@KtSymbolByFirBuilder)
else -> throwUnexpectedElementError(coneType)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,32 @@

package org.jetbrains.kotlin.analysis.api.fir.components

import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnostic
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirPsiDiagnostic
import org.jetbrains.kotlin.fir.analysis.diagnostics.toFirDiagnostics
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
import org.jetbrains.kotlin.fir.typeContext
import org.jetbrains.kotlin.fir.types.ConeInferenceContext
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.ConeStarProjection
import org.jetbrains.kotlin.fir.types.ConeTypeProjection
import org.jetbrains.kotlin.analysis.api.KtStarProjectionTypeArgument
import org.jetbrains.kotlin.analysis.api.KtTypeArgument
import org.jetbrains.kotlin.analysis.api.KtTypeArgumentWithVariance
import org.jetbrains.kotlin.analysis.api.diagnostics.KtDiagnosticWithPsi
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KT_DIAGNOSTIC_CONVERTER
import org.jetbrains.kotlin.analysis.api.fir.types.KtFirType
import org.jetbrains.kotlin.analysis.api.types.KtSubstitutor
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnostic
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirPsiDiagnostic
import org.jetbrains.kotlin.fir.analysis.diagnostics.toFirDiagnostics
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
import org.jetbrains.kotlin.fir.typeContext
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.types.TypeCheckerState
import org.jetbrains.kotlin.types.model.convertVariance
import org.jetbrains.kotlin.utils.addToStdlib.safeAs

internal interface KtFirAnalysisSessionComponent {
val analysisSession: KtFirAnalysisSession
Expand Down Expand Up @@ -67,6 +72,30 @@ internal interface KtFirAnalysisSessionComponent {

fun createTypeCheckerContext(): TypeCheckerState {
// TODO use correct session here,
return analysisSession.firResolveState.rootModuleSession.typeContext.newTypeCheckerState(errorTypesEqualToAnything = true, stubTypesEqualToAnything = true)
return analysisSession.firResolveState.rootModuleSession.typeContext.newTypeCheckerState(
errorTypesEqualToAnything = true,
stubTypesEqualToAnything = true
)
}

fun FirQualifiedAccessExpression.createSubstitutorFromTypeArguments(): KtSubstitutor? {
val symbol = when (val calleeReference = calleeReference) {
is FirResolvedNamedReference -> calleeReference.resolvedSymbol as? FirCallableSymbol<*>
is FirErrorNamedReference -> calleeReference.candidateSymbol as? FirCallableSymbol<*>
else -> null
} ?: return null
return createSubstitutorFromTypeArguments(symbol)
}

fun FirQualifiedAccessExpression.createSubstitutorFromTypeArguments(functionSymbol: FirCallableSymbol<*>): KtSubstitutor {
val typeArgumentMap = mutableMapOf<FirTypeParameterSymbol, ConeKotlinType>()
for (i in typeArguments.indices) {
val type = typeArguments[i].safeAs<FirTypeProjectionWithVariance>()?.typeRef?.coneType
if (type != null) {
typeArgumentMap[functionSymbol.typeParameterSymbols[i]] = type
}
}
val coneSubstitutor = substitutorByMap(typeArgumentMap, rootModuleSession)
return firSymbolBuilder.typeBuilder.buildSubstitutor(coneSubstitutor)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ import org.jetbrains.kotlin.fir.references.FirSuperReference
import org.jetbrains.kotlin.fir.references.impl.FirSimpleNamedReference
import org.jetbrains.kotlin.fir.resolve.calls.FirErrorReferenceWithCandidate
import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.idea.references.FirReferenceResolveHelper
import org.jetbrains.kotlin.idea.references.readWriteAccess
import org.jetbrains.kotlin.idea.references.readWriteAccessWithFullExpressionWithPossibleResolve
import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.findAssignment
Expand All @@ -61,7 +59,11 @@ internal class KtFirCallResolver(
when (val fir = call.getOrBuildFir(firResolveState)) {
is FirResolvedNamedReference -> {
val propertySymbol = fir.resolvedSymbol as? FirPropertySymbol ?: return null
val access = call.readWriteAccess(useResolveForReadWrite = false)

@Suppress("DEPRECATION")
val access =
call.readWriteAccessWithFullExpressionWithPossibleResolve(readWriteAccessWithFullExpressionByResolve = { null }).first

val setterValue = findAssignment(call)?.right
val accessor = when {
access.isWrite -> propertySymbol.setterSymbol?.fir
Expand Down Expand Up @@ -226,26 +228,8 @@ internal class KtFirCallResolver(
}

private fun FirFunctionCall.asSimpleFunctionCall(): KtFunctionCall? {
val calleeReference = this.calleeReference
val target = calleeReference.createCallTarget() ?: return null
val symbol = when (calleeReference) {
is FirResolvedNamedReference -> calleeReference.resolvedSymbol as? FirCallableSymbol<*>
is FirErrorNamedReference -> calleeReference.candidateSymbol as? FirCallableSymbol<*>
else -> null
} ?: return null
return KtFunctionCall(createArgumentMapping(), target, createSubstitutorFromTypeArguments(symbol), token)
}

private fun FirFunctionCall.createSubstitutorFromTypeArguments(functionSymbol: FirCallableSymbol<*>): KtSubstitutor {
val typeArgumentMap = mutableMapOf<FirTypeParameterSymbol, ConeKotlinType>()
for (i in typeArguments.indices) {
val type = typeArguments[i].safeAs<FirTypeProjectionWithVariance>()?.typeRef?.coneType
if (type != null) {
typeArgumentMap[functionSymbol.typeParameterSymbols[i]] = type
}
}
val coneSubstitutor = substitutorByMap(typeArgumentMap, rootModuleSession)
return firSymbolBuilder.typeBuilder.buildSubstitutor(coneSubstitutor)
val target = this.calleeReference.createCallTarget() ?: return null
return KtFunctionCall(createArgumentMapping(), target, createSubstitutorFromTypeArguments() ?: return null, token)
}

private fun FirAnnotationCall.asAnnotationCall(): KtAnnotationCall? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.analysis.api.fir.evaluate.KtFirConstantValueConverte
import org.jetbrains.kotlin.analysis.api.symbols.markers.*
import org.jetbrains.kotlin.analysis.api.tokens.ValidityToken
import org.jetbrains.kotlin.analysis.api.withValidityAssertion
import org.jetbrains.kotlin.fir.expressions.FirWhenBranch
import org.jetbrains.kotlin.psi.KtExpression

internal class KtFirCompileTimeConstantProvider(
Expand All @@ -28,6 +29,15 @@ internal class KtFirCompileTimeConstantProvider(
FirCompileTimeConstantEvaluator.evaluate(fir)?.let { KtFirConstantValueConverter.toConstantValue(it) }
?: KtFirConstantValueConverter.toConstantValue(fir, firResolveState.rootModuleSession)
}
// For invalid code like the following,
// ```
// when {
// true, false -> {}
// }
// ```
// `false` does not have a corresponding elements on the FIR side and hence the containing `FirWhenBranch` is returned. In this
// case, we simply report null since FIR does not know about it.
is FirWhenBranch -> null
else -> throwUnexpectedFirElementError(fir, expression)
}
}
Expand Down
Loading

0 comments on commit b4dae8d

Please sign in to comment.