-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce ComposableCallstackTracker (#81)
This feature is experimental. Resolves #77.
- Loading branch information
Showing
67 changed files
with
1,198 additions
and
676 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
plugins { | ||
kotlin("jvm") | ||
id(libs.plugins.gradle.publish.maven.get().pluginId) | ||
} | ||
|
||
sourceSets { | ||
getByName("main").java.srcDir("src/main/kotlin") | ||
} | ||
|
||
kotlin { | ||
explicitApi() | ||
} | ||
|
||
dependencies { | ||
implementation(libs.kotlin.compiler.embedded) | ||
implementation(libs.fastlist) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
POM_NAME=ComposeInvestigator Compiler Base | ||
POM_ARTIFACT_ID=composeinvestigator-compiler-base | ||
|
||
VERSION_NAME=0.1.0-SNAPSHOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
compiler-base/src/main/kotlin/land/sungbin/composeinvestigator/compiler/base/names.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Designed and developed by Ji Sungbin 2023. | ||
* | ||
* Licensed under the MIT. | ||
* Please see full license: https://github.com/jisungbin/ComposeInvestigator/blob/main/LICENSE | ||
*/ | ||
|
||
package land.sungbin.composeinvestigator.compiler.base | ||
|
||
import org.jetbrains.kotlin.name.CallableId | ||
import org.jetbrains.kotlin.name.FqName | ||
import org.jetbrains.kotlin.name.Name | ||
import org.jetbrains.kotlin.name.SpecialNames | ||
|
||
// ===== PACKAGE ===== // | ||
|
||
public const val AndroidxComposeRuntime: String = "androidx.compose.runtime" | ||
public const val ComposeInvestigatorRuntime: String = "land.sungbin.composeinvestigator.runtime" | ||
public const val ComposeInvestigatorRuntimeAffect: String = "land.sungbin.composeinvestigator.runtime.affect" | ||
|
||
// ===== FULLY-QUALIFIED NAME ===== // | ||
|
||
// START Kotlin/Java Standard Library | ||
public val ITERABLE_TO_LIST_FQN: FqName = FqName("kotlin.collections.toList") | ||
public val EMPTY_LIST_FQN: FqName = FqName("kotlin.collections.emptyList") | ||
|
||
public val MUTABLE_LIST_OF_FQN: FqName = FqName("kotlin.collections.mutableListOf") | ||
public val MUTABLE_LIST_ADD_FQN: FqName = FqName("kotlin.collections.MutableList.add") | ||
|
||
public val HASH_CODE_FQN: FqName = FqName("kotlin.hashCode") | ||
|
||
public val STACK_FQN: FqName = FqName("java.util.Stack") | ||
public val Stack_PUSH: Name = Name.identifier("push") | ||
public val Stack_POP: Name = Name.identifier("pop") | ||
// END Kotlin/Java Standard Library | ||
|
||
// START Compose Runtime | ||
public val COMPOSER_FQN: FqName = FqName("$AndroidxComposeRuntime.Composer") | ||
|
||
public val Composer_SKIPPING: Name = Name.identifier("skipping") | ||
public val Composer_SKIP_TO_GROUP_END: Name = Name.identifier("skipToGroupEnd") | ||
|
||
public val SCOPE_UPDATE_SCOPE_FQN: FqName = FqName("$AndroidxComposeRuntime.ScopeUpdateScope") | ||
public val ScopeUpdateScope_UPDATE_SCOPE: Name = Name.identifier("updateScope") | ||
|
||
public val STATE_FQN: FqName = FqName("$AndroidxComposeRuntime.State") | ||
// END Compose Runtime | ||
|
||
// START Compose Animation | ||
public val ANIMATABLE_FQN: FqName = FqName("androidx.compose.animation.core.Animatable") | ||
// END Compose Animation | ||
|
||
// START ComposeInvestigatorConfig | ||
public val COMPOSE_INVESTIGATOR_CONFIG_FQN: FqName = FqName("$ComposeInvestigatorRuntime.ComposeInvestigatorConfig") | ||
public val ComposeInvestigatorConfig_INVALIDATION_LOGGER: Name = Name.identifier("invalidationLogger") | ||
// END ComposeInvestigatorConfig | ||
|
||
// START ComposableInvalidationLogger | ||
public val COMPOSABLE_INVALIDATION_LOGGER_FQN: FqName = FqName("$ComposeInvestigatorRuntime.ComposableInvalidationLogger") | ||
public val ComposableInvalidationLogger_INVOKE: Name = Name.identifier("invoke") | ||
|
||
public val INVALIDATION_REASON_FQN: FqName = FqName("$ComposeInvestigatorRuntime.InvalidationReason") | ||
public val InvalidationReason_Invalidate: Name = Name.identifier("Invalidate") | ||
|
||
public val COMPOSABLE_INVALIDATION_TYPE_FQN: FqName = FqName("$ComposeInvestigatorRuntime.ComposableInvalidationType") | ||
public val ComposableInvalidationType_PROCESSED: Name = Name.identifier("Processed") | ||
public val ComposableInvalidationType_SKIPPED: Name = Name.identifier("Skipped") | ||
// END ComposableInvalidationLogger | ||
|
||
// START ComposableInvalidationTrackTable | ||
public val CURRENT_COMPOSABLE_INVALIDATION_TRACKER_FQN: FqName = FqName("$ComposeInvestigatorRuntime.currentComposableInvalidationTracker") | ||
|
||
public val COMPOSABLE_NAME_FQN: FqName = FqName("$ComposeInvestigatorRuntime.ComposableName") | ||
|
||
public val COMPOSABLE_INVALIDATION_TRACK_TABLE_FQN: FqName = FqName("$ComposeInvestigatorRuntime.ComposableInvalidationTrackTable") | ||
public val ComposableInvalidationTrackTable_CURRENT_COMPOSABLE_NAME: Name = Name.identifier("currentComposableName") | ||
public val ComposableInvalidationTrackTable_CURRENT_COMPOSABLE_KEY_NAME: Name = Name.identifier("currentComposableKeyName") | ||
public val ComposableInvalidationTrackTable_CALL_LISTENERS: Name = Name.identifier("callListeners") | ||
public val ComposableInvalidationTrackTable_COMPUTE_INVALIDATION_REASON: Name = Name.identifier("computeInvalidationReason") | ||
// END ComposableInvalidationTrackTable | ||
|
||
// START StateObjectTracker | ||
public val REGISTER_STATE_OBJECT_TRACKING_FQN: FqName = FqName("$ComposeInvestigatorRuntime.registerStateObjectTracking") | ||
// END StateObjectTracker | ||
|
||
// START DeclarationStability | ||
public val DECLARATION_STABILITY_FQN: FqName = FqName("$ComposeInvestigatorRuntime.DeclarationStability") | ||
public val DeclarationStability_CERTAIN: Name = Name.identifier("Certain") | ||
public val DeclarationStability_RUNTIME: Name = Name.identifier("Runtime") | ||
public val DeclarationStability_UNKNOWN: Name = Name.identifier("Unknown") | ||
public val DeclarationStability_PARAMETER: Name = Name.identifier("Parameter") | ||
public val DeclarationStability_COMBINED: Name = Name.identifier("Combined") | ||
// END DeclarationStability | ||
|
||
// START affect/AffectedField | ||
public val AFFECTED_FIELD_FQN: FqName = FqName("$ComposeInvestigatorRuntimeAffect.AffectedField") | ||
public val AffectedField_VALUE_PARAMETER: Name = Name.identifier("ValueParameter") | ||
// END affect/AffectableField | ||
|
||
// START affect/AffectedComposable | ||
public val AFFECTED_COMPOSABLE_FQN: FqName = FqName("$ComposeInvestigatorRuntimeAffect.AffectedComposable") | ||
// END affect/AffectedComposable | ||
|
||
public fun CallableId.Companion.fromFqName(fqName: FqName): CallableId = | ||
CallableId(packageName = fqName.parent(), callableName = fqName.shortName()) | ||
|
||
@Suppress("UnusedReceiverParameter") | ||
public val SpecialNames.UNKNOWN_STRING: String get() = "<unknown>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
POM_NAME=ComposeInvestigator Compiler Callstack Tracker | ||
POM_ARTIFACT_ID=composeinvestigator-compiler-callstack | ||
|
||
VERSION_NAME=0.1.0-SNAPSHOT |
34 changes: 34 additions & 0 deletions
34
...sungbin/composeinvestigator/compiler/callstack/ComposableCallstackTrackPluginRegistrar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Designed and developed by Ji Sungbin 2023. | ||
* | ||
* Licensed under the MIT. | ||
* Please see full license: https://github.com/jisungbin/ComposeInvestigator/blob/main/LICENSE | ||
*/ | ||
|
||
@file:Suppress("unused", "DEPRECATION", "UnstableApiUsage") | ||
|
||
package land.sungbin.composeinvestigator.compiler.callstack | ||
|
||
import com.google.auto.service.AutoService | ||
import land.sungbin.composeinvestigator.compiler.base.VerboseLogger | ||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension | ||
import org.jetbrains.kotlin.com.intellij.mock.MockProject | ||
import org.jetbrains.kotlin.com.intellij.openapi.extensions.LoadingOrder | ||
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar | ||
import org.jetbrains.kotlin.config.CompilerConfiguration | ||
|
||
@AutoService(ComponentRegistrar::class) | ||
public class ComposableCallstackTrackPluginRegistrar : ComponentRegistrar { | ||
override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) { | ||
val verbose = configuration[ComposableCallstackTrackerConfiguration.KEY_VERBOSE]?.toBooleanStrictOrNull() ?: false | ||
val logger = VerboseLogger(configuration).apply { if (verbose) verbose() } | ||
|
||
project.extensionArea | ||
.getExtensionPoint(IrGenerationExtension.extensionPointName) | ||
.registerExtension( | ||
ComposableCallstackTrackingExtension(logger = logger), | ||
LoadingOrder.FIRST, | ||
project, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...nd/sungbin/composeinvestigator/compiler/callstack/ComposableCallstackTrackingExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Designed and developed by Ji Sungbin 2023. | ||
* | ||
* Licensed under the MIT. | ||
* Please see full license: https://github.com/jisungbin/ComposeInvestigator/blob/main/LICENSE | ||
*/ | ||
|
||
package land.sungbin.composeinvestigator.compiler.callstack | ||
|
||
import land.sungbin.composeinvestigator.compiler.base.VerboseLogger | ||
import land.sungbin.composeinvestigator.compiler.callstack.internal.ComposableCallstackTrackingTransformer | ||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension | ||
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext | ||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment | ||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid | ||
|
||
internal class ComposableCallstackTrackingExtension(private val logger: VerboseLogger) : IrGenerationExtension { | ||
override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) { | ||
moduleFragment.transformChildrenVoid( | ||
ComposableCallstackTrackingTransformer( | ||
context = pluginContext, | ||
logger = logger, | ||
), | ||
) | ||
} | ||
} |
Oops, something went wrong.