Skip to content

Commit

Permalink
Move SkiePhaseScheduler to core module.
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipDolnik committed Apr 18, 2024
1 parent 680bb0e commit f187dfe
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 68 deletions.
2 changes: 1 addition & 1 deletion SKIE/acceptance-tests
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import co.touchlab.skie.analytics.performance.SkiePerformanceAnalytics
import co.touchlab.skie.configuration.RootConfiguration
import co.touchlab.skie.configuration.SkieConfigurationFlag
import co.touchlab.skie.configuration.provider.CompilerSkieConfigurationData
import co.touchlab.skie.phases.SkiePhaseScheduler
import co.touchlab.skie.plugin.analytics.AnalyticsCollector
import co.touchlab.skie.util.CompilerShim
import co.touchlab.skie.util.FrameworkLayout
Expand All @@ -29,6 +30,8 @@ interface CommonSkieContext {

val reporter: Reporter

val skiePhaseScheduler: SkiePhaseScheduler

val compilerShim: CompilerShim

val skieBuildDirectory: SkieBuildDirectory
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package co.touchlab.skie.phases

import co.touchlab.skie.phases.util.SkiePhaseGroup
import co.touchlab.skie.phases.util.run

interface SkiePhaseScheduler {

val classExportPhases: SkiePhaseGroup<ClassExportPhase, ClassExportPhase.Context>

val frontendIrPhases: SkiePhaseGroup<FrontendIrPhase, FrontendIrPhase.Context>

val symbolTablePhases: SkiePhaseGroup<SymbolTablePhase, SymbolTablePhase.Context>

val kotlinIrPhases: SkiePhaseGroup<KotlinIrPhase, KotlinIrPhase.Context>

val kirPhases: SkiePhaseGroup<KirPhase, KirPhase.Context>

val sirPhases: SkiePhaseGroup<SirPhase, SirPhase.Context>

val linkPhases: SkiePhaseGroup<LinkPhase, LinkPhase.Context>

context(ScheduledPhase.Context)
fun runClassExportPhases(contextFactory: () -> ClassExportPhase.Context) {
classExportPhases.run(contextFactory)
}

context(ScheduledPhase.Context)
fun runFrontendIrPhases(contextFactory: () -> FrontendIrPhase.Context) {
frontendIrPhases.run(contextFactory)
}

context(ScheduledPhase.Context)
fun runSymbolTablePhases(contextFactory: () -> SymbolTablePhase.Context) {
symbolTablePhases.run(contextFactory)
}

context(ScheduledPhase.Context)
fun runKotlinIrPhases(contextFactory: () -> KotlinIrPhase.Context) {
kotlinIrPhases.run(contextFactory)
}

context(ScheduledPhase.Context)
fun runKirPhases(contextFactory: () -> KirPhase.Context) {
kirPhases.run(contextFactory)
}

context(ScheduledPhase.Context)
fun runSirPhases(contextFactory: () -> SirPhase.Context) {
sirPhases.run(contextFactory)
}

context(ScheduledPhase.Context)
fun runLinkPhases(contextFactory: () -> LinkPhase.Context) {
linkPhases.run(contextFactory)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package co.touchlab.skie.phases.util

import co.touchlab.skie.phases.KirPhase

abstract class StatefulKirPhase : KirPhase, StatefulScheduledPhase<KirPhase.Context>()
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import co.touchlab.skie.configuration.RootConfiguration
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.LinkerPhaseScheduler
import co.touchlab.skie.phases.SkiePhaseScheduler
import co.touchlab.skie.plugin.analytics.AnalyticsCollector
import co.touchlab.skie.util.ActualCompilerShim
Expand All @@ -25,7 +26,7 @@ class InitPhaseContext(
override val context: InitPhase.Context
get() = this

val skiePhaseScheduler: SkiePhaseScheduler = SkiePhaseScheduler()
override val skiePhaseScheduler: SkiePhaseScheduler = LinkerPhaseScheduler()

override val skieDirectories: SkieDirectories = compilerConfiguration.getNotNull(SkieConfigurationKeys.SkieDirectories)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import co.touchlab.skie.kir.descriptor.NativeDescriptorProvider
import co.touchlab.skie.kir.irbuilder.impl.DeclarationBuilderImpl
import co.touchlab.skie.phases.BackgroundPhase
import co.touchlab.skie.phases.ScheduledPhase
import co.touchlab.skie.phases.SkiePhaseScheduler
import co.touchlab.skie.phases.configurables
import co.touchlab.skie.phases.util.StatefulScheduledPhase
import kotlinx.coroutines.CoroutineExceptionHandler
Expand All @@ -37,8 +36,6 @@ class MainSkieContext internal constructor(
exportedDependencies: Collection<ModuleDescriptor>,
) : ForegroundPhaseCompilerContext, BackgroundPhase.Context, CommonSkieContext by initPhaseContext {

val skiePhaseScheduler: SkiePhaseScheduler = initPhaseContext.skiePhaseScheduler

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 @@ -6,8 +6,5 @@ import org.jetbrains.kotlin.config.CompilerConfiguration
val InitPhase.Context.compilerConfiguration: CompilerConfiguration
get() = typedContext.compilerConfiguration

val InitPhase.Context.skiePhaseScheduler: SkiePhaseScheduler
get() = typedContext.skiePhaseScheduler

private val InitPhase.Context.typedContext: InitPhaseContext
get() = context as InitPhaseContext
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("MemberVisibilityCanBePrivate", "RemoveExplicitTypeArguments", "UNUSED_ANONYMOUS_PARAMETER")
@file:Suppress("RemoveExplicitTypeArguments", "UNUSED_ANONYMOUS_PARAMETER")

package co.touchlab.skie.phases

Expand Down Expand Up @@ -82,12 +82,11 @@ import co.touchlab.skie.phases.typeconflicts.RenameTypesConflictingWithKotlinMod
import co.touchlab.skie.phases.typeconflicts.RenameTypesConflictsWithOtherTypesPhase
import co.touchlab.skie.phases.typeconflicts.TemporarilyRenameTypesConflictingWithExternalModulesPhase
import co.touchlab.skie.phases.util.SkiePhaseGroup
import co.touchlab.skie.phases.util.run
import co.touchlab.skie.util.addAll

class SkiePhaseScheduler {
class LinkerPhaseScheduler : SkiePhaseScheduler {

val classExportPhases = SkiePhaseGroup<ClassExportPhase, ClassExportPhase.Context> { context ->
override val classExportPhases = SkiePhaseGroup<ClassExportPhase, ClassExportPhase.Context> { context ->
addAll(
VerifyModuleNamePhase,
VerifyMinOSVersionPhase,
Expand All @@ -98,27 +97,27 @@ class SkiePhaseScheduler {
)
}

val frontendIrPhases = SkiePhaseGroup<FrontendIrPhase, FrontendIrPhase.Context> { context ->
override val frontendIrPhases = SkiePhaseGroup<FrontendIrPhase, FrontendIrPhase.Context> { context ->
addAll(
DefaultArgumentGenerator(context),
SuspendGenerator,
)
}

val symbolTablePhases = SkiePhaseGroup<SymbolTablePhase, SymbolTablePhase.Context> { context ->
override val symbolTablePhases = SkiePhaseGroup<SymbolTablePhase, SymbolTablePhase.Context> { context ->
addAll(
DeclareMissingSymbolsPhase,
)
}

val kotlinIrPhases = SkiePhaseGroup<KotlinIrPhase, KotlinIrPhase.Context> { context ->
override val kotlinIrPhases = SkiePhaseGroup<KotlinIrPhase, KotlinIrPhase.Context> { context ->
addAll(
KotlinIrAnalyticsPhase,
GenerateIrPhase,
)
}

val kirPhases = SkiePhaseGroup<KirPhase, KirPhase.Context> { context ->
override val kirPhases = SkiePhaseGroup<KirPhase, KirPhase.Context> { context ->
addAll(
VerifyDescriptorProviderConsistencyPhase,

Expand All @@ -145,7 +144,7 @@ class SkiePhaseScheduler {
)
}

val sirPhases = SkiePhaseGroup<SirPhase, SirPhase.Context> { context ->
override val sirPhases = SkiePhaseGroup<SirPhase, SirPhase.Context> { context ->
addAll(
// Debug(before)

Expand Down Expand Up @@ -247,7 +246,7 @@ class SkiePhaseScheduler {
)
}

val linkPhases = SkiePhaseGroup<LinkPhase, LinkPhase.Context> { context ->
override val linkPhases = SkiePhaseGroup<LinkPhase, LinkPhase.Context> { context ->
addAll(
ConfigureSwiftSpecificLinkerArgsPhase,
AwaitAllBackgroundJobsPhase,
Expand All @@ -256,39 +255,4 @@ class SkiePhaseScheduler {
LogSkiePerformanceAnalyticsPhase,
)
}

context(ScheduledPhase.Context)
fun runClassExportPhases(contextFactory: () -> ClassExportPhase.Context) {
classExportPhases.run(contextFactory)
}

context(ScheduledPhase.Context)
fun runFrontendIrPhases(contextFactory: () -> FrontendIrPhase.Context) {
frontendIrPhases.run(contextFactory)
}

context(ScheduledPhase.Context)
fun runSymbolTablePhases(contextFactory: () -> SymbolTablePhase.Context) {
symbolTablePhases.run(contextFactory)
}

context(ScheduledPhase.Context)
fun runKotlinIrPhases(contextFactory: () -> KotlinIrPhase.Context) {
kotlinIrPhases.run(contextFactory)
}

context(ScheduledPhase.Context)
fun runKirPhases(contextFactory: () -> KirPhase.Context) {
kirPhases.run(contextFactory)
}

context(ScheduledPhase.Context)
fun runSirPhases(contextFactory: () -> SirPhase.Context) {
sirPhases.run(contextFactory)
}

context(ScheduledPhase.Context)
fun runLinkPhases(contextFactory: () -> LinkPhase.Context) {
linkPhases.run(contextFactory)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import co.touchlab.skie.phases.features.defaultarguments.delegate.ClassMethodsDe
import co.touchlab.skie.phases.features.defaultarguments.delegate.ConstructorsDefaultArgumentGeneratorDelegate
import co.touchlab.skie.phases.features.defaultarguments.delegate.ExtensionFunctionDefaultArgumentGeneratorDelegate
import co.touchlab.skie.phases.features.defaultarguments.delegate.TopLevelFunctionDefaultArgumentGeneratorDelegate
import co.touchlab.skie.phases.util.StatefulCompilerDependentKirPhase
import co.touchlab.skie.phases.util.StatefulKirPhase
import co.touchlab.skie.phases.util.StatefulSirPhase
import co.touchlab.skie.util.SharedCounter

Expand All @@ -29,9 +29,9 @@ class DefaultArgumentGenerator(
}
}

object RegisterOverloadsPhase : StatefulCompilerDependentKirPhase()
object RegisterOverloadsPhase : StatefulKirPhase()

object RemoveManglingOfOverloadsInitPhase : StatefulCompilerDependentKirPhase()
object RemoveManglingOfOverloadsInitPhase : StatefulKirPhase()

object RemoveManglingOfOverloadsFinalizePhase : StatefulSirPhase()
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import co.touchlab.skie.kir.descriptor.DescriptorProvider
import co.touchlab.skie.kir.descriptor.allExposedMembers
import co.touchlab.skie.phases.FrontendIrPhase
import co.touchlab.skie.phases.descriptorProvider
import co.touchlab.skie.phases.util.StatefulCompilerDependentKirPhase
import co.touchlab.skie.phases.util.StatefulKirPhase
import co.touchlab.skie.phases.util.StatefulSirPhase
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor

Expand Down Expand Up @@ -38,13 +38,13 @@ object SuspendGenerator : FrontendIrPhase {
private val SimpleFunctionDescriptor.isSupported: Boolean
get() = this.isSuspend

object FlowMappingConfigurationPhase : StatefulCompilerDependentKirPhase()
object FlowMappingConfigurationPhase : StatefulKirPhase()

object KotlinBridgingFunctionVisibilityConfigurationInitPhase : StatefulCompilerDependentKirPhase()
object KotlinBridgingFunctionVisibilityConfigurationInitPhase : StatefulKirPhase()

object KotlinBridgingFunctionVisibilityConfigurationFinalizePhase : StatefulSirPhase()

object SwiftBridgeGeneratorInitPhase : StatefulCompilerDependentKirPhase()
object SwiftBridgeGeneratorInitPhase : StatefulKirPhase()

object SwiftBridgeGeneratorFinalizePhase : StatefulSirPhase()
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import co.touchlab.skie.phases.declarationBuilder
import co.touchlab.skie.phases.descriptorKirProvider
import co.touchlab.skie.phases.descriptorProvider
import co.touchlab.skie.phases.mapper
import co.touchlab.skie.phases.util.StatefulCompilerDependentKirPhase
import co.touchlab.skie.phases.util.StatefulKirPhase
import co.touchlab.skie.phases.util.StatefulSirPhase
import co.touchlab.skie.phases.util.doInPhase
import co.touchlab.skie.sir.element.SirVisibility
Expand Down Expand Up @@ -165,7 +165,7 @@ class ExtraClassExportPhase(
}
}

object HideExportFunctionsInitPhase : StatefulCompilerDependentKirPhase()
object HideExportFunctionsInitPhase : StatefulKirPhase()

object HideExportFunctionsFinalizePhase : StatefulSirPhase()
}
Expand Down

This file was deleted.

0 comments on commit f187dfe

Please sign in to comment.