Skip to content

Commit acd57be

Browse files
committed
Upgrade to the most recent dev version:
* Get rid of swift-export-experimental repo * Fix swift export API usages * Add a bit of tests on strings and chars
1 parent fd2b6c9 commit acd57be

File tree

9 files changed

+94
-46
lines changed

9 files changed

+94
-46
lines changed

build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ allprojects {
4141
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
4242
maven("https://maven.pkg.jetbrains.space/kotlin/p/wasm/experimental")
4343
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
44-
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/swift-export-experimental")
4544
}
4645
afterEvaluate {
4746
dependencies {

gradle.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
systemProp.kotlinVersion=2.0.0
1+
systemProp.kotlinVersion=2.1.0-dev-3023
22
systemProp.kotlinIdeVersion=1.9.20-506
33
systemProp.kotlinIdeVersionSuffix=IJ8109.175
4-
systemProp.swiftExportVersion=2.0.20-dev-3623
54
systemProp.policy=executor.policy
65
systemProp.indexes=indexes.json
76
systemProp.indexesJs=indexesJs.json

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ pluginManagement {
1010
gradlePluginPortal()
1111
mavenCentral()
1212
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
13+
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
1314
}
1415
}

src/main/kotlin/com/compiler/server/compiler/components/CliUtils.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import com.compiler.server.model.ErrorDescriptor
66
import com.compiler.server.model.ProjectSeveriry
77
import com.compiler.server.model.TextInterval
88
import org.jetbrains.kotlin.cli.common.CLICompiler
9-
import org.jetbrains.kotlin.cli.common.CLITool
109
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
1110
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
1211
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
@@ -56,7 +55,7 @@ fun <T> CLICompiler<*>.tryCompilation(inputDirectory: Path, inputFiles: List<Pat
5655
inputFiles.forEach { put(it.outputFilePathString(), mutableListOf()) }
5756
}
5857
val defaultFileName = inputFiles.singleOrNull()?.outputFilePathString() ?: ""
59-
val exitCode = CLITool.doMainNoExit(this, arguments.toTypedArray(), object : MessageRenderer {
58+
val exitCode = CLICompiler.doMainNoExit(this, arguments.toTypedArray(), object : MessageRenderer {
6059
override fun renderPreamble(): String = ""
6160

6261
override fun render(

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import com.compiler.server.base.BaseExecutorTest
44
import org.junit.jupiter.api.Test
55
import kotlin.test.assertContains
66
import kotlin.test.assertEquals
7-
import kotlin.test.assertTrue
87

98
class SwiftConverterTest : BaseExecutorTest() {
109

@@ -18,11 +17,6 @@ class SwiftConverterTest : BaseExecutorTest() {
1817
assertContains(actual.swiftCode.trimEnd(), expected)
1918
}
2019

21-
private fun shouldFailTest(input: String) {
22-
val actual = translateToSwift(input)
23-
assertTrue(actual.hasErrors())
24-
}
25-
2620
@Test
2721
fun basicSwiftExportTest() = containsTest(
2822
input = """
@@ -46,11 +40,16 @@ class SwiftConverterTest : BaseExecutorTest() {
4640
input = "public class MyClass { public fun A() {}}",
4741
expected = """
4842
import KotlinRuntime
49-
43+
5044
public class MyClass : KotlinRuntime.KotlinBase {
5145
public override init() {
5246
stub()
5347
}
48+
public override init(
49+
__externalRCRef: Swift.UInt
50+
) {
51+
stub()
52+
}
5453
public func A() -> Swift.Void {
5554
stub()
5655
}
@@ -66,17 +65,15 @@ class SwiftConverterTest : BaseExecutorTest() {
6665
val myProperty: Int = 42
6766
""".trimIndent(),
6867
expected = """
69-
public extension Playground.foo.bar {
68+
@_exported import pkg
69+
70+
public extension pkg.foo.bar {
7071
public static var myProperty: Swift.Int32 {
7172
get {
7273
stub()
7374
}
7475
}
7576
}
76-
public enum foo {
77-
public enum bar {
78-
}
79-
}
8077
""".trimIndent()
8178
)
8279

@@ -96,4 +93,18 @@ class SwiftConverterTest : BaseExecutorTest() {
9693
}
9794
""".trimIndent()
9895
)
96+
97+
@Test
98+
fun `unsupported type declaration`() = exactTest(
99+
input = """
100+
interface Foo
101+
102+
fun produceFoo(): Foo = TODO()
103+
""".trimIndent(),
104+
expected = """
105+
public func produceFoo() -> Swift.Never {
106+
stub()
107+
}
108+
""".trimIndent()
109+
)
99110
}

swift-export-playground/build.gradle.kts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,29 @@ repositories {
66
mavenCentral()
77
// For Analysis API components
88
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide-plugin-dependencies")
9-
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/swift-export-experimental")
9+
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
1010
}
1111

1212
val kotlinVersion = rootProject.properties["systemProp.kotlinVersion"]
13-
val swiftExportVersion = rootProject.properties["systemProp.swiftExportVersion"]
13+
val aaVersion = "2.1.0-dev-2515"
1414

1515
dependencies {
16-
implementation("org.jetbrains.kotlin:kotlin-compiler:$kotlinVersion")
17-
// For K/N Distribution class
18-
implementation("org.jetbrains.kotlin:kotlin-native-utils:$kotlinVersion")
16+
implementation("org.jetbrains.kotlin:kotlin-compiler:$aaVersion")
1917

2018
// Analysis API components which are required for the Swift export
21-
implementation("org.jetbrains.kotlin:analysis-api-standalone-for-ide:$kotlinVersion") { isTransitive = false }
22-
implementation("org.jetbrains.kotlin:high-level-api-for-ide:$kotlinVersion") { isTransitive = false }
23-
implementation("org.jetbrains.kotlin:high-level-api-fir-for-ide:$kotlinVersion") { isTransitive = false }
24-
implementation("org.jetbrains.kotlin:high-level-api-impl-base-for-ide:$kotlinVersion") { isTransitive = false }
25-
implementation("org.jetbrains.kotlin:low-level-api-fir-for-ide:$kotlinVersion") { isTransitive = false }
26-
implementation("org.jetbrains.kotlin:symbol-light-classes-for-ide:$kotlinVersion") { isTransitive = false }
19+
implementation("org.jetbrains.kotlin:analysis-api-standalone-for-ide:$aaVersion") { isTransitive = false }
20+
implementation("org.jetbrains.kotlin:high-level-api-for-ide:$aaVersion") { isTransitive = false }
21+
implementation("org.jetbrains.kotlin:high-level-api-fir-for-ide:$aaVersion") { isTransitive = false }
22+
implementation("org.jetbrains.kotlin:high-level-api-impl-base-for-ide:$aaVersion") { isTransitive = false }
23+
implementation("org.jetbrains.kotlin:low-level-api-fir-for-ide:$aaVersion") { isTransitive = false }
24+
implementation("org.jetbrains.kotlin:symbol-light-classes-for-ide:$aaVersion") { isTransitive = false }
25+
implementation("org.jetbrains.kotlin:analysis-api-platform-interface-for-ide:$aaVersion") { isTransitive = false }
2726

2827
// Swift export not-yet-published dependencies.
29-
implementation("org.jetbrains.kotlin:sir:$swiftExportVersion") { isTransitive = false }
30-
implementation("org.jetbrains.kotlin:sir-providers:$swiftExportVersion") { isTransitive = false }
31-
implementation("org.jetbrains.kotlin:sir-light-classes:$swiftExportVersion") { isTransitive = false }
32-
implementation("org.jetbrains.kotlin:sir-printer:$swiftExportVersion") { isTransitive = false }
28+
implementation("org.jetbrains.kotlin:sir:$kotlinVersion") { isTransitive = false }
29+
implementation("org.jetbrains.kotlin:sir-providers:$kotlinVersion") { isTransitive = false }
30+
implementation("org.jetbrains.kotlin:sir-light-classes:$kotlinVersion") { isTransitive = false }
31+
implementation("org.jetbrains.kotlin:sir-printer:$kotlinVersion") { isTransitive = false }
3332

3433
testImplementation("junit:junit:4.13.2")
3534
testImplementation("org.jetbrains.kotlin:kotlin-test:$kotlinVersion")
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,42 @@
1-
import org.jetbrains.kotlin.analysis.project.structure.KtModule
1+
import org.jetbrains.kotlin.analysis.api.projectStructure.KaModule
2+
import org.jetbrains.kotlin.name.FqName
3+
import org.jetbrains.kotlin.sir.SirModule
4+
25
import org.jetbrains.kotlin.sir.providers.SirSession
6+
import org.jetbrains.kotlin.sir.providers.SirTrampolineDeclarationsProvider
37
import org.jetbrains.kotlin.sir.providers.SirTypeProvider
48
import org.jetbrains.kotlin.sir.providers.impl.*
9+
import org.jetbrains.kotlin.sir.providers.utils.UnsupportedDeclarationReporter
510
import org.jetbrains.sir.lightclasses.SirDeclarationFromKtSymbolProvider
611

712
internal class PlaygroundSirSession(
8-
ktModule: KtModule,
13+
ktModule: KaModule,
14+
moduleForPackageEnums: SirModule,
15+
unsupportedDeclarationReporter: UnsupportedDeclarationReporter,
16+
targetPackageFqName: FqName?,
917
) : SirSession {
1018
override val declarationNamer = SirDeclarationNamerImpl()
11-
override val enumGenerator = SirEnumGeneratorImpl()
1219
override val moduleProvider = SirSingleModuleProvider("Playground")
1320
override val declarationProvider = CachingSirDeclarationProvider(
1421
declarationsProvider = SirDeclarationFromKtSymbolProvider(
1522
ktModule = ktModule,
1623
sirSession = sirSession,
1724
)
1825
)
26+
override val enumGenerator = SirEnumGeneratorImpl(moduleForPackageEnums)
1927
override val parentProvider = SirParentProviderImpl(
2028
sirSession = sirSession,
29+
packageEnumGenerator = enumGenerator,
2130
)
2231
override val typeProvider = SirTypeProviderImpl(
2332
errorTypeStrategy = SirTypeProvider.ErrorTypeStrategy.ErrorType,
2433
unsupportedTypeStrategy = SirTypeProvider.ErrorTypeStrategy.ErrorType,
2534
sirSession = sirSession,
2635
)
27-
override val visibilityChecker = SirVisibilityCheckerImpl()
36+
override val visibilityChecker = SirVisibilityCheckerImpl(unsupportedDeclarationReporter)
2837
override val childrenProvider = SirDeclarationChildrenProviderImpl(
2938
sirSession = sirSession,
3039
)
40+
41+
override val trampolineDeclarationsProvider: SirTrampolineDeclarationsProvider = SirTrampolineDeclarationsProviderImpl(sirSession, targetPackageFqName)
3142
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import org.jetbrains.kotlin.analysis.api.KtAnalysisApiInternals
21
import org.jetbrains.kotlin.analysis.api.analyze
3-
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeTokenProvider
4-
import org.jetbrains.kotlin.analysis.api.standalone.KtAlwaysAccessibleLifetimeTokenProvider
52
import org.jetbrains.kotlin.analysis.api.standalone.buildStandaloneAnalysisAPISession
63
import org.jetbrains.kotlin.analysis.project.structure.KtModule
74
import org.jetbrains.kotlin.analysis.project.structure.builder.buildKtLibraryModule
@@ -11,6 +8,8 @@ import org.jetbrains.kotlin.psi.KtFile
118
import org.jetbrains.kotlin.sir.SirFunctionBody
129
import org.jetbrains.kotlin.sir.SirModule
1310
import org.jetbrains.kotlin.sir.SirMutableDeclarationContainer
11+
import org.jetbrains.kotlin.sir.builder.buildModule
12+
import org.jetbrains.kotlin.sir.providers.utils.SimpleUnsupportedDeclarationReporter
1413
import org.jetbrains.kotlin.sir.util.addChild
1514
import org.jetbrains.sir.printer.SirAsSwiftSourcesPrinter
1615
import java.nio.file.Path
@@ -26,11 +25,15 @@ fun runSwiftExport(
2625
val (ktModule, sources) = collectModuleAndSources(sourceFile, "Playground", stdlibPath)
2726

2827
return analyze(ktModule) {
29-
val sirSession = PlaygroundSirSession(ktModule)
28+
val pkgModule = buildModule {
29+
name = "pkg"
30+
}
31+
val unsupportedDeclarationReporter = SimpleUnsupportedDeclarationReporter()
32+
val sirSession = PlaygroundSirSession(ktModule, pkgModule, unsupportedDeclarationReporter, targetPackageFqName = null)
3033
val sirModule: SirModule = with(sirSession) {
3134
ktModule.sirModule().also {
3235
sources.flatMap { file ->
33-
file.getFileSymbol().getFileScope().extractDeclarations(analysisSession)
36+
file.symbol.fileScope.extractDeclarations(useSiteSession)
3437
}.forEach { topLevelDeclaration ->
3538
val parent = topLevelDeclaration.parent as? SirMutableDeclarationContainer
3639
?: error("top level declaration can contain only module or extension to package as a parent")
@@ -49,15 +52,12 @@ fun runSwiftExport(
4952
}
5053
}
5154

52-
@OptIn(KtAnalysisApiInternals::class)
5355
private fun collectModuleAndSources(
5456
sourceRoot: Path,
5557
kotlinModuleName: String,
5658
stdlibPath: Path?,
5759
): Pair<KtModule, List<KtFile>> {
5860
val analysisAPISession = buildStandaloneAnalysisAPISession {
59-
registerProjectService(KtLifetimeTokenProvider::class.java, KtAlwaysAccessibleLifetimeTokenProvider())
60-
6161
buildKtModuleProvider {
6262
platform = NativePlatforms.unspecifiedNativePlatform
6363

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,16 @@ class SwiftExportTests {
3939
""".trimIndent(),
4040
"""
4141
import KotlinRuntime
42-
42+
4343
public class A : KotlinRuntime.KotlinBase {
4444
public override init() {
4545
stub()
4646
}
47+
public override init(
48+
__externalRCRef: Swift.UInt
49+
) {
50+
stub()
51+
}
4752
}
4853
""".trimIndent()
4954
)
@@ -55,7 +60,7 @@ class SwiftExportTests {
5560
""".trimIndent(),
5661
"""
5762
import KotlinRuntime
58-
63+
5964
public class O : KotlinRuntime.KotlinBase {
6065
public static var shared: Playground.O {
6166
get {
@@ -65,6 +70,11 @@ class SwiftExportTests {
6570
private override init() {
6671
stub()
6772
}
73+
public override init(
74+
__externalRCRef: Swift.UInt
75+
) {
76+
stub()
77+
}
6878
}
6979
""".trimIndent()
7080
)
@@ -78,4 +88,23 @@ class SwiftExportTests {
7888
public typealias MyInt = Swift.Int32
7989
""".trimIndent()
8090
)
91+
92+
@Test
93+
fun `strings and chars`() = testSources(
94+
"""
95+
fun produceString(): String = "hello"
96+
97+
fun firstChar(str: String): Char = str.first()
98+
""".trimIndent(),
99+
"""
100+
public func firstChar(
101+
str: Swift.String
102+
) -> Swift.Unicode.UTF16.CodeUnit {
103+
stub()
104+
}
105+
public func produceString() -> Swift.String {
106+
stub()
107+
}
108+
""".trimIndent()
109+
)
81110
}

0 commit comments

Comments
 (0)