Skip to content

Commit

Permalink
Fix that swift runtime classes were registered even without the runti…
Browse files Browse the repository at this point in the history
…me being present.
  • Loading branch information
FilipDolnik committed Nov 27, 2023
1 parent 6933427 commit ac47675
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SirPhaseContext(

override val oirProvider: OirProvider = OirProvider(kirProvider.skieModule, extraDescriptorBuiltins, kirProvider, namer)

override val sirProvider: SirProvider = SirProvider(framework, kirProvider, configurationProvider)
override val sirProvider: SirProvider = SirProvider(framework, kirProvider, configurationProvider, skieConfiguration)

override val kirBuiltins: KirBuiltins = kirProvider.kirBuiltins

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class KirBuiltins(
private val extraDescriptorBuiltins: ExtraDescriptorBuiltins,
private val namer: ObjCExportNamer,
) {
// TODO Builtin methods are not supported yet
// TODO Not all Builtin methods are not supported yet (supported are only those converted from Kotlin equivalents in Any)

val Base by Class(
name = namer.kotlinAnyName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ class SirProvider(
framework: FrameworkLayout,
private val kirProvider: KirProvider,
private val configurationProvider: ConfigurationProvider,
skieConfiguration: SkieConfiguration,
) {

val kotlinModule: SirModule.Kotlin = SirModule.Kotlin(framework.moduleName)

val skieModule: SirModule.Skie = SirModule.Skie(framework.moduleName)

val sirBuiltins by lazy {
SirBuiltins(this)
SirBuiltins(this, skieConfiguration)
}

private val externalModuleCache = mutableMapOf<String, SirModule.External>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package co.touchlab.skie.sir.builtin

import co.touchlab.skie.configuration.SkieConfiguration
import co.touchlab.skie.configuration.SkieConfigurationFlag
import co.touchlab.skie.sir.SirProvider
import co.touchlab.skie.sir.element.SirClass
import co.touchlab.skie.sir.element.SirDeclarationParent
Expand All @@ -15,13 +17,14 @@ import kotlin.reflect.KProperty
@Suppress("PropertyName", "FunctionName")
class SirBuiltins(
sirProvider: SirProvider,
skieConfiguration: SkieConfiguration,
) {

val Swift = Modules.Swift(sirProvider)

val Foundation = Modules.Foundation(sirProvider, Swift)

val Skie = Modules.Skie(sirProvider.skieModule)
val Skie = Modules.Skie(skieConfiguration, sirProvider.skieModule)

object Modules {

Expand Down Expand Up @@ -102,52 +105,71 @@ class SirBuiltins(
}

class Skie(
private val skieConfiguration: SkieConfiguration,
override val module: SirModule.Skie,
) : ModuleBase() {

override val origin: SirClass.Origin = SirClass.Origin.Generated

// The SkieSwiftFlow classes are only stubs (correct super types, and content are currently not needed)

val SkieSwiftFlow by Class {
val SkieSwiftFlow by RuntimeClass {
SirTypeParameter("T")
}

val SkieSwiftSharedFlow by Class {
val SkieSwiftSharedFlow by RuntimeClass {
SirTypeParameter("T")
}

val SkieSwiftMutableSharedFlow by Class {
val SkieSwiftMutableSharedFlow by RuntimeClass {
SirTypeParameter("T")
}

val SkieSwiftStateFlow by Class {
val SkieSwiftStateFlow by RuntimeClass {
SirTypeParameter("T")
}

val SkieSwiftMutableStateFlow by Class {
val SkieSwiftMutableStateFlow by RuntimeClass {
SirTypeParameter("T")
}

val SkieSwiftOptionalFlow by Class {
val SkieSwiftOptionalFlow by RuntimeClass {
SirTypeParameter("T")
}

val SkieSwiftOptionalSharedFlow by Class {
val SkieSwiftOptionalSharedFlow by RuntimeClass {
SirTypeParameter("T")
}

val SkieSwiftOptionalMutableSharedFlow by Class {
val SkieSwiftOptionalMutableSharedFlow by RuntimeClass {
SirTypeParameter("T")
}

val SkieSwiftOptionalStateFlow by Class {
val SkieSwiftOptionalStateFlow by RuntimeClass {
SirTypeParameter("T")
}

val SkieSwiftOptionalMutableStateFlow by Class {
val SkieSwiftOptionalMutableStateFlow by RuntimeClass {
SirTypeParameter("T")
}

private fun RuntimeClass(
superTypes: List<SirDeclaredSirType> = emptyList(),
parent: SirDeclarationParent = module,
nameOverride: String? = null,
apply: (SirClass.() -> Unit) = { },
): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, SirClass?>> =
if (SkieConfigurationFlag.Feature_CoroutinesInterop in skieConfiguration.enabledConfigurationFlags) {
ClassDeclarationPropertyProvider(
kind = SirClass.Kind.Class,
parent = parent,
superTypes = superTypes,
nameOverride = nameOverride,
apply = apply,
)
} else {
NoClassDeclarationPropertyProvider
}
}

abstract class ModuleBase {
Expand Down Expand Up @@ -201,7 +223,7 @@ class SirBuiltins(
typeFactory = typeFactory,
)

inner class ClassDeclarationPropertyProvider(
protected inner class ClassDeclarationPropertyProvider(
private val kind: SirClass.Kind,
private val parent: SirDeclarationParent,
private val superTypes: List<SirDeclaredSirType> = emptyList(),
Expand All @@ -219,6 +241,18 @@ class SirBuiltins(
)
}

protected object NoClassDeclarationPropertyProvider : PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, SirClass?>> {

override fun provideDelegate(thisRef: Any?, property: KProperty<*>): ReadOnlyProperty<Any?, SirClass?> =
NoClassDeclarationProperty

private object NoClassDeclarationProperty : ReadOnlyProperty<Any?, SirClass?> {

override fun getValue(thisRef: Any?, property: KProperty<*>): SirClass? =
null
}
}

private inner class ClassDeclarationProperty(
name: String,
kind: SirClass.Kind,
Expand Down

0 comments on commit ac47675

Please sign in to comment.