[FIR] Replace static cone types for integers with default classIds in ILT

This commit is contained in:
Dmitriy Novozhilov
2019-12-12 10:33:56 +03:00
parent c6b9593157
commit 4faa2c0c2c
6 changed files with 83 additions and 67 deletions
@@ -0,0 +1,18 @@
/*
* Copyright 2010-2019 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
enum class ConeNullability(val suffix: String) {
NULLABLE("?"),
UNKNOWN("!"),
NOT_NULL("");
val isNullable: Boolean get() = this != NOT_NULL
companion object {
fun create(isNullable: Boolean) = if (isNullable) NULLABLE else NOT_NULL
}
}
@@ -0,0 +1,15 @@
/*
* Copyright 2010-2019 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.name.ClassId
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
val ConeKotlinType.isNullable: Boolean get() = nullability != ConeNullability.NOT_NULL
val ConeKotlinType.isMarkedNullable: Boolean get() = nullability == ConeNullability.NULLABLE
val ConeKotlinType.classId: ClassId? get() = this.safeAs<ConeClassLikeType>()?.lookupTag?.classId
@@ -5,24 +5,12 @@
package org.jetbrains.kotlin.fir.types
import org.jetbrains.kotlin.descriptors.annotations.Annotations
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.resolve.constants.IntegerLiteralTypeConstructor
import org.jetbrains.kotlin.types.KotlinTypeFactory
import org.jetbrains.kotlin.types.SimpleType
import org.jetbrains.kotlin.types.model.*
sealed class ConeKotlinTypeProjection : TypeArgumentMarker {
abstract val kind: ProjectionKind
companion object {
val EMPTY_ARRAY = arrayOf<ConeKotlinTypeProjection>()
}
}
enum class ProjectionKind {
STAR, IN, OUT, INVARIANT;
@@ -37,40 +25,37 @@ enum class ProjectionKind {
}
}
sealed class ConeKotlinTypeProjection : TypeArgumentMarker {
abstract val kind: ProjectionKind
companion object {
val EMPTY_ARRAY = arrayOf<ConeKotlinTypeProjection>()
}
}
object ConeStarProjection : ConeKotlinTypeProjection() {
override val kind: ProjectionKind
get() = ProjectionKind.STAR
}
interface ConeTypedProjection {
val type: ConeKotlinType
}
data class ConeKotlinTypeProjectionIn(override val type: ConeKotlinType) : ConeKotlinTypeProjection(), ConeTypedProjection {
data class ConeKotlinTypeProjectionIn(override val type: ConeKotlinType) : ConeKotlinTypeProjection(),
ConeTypedProjection {
override val kind: ProjectionKind
get() = ProjectionKind.IN
}
data class ConeKotlinTypeProjectionOut(override val type: ConeKotlinType) : ConeKotlinTypeProjection(), ConeTypedProjection {
data class ConeKotlinTypeProjectionOut(override val type: ConeKotlinType) : ConeKotlinTypeProjection(),
ConeTypedProjection {
override val kind: ProjectionKind
get() = ProjectionKind.OUT
}
enum class ConeNullability(val suffix: String) {
NULLABLE("?"),
UNKNOWN("!"),
NOT_NULL("");
val isNullable: Boolean get() = this != NOT_NULL
companion object {
fun create(isNullable: Boolean) = if (isNullable) NULLABLE else NOT_NULL
}
}
// We assume type IS an invariant type projection to prevent additional wrapper here
// (more exactly, invariant type projection contains type)
sealed class ConeKotlinType : ConeKotlinTypeProjection(), ConeTypedProjection, KotlinTypeMarker, TypeArgumentListMarker {
sealed class ConeKotlinType : ConeKotlinTypeProjection(),
ConeTypedProjection,
KotlinTypeMarker,
TypeArgumentListMarker {
override val kind: ProjectionKind
get() = ProjectionKind.INVARIANT
@@ -86,9 +71,9 @@ sealed class ConeKotlinType : ConeKotlinTypeProjection(), ConeTypedProjection, K
}
}
val ConeKotlinType.isNullable: Boolean get() = nullability != ConeNullability.NOT_NULL
val ConeKotlinType.isMarkedNullable: Boolean get() = nullability == ConeNullability.NULLABLE
interface ConeTypedProjection {
val type: ConeKotlinType
}
typealias ConeKotlinErrorType = ConeClassErrorType