[FIR] Replace static cone types for integers with default classIds in ILT
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
+15
-13
@@ -6,10 +6,9 @@
|
||||
package org.jetbrains.kotlin.fir.resolve.calls
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeIntegerLiteralTypeImpl
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.arrayElementType
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeUnsafe
|
||||
import org.jetbrains.kotlin.fir.declarations.classId
|
||||
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.resolve.calls.results.*
|
||||
import org.jetbrains.kotlin.types.checker.requireOrDescribe
|
||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
@@ -62,21 +61,24 @@ abstract class AbstractConeCallConflictResolver(
|
||||
// TODO: support unsigned types
|
||||
// see OverloadingConflictResolver.kt:294
|
||||
|
||||
val int = ConeIntegerLiteralTypeImpl.INT_TYPE
|
||||
val long = ConeIntegerLiteralTypeImpl.LONG_TYPE
|
||||
val byte = ConeIntegerLiteralTypeImpl.BYTE_TYPE
|
||||
val short = ConeIntegerLiteralTypeImpl.SHORT_TYPE
|
||||
val int = StandardClassIds.Int
|
||||
val long = StandardClassIds.Long
|
||||
val byte = StandardClassIds.Byte
|
||||
val short = StandardClassIds.Short
|
||||
|
||||
val specificClassId = specific.classId ?: return false
|
||||
val generalClassId = general.classId ?: return false
|
||||
|
||||
when {
|
||||
//TypeUtils.equalTypes(specific, _double) && TypeUtils.equalTypes(general, _float) -> return true
|
||||
specific == int -> {
|
||||
specificClassId == int -> {
|
||||
when {
|
||||
general == long -> return true
|
||||
general == byte -> return true
|
||||
general == short -> return true
|
||||
generalClassId == long -> return true
|
||||
generalClassId == byte -> return true
|
||||
generalClassId == short -> return true
|
||||
}
|
||||
}
|
||||
specific == short && general == byte -> return true
|
||||
specificClassId == short && generalClassId == byte -> return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
+9
-8
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirIntegerOperator
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirIntegerOperatorCall
|
||||
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
@@ -106,11 +107,11 @@ class IntegerLiteralTypeApproximationTransformer(
|
||||
}
|
||||
|
||||
fun ConeClassLikeType.toConstKind(): FirConstKind<*> {
|
||||
return when (this) {
|
||||
ConeIntegerLiteralTypeImpl.INT_TYPE -> FirConstKind.Int
|
||||
ConeIntegerLiteralTypeImpl.LONG_TYPE -> FirConstKind.Long
|
||||
ConeIntegerLiteralTypeImpl.SHORT_TYPE -> FirConstKind.Short
|
||||
ConeIntegerLiteralTypeImpl.BYTE_TYPE -> FirConstKind.Byte
|
||||
return when (classId) {
|
||||
StandardClassIds.Int -> FirConstKind.Int
|
||||
StandardClassIds.Long -> FirConstKind.Long
|
||||
StandardClassIds.Short -> FirConstKind.Short
|
||||
StandardClassIds.Byte -> FirConstKind.Byte
|
||||
else -> throw IllegalStateException()
|
||||
}
|
||||
}
|
||||
@@ -171,9 +172,9 @@ class IntegerOperatorsTypeUpdater(val approximator: IntegerLiteralTypeApproximat
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
val expectedType = when (argumentType) {
|
||||
ConeIntegerLiteralTypeImpl.LONG_TYPE -> argumentType
|
||||
else -> ConeIntegerLiteralTypeImpl.INT_TYPE
|
||||
val expectedType = when (argumentType.classId) {
|
||||
StandardClassIds.Long -> argumentType
|
||||
else -> ConeIntegerLiteralTypeImpl.createType(StandardClassIds.Int)
|
||||
}
|
||||
functionCall.transformSingle(approximator, expectedType)
|
||||
functionCall.replaceTypeRef(functionCall.resultType.resolvedTypeFromPrototype(expectedType))
|
||||
|
||||
@@ -17,17 +17,17 @@ class ConeIntegerLiteralTypeImpl : ConeIntegerLiteralType {
|
||||
constructor(value: Long) : super(value) {
|
||||
possibleTypes = mutableListOf()
|
||||
|
||||
fun checkBoundsAndAddPossibleType(type: ConeClassLikeType, range: LongRange) {
|
||||
fun checkBoundsAndAddPossibleType(classId: ClassId, range: LongRange) {
|
||||
if (value in range) {
|
||||
possibleTypes.add(type)
|
||||
possibleTypes.add(createType(classId))
|
||||
}
|
||||
}
|
||||
|
||||
fun addSignedPossibleTypes() {
|
||||
checkBoundsAndAddPossibleType(INT_TYPE, INT_RANGE)
|
||||
possibleTypes += LONG_TYPE
|
||||
checkBoundsAndAddPossibleType(BYTE_TYPE, BYTE_RANGE)
|
||||
checkBoundsAndAddPossibleType(SHORT_TYPE, SHORT_RANGE)
|
||||
checkBoundsAndAddPossibleType(StandardClassIds.Int, INT_RANGE)
|
||||
possibleTypes += createType(StandardClassIds.Long)
|
||||
checkBoundsAndAddPossibleType(StandardClassIds.Byte, BYTE_RANGE)
|
||||
checkBoundsAndAddPossibleType(StandardClassIds.Short, SHORT_RANGE)
|
||||
}
|
||||
|
||||
addSignedPossibleTypes()
|
||||
@@ -53,15 +53,10 @@ class ConeIntegerLiteralTypeImpl : ConeIntegerLiteralType {
|
||||
}
|
||||
|
||||
companion object {
|
||||
private fun createType(classId: ClassId): ConeClassLikeType {
|
||||
fun createType(classId: ClassId): ConeClassLikeType {
|
||||
return ConeClassLikeTypeImpl(ConeClassLikeLookupTagImpl(classId), emptyArray(), false)
|
||||
}
|
||||
|
||||
val INT_TYPE = createType(StandardClassIds.Int)
|
||||
val LONG_TYPE = createType(StandardClassIds.Long)
|
||||
val SHORT_TYPE = createType(StandardClassIds.Short)
|
||||
val BYTE_TYPE = createType(StandardClassIds.Byte)
|
||||
|
||||
private val NUMBER_TYPE = createType(StandardClassIds.Number)
|
||||
|
||||
private val INT_RANGE = Int.MIN_VALUE.toLong()..Int.MAX_VALUE.toLong()
|
||||
|
||||
Reference in New Issue
Block a user