Skip to content

Commit

Permalink
rebase and fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim092001 committed Jan 7, 2023
1 parent 8f4d527 commit 210d584
Show file tree
Hide file tree
Showing 24 changed files with 42 additions and 95 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// FIR_DISABLE_LAZY_RESOLVE_CHECKS
import kotlin.Self

@Self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,16 @@

package org.jetbrains.kotlin.fir.resolve.calls

import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRefsOwner
import org.jetbrains.kotlin.fir.declarations.hasAnnotation
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.ConeTypeIntersector
import org.jetbrains.kotlin.fir.types.FirTypeProjection
import org.jetbrains.kotlin.fir.types.builder.buildPlaceholderProjection
import org.jetbrains.kotlin.fir.types.builder.buildTypeProjectionWithVariance
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.fir.types.builder.buildTypeProjectionWithVariance
import org.jetbrains.kotlin.fir.types.isRaw
import org.jetbrains.kotlin.fir.types.toFirResolvedTypeRef
import org.jetbrains.kotlin.types.Variance

sealed class TypeArgumentMapping {
abstract operator fun get(typeParameterIndex: Int): FirTypeProjection
Expand Down Expand Up @@ -86,7 +76,7 @@ internal object MapTypeArguments : ResolutionStage() {
if (classLikeSymbol != null) {
val firClassSymbol = classLikeSymbol as FirClassSymbol

val isSelf = firClassSymbol.hasAnnotation(StandardClassIds.Annotations.Self)
val isSelf = firClassSymbol.hasAnnotation(StandardClassIds.Annotations.Self, context.session)

if (isSelf && callInfo.callKind is CallKind.Function) {
val constructorTypeParametersSize = firConstructorSymbol.typeParameterSymbols.size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,32 @@ import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toPersistentList
import org.jetbrains.kotlin.KtFakeSourceElementKind
import org.jetbrains.kotlin.fakeElement
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.builder.FirTypeParameterBuilder
import org.jetbrains.kotlin.fir.declarations.utils.classId
import org.jetbrains.kotlin.fir.declarations.utils.expandedConeType
import org.jetbrains.kotlin.fir.declarations.utils.isCompanion
import org.jetbrains.kotlin.fir.declarations.utils.isData
import org.jetbrains.kotlin.fir.declarations.utils.superConeTypes
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
import org.jetbrains.kotlin.fir.expressions.FirStatement
import org.jetbrains.kotlin.fir.extensions.FirSupertypeGenerationExtension
import org.jetbrains.kotlin.fir.extensions.extensionService
import org.jetbrains.kotlin.fir.extensions.supertypeGenerators
import org.jetbrains.kotlin.fir.references.builder.buildResolvedNamedReference
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.providers.firProvider
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.LocalClassesNavigationInfo
import org.jetbrains.kotlin.fir.scopes.*
import org.jetbrains.kotlin.fir.scopes.FirScope
import org.jetbrains.kotlin.fir.scopes.createImportingScopes
import org.jetbrains.kotlin.fir.scopes.getNestedClassifierScope
import org.jetbrains.kotlin.fir.scopes.impl.FirMemberTypeParameterScope
import org.jetbrains.kotlin.fir.scopes.impl.FirSelfTypeScope
import org.jetbrains.kotlin.fir.scopes.impl.nestedClassifierScope
import org.jetbrains.kotlin.fir.scopes.impl.wrapNestedClassifierScopeWithSubstitutionForSuperType
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.fir.types.*
Expand All @@ -52,12 +46,10 @@ import org.jetbrains.kotlin.fir.types.impl.FirImplicitBuiltinTypeRef
import org.jetbrains.kotlin.fir.visitors.FirDefaultTransformer
import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitor
import org.jetbrains.kotlin.fir.visitors.FirTransformer
import org.jetbrains.kotlin.fir.visitors.transformSingle
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.types.model.TypeArgumentMarker
import org.jetbrains.kotlin.utils.addIfNotNull

Expand Down Expand Up @@ -382,7 +374,7 @@ open class FirSupertypeResolverVisitor(

@OptIn(PrivateForInline::class)
val resolvedTypesRefs = transformer.withFile(useSiteFile) {
addSelfToTypeParameters(classLikeDeclaration)
addSelfToTypeParameters(classLikeDeclaration, session)
val scopes = prepareScopes(classLikeDeclaration)
resolveSuperTypeRefs(
transformer,
Expand Down Expand Up @@ -456,8 +448,8 @@ open class FirSupertypeResolverVisitor(
}
}

private fun addSelfToTypeParameters(firClass: FirClassLikeDeclaration) {
val isSelf = firClass.getAnnotationByClassId(StandardClassIds.Annotations.Self) != null
private fun addSelfToTypeParameters(firClass: FirClassLikeDeclaration, session: FirSession) {
val isSelf = firClass.getAnnotationByClassId(StandardClassIds.Annotations.Self, session) != null
val params = firClass.typeParameters
if (params is MutableList && isSelf) {
val selfSymbol = FirTypeParameterSymbol()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ class BodyResolveContext(

val typeParameterScope = (owner as? FirRegularClass)?.typeParameterScope()
val selfTypeScope: FirSelfTypeScope? =
if (owner.hasAnnotation(StandardClassIds.Annotations.Self)) {
if (owner.hasAnnotation(StandardClassIds.Annotations.Self, holder.session)) {
FirSelfTypeScope(owner)
} else
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import org.jetbrains.kotlin.name.StandardClassIds.Annotations.Deprecated
import org.jetbrains.kotlin.name.StandardClassIds.Annotations.DeprecatedSinceKotlin
import org.jetbrains.kotlin.name.StandardClassIds.Annotations.JvmRecord
import org.jetbrains.kotlin.name.StandardClassIds.Annotations.WasExperimental
import org.jetbrains.kotlin.name.StandardClassIds.Annotations.Self
import org.jetbrains.kotlin.utils.addToStdlib.shouldNotBeCalled

internal abstract class AbstractFirSpecificAnnotationResolveTransformer(
Expand All @@ -48,7 +49,7 @@ internal abstract class AbstractFirSpecificAnnotationResolveTransformer(
protected val computationSession: CompilerRequiredAnnotationsComputationSession
) : FirDefaultTransformer<Nothing?>() {
companion object {
private val REQUIRED_ANNOTATIONS: Set<ClassId> = setOf(Deprecated, DeprecatedSinceKotlin, WasExperimental, JvmRecord)
private val REQUIRED_ANNOTATIONS: Set<ClassId> = setOf(Deprecated, DeprecatedSinceKotlin, WasExperimental, JvmRecord, Self)

private val REQUIRED_ANNOTATION_NAMES: Set<Name> = REQUIRED_ANNOTATIONS.mapTo(mutableSetOf()) { it.shortClassName }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import org.jetbrains.kotlin.name.StandardClassIds.Annotations.Deprecated
import org.jetbrains.kotlin.name.StandardClassIds.Annotations.DeprecatedSinceKotlin
import org.jetbrains.kotlin.name.StandardClassIds.Annotations.JvmRecord
import org.jetbrains.kotlin.name.StandardClassIds.Annotations.WasExperimental
import org.jetbrains.kotlin.name.StandardClassIds.Annotations.Self

class FirCompilerRequiredAnnotationsResolveProcessor(
session: FirSession,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ sealed class FirCallableDeclaration : FirMemberDeclaration() {

abstract override fun replaceResolvePhase(newResolvePhase: FirResolvePhase)

abstract override fun replaceTypeParameters(newTypeParameters: List<FirTypeParameterRef>)

abstract override fun replaceAnnotations(newAnnotations: List<FirAnnotation>)

abstract override fun replaceTypeParameters(newTypeParameters: List<FirTypeParameterRef>)

abstract fun replaceReturnTypeRef(newReturnTypeRef: FirTypeRef)

abstract fun replaceReceiverParameter(newReceiverParameter: FirReceiverParameter?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ sealed class FirClassLikeDeclaration : FirMemberDeclaration(), FirStatement {

abstract override fun replaceResolvePhase(newResolvePhase: FirResolvePhase)

abstract override fun replaceTypeParameters(newTypeParameters: List<FirTypeParameterRef>)

abstract override fun replaceAnnotations(newAnnotations: List<FirAnnotation>)

abstract override fun replaceTypeParameters(newTypeParameters: List<FirTypeParameterRef>)

abstract fun replaceDeprecationsProvider(newDeprecationsProvider: DeprecationsProvider)

abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirClassLikeDeclaration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ sealed class FirFunction : FirCallableDeclaration(), FirTargetElement, FirContro

abstract override fun replaceResolvePhase(newResolvePhase: FirResolvePhase)

abstract override fun replaceTypeParameters(newTypeParameters: List<FirTypeParameterRef>)

abstract override fun replaceAnnotations(newAnnotations: List<FirAnnotation>)

abstract override fun replaceTypeParameters(newTypeParameters: List<FirTypeParameterRef>)

abstract override fun replaceReturnTypeRef(newReturnTypeRef: FirTypeRef)

abstract override fun replaceReceiverParameter(newReceiverParameter: FirReceiverParameter?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ sealed class FirMemberDeclaration : FirDeclaration(), FirTypeParameterRefsOwner

abstract override fun replaceResolvePhase(newResolvePhase: FirResolvePhase)

abstract override fun replaceTypeParameters(newTypeParameters: List<FirTypeParameterRef>)

abstract override fun replaceAnnotations(newAnnotations: List<FirAnnotation>)

abstract override fun replaceTypeParameters(newTypeParameters: List<FirTypeParameterRef>)

abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirMemberDeclaration

abstract override fun <D> transformTypeParameters(transformer: FirTransformer<D>, data: D): FirMemberDeclaration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ open class FirBackingFieldImpl @FirImplementationDetail constructor(
initializer = newInitializer
}

override fun replaceAnnotations(newAnnotations: List<FirAnnotation>) {
annotations = newAnnotations.toMutableOrEmpty()
}

override fun replaceTypeParameters(newTypeParameters: List<FirTypeParameterRef>) {
require(newTypeParameters.all { it is FirTypeParameter })
typeParameters.clear()
typeParameters.addAll(newTypeParameters.map { it as FirTypeParameter })
}

override fun replaceAnnotations(newAnnotations: List<FirAnnotation>) {
annotations = newAnnotations.toMutableOrEmpty()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ open class FirPropertyAccessorImpl @FirImplementationDetail constructor(
contractDescription = newContractDescription
}

override fun replaceAnnotations(newAnnotations: List<FirAnnotation>) {
annotations = newAnnotations.toMutableOrEmpty()
}

override fun replaceTypeParameters(newTypeParameters: List<FirTypeParameterRef>) {
require(newTypeParameters.all { it is FirTypeParameter })
typeParameters.clear()
typeParameters.addAll(newTypeParameters.map { it as FirTypeParameter })
}

override fun replaceAnnotations(newAnnotations: List<FirAnnotation>) {
annotations = newAnnotations.toMutableOrEmpty()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ internal class FirSimpleFunctionImpl(
contractDescription = newContractDescription
}

override fun replaceAnnotations(newAnnotations: List<FirAnnotation>) {
annotations = newAnnotations.toMutableOrEmpty()
}

override fun replaceTypeParameters(newTypeParameters: List<FirTypeParameterRef>) {
require(newTypeParameters.all { it is FirTypeParameter })
typeParameters.clear()
typeParameters.addAll(newTypeParameters.map { it as FirTypeParameter })
}

override fun replaceAnnotations(newAnnotations: List<FirAnnotation>) {
annotations = newAnnotations.toMutableOrEmpty()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class FieldList(
override val name: String,
val baseType: Importable,
override var withReplace: Boolean,
override val overrideTypeRequire: Boolean,
override val overrideTypeRequire: Boolean = true,
useMutableOrEmpty: Boolean = false
) : Field() {
override var defaultValueInImplementation: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,16 @@ fun SmartPrinter.printImplementation(implementation: Implementation) {
println("${field.name}.addAll($newValue)")
}

else -> {
if (field.useNullableForReplace) {
println("require($newValue != null)")
}
print("${field.name} = $newValue")
if (field.origin is FieldList && field.isMutableOrEmpty) {
print(".toMutableOrEmpty()")
else -> {
if (field.useNullableForReplace) {
println("require($newValue != null)")
}
print("${field.name} = $newValue")
if (field.origin is FieldList && field.isMutableOrEmpty) {
print(".toMutableOrEmpty()")
}
println()
}
println()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND: JVM_IR

// WITH_STDLIB

Expand Down
1 change: 0 additions & 1 deletion compiler/testData/codegen/box/fir/selfTypeBuilderTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND: JVM_IR

// WITH_STDLIB

Expand Down
1 change: 0 additions & 1 deletion compiler/testData/codegen/box/fir/selfTypes.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND: JVM_IR

// WITH_STDLIB

Expand Down

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

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

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

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

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

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

0 comments on commit 210d584

Please sign in to comment.