Pass languageVersionSettings to AbstractTypeApproximator
This commit is contained in:
committed by
TeamCityServer
parent
59372fd15f
commit
e74a0c7ef7
@@ -3009,7 +3009,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
|||||||
@NotNull
|
@NotNull
|
||||||
private KotlinType approximateCapturedType(@NotNull KotlinType type) {
|
private KotlinType approximateCapturedType(@NotNull KotlinType type) {
|
||||||
if (state.getLanguageVersionSettings().supportsFeature(LanguageFeature.NewInference)) {
|
if (state.getLanguageVersionSettings().supportsFeature(LanguageFeature.NewInference)) {
|
||||||
TypeApproximator approximator = new TypeApproximator(state.getModule().getBuiltIns());
|
TypeApproximator approximator = new TypeApproximator(state.getModule().getBuiltIns(), state.getLanguageVersionSettings());
|
||||||
|
|
||||||
KotlinType approximatedType =
|
KotlinType approximatedType =
|
||||||
TypeUtils.contains(type, (containedType) -> CapturedTypeConstructorKt.isCaptured(containedType)) ?
|
TypeUtils.contains(type, (containedType) -> CapturedTypeConstructorKt.isCaptured(containedType)) ?
|
||||||
|
|||||||
@@ -330,7 +330,7 @@ class GenerationState private constructor(
|
|||||||
|
|
||||||
val typeApproximator: TypeApproximator? =
|
val typeApproximator: TypeApproximator? =
|
||||||
if (languageVersionSettings.supportsFeature(LanguageFeature.NewInference))
|
if (languageVersionSettings.supportsFeature(LanguageFeature.NewInference))
|
||||||
TypeApproximator(module.builtIns)
|
TypeApproximator(module.builtIns, languageVersionSettings)
|
||||||
else
|
else
|
||||||
null
|
null
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.declarations.builder.buildProperty
|
|||||||
import org.jetbrains.kotlin.fir.declarations.builder.buildPropertyAccessor
|
import org.jetbrains.kotlin.fir.declarations.builder.buildPropertyAccessor
|
||||||
import org.jetbrains.kotlin.fir.declarations.builder.buildValueParameterCopy
|
import org.jetbrains.kotlin.fir.declarations.builder.buildValueParameterCopy
|
||||||
import org.jetbrains.kotlin.fir.diagnostics.ConeIntermediateDiagnostic
|
import org.jetbrains.kotlin.fir.diagnostics.ConeIntermediateDiagnostic
|
||||||
|
import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||||
import org.jetbrains.kotlin.fir.serialization.FirElementSerializer
|
import org.jetbrains.kotlin.fir.serialization.FirElementSerializer
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirAnonymousFunctionSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirAnonymousFunctionSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirDelegateFieldSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirDelegateFieldSymbol
|
||||||
@@ -43,7 +44,7 @@ class FirMetadataSerializer(
|
|||||||
components: Fir2IrComponents,
|
components: Fir2IrComponents,
|
||||||
parent: MetadataSerializer?
|
parent: MetadataSerializer?
|
||||||
) : MetadataSerializer {
|
) : MetadataSerializer {
|
||||||
private val approximator = object : AbstractTypeApproximator(session.typeContext) {
|
private val approximator = object : AbstractTypeApproximator(session.typeContext, session.languageVersionSettings) {
|
||||||
override fun createErrorType(debugName: String): SimpleTypeMarker {
|
override fun createErrorType(debugName: String): SimpleTypeMarker {
|
||||||
return ConeKotlinErrorType(ConeIntermediateDiagnostic(debugName))
|
return ConeKotlinErrorType(ConeIntermediateDiagnostic(debugName))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.backend
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||||
import org.jetbrains.kotlin.fir.expressions.classId
|
import org.jetbrains.kotlin.fir.expressions.classId
|
||||||
|
import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||||
import org.jetbrains.kotlin.fir.resolve.substitution.AbstractConeSubstitutor
|
import org.jetbrains.kotlin.fir.resolve.substitution.AbstractConeSubstitutor
|
||||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||||
@@ -63,7 +64,7 @@ class Fir2IrTypeConverter(
|
|||||||
private val capturedTypeCache = mutableMapOf<ConeCapturedType, IrType>()
|
private val capturedTypeCache = mutableMapOf<ConeCapturedType, IrType>()
|
||||||
private val errorTypeForCapturedTypeStub by lazy { createErrorType() }
|
private val errorTypeForCapturedTypeStub by lazy { createErrorType() }
|
||||||
|
|
||||||
private val typeApproximator = ConeTypeApproximator(session.typeContext)
|
private val typeApproximator = ConeTypeApproximator(session.typeContext, session.languageVersionSettings)
|
||||||
|
|
||||||
fun FirTypeRef.toIrType(typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT): IrType {
|
fun FirTypeRef.toIrType(typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT): IrType {
|
||||||
capturedTypeCache.clear()
|
capturedTypeCache.clear()
|
||||||
|
|||||||
+2
-5
@@ -6,10 +6,9 @@
|
|||||||
package org.jetbrains.kotlin.fir.backend.generators
|
package org.jetbrains.kotlin.fir.backend.generators
|
||||||
|
|
||||||
import org.jetbrains.kotlin.backend.common.ir.isMethodOfAny
|
import org.jetbrains.kotlin.backend.common.ir.isMethodOfAny
|
||||||
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
|
import org.jetbrains.kotlin.fir.*
|
||||||
import org.jetbrains.kotlin.fir.backend.*
|
import org.jetbrains.kotlin.fir.backend.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.dispatchReceiverClassOrNull
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.*
|
import org.jetbrains.kotlin.fir.expressions.*
|
||||||
import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression
|
import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression
|
||||||
import org.jetbrains.kotlin.fir.references.FirDelegateFieldReference
|
import org.jetbrains.kotlin.fir.references.FirDelegateFieldReference
|
||||||
@@ -17,7 +16,6 @@ import org.jetbrains.kotlin.fir.references.FirReference
|
|||||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||||
import org.jetbrains.kotlin.fir.references.FirSuperReference
|
import org.jetbrains.kotlin.fir.references.FirSuperReference
|
||||||
import org.jetbrains.kotlin.fir.references.impl.FirReferencePlaceholderForResolvedAnnotations
|
import org.jetbrains.kotlin.fir.references.impl.FirReferencePlaceholderForResolvedAnnotations
|
||||||
import org.jetbrains.kotlin.fir.render
|
|
||||||
import org.jetbrains.kotlin.fir.resolve.FirSamResolverImpl
|
import org.jetbrains.kotlin.fir.resolve.FirSamResolverImpl
|
||||||
import org.jetbrains.kotlin.fir.resolve.calls.getExpectedTypeForSAMConversion
|
import org.jetbrains.kotlin.fir.resolve.calls.getExpectedTypeForSAMConversion
|
||||||
import org.jetbrains.kotlin.fir.resolve.calls.isFunctional
|
import org.jetbrains.kotlin.fir.resolve.calls.isFunctional
|
||||||
@@ -31,7 +29,6 @@ import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutorByMap
|
|||||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||||
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||||
import org.jetbrains.kotlin.fir.typeContext
|
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.UNDEFINED_PARAMETER_INDEX
|
import org.jetbrains.kotlin.ir.builders.declarations.UNDEFINED_PARAMETER_INDEX
|
||||||
@@ -51,7 +48,7 @@ class CallAndReferenceGenerator(
|
|||||||
private val conversionScope: Fir2IrConversionScope
|
private val conversionScope: Fir2IrConversionScope
|
||||||
) : Fir2IrComponents by components {
|
) : Fir2IrComponents by components {
|
||||||
|
|
||||||
private val approximator = ConeTypeApproximator(session.typeContext)
|
private val approximator = ConeTypeApproximator(session.typeContext, session.languageVersionSettings)
|
||||||
private val adapterGenerator = AdapterGenerator(components, conversionScope)
|
private val adapterGenerator = AdapterGenerator(components, conversionScope)
|
||||||
private val samResolver = FirSamResolverImpl(session, scopeSession)
|
private val samResolver = FirSamResolverImpl(session, scopeSession)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ class InferenceComponents(val session: FirSession) : FirSessionComponent {
|
|||||||
get() = this@InferenceComponents.session
|
get() = this@InferenceComponents.session
|
||||||
}
|
}
|
||||||
|
|
||||||
val approximator: ConeTypeApproximator = ConeTypeApproximator(ctx)
|
val approximator: ConeTypeApproximator = ConeTypeApproximator(ctx, session.languageVersionSettings)
|
||||||
val trivialConstraintTypeInferenceOracle = TrivialConstraintTypeInferenceOracle.create(ctx)
|
val trivialConstraintTypeInferenceOracle = TrivialConstraintTypeInferenceOracle.create(ctx)
|
||||||
private val incorporator = ConstraintIncorporator(approximator, trivialConstraintTypeInferenceOracle, ConeConstraintSystemUtilContext)
|
private val incorporator = ConstraintIncorporator(approximator, trivialConstraintTypeInferenceOracle, ConeConstraintSystemUtilContext)
|
||||||
private val injector = ConstraintInjector(
|
private val injector = ConstraintInjector(
|
||||||
|
|||||||
@@ -5,10 +5,12 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.types
|
package org.jetbrains.kotlin.fir.types
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||||
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
||||||
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
|
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
|
||||||
|
|
||||||
class ConeTypeApproximator(inferenceContext: ConeInferenceContext) : AbstractTypeApproximator(inferenceContext) {
|
class ConeTypeApproximator(inferenceContext: ConeInferenceContext, languageVersionSettings: LanguageVersionSettings) :
|
||||||
|
AbstractTypeApproximator(inferenceContext, languageVersionSettings) {
|
||||||
fun approximateToSuperType(type: ConeKotlinType, conf: TypeApproximatorConfiguration): ConeKotlinType? {
|
fun approximateToSuperType(type: ConeKotlinType, conf: TypeApproximatorConfiguration): ConeKotlinType? {
|
||||||
return super.approximateToSuperType(type, conf) as ConeKotlinType?
|
return super.approximateToSuperType(type, conf) as ConeKotlinType?
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -700,7 +700,7 @@ public class DescriptorResolver {
|
|||||||
BindingTrace trace,
|
BindingTrace trace,
|
||||||
@NotNull LexicalScope scope
|
@NotNull LexicalScope scope
|
||||||
) {
|
) {
|
||||||
UnwrappedType approximatedType = typeApproximator.approximateDeclarationType(type, true, languageVersionSettings);
|
UnwrappedType approximatedType = typeApproximator.approximateDeclarationType(type, true);
|
||||||
VariableDescriptor variableDescriptor = new LocalVariableDescriptor(
|
VariableDescriptor variableDescriptor = new LocalVariableDescriptor(
|
||||||
scope.getOwnerDescriptor(),
|
scope.getOwnerDescriptor(),
|
||||||
annotationResolver.resolveAnnotationsWithArguments(scope, parameter.getModifierList(), trace),
|
annotationResolver.resolveAnnotationsWithArguments(scope, parameter.getModifierList(), trace),
|
||||||
@@ -1244,7 +1244,7 @@ public class DescriptorResolver {
|
|||||||
KotlinType publicType = transformAnonymousTypeIfNeeded(
|
KotlinType publicType = transformAnonymousTypeIfNeeded(
|
||||||
functionDescriptor, function, type, trace, anonymousTypeTransformers, languageVersionSettings
|
functionDescriptor, function, type, trace, anonymousTypeTransformers, languageVersionSettings
|
||||||
);
|
);
|
||||||
UnwrappedType approximatedType = typeApproximator.approximateDeclarationType(publicType, false, languageVersionSettings);
|
UnwrappedType approximatedType = typeApproximator.approximateDeclarationType(publicType, false);
|
||||||
KotlinType sanitizedType = declarationReturnTypeSanitizer.sanitizeReturnType(approximatedType, wrappedTypeFactory, trace, languageVersionSettings);
|
KotlinType sanitizedType = declarationReturnTypeSanitizer.sanitizeReturnType(approximatedType, wrappedTypeFactory, trace, languageVersionSettings);
|
||||||
functionsTypingVisitor.checkTypesForReturnStatements(function, trace, sanitizedType);
|
functionsTypingVisitor.checkTypesForReturnStatements(function, trace, sanitizedType);
|
||||||
return sanitizedType;
|
return sanitizedType;
|
||||||
|
|||||||
+1
-1
@@ -180,5 +180,5 @@ class VariableTypeAndInitializerResolver(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun approximateType(type: KotlinType, local: Boolean): UnwrappedType =
|
private fun approximateType(type: KotlinType, local: Boolean): UnwrappedType =
|
||||||
typeApproximator.approximateDeclarationType(type, local, expressionTypingServices.languageVersionSettings)
|
typeApproximator.approximateDeclarationType(type, local)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -218,7 +218,7 @@ class ResolvedAtomCompleter(
|
|||||||
return FunctionLiteralTypes.ProcessedType(
|
return FunctionLiteralTypes.ProcessedType(
|
||||||
substitutedType,
|
substitutedType,
|
||||||
approximatedType = typeApproximator.approximateDeclarationType(
|
approximatedType = typeApproximator.approximateDeclarationType(
|
||||||
substitutedType, local = true, languageVersionSettings = topLevelCallContext.languageVersionSettings
|
substitutedType, local = true
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -23,10 +23,10 @@ class TypeTranslatorImpl(
|
|||||||
override val constantValueGenerator: ConstantValueGenerator =
|
override val constantValueGenerator: ConstantValueGenerator =
|
||||||
ConstantValueGeneratorImpl(moduleDescriptor, symbolTable, this)
|
ConstantValueGeneratorImpl(moduleDescriptor, symbolTable, this)
|
||||||
|
|
||||||
private val typeApproximatorForNI = TypeApproximator(moduleDescriptor.builtIns)
|
private val typeApproximatorForNI = TypeApproximator(moduleDescriptor.builtIns, languageVersionSettings)
|
||||||
|
|
||||||
override fun approximateType(type: KotlinType): KotlinType =
|
override fun approximateType(type: KotlinType): KotlinType =
|
||||||
typeApproximatorForNI.approximateDeclarationType(type, local = false, languageVersionSettings)
|
typeApproximatorForNI.approximateDeclarationType(type, local = false)
|
||||||
|
|
||||||
override fun commonSupertype(types: Collection<KotlinType>): KotlinType =
|
override fun commonSupertype(types: Collection<KotlinType>): KotlinType =
|
||||||
CommonSupertypes.commonSupertype(types)
|
CommonSupertypes.commonSupertype(types)
|
||||||
|
|||||||
+6
-1
@@ -5,11 +5,16 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.types
|
package org.jetbrains.kotlin.types
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.config.LanguageFeature
|
||||||
|
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||||
import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator.commonSuperType
|
import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator.commonSuperType
|
||||||
import org.jetbrains.kotlin.types.model.*
|
import org.jetbrains.kotlin.types.model.*
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
||||||
abstract class AbstractTypeApproximator(val ctx: TypeSystemInferenceExtensionContext) : TypeSystemInferenceExtensionContext by ctx {
|
abstract class AbstractTypeApproximator(
|
||||||
|
val ctx: TypeSystemInferenceExtensionContext,
|
||||||
|
protected val languageVersionSettings: LanguageVersionSettings,
|
||||||
|
) : TypeSystemInferenceExtensionContext by ctx {
|
||||||
|
|
||||||
private class ApproximationResult(val type: KotlinTypeMarker?)
|
private class ApproximationResult(val type: KotlinTypeMarker?)
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,11 @@ import org.jetbrains.kotlin.config.LanguageFeature
|
|||||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.ClassicTypeSystemContextForCS
|
import org.jetbrains.kotlin.resolve.calls.components.ClassicTypeSystemContextForCS
|
||||||
|
|
||||||
class TypeApproximator(builtIns: KotlinBuiltIns) : AbstractTypeApproximator(ClassicTypeSystemContextForCS(builtIns)) {
|
class TypeApproximator(
|
||||||
fun approximateDeclarationType(baseType: KotlinType, local: Boolean, languageVersionSettings: LanguageVersionSettings): UnwrappedType {
|
builtIns: KotlinBuiltIns,
|
||||||
|
languageVersionSettings: LanguageVersionSettings,
|
||||||
|
) : AbstractTypeApproximator(ClassicTypeSystemContextForCS(builtIns), languageVersionSettings) {
|
||||||
|
fun approximateDeclarationType(baseType: KotlinType, local: Boolean): UnwrappedType {
|
||||||
if (!languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) return baseType.unwrap()
|
if (!languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) return baseType.unwrap()
|
||||||
|
|
||||||
val configuration = if (local) TypeApproximatorConfiguration.LocalDeclaration else TypeApproximatorConfiguration.PublicDeclaration
|
val configuration = if (local) TypeApproximatorConfiguration.LocalDeclaration else TypeApproximatorConfiguration.PublicDeclaration
|
||||||
|
|||||||
+2
-1
@@ -199,7 +199,8 @@ internal fun KotlinType.toPsiType(lightDeclaration: PsiModifierListOwner?, conte
|
|||||||
|
|
||||||
val signatureWriter = BothSignatureWriter(BothSignatureWriter.Mode.TYPE)
|
val signatureWriter = BothSignatureWriter(BothSignatureWriter.Mode.TYPE)
|
||||||
val typeMappingMode = if (boxed) TypeMappingMode.GENERIC_ARGUMENT_UAST else TypeMappingMode.DEFAULT_UAST
|
val typeMappingMode = if (boxed) TypeMappingMode.GENERIC_ARGUMENT_UAST else TypeMappingMode.DEFAULT_UAST
|
||||||
val approximatedType = TypeApproximator(this.builtIns).approximateDeclarationType(this, true, languageVersionSettings)
|
val approximatedType =
|
||||||
|
TypeApproximator(this.builtIns, languageVersionSettings).approximateDeclarationType(this, true)
|
||||||
typeMapper.mapType(approximatedType, signatureWriter, typeMappingMode)
|
typeMapper.mapType(approximatedType, signatureWriter, typeMappingMode)
|
||||||
|
|
||||||
val signature = StringCharacterIterator(signatureWriter.toString())
|
val signature = StringCharacterIterator(signatureWriter.toString())
|
||||||
|
|||||||
Reference in New Issue
Block a user