From 35b14573e3c28ef7f70ea062f36ed989bf6e22e2 Mon Sep 17 00:00:00 2001 From: Tadeas Kriz Date: Thu, 3 Oct 2024 10:38:40 -0400 Subject: [PATCH] Add default implementation for `@_spi` property in flow protocol. This is required when Swift evolution is enabled. --- .../runtime/SupportedFlowRuntimeGenerator.kt | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/phases/runtime/SupportedFlowRuntimeGenerator.kt b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/phases/runtime/SupportedFlowRuntimeGenerator.kt index aec500e7..6c992617 100644 --- a/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/phases/runtime/SupportedFlowRuntimeGenerator.kt +++ b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/phases/runtime/SupportedFlowRuntimeGenerator.kt @@ -10,6 +10,7 @@ import co.touchlab.skie.sir.SirFqName import co.touchlab.skie.sir.element.SirClass import co.touchlab.skie.sir.element.SirConditionalConstraint import co.touchlab.skie.sir.element.SirConstructor +import co.touchlab.skie.sir.element.SirExtension import co.touchlab.skie.sir.element.SirGetter import co.touchlab.skie.sir.element.SirModality import co.touchlab.skie.sir.element.SirProperty @@ -48,11 +49,11 @@ object SupportedFlowRuntimeGenerator { context(SirPhase.Context) private fun generateSkieSwiftFlowProtocol(skieSwiftFlowIterator: SirClass): SkieSwiftFlowProtocol { namespaceProvider.getSkieNamespaceFile("SkieSwiftFlowProtocol").apply { - SirClass( + val skieSwiftFlowProtocol = SirClass( baseName = "SkieSwiftFlowProtocol", kind = SirClass.Kind.Protocol, superTypes = listOf(sirBuiltins._Concurrency.AsyncSequence.defaultType), - ).apply { + ).run { val elementTypeParameter = SirTypeParameter( name = "Element", isPrimaryAssociatedType = true, @@ -82,11 +83,31 @@ object SupportedFlowRuntimeGenerator { SirGetter() } - return SkieSwiftFlowProtocol( + SkieSwiftFlowProtocol( self = this, delegateProperty = delegateProperty, ) } + + SirExtension( + skieSwiftFlowProtocol.self, + ).apply { + SirProperty( + skieSwiftFlowProtocol.delegateProperty.identifier, + skieSwiftFlowProtocol.delegateProperty.type, + visibility = SirVisibility.Internal, + ).apply { + addOverride(skieSwiftFlowProtocol.delegateProperty) + + SirGetter().apply { + bodyBuilder.add { + addStatement("""Swift.fatalError("SkieSwiftFlowProtocol has to be conformed to with @_spi(SKIE) enabled and property '${skieSwiftFlowProtocol.delegateProperty.identifier}' implemented")""") + } + } + } + } + + return skieSwiftFlowProtocol } }