[FIR] Split cone types declarations into multiple files

This commit is contained in:
Dmitriy Novozhilov
2022-01-28 14:34:00 +03:00
committed by teamcity
parent 84913772ec
commit 9c6292db6f
4 changed files with 234 additions and 206 deletions
@@ -0,0 +1,41 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.types
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
abstract class ConeIntegerLiteralType(
val value: Long,
val isUnsigned: Boolean,
override val nullability: ConeNullability
) : ConeSimpleKotlinType(), TypeConstructorMarker {
abstract val possibleTypes: Collection<ConeClassLikeType>
abstract val supertypes: List<ConeClassLikeType>
override val typeArguments: Array<out ConeTypeProjection> = emptyArray()
abstract fun getApproximatedType(expectedType: ConeKotlinType? = null): ConeClassLikeType
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as ConeIntegerLiteralType
if (possibleTypes != other.possibleTypes) return false
if (nullability != other.nullability) return false
return true
}
override fun hashCode(): Int {
return 31 * possibleTypes.hashCode() + nullability.hashCode()
}
}
fun ConeIntegerLiteralType.canBeInt(): Boolean {
return value in Int.MIN_VALUE..Int.MAX_VALUE
}
@@ -0,0 +1,68 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.types
import org.jetbrains.kotlin.types.model.TypeArgumentMarker
enum class ProjectionKind {
STAR, IN, OUT, INVARIANT;
}
sealed class ConeTypeProjection : TypeArgumentMarker {
abstract val kind: ProjectionKind
companion object {
val EMPTY_ARRAY = arrayOf<ConeTypeProjection>()
}
}
object ConeStarProjection : ConeTypeProjection() {
override val kind: ProjectionKind
get() = ProjectionKind.STAR
}
sealed class ConeKotlinTypeProjection : ConeTypeProjection() {
abstract val type: ConeKotlinType
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is ConeKotlinTypeProjection) return false
if (kind != other.kind) return false
if (type != other.type) return false
return true
}
override fun hashCode(): Int {
return type.hashCode() * 31 + kind.hashCode()
}
}
data class ConeKotlinTypeProjectionIn(override val type: ConeKotlinType) : ConeKotlinTypeProjection() {
override val kind: ProjectionKind
get() = ProjectionKind.IN
}
data class ConeKotlinTypeProjectionOut(override val type: ConeKotlinType) : ConeKotlinTypeProjection() {
override val kind: ProjectionKind
get() = ProjectionKind.OUT
}
data class ConeKotlinTypeConflictingProjection(override val type: ConeKotlinType) : ConeKotlinTypeProjection() {
override val kind: ProjectionKind
get() = ProjectionKind.INVARIANT
}
val ConeTypeProjection.type: ConeKotlinType?
get() = when (this) {
ConeStarProjection -> null
is ConeKotlinTypeProjection -> type
is ConeKotlinType -> this
}
val ConeTypeProjection.isStarProjection: Boolean
get() = this == ConeStarProjection
@@ -0,0 +1,125 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.types
import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTag
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.model.*
// ----------------------------------- Type variable type -----------------------------------
class ConeTypeVariableType(
override val nullability: ConeNullability,
override val lookupTag: ConeTypeVariableTypeConstructor,
override val attributes: ConeAttributes = ConeAttributes.Empty,
) : ConeLookupTagBasedType() {
override val typeArguments: Array<out ConeTypeProjection> get() = emptyArray()
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is ConeTypeVariableType) return false
if (nullability != other.nullability) return false
if (lookupTag != other.lookupTag) return false
return true
}
override fun hashCode(): Int {
var result = 0
result = 31 * result + nullability.hashCode()
result = 31 * result + lookupTag.hashCode()
return result
}
}
class ConeTypeVariableTypeConstructor(
val debugName: String,
val originalTypeParameter: TypeParameterMarker?
) : ConeClassifierLookupTag(), TypeVariableTypeConstructorMarker {
override val name: Name get() = Name.identifier(debugName)
var isContainedInInvariantOrContravariantPositions: Boolean = false
private set
fun recordInfoAboutTypeVariableUsagesAsInvariantOrContravariantParameter() {
isContainedInInvariantOrContravariantPositions = true
}
}
// ----------------------------------- Stub types -----------------------------------
data class ConeStubTypeConstructor(
val variable: ConeTypeVariable,
val isTypeVariableInSubtyping: Boolean,
val isForFixation: Boolean = false,
) : TypeConstructorMarker
sealed class ConeStubType(val constructor: ConeStubTypeConstructor, override val nullability: ConeNullability) : StubTypeMarker,
ConeSimpleKotlinType() {
override val typeArguments: Array<out ConeTypeProjection>
get() = emptyArray()
override val attributes: ConeAttributes
get() = ConeAttributes.Empty
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as ConeStubType
if (constructor != other.constructor) return false
if (nullability != other.nullability) return false
return true
}
override fun hashCode(): Int {
var result = 0
result = 31 * result + constructor.hashCode()
result = 31 * result + nullability.hashCode()
return result
}
}
open class ConeStubTypeForChainInference(
constructor: ConeStubTypeConstructor,
nullability: ConeNullability
) : ConeStubType(constructor, nullability) {
constructor(variable: ConeTypeVariable, nullability: ConeNullability) : this(
ConeStubTypeConstructor(
variable,
isTypeVariableInSubtyping = false
), nullability
)
}
class ConeStubTypeForSyntheticFixation(
constructor: ConeStubTypeConstructor,
nullability: ConeNullability
) : ConeStubTypeForChainInference(constructor, nullability)
class ConeStubTypeForTypeVariableInSubtyping(
constructor: ConeStubTypeConstructor,
nullability: ConeNullability
) : ConeStubType(constructor, nullability) {
constructor(variable: ConeTypeVariable, nullability: ConeNullability) : this(
ConeStubTypeConstructor(
variable,
isTypeVariableInSubtyping = true
), nullability
)
}
open class ConeTypeVariable(name: String, originalTypeParameter: TypeParameterMarker? = null) : TypeVariableMarker {
val typeConstructor = ConeTypeVariableTypeConstructor(name, originalTypeParameter)
val defaultType = ConeTypeVariableType(ConeNullability.NOT_NULL, typeConstructor)
override fun toString(): String {
return defaultType.toString()
}
}
@@ -9,70 +9,9 @@ import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTag
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.model.*
import org.jetbrains.kotlin.utils.addToStdlib.foldMap
enum class ProjectionKind {
STAR, IN, OUT, INVARIANT;
}
sealed class ConeTypeProjection : TypeArgumentMarker {
abstract val kind: ProjectionKind
companion object {
val EMPTY_ARRAY = arrayOf<ConeTypeProjection>()
}
}
object ConeStarProjection : ConeTypeProjection() {
override val kind: ProjectionKind
get() = ProjectionKind.STAR
}
sealed class ConeKotlinTypeProjection : ConeTypeProjection() {
abstract val type: ConeKotlinType
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is ConeKotlinTypeProjection) return false
if (kind != other.kind) return false
if (type != other.type) return false
return true
}
override fun hashCode(): Int {
return type.hashCode() * 31 + kind.hashCode()
}
}
data class ConeKotlinTypeProjectionIn(override val type: ConeKotlinType) : ConeKotlinTypeProjection() {
override val kind: ProjectionKind
get() = ProjectionKind.IN
}
data class ConeKotlinTypeProjectionOut(override val type: ConeKotlinType) : ConeKotlinTypeProjection() {
override val kind: ProjectionKind
get() = ProjectionKind.OUT
}
data class ConeKotlinTypeConflictingProjection(override val type: ConeKotlinType) : ConeKotlinTypeProjection() {
override val kind: ProjectionKind
get() = ProjectionKind.INVARIANT
}
val ConeTypeProjection.type: ConeKotlinType?
get() = when (this) {
ConeStarProjection -> null
is ConeKotlinTypeProjection -> type
is ConeKotlinType -> this
}
val ConeTypeProjection.isStarProjection: Boolean
get() = this == ConeStarProjection
// We assume type IS an invariant type projection to prevent additional wrapper here
// (more exactly, invariant type projection contains type)
sealed class ConeKotlinType : ConeKotlinTypeProjection(), KotlinTypeMarker, TypeArgumentListMarker {
@@ -237,31 +176,6 @@ data class ConeCapturedType(
}
}
class ConeTypeVariableType(
override val nullability: ConeNullability,
override val lookupTag: ConeTypeVariableTypeConstructor,
override val attributes: ConeAttributes = ConeAttributes.Empty,
) : ConeLookupTagBasedType() {
override val typeArguments: Array<out ConeTypeProjection> get() = emptyArray()
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is ConeTypeVariableType) return false
if (nullability != other.nullability) return false
if (lookupTag != other.lookupTag) return false
return true
}
override fun hashCode(): Int {
var result = 0
result = 31 * result + nullability.hashCode()
result = 31 * result + lookupTag.hashCode()
return result
}
}
data class ConeDefinitelyNotNullType(val original: ConeSimpleKotlinType) : ConeSimpleKotlinType(), DefinitelyNotNullTypeMarker {
override val typeArguments: Array<out ConeTypeProjection>
@@ -328,123 +242,3 @@ fun ConeIntersectionType.withAlternative(alternativeType: ConeKotlinType): ConeI
fun ConeIntersectionType.mapTypes(func: (ConeKotlinType) -> ConeKotlinType): ConeIntersectionType {
return ConeIntersectionType(intersectedTypes.map(func), alternativeType?.let(func))
}
data class ConeStubTypeConstructor(
val variable: ConeTypeVariable,
val isTypeVariableInSubtyping: Boolean,
val isForFixation: Boolean = false,
) : TypeConstructorMarker
sealed class ConeStubType(val constructor: ConeStubTypeConstructor, override val nullability: ConeNullability) : StubTypeMarker,
ConeSimpleKotlinType() {
override val typeArguments: Array<out ConeTypeProjection>
get() = emptyArray()
override val attributes: ConeAttributes
get() = ConeAttributes.Empty
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as ConeStubType
if (constructor != other.constructor) return false
if (nullability != other.nullability) return false
return true
}
override fun hashCode(): Int {
var result = 0
result = 31 * result + constructor.hashCode()
result = 31 * result + nullability.hashCode()
return result
}
}
open class ConeStubTypeForChainInference(
constructor: ConeStubTypeConstructor,
nullability: ConeNullability
) : ConeStubType(constructor, nullability) {
constructor(variable: ConeTypeVariable, nullability: ConeNullability) : this(
ConeStubTypeConstructor(
variable,
isTypeVariableInSubtyping = false
), nullability
)
}
class ConeStubTypeForSyntheticFixation(
constructor: ConeStubTypeConstructor,
nullability: ConeNullability
) : ConeStubTypeForChainInference(constructor, nullability)
class ConeStubTypeForTypeVariableInSubtyping(
constructor: ConeStubTypeConstructor,
nullability: ConeNullability
) : ConeStubType(constructor, nullability) {
constructor(variable: ConeTypeVariable, nullability: ConeNullability) : this(
ConeStubTypeConstructor(
variable,
isTypeVariableInSubtyping = true
), nullability
)
}
open class ConeTypeVariable(name: String, originalTypeParameter: TypeParameterMarker? = null) : TypeVariableMarker {
val typeConstructor = ConeTypeVariableTypeConstructor(name, originalTypeParameter)
val defaultType = ConeTypeVariableType(ConeNullability.NOT_NULL, typeConstructor)
override fun toString(): String {
return defaultType.toString()
}
}
class ConeTypeVariableTypeConstructor(
val debugName: String,
val originalTypeParameter: TypeParameterMarker?
) : ConeClassifierLookupTag(), TypeVariableTypeConstructorMarker {
override val name: Name get() = Name.identifier(debugName)
var isContainedInInvariantOrContravariantPositions: Boolean = false
private set
fun recordInfoAboutTypeVariableUsagesAsInvariantOrContravariantParameter() {
isContainedInInvariantOrContravariantPositions = true
}
}
abstract class ConeIntegerLiteralType(
val value: Long,
val isUnsigned: Boolean,
override val nullability: ConeNullability
) : ConeSimpleKotlinType(), TypeConstructorMarker {
abstract val possibleTypes: Collection<ConeClassLikeType>
abstract val supertypes: List<ConeClassLikeType>
override val typeArguments: Array<out ConeTypeProjection> = emptyArray()
abstract fun getApproximatedType(expectedType: ConeKotlinType? = null): ConeClassLikeType
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as ConeIntegerLiteralType
if (possibleTypes != other.possibleTypes) return false
if (nullability != other.nullability) return false
return true
}
override fun hashCode(): Int {
return 31 * possibleTypes.hashCode() + nullability.hashCode()
}
}
fun ConeIntegerLiteralType.canBeInt(): Boolean {
return value in Int.MIN_VALUE..Int.MAX_VALUE
}