Skip to content

Commit 0641af2

Browse files
committed
Update to the latest Swift export version
1 parent d331d72 commit 0641af2

File tree

5 files changed

+39
-31
lines changed

5 files changed

+39
-31
lines changed

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
systemProp.kotlinVersion=2.0.0-RC1
22
systemProp.kotlinIdeVersion=1.9.20-506
33
systemProp.kotlinIdeVersionSuffix=IJ8109.175
4-
systemProp.swiftExportVersion=2.0.20-dev-1552
4+
systemProp.swiftExportVersion=2.0.20-dev-2553
55
systemProp.policy=executor.policy
66
systemProp.indexes=indexes.json
77
systemProp.indexesJs=indexesJs.json

src/test/kotlin/com/compiler/server/SwiftConverterTest.kt

+9-11
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ class SwiftConverterTest : BaseExecutorTest() {
4545
fun `class declaration`() = exactTest(
4646
input = "public class MyClass { public fun A() {}}",
4747
expected = """
48-
import KotlinBridges
4948
import KotlinRuntime
50-
51-
public class MyClass {
52-
public init() {
49+
50+
public class MyClass : KotlinRuntime.KotlinBase {
51+
public override init() {
5352
fatalError()
5453
}
5554
public func A() -> Swift.Void {
@@ -67,9 +66,6 @@ class SwiftConverterTest : BaseExecutorTest() {
6766
val myProperty: Int = 42
6867
""".trimIndent(),
6968
expected = """
70-
import KotlinBridges
71-
import KotlinRuntime
72-
7369
public extension Playground.foo.bar {
7470
public static var myProperty: Swift.Int32 {
7571
get {
@@ -87,15 +83,17 @@ class SwiftConverterTest : BaseExecutorTest() {
8783
@Test
8884
fun `invalid code`() = exactTest(
8985
input = "abracadabra",
90-
// For now, we unconditionally import a few modules. Will be gone in the future versions
9186
expected = """
92-
import KotlinBridges
93-
import KotlinRuntime
9487
""".trimIndent()
9588
)
9689

9790
@Test
98-
fun `more invalid code`() = shouldFailTest(
91+
fun `more invalid code`() = exactTest(
9992
input = "fun foo(): Bar = error()",
93+
expected = """
94+
public func foo() -> ERROR_TYPE {
95+
fatalError()
96+
}
97+
""".trimIndent()
10098
)
10199
}
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
1-
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
1+
import org.jetbrains.kotlin.analysis.project.structure.KtModule
22
import org.jetbrains.kotlin.sir.providers.SirSession
3+
import org.jetbrains.kotlin.sir.providers.SirTypeProvider
34
import org.jetbrains.kotlin.sir.providers.impl.*
45
import org.jetbrains.sir.lightclasses.SirDeclarationFromKtSymbolProvider
56

67
internal class PlaygroundSirSession(
7-
private val ktAnalysisSession: KtAnalysisSession,
8+
ktModule: KtModule,
89
) : SirSession {
910
override val declarationNamer = SirDeclarationNamerImpl()
1011
override val enumGenerator = SirEnumGeneratorImpl()
11-
override val moduleProvider = SirSingleModuleProvider("Playground", "KotlinBridges")
12+
override val moduleProvider = SirSingleModuleProvider("Playground")
1213
override val declarationProvider = CachingSirDeclarationProvider(
1314
declarationsProvider = SirDeclarationFromKtSymbolProvider(
14-
ktAnalysisSession = ktAnalysisSession,
15+
ktModule = ktModule,
1516
sirSession = sirSession,
1617
)
1718
)
1819
override val parentProvider = SirParentProviderImpl(
19-
ktAnalysisSession = ktAnalysisSession,
2020
sirSession = sirSession,
2121
)
2222
override val typeProvider = SirTypeProviderImpl(
23-
ktAnalysisSession = ktAnalysisSession,
24-
sirSession = sirSession,
25-
)
26-
override val visibilityChecker = SirVisibilityCheckerImpl(
27-
ktAnalysisSession = ktAnalysisSession,
23+
errorTypeStrategy = SirTypeProvider.ErrorTypeStrategy.ErrorType,
24+
unsupportedTypeStrategy = SirTypeProvider.ErrorTypeStrategy.ErrorType,
2825
sirSession = sirSession,
2926
)
27+
override val visibilityChecker = SirVisibilityCheckerImpl()
3028
override val childrenProvider = SirDeclarationChildrenProviderImpl(
31-
ktAnalysisSession = ktAnalysisSession,
3229
sirSession = sirSession,
3330
)
3431
}

swift-export-playground/src/main/kotlin/Runner.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ fun runSwiftExport(
2424
): String {
2525
val (ktModule, sources) = collectModuleAndSources(sourceFile, "Playground", stdlibPath)
2626

27-
val sirModule: SirModule = analyze(ktModule) {
28-
val sirSession = PlaygroundSirSession(analysisSession)
29-
with(sirSession) {
27+
return analyze(ktModule) {
28+
val sirSession = PlaygroundSirSession(ktModule)
29+
val sirModule: SirModule = with(sirSession) {
3030
ktModule.sirModule().also {
3131
sources.flatMap { file ->
32-
file.getFileSymbol().getFileScope().extractDeclarations()
32+
file.getFileSymbol().getFileScope().extractDeclarations(analysisSession)
3333
}.forEach { topLevelDeclaration ->
3434
val parent = topLevelDeclaration.parent as? SirMutableDeclarationContainer
3535
?: error("top level declaration can contain only module or extension to package as a parent")
3636
parent.addChild { topLevelDeclaration }
3737
}
3838
}
3939
}
40+
SirAsSwiftSourcesPrinter.print(sirModule, stableDeclarationsOrder = true, renderDocComments = true)
4041
}
41-
return SirAsSwiftSourcesPrinter.print(sirModule, stableDeclarationsOrder = true, renderDocComments = true)
4242
}
4343

4444
@OptIn(KtAnalysisApiInternals::class)

swift-export-playground/src/test/kotlin/Tests.kt

+16-3
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,25 @@ class SwiftExportTests {
2626
fun foo(): Int = 5
2727
""",
2828
"""
29-
import KotlinBridges
30-
import KotlinRuntime
31-
3229
public func foo() -> Swift.Int32 {
3330
fatalError()
3431
}
3532
"""
3633
)
34+
35+
@Test
36+
fun `class declaration`() = testSources(
37+
"""
38+
class A
39+
""".trimIndent(),
40+
"""
41+
import KotlinRuntime
42+
43+
public class A : KotlinRuntime.KotlinBase {
44+
public override init() {
45+
fatalError()
46+
}
47+
}
48+
""".trimIndent()
49+
)
3750
}

0 commit comments

Comments
 (0)