Skip to content

Commit

Permalink
Move compiler independent link phases to core module.
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipDolnik committed Apr 16, 2024
1 parent 6c84aca commit 4a705f0
Show file tree
Hide file tree
Showing 31 changed files with 96 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.touchlab.skie.phases.analytics.performance
package co.touchlab.skie.analytics.performance

import co.touchlab.skie.configuration.RootConfiguration
import co.touchlab.skie.configuration.SkieConfigurationFlag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package co.touchlab.skie.context
import co.touchlab.skie.configuration.RootConfiguration
import co.touchlab.skie.configuration.SkieConfigurationFlag
import co.touchlab.skie.configuration.provider.CompilerSkieConfigurationData
import co.touchlab.skie.phases.analytics.performance.SkiePerformanceAnalytics
import co.touchlab.skie.analytics.performance.SkiePerformanceAnalytics
import co.touchlab.skie.plugin.analytics.AnalyticsCollector
import co.touchlab.skie.util.CompilerShim
import co.touchlab.skie.util.FrameworkLayout
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package co.touchlab.skie.phases

interface CompilerIndependentLinkPhase : LinkPhase<CompilerIndependentLinkPhase.Context> {

interface Context : LinkPhase.Context {

override val context: Context
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package co.touchlab.skie.phases

interface ForegroundPhase<in C : ForegroundPhase.Context> : ScheduledPhase<C> {

interface Context : ScheduledPhase.Context {

override val context: Context
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package co.touchlab.skie.phases

import co.touchlab.skie.kir.descriptor.DescriptorKirProvider
import java.nio.file.Path

interface LinkPhase : ForegroundPhase<LinkPhase.Context> {
interface LinkPhase<in C : LinkPhase.Context> : ForegroundPhase<C> {

interface Context : ForegroundPhase.Context {

override val context: Context

val descriptorKirProvider: DescriptorKirProvider

fun link(additionalObjectFiles: List<Path>)

suspend fun awaitAllBackgroundJobs()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import co.touchlab.skie.configuration.SwiftCompilerConfiguration
import co.touchlab.skie.context.CommonSkieContext
import co.touchlab.skie.phases.util.StatefulScheduledPhase

interface ScheduledPhase<C : ScheduledPhase.Context> {
interface ScheduledPhase<in C : ScheduledPhase.Context> {

context(C)
fun isActive(): Boolean = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package co.touchlab.skie.phases.analytics

import co.touchlab.skie.phases.CompilerIndependentLinkPhase
import co.touchlab.skie.phases.LinkPhase

// Cannot run in the background otherwise there is a risk of a deadlock
object LogSkiePerformanceAnalyticsPhase : LinkPhase {
object LogSkiePerformanceAnalyticsPhase : CompilerIndependentLinkPhase {

context(LinkPhase.Context)
override suspend fun execute() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package co.touchlab.skie.phases.other

import co.touchlab.skie.phases.CompilerIndependentLinkPhase

object AwaitAllBackgroundJobsPhase : CompilerIndependentLinkPhase {

context(CompilerIndependentLinkPhase.Context)
override suspend fun execute() {
awaitAllBackgroundJobs()
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package co.touchlab.skie.phases.other

import co.touchlab.skie.phases.CompilerIndependentLinkPhase
import co.touchlab.skie.phases.LinkPhase

object LinkObjectFilesPhase : LinkPhase {
object LinkObjectFilesPhase : CompilerIndependentLinkPhase {

context(LinkPhase.Context)
override suspend fun execute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import co.touchlab.skie.configuration.SimpleFunctionConfiguration
import co.touchlab.skie.configuration.ValueParameterConfiguration
import co.touchlab.skie.configuration.provider.ConfigurationProvider
import co.touchlab.skie.configuration.provider.IdentifiedConfigurationTarget
import co.touchlab.skie.phases.ForegroundPhase
import co.touchlab.skie.phases.CompilerDependentForegroundPhase
import org.jetbrains.kotlin.backend.common.serialization.findPackage
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
Expand Down Expand Up @@ -138,19 +138,19 @@ class DescriptorConfigurationProvider(
}
}

context(ForegroundPhase.Context)
context(CompilerDependentForegroundPhase.Context)
val ClassDescriptor.configuration: ClassConfiguration
get() = descriptorConfigurationProvider.getConfiguration(this)

context(ForegroundPhase.Context)
context(CompilerDependentForegroundPhase.Context)
val SimpleFunctionDescriptor.configuration: SimpleFunctionConfiguration
get() = descriptorConfigurationProvider.getConfiguration(this)

context(ForegroundPhase.Context)
context(CompilerDependentForegroundPhase.Context)
val ConstructorDescriptor.configuration: ConstructorConfiguration
get() = descriptorConfigurationProvider.getConfiguration(this)

context(ForegroundPhase.Context)
context(CompilerDependentForegroundPhase.Context)
val FunctionDescriptor.configuration: FunctionConfiguration
get() = when (this) {
is SimpleFunctionDescriptor -> configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package co.touchlab.skie.context
import co.touchlab.skie.kir.descriptor.MutableDescriptorProvider
import co.touchlab.skie.kir.irbuilder.impl.DeclarationBuilderImpl
import co.touchlab.skie.phases.ClassExportPhase
import co.touchlab.skie.phases.CompilerDependentForegroundPhase
import co.touchlab.skie.phases.ForegroundPhase

class ClassExportPhaseContext(
mainSkieContext: MainSkieContext,
) : ClassExportPhase.Context, ForegroundPhase.Context by mainSkieContext {
) : ClassExportPhase.Context, CompilerDependentForegroundPhase.Context by mainSkieContext {

override val context: ClassExportPhaseContext = this

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import co.touchlab.skie.kir.descriptor.ObjCExportedInterfaceProvider
import co.touchlab.skie.kir.type.translation.KirCustomTypeMappers
import co.touchlab.skie.kir.type.translation.KirDeclarationTypeTranslator
import co.touchlab.skie.kir.type.translation.KirTypeTranslator
import co.touchlab.skie.phases.CompilerDependentForegroundPhase
import co.touchlab.skie.phases.DescriptorConversionPhase
import co.touchlab.skie.phases.ForegroundPhase
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportNamer

class DescriptorConversionPhaseContext(
mainSkieContext: MainSkieContext,
override val objCExportedInterfaceProvider: ObjCExportedInterfaceProvider,
) : DescriptorConversionPhase.Context, ForegroundPhase.Context by mainSkieContext {
) : DescriptorConversionPhase.Context, CompilerDependentForegroundPhase.Context by mainSkieContext {

override val context: DescriptorConversionPhase.Context = this

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package co.touchlab.skie.context

import co.touchlab.skie.kir.irbuilder.impl.DeclarationBuilderImpl
import co.touchlab.skie.phases.CompilerDependentForegroundPhase
import co.touchlab.skie.phases.DescriptorModificationPhase
import co.touchlab.skie.phases.ForegroundPhase

class DescriptorModificationPhaseContext(
mainSkieContext: MainSkieContext,
) : DescriptorModificationPhase.Context, ForegroundPhase.Context by mainSkieContext {
) : DescriptorModificationPhase.Context, CompilerDependentForegroundPhase.Context by mainSkieContext {

override val context: DescriptorModificationPhaseContext = this

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import co.touchlab.skie.configuration.provider.CompilerSkieConfigurationData
import co.touchlab.skie.configuration.provider.ConfigurationProvider
import co.touchlab.skie.phases.InitPhase
import co.touchlab.skie.phases.SkiePhaseScheduler
import co.touchlab.skie.phases.analytics.performance.SkiePerformanceAnalytics
import co.touchlab.skie.analytics.performance.SkiePerformanceAnalytics
import co.touchlab.skie.plugin.analytics.AnalyticsCollector
import co.touchlab.skie.util.ActualCompilerShim
import co.touchlab.skie.util.CompilerShim
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package co.touchlab.skie.context

import co.touchlab.skie.kir.irbuilder.impl.DeclarationBuilderImpl
import co.touchlab.skie.kir.util.SkieSymbolTable
import co.touchlab.skie.phases.CompilerDependentForegroundPhase
import co.touchlab.skie.phases.ForegroundPhase
import co.touchlab.skie.phases.KotlinIrPhase
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
Expand All @@ -16,7 +17,7 @@ class KotlinIrPhaseContext(
mainSkieContext: MainSkieContext,
override val moduleFragment: IrModuleFragment,
override val pluginContext: IrPluginContext,
) : KotlinIrPhase.Context, ForegroundPhase.Context by mainSkieContext {
) : KotlinIrPhase.Context, CompilerDependentForegroundPhase.Context by mainSkieContext {

override val context: KotlinIrPhaseContext = this

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package co.touchlab.skie.context

import co.touchlab.skie.kir.descriptor.DescriptorKirProvider
import co.touchlab.skie.phases.ForegroundPhase
import co.touchlab.skie.phases.LinkPhase
import co.touchlab.skie.phases.CompilerDependentForegroundPhase
import co.touchlab.skie.phases.CompilerDependentLinkPhase
import java.nio.file.Path

class LinkPhaseContext(
private val mainSkieContext: MainSkieContext,
private val link: (additionalObjectFiles: List<Path>) -> Unit,
) : LinkPhase.Context, ForegroundPhase.Context by mainSkieContext {
) : CompilerDependentLinkPhase.Context, CompilerDependentForegroundPhase.Context by mainSkieContext {

override val context: LinkPhase.Context = this
override val context: CompilerDependentLinkPhase.Context = this

override val descriptorKirProvider: DescriptorKirProvider = mainSkieContext.descriptorKirProvider

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import co.touchlab.skie.phases.ScheduledPhase
import co.touchlab.skie.phases.util.StatefulScheduledPhase
import co.touchlab.skie.configuration.SwiftCompilerConfiguration
import co.touchlab.skie.configuration.SwiftCompilerConfiguration.BuildType
import co.touchlab.skie.phases.CompilerDependentForegroundPhase
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -35,7 +36,7 @@ class MainSkieContext internal constructor(
frontendServices: FrontendServices,
val mainModuleDescriptor: ModuleDescriptor,
exportedDependencies: Collection<ModuleDescriptor>,
) : ForegroundPhase.Context, BackgroundPhase.Context, InitPhase.Context by initPhaseContext {
) : CompilerDependentForegroundPhase.Context, BackgroundPhase.Context, InitPhase.Context by initPhaseContext {

private val skieCoroutineScope: CoroutineScope = CoroutineScope(Dispatchers.Default) + CoroutineExceptionHandler { _, _ ->
// Hides default stderr output because the exception is handled at the end of the job
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package co.touchlab.skie.context

import co.touchlab.skie.kir.irbuilder.impl.DeclarationBuilderImpl
import co.touchlab.skie.kir.util.SkieSymbolTable
import co.touchlab.skie.phases.CompilerDependentForegroundPhase
import co.touchlab.skie.phases.ForegroundPhase
import co.touchlab.skie.phases.SymbolTablePhase
import org.jetbrains.kotlin.ir.util.SymbolTable

class SymbolTablePhaseContext(
mainSkieContext: MainSkieContext,
symbolTable: SymbolTable,
) : SymbolTablePhase.Context, ForegroundPhase.Context by mainSkieContext {
) : SymbolTablePhase.Context, CompilerDependentForegroundPhase.Context by mainSkieContext {

override val context: SymbolTablePhaseContext = this

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package co.touchlab.skie.phases
import co.touchlab.skie.kir.descriptor.MutableDescriptorProvider
import co.touchlab.skie.kir.irbuilder.DeclarationBuilder

interface ClassExportPhase : ForegroundPhase<ClassExportPhase.Context> {
interface ClassExportPhase : CompilerDependentForegroundPhase<ClassExportPhase.Context> {

interface Context : ForegroundPhase.Context {
interface Context : CompilerDependentForegroundPhase.Context {

override val context: Context

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import org.jetbrains.kotlin.backend.konan.KonanConfig
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.konan.target.AppleConfigurables

interface ForegroundPhase<C : ForegroundPhase.Context> : ScheduledPhase<C> {
interface CompilerDependentForegroundPhase<in C : CompilerDependentForegroundPhase.Context> : ForegroundPhase<C> {

interface Context : ScheduledPhase.Context {
interface Context : ForegroundPhase.Context {

override val context: Context

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package co.touchlab.skie.phases

import co.touchlab.skie.kir.descriptor.DescriptorKirProvider

interface CompilerDependentLinkPhase : LinkPhase<CompilerDependentLinkPhase.Context>, CompilerDependentForegroundPhase<CompilerDependentLinkPhase.Context> {

interface Context : CompilerIndependentLinkPhase.Context, CompilerDependentForegroundPhase.Context {

override val context: Context

val descriptorKirProvider: DescriptorKirProvider
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import co.touchlab.skie.kir.type.translation.KirDeclarationTypeTranslator
import co.touchlab.skie.kir.type.translation.KirTypeTranslator
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportNamer

interface DescriptorConversionPhase : ForegroundPhase<DescriptorConversionPhase.Context> {
interface DescriptorConversionPhase : CompilerDependentForegroundPhase<DescriptorConversionPhase.Context> {

interface Context : ForegroundPhase.Context {
interface Context : CompilerDependentForegroundPhase.Context {

override val context: Context

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package co.touchlab.skie.phases

import co.touchlab.skie.kir.irbuilder.DeclarationBuilder

interface DescriptorModificationPhase : ForegroundPhase<DescriptorModificationPhase.Context> {
interface DescriptorModificationPhase : CompilerDependentForegroundPhase<DescriptorModificationPhase.Context> {

interface Context : ForegroundPhase.Context {
interface Context : CompilerDependentForegroundPhase.Context {

override val context: Context

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment

interface KotlinIrPhase : ForegroundPhase<KotlinIrPhase.Context> {
interface KotlinIrPhase : CompilerDependentForegroundPhase<KotlinIrPhase.Context> {

interface Context : ForegroundPhase.Context {
interface Context : CompilerDependentForegroundPhase.Context {

override val context: Context

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package co.touchlab.skie.phases

import co.touchlab.skie.kir.irbuilder.impl.GenerateIrPhase
import co.touchlab.skie.phases.other.GenerateIrPhase
import co.touchlab.skie.phases.analytics.ClassExportAnalyticsPhase
import co.touchlab.skie.phases.analytics.KotlinIrAnalyticsPhase
import co.touchlab.skie.phases.analytics.LogSkiePerformanceAnalyticsPhase
Expand Down Expand Up @@ -249,7 +249,7 @@ class SkiePhaseScheduler {
)
}

val linkPhases = SkiePhaseGroup<LinkPhase, LinkPhase.Context> { context ->
val linkPhases = SkiePhaseGroup<LinkPhase<CompilerDependentLinkPhase.Context>, CompilerDependentLinkPhase.Context> { context ->
addAll(
ConfigureSwiftSpecificLinkerArgsPhase,
AwaitAllBackgroundJobsPhase,
Expand Down Expand Up @@ -290,7 +290,7 @@ class SkiePhaseScheduler {
}

context(ScheduledPhase.Context)
fun runLinkPhases(contextFactory: () -> LinkPhase.Context) {
fun runLinkPhases(contextFactory: () -> CompilerDependentLinkPhase.Context) {
linkPhases.run(contextFactory)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package co.touchlab.skie.phases
import co.touchlab.skie.kir.irbuilder.impl.DeclarationBuilderImpl
import co.touchlab.skie.kir.util.SkieSymbolTable

interface SymbolTablePhase : ForegroundPhase<SymbolTablePhase.Context> {
interface SymbolTablePhase : CompilerDependentForegroundPhase<SymbolTablePhase.Context> {

interface Context : ForegroundPhase.Context {
interface Context : CompilerDependentForegroundPhase.Context {

override val context: Context

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package co.touchlab.skie.phases.other

import co.touchlab.skie.phases.LinkPhase
import co.touchlab.skie.phases.CompilerDependentLinkPhase
import org.jetbrains.kotlin.backend.konan.KonanConfigKeys
import org.jetbrains.kotlin.konan.target.platformName
import java.io.File

object ConfigureSwiftSpecificLinkerArgsPhase : LinkPhase {
object ConfigureSwiftSpecificLinkerArgsPhase : CompilerDependentLinkPhase {

context(LinkPhase.Context)
context(CompilerDependentLinkPhase.Context)
override suspend fun execute() {
val swiftLibSearchPaths = listOf(
File(configurables.absoluteTargetToolchain, "usr/lib/swift/${configurables.platformName().lowercase()}"),
Expand Down
Loading

0 comments on commit 4a705f0

Please sign in to comment.