Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,33 @@ object VerifyFrameworkHeaderPhase : SirPhase {

private const val className = "HeaderVerification"

context(SirPhase.Context)
override fun isActive(): Boolean = globalConfiguration[TestConfigurationKeys.EnableVerifyFrameworkHeaderPhase]
context(context: SirPhase.Context)
override fun isActive(): Boolean = context.globalConfiguration[TestConfigurationKeys.EnableVerifyFrameworkHeaderPhase]

context(SirPhase.Context)
context(context: SirPhase.Context)
override suspend fun execute() {
val headerValidationSwiftFilePath = globalConfiguration[TestConfigurationKeys.VerifyFrameworkHeaderPhaseSwiftFilePath]
val headerValidationSwiftFilePath = context.globalConfiguration[TestConfigurationKeys.VerifyFrameworkHeaderPhaseSwiftFilePath]

val fileContent = generateFileContent()

headerValidationSwiftFilePath.writeText(fileContent)
}

context(SirPhase.Context)
context(context: SirPhase.Context)
private fun generateFileContent(): String {
// Not used outside of this file; therefore it's intentionally not included in SirProvider
val sirModule = SirModule.Skie(className)

val sirFile = SirIrFile(sirModule, Path("$className.swift"))

sirFile.imports.add(framework.frameworkName)
sirFile.imports.add(context.framework.frameworkName)

sirFile.addVerificationFileBody()

return SirCodeGenerator.generate(sirFile)
}

context(SirPhase.Context)
context(context: SirPhase.Context)
private fun SirIrFile.addVerificationFileBody() {
SirClass(
baseName = className,
Expand All @@ -70,17 +70,17 @@ object VerifyFrameworkHeaderPhase : SirPhase {
}
}

context(SirPhase.Context, SirClass)
context(context: SirPhase.Context, sirClass: SirClass)
private fun addVerificationClassBody() {
sirProvider.allLocalCallableDeclarations
context.sirProvider.allLocalCallableDeclarations
.filter { it.visibility.isAccessibleFromOtherModules }
.filter { it.findFirstSkieErrorType() == null }
.forEach {
addCallableDeclarationVerification(it)
}
}

context(SirClass, SirPhase.Context)
context(sirClass: SirClass, context: SirPhase.Context)
private fun addCallableDeclarationVerification(callableDeclaration: SirCallableDeclaration) {
when (callableDeclaration) {
is SirConstructor -> addConstructorVerification(callableDeclaration)
Expand All @@ -89,7 +89,7 @@ object VerifyFrameworkHeaderPhase : SirPhase {
}
}

context(SirClass)
context(sirClass: SirClass)
private fun addConstructorVerification(constructor: SirConstructor) {
SirSimpleFunction(
identifier = constructor.getVerificationFunctionIdentifier(),
Expand All @@ -116,11 +116,11 @@ object VerifyFrameworkHeaderPhase : SirPhase {
}
}

context(SirClass)
context(sirClass: SirClass)
private fun addSimpleFunctionVerification(function: SirSimpleFunction) {
function.shallowCopy(
identifier = function.getVerificationFunctionIdentifier(),
parent = this@SirClass,
parent = sirClass,
visibility = SirVisibility.Public,
isReplaced = false,
isHidden = false,
Expand Down Expand Up @@ -151,7 +151,7 @@ object VerifyFrameworkHeaderPhase : SirPhase {
}
}

context(SirClass, SirPhase.Context)
context(sirClass: SirClass, context: SirPhase.Context)
private fun addPropertyVerification(property: SirProperty) {
property.getter?.let {
addPropertyGetterVerification(it)
Expand All @@ -163,7 +163,7 @@ object VerifyFrameworkHeaderPhase : SirPhase {
}
}

context(SirClass)
context(sirClass: SirClass)
private fun addPropertyGetterVerification(getter: SirGetter) {
val property = getter.property

Expand All @@ -190,13 +190,13 @@ object VerifyFrameworkHeaderPhase : SirPhase {
}
}

context(SirClass, SirPhase.Context)
context(sirClass: SirClass, context: SirPhase.Context)
private fun addPropertySetterVerification(setter: SirSetter) {
val property = setter.property

SirSimpleFunction(
identifier = property.getVerificationFunctionIdentifier(),
returnType = sirBuiltins.Swift.Void.defaultType,
returnType = context.sirBuiltins.Swift.Void.defaultType,
deprecationLevel = property.deprecationLevel,
throws = setter.throws,
attributes = setter.attributes + property.attributes,
Expand Down Expand Up @@ -251,10 +251,10 @@ object VerifyFrameworkHeaderPhase : SirPhase {
}
}

context(SirClass)
private fun nextIndex(): Int = declarations.size
context(sirClass: SirClass)
private fun nextIndex(): Int = sirClass.declarations.size

context(SirClass)
context(sirClass: SirClass)
private fun SirCallableDeclaration.getVerificationFunctionIdentifier(): String =
(((this.parent as? SirDeclarationNamespace)?.fqName?.toLocalString()?.let { "${it}__" } ?: "") +
this.identifierAfterVisibilityChange +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import co.touchlab.skie.phases.SirPhase

object VerifyTestPhasesAreExecutedPhase : SirPhase {

context(SirPhase.Context)
context(context: SirPhase.Context)
override suspend fun execute() {
val shouldCrash = kirProvider.kotlinClasses.any { it.swiftName == "VerifySkieTestPhasesAreExecuted" }
val shouldCrash = context.kirProvider.kotlinClasses.any { it.swiftName == "VerifySkieTestPhasesAreExecuted" }

if (shouldCrash) {
error("Test phases are executed.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ internal class TestRunner(
),
)

context(TempFileSystem)
context(tempFileSystem: TempFileSystem)
private fun withJvmInlineAnnotation(
kotlinFiles: List<Path>,
): List<Path> {
val packageRegex = Regex("package (.*)\\n")

val kotlinDirectory = createDirectory("kotlin")
val kotlinDirectory = tempFileSystem.createDirectory("kotlin")

val jvmInlineFiles = kotlinFiles
.mapNotNull { packageRegex.find(it.readText())?.groupValues?.getOrNull(1) }
Expand All @@ -106,43 +106,43 @@ internal class TestRunner(
return kotlinFiles + jvmInlineFiles
}

context(TempFileSystem, TestLogger)
context(tempFileSystem: TempFileSystem, testLogger: TestLogger)
private fun compileKotlin(
kotlinFiles: List<Path>,
compilerArgumentsProvider: CompilerArgumentsProvider,
): IntermediateResult<Path> =
KotlinTestCompiler(this@TempFileSystem, this@TestLogger).compile(kotlinFiles, compilerArgumentsProvider)
KotlinTestCompiler(tempFileSystem, testLogger).compile(kotlinFiles, compilerArgumentsProvider)

context(TempFileSystem)
context(tempFileSystem: TempFileSystem)
private fun generateConfiguration(
baseConfiguration: CompilerSkieConfigurationData,
configFiles: List<Path>,
): IntermediateResult<Path> =
PluginConfigurationGenerator(this@TempFileSystem).generate(baseConfiguration, configFiles)
PluginConfigurationGenerator(tempFileSystem).generate(baseConfiguration, configFiles)

context(TempFileSystem, TestLogger)
context(tempFileSystem: TempFileSystem, testLogger: TestLogger)
private fun linkKotlin(
klib: Path,
skieConfigurationData: CompilerSkieConfigurationData,
compilerArgumentsProvider: CompilerArgumentsProvider,
): IntermediateResult<Path> =
KotlinTestLinker(this@TempFileSystem, this@TestLogger).link(klib, skieConfigurationData, compilerArgumentsProvider)
KotlinTestLinker(tempFileSystem, testLogger).link(klib, skieConfigurationData, compilerArgumentsProvider)

context(TempFileSystem)
context(tempFileSystem: TempFileSystem)
private fun enhanceSwiftCode(swiftCode: String): Path =
SwiftCodeEnhancer(this@TempFileSystem).enhance(swiftCode)
SwiftCodeEnhancer(tempFileSystem).enhance(swiftCode)

context(TempFileSystem, TestLogger)
context(tempFileSystem: TempFileSystem, testLogger: TestLogger)
private fun compileSwift(
kotlinFramework: Path,
swiftFiles: List<Path>,
compilerArgumentsProvider: CompilerArgumentsProvider,
): IntermediateResult<Path> =
SwiftTestCompiler(this@TempFileSystem, this@TestLogger, compilerArgumentsProvider.target).compile(kotlinFramework, swiftFiles)
SwiftTestCompiler(tempFileSystem, testLogger, compilerArgumentsProvider.target).compile(kotlinFramework, swiftFiles)

context(TestLogger)
context(testLogger: TestLogger)
private fun runSwift(binary: Path): TestResult =
SwiftProgramRunner(this@TestLogger).runProgram(binary)
SwiftProgramRunner(testLogger).runProgram(binary)

private fun writeResult(test: TestNode.Test, result: TestResultWithLogs) {
val resultAsText = result.hasSucceededAsString(test)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ object KotlinGenerator {
}
}

context(Context)
context(context: Context)
private fun SmartStringBuilder.append(file: KotlinFile) {
file.declarations.forEach {
append(it)
}
}

context(Context)
context(context: Context)
private fun SmartStringBuilder.append(declaration: KotlinDeclaration) {
+""

Expand All @@ -48,7 +48,7 @@ object KotlinGenerator {
}
}

context(Context)
context(context: Context)
private fun SmartStringBuilder.append(clazz: KotlinClass) {
when (clazz.kind) {
KotlinClass.Kind.Class -> append("class ")
Expand All @@ -70,14 +70,14 @@ object KotlinGenerator {
+"}"
}

context(Context)
context(context: Context)
private fun SmartStringBuilder.appendTypeParameters(clazz: KotlinClass) {
when (clazz.typeParameters.size) {
0 -> {}
1 -> {
val typeParameter = clazz.typeParameters.single()

typeParameter.bounds.forEach { registerType(it) }
typeParameter.bounds.forEach { context.registerType(it) }

append("<${typeParameter.name}")
appendSingleBound(typeParameter)
Expand All @@ -88,7 +88,7 @@ object KotlinGenerator {

indented {
clazz.typeParameters.forEach { typeParameter ->
typeParameter.bounds.forEach { registerType(it) }
typeParameter.bounds.forEach { context.registerType(it) }

append(typeParameter.name)
appendSingleBound(typeParameter)
Expand All @@ -103,14 +103,14 @@ object KotlinGenerator {
appendWhere(clazz)
}

context(Context)
context(context: Context)
private fun SmartStringBuilder.appendSingleBound(typeParameter: KotlinTypeParameter) {
if (typeParameter.bounds.size == 1) {
append(" : ${typeParameter.bounds.single().toKotlinName()}")
}
}

context(Context)
context(context: Context)
private fun SmartStringBuilder.appendWhere(clazz: KotlinClass) {
val typeParametersWithBounds = clazz.typeParameters
.filter { it.bounds.size > 1 }
Expand All @@ -129,13 +129,13 @@ object KotlinGenerator {
}
}

context(Context)
context(context: Context)
private fun SmartStringBuilder.append(function: KotlinFunction) {
function.extensionReceiver?.let { registerType(it) }
function.extensionReceiver?.let { context.registerType(it) }
function.valueParameters.forEach {
registerType(it.type)
context.registerType(it.type)
}
registerType(function.returnType)
context.registerType(function.returnType)

function.annotations.forEach {
+it
Expand All @@ -152,9 +152,9 @@ object KotlinGenerator {
+"}"
}

context(Context)
context(context: Context)
private fun SmartStringBuilder.append(property: KotlinProperty) {
registerType(property.type)
context.registerType(property.type)

+"val ${property.name}: ${property.type.toKotlinName()} = ${property.initializer}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import io.outfoxx.swiftpoet.parameterizedBy

object TestFileGenerationPhase : SirPhase {

context(SirPhase.Context)
context(context: SirPhase.Context)
override suspend fun execute() {
val kirClass = kirProvider.getClassByFqName("co.touchlab.skie.test.KotlinFile")
val kirClass = context.kirProvider.getClassByFqName("co.touchlab.skie.test.KotlinFile")
val sirClass = kirClass.originalSirClass

namespaceProvider.getSkieNamespaceWrittenSourceFile("TypeVerification").content = """
context.namespaceProvider.getSkieNamespaceWrittenSourceFile("TypeVerification").content = """
@resultBuilder
struct VerifyReturnType<ReturnType> {
let value: ReturnType
Expand Down Expand Up @@ -62,7 +62,7 @@ object TestFileGenerationPhase : SirPhase {

val swiftFileBuilders = mutableListOf<FileSpec.Builder>()

FileSpec.builder(framework.frameworkName, "TypeVerification+verify")
FileSpec.builder(context.framework.frameworkName, "TypeVerification+verify")
.also { swiftFileBuilders.add(it) }
.apply {
val parameterCounts = kirClass.callableDeclarations
Expand Down Expand Up @@ -125,7 +125,7 @@ object TestFileGenerationPhase : SirPhase {
}
}

FileSpec.builder(framework.frameworkName, "KotlinFile_access")
FileSpec.builder(context.framework.frameworkName, "KotlinFile_access")
.also { swiftFileBuilders.add(it) }
.apply {
addImport("Foundation")
Expand Down Expand Up @@ -232,7 +232,7 @@ object TestFileGenerationPhase : SirPhase {
swiftFileBuilders.forEach { builder ->
val file = builder.build()

namespaceProvider.getSkieNamespaceWrittenSourceFile(file.name).content = file.toString()
context.namespaceProvider.getSkieNamespaceWrittenSourceFile(file.name).content = file.toString()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ class SimpleFunctionConfiguration(
}
}

context(CommonSkieContext)
context(commonSkieContext: CommonSkieContext)
val SimpleFunctionConfiguration.isSuspendInteropEnabled: Boolean
get() = SkieConfigurationFlag.Feature_CoroutinesInterop.isEnabled && this[SuspendInterop.Enabled]
get() = commonSkieContext.run { SkieConfigurationFlag.Feature_CoroutinesInterop.isEnabled } && this[SuspendInterop.Enabled]
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ enum class SupportedFlow(private val directParent: SupportedFlow?) {
fun getCoroutinesKirClass(kirProvider: KirProvider): KirClass =
kirProvider.getClassByFqName(coroutinesFlowFqName)

context(SirPhase.Context)
fun getCoroutinesKirClass(): KirClass = getCoroutinesKirClass(kirProvider)
context(context: SirPhase.Context)
fun getCoroutinesKirClass(): KirClass = getCoroutinesKirClass(context.kirProvider)

sealed interface Variant {

Expand All @@ -42,14 +42,14 @@ enum class SupportedFlow(private val directParent: SupportedFlow?) {

fun getSwiftClass(sirProvider: SirProvider): SirClass

context(SirPhase.Context)
fun getCoroutinesKirClass(): KirClass = getCoroutinesKirClass(kirProvider)
context(context: SirPhase.Context)
fun getCoroutinesKirClass(): KirClass = getCoroutinesKirClass(context.kirProvider)

context(SirPhase.Context)
fun getKotlinKirClass(): KirClass = getKotlinKirClass(kirProvider)
context(context: SirPhase.Context)
fun getKotlinKirClass(): KirClass = getKotlinKirClass(context.kirProvider)

context(SirPhase.Context)
fun getSwiftClass(): SirClass = getSwiftClass(sirProvider)
context(context: SirPhase.Context)
fun getSwiftClass(): SirClass = getSwiftClass(context.sirProvider)

fun isCastableTo(variant: Variant): Boolean

Expand Down
Loading