Skip to content

Commit

Permalink
Change how compiler features are rolled out
Browse files Browse the repository at this point in the history
This change introduces a new mechnism to roll out compiler
features that are intended to be made the eventual default
behavior. Instead of introducing a flag that can be confused
with configuration option will always be options, all such
features are now enabled or disabled through "featureFlag".

Relnote: """Changed how features being rolled out are
enabled and disabled. Features, such as strong skipping and
non-skipping group optimizations are now enabled through the
"featureFlag" option instead of their own option.

A feature with a feature flag start off initially disabled
and will eventually become enabled by default.

For example, to enable strong skipping use:

  -P plugin:androidx.compose.compiler.plugins.kotlin:featureFlag=StrongSkipping

To enable the non-skipping groups optimization use:

  -P plugin:androidx.compose.compiler.plugins.kotlin:featureFlag=OptimizeNonSkippingGroups

the options strongSkipping, experimentialStrongSkipping,
and nonSkippingGroupOptimization are now all depricated
and will report an warning if used but are still honored.

A feature flag can be removed if its name is prefixed
with a "-". For example:

  -P plugin:androidx.compose.compiler.plugins.kotlin:featureFlag=-StrongSkipping

will disable strong skipping.

Using a feature that is unknown to the plugin will
report a warning.

If a feature is enabled that is enabled by default or
disabled and is disabled by default, a warning will be
issued.
"""

Test: ./gradlew :compose:c:c-h:i-t:check
Change-Id: Iab20b3f0e5e818a98f7952bbe1e1ebbd2b8251c7 ( https://android-review.googlesource.com/q/Iab20b3f0e5e818a98f7952bbe1e1ebbd2b8251c7 )

Moved from: androidx/androidx@881d783
  • Loading branch information
chuckjaz authored and Space Cloud committed May 2, 2024
1 parent 3810dd7 commit cdfe659
Show file tree
Hide file tree
Showing 28 changed files with 472 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ internal const val TEST_RESOURCES_ROOT = "plugins/compose/compiler-hosted/integr
abstract class AbstractIrTransformTest(useFir: Boolean) : AbstractCodegenTest(useFir) {
override fun CompilerConfiguration.updateConfiguration() {
put(ComposeConfiguration.SOURCE_INFORMATION_ENABLED_KEY, true)
put(ComposeConfiguration.STRONG_SKIPPING_ENABLED_KEY, true)
put(ComposeConfiguration.NON_SKIPPING_GROUP_OPTIMIZATION_ENABLED_KEY, true)
put(ComposeConfiguration.FEATURE_FLAGS, listOf(
FeatureFlag.StrongSkipping.featureName,
FeatureFlag.OptimizeNonSkippingGroups.featureName,
))
}

@JvmField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ abstract class AbstractLiveLiteralTransformTests(
pluginContext,
symbolRemapper,
ModuleMetricsImpl("temp") { stabilityInferencer.stabilityOf(it) },
stabilityInferencer
stabilityInferencer,
FeatureFlags()
) {
override fun makeKeySet(): MutableSet<String> {
return super.makeKeySet().also { builtKeys = it }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import org.junit.Test
class ComposeModuleMetricsTests(useFir: Boolean) : AbstractMetricsTransformTest(useFir) {
override fun CompilerConfiguration.updateConfiguration() {
// Tests in this file are about testing the output, so we want non-skippable composables
put(ComposeConfiguration.STRONG_SKIPPING_ENABLED_KEY, false)
put(
ComposeConfiguration.FEATURE_FLAGS,
listOf(FeatureFlag.StrongSkipping.disabledName)
)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ class ControlFlowTransformTestsNoSource(
) : AbstractControlFlowTransformTests(useFir) {
override fun CompilerConfiguration.updateConfiguration() {
put(ComposeConfiguration.SOURCE_INFORMATION_ENABLED_KEY, false)
put(ComposeConfiguration.NON_SKIPPING_GROUP_OPTIMIZATION_ENABLED_KEY, true)
put(
ComposeConfiguration.FEATURE_FLAGS,
listOf(FeatureFlag.OptimizeNonSkippingGroups.featureName)
)
put(ComposeConfiguration.TRACE_MARKERS_ENABLED_KEY, false)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import org.junit.Test
class LambdaMemoizationTransformTests(useFir: Boolean) : AbstractIrTransformTest(useFir) {
override fun CompilerConfiguration.updateConfiguration() {
put(ComposeConfiguration.SOURCE_INFORMATION_ENABLED_KEY, true)
put(ComposeConfiguration.NON_SKIPPING_GROUP_OPTIMIZATION_ENABLED_KEY, true)
put(
ComposeConfiguration.FEATURE_FLAGS,
listOf(FeatureFlag.OptimizeNonSkippingGroups.featureName)
)
languageVersionSettings = LanguageVersionSettingsImpl(
languageVersion = languageVersionSettings.languageVersion,
apiVersion = languageVersionSettings.apiVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ import org.junit.Test
class RememberIntrinsicTransformTests(useFir: Boolean) : AbstractIrTransformTest(useFir) {
override fun CompilerConfiguration.updateConfiguration() {
put(ComposeConfiguration.SOURCE_INFORMATION_ENABLED_KEY, true)
put(ComposeConfiguration.INTRINSIC_REMEMBER_OPTIMIZATION_ENABLED_KEY, true)
put(ComposeConfiguration.NON_SKIPPING_GROUP_OPTIMIZATION_ENABLED_KEY, true)
put(
ComposeConfiguration.FEATURE_FLAGS,
listOf(
FeatureFlag.OptimizeNonSkippingGroups.featureName,
FeatureFlag.IntrinsicRemember.featureName
)
)
}

private fun comparisonPropagation(
Expand Down Expand Up @@ -793,9 +798,14 @@ class RememberIntrinsicTransformTestsStrongSkipping(
) : AbstractIrTransformTest(useFir) {
override fun CompilerConfiguration.updateConfiguration() {
put(ComposeConfiguration.SOURCE_INFORMATION_ENABLED_KEY, true)
put(ComposeConfiguration.INTRINSIC_REMEMBER_OPTIMIZATION_ENABLED_KEY, true)
put(ComposeConfiguration.NON_SKIPPING_GROUP_OPTIMIZATION_ENABLED_KEY, true)
put(ComposeConfiguration.STRONG_SKIPPING_ENABLED_KEY, true)
put(
ComposeConfiguration.FEATURE_FLAGS,
listOf(
FeatureFlag.IntrinsicRemember.featureName,
FeatureFlag.OptimizeNonSkippingGroups.featureName,
FeatureFlag.StrongSkipping.featureName
)
)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ class RunComposableTests(useFir: Boolean) : AbstractCodegenTest(useFir) {
val instanceClass = compiledClassesLoader.loadClass(className)

val instanceOfClass = instanceClass.getDeclaredConstructor().newInstance()
println(instanceClass.methods.joinToString())
val testMethod = instanceClass.getMethod(
"test",
Composer::class.java,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ class MultipleStabilityConfigurationTest(useFir: Boolean) : AbstractIrTransformT
"$PATH_TO_CONFIG_FILES/config2.conf"
)
)
put(ComposeConfiguration.STRONG_SKIPPING_ENABLED_KEY, false)
put(
ComposeConfiguration.FEATURE_FLAGS,
listOf(FeatureFlag.OptimizeNonSkippingGroups.featureName)
)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ class StrongSkippingModeTransformTests(
}

override fun CompilerConfiguration.updateConfiguration() {
put(ComposeConfiguration.STRONG_SKIPPING_ENABLED_KEY, true)
put(
ComposeConfiguration.INTRINSIC_REMEMBER_OPTIMIZATION_ENABLED_KEY,
intrinsicRememberEnabled
ComposeConfiguration.FEATURE_FLAGS,
listOf(
FeatureFlag.StrongSkipping.featureName,
FeatureFlag.OptimizeNonSkippingGroups.featureName,
FeatureFlag.IntrinsicRemember.name(intrinsicRememberEnabled)
)
)
put(ComposeConfiguration.NON_SKIPPING_GROUP_OPTIMIZATION_ENABLED_KEY, true)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,15 @@ class ComposeIrGenerationExtension(
private val generateFunctionKeyMetaClasses: Boolean = false,
private val sourceInformationEnabled: Boolean = true,
private val traceMarkersEnabled: Boolean = true,
private val intrinsicRememberEnabled: Boolean = false,
private val nonSkippingGroupOptimizationEnabled: Boolean = false,
private val decoysEnabled: Boolean = false,
private val metricsDestination: String? = null,
private val reportsDestination: String? = null,
private val validateIr: Boolean = false,
private val useK2: Boolean = false,
private val strongSkippingEnabled: Boolean = false,
private val stableTypeMatchers: Set<FqNameMatcher> = emptySet(),
private val moduleMetricsFactory: ((StabilityInferencer) -> ModuleMetrics)? = null,
private val descriptorSerializerContext: ComposeDescriptorSerializerContext? = null,
private val featureFlags: FeatureFlags,
) : IrGenerationExtension {
var metrics: ModuleMetrics = EmptyModuleMetrics
private set
Expand Down Expand Up @@ -111,7 +109,8 @@ class ComposeIrGenerationExtension(
symbolRemapper,
metrics,
descriptorSerializerContext?.hideFromObjCDeclarationsSet,
stabilityInferencer
stabilityInferencer,
featureFlags,
).lower(moduleFragment)
}

Expand All @@ -124,7 +123,8 @@ class ComposeIrGenerationExtension(
classStabilityInferredCollection = descriptorSerializerContext
?.classStabilityInferredCollection?.takeIf {
!pluginContext.platform.isJvm()
}
},
featureFlags,
).lower(moduleFragment)

LiveLiteralTransformer(
Expand All @@ -134,7 +134,8 @@ class ComposeIrGenerationExtension(
pluginContext,
symbolRemapper,
metrics,
stabilityInferencer
stabilityInferencer,
featureFlags,
).lower(moduleFragment)

ComposableFunInterfaceLowering(pluginContext).lower(moduleFragment)
Expand All @@ -143,7 +144,8 @@ class ComposeIrGenerationExtension(
pluginContext,
symbolRemapper,
metrics,
stabilityInferencer
stabilityInferencer,
featureFlags,
)

functionKeyTransformer.lower(moduleFragment)
Expand All @@ -154,9 +156,7 @@ class ComposeIrGenerationExtension(
symbolRemapper,
metrics,
stabilityInferencer,
strongSkippingEnabled,
intrinsicRememberEnabled,
nonSkippingGroupOptimizationEnabled,
featureFlags,
).lower(moduleFragment)

if (!useK2) {
Expand Down Expand Up @@ -186,6 +186,7 @@ class ComposeIrGenerationExtension(
idSignatureBuilder,
stabilityInferencer,
metrics,
featureFlags,
).lower(moduleFragment)

SubstituteDecoyCallsTransformer(
Expand All @@ -194,6 +195,7 @@ class ComposeIrGenerationExtension(
idSignatureBuilder,
stabilityInferencer,
metrics,
featureFlags,
).lower(moduleFragment)
}

Expand All @@ -206,13 +208,15 @@ class ComposeIrGenerationExtension(
stabilityInferencer,
decoysEnabled,
metrics,
featureFlags,
).lower(moduleFragment)

ComposableTargetAnnotationsTransformer(
pluginContext,
symbolRemapper,
metrics,
stabilityInferencer
stabilityInferencer,
featureFlags,
).lower(moduleFragment)

// transform calls to the currentComposer to just use the local parameter from the
Expand All @@ -226,9 +230,7 @@ class ComposeIrGenerationExtension(
stabilityInferencer,
sourceInformationEnabled,
traceMarkersEnabled,
intrinsicRememberEnabled,
nonSkippingGroupOptimizationEnabled,
strongSkippingEnabled
featureFlags,
).lower(moduleFragment)

if (decoysEnabled) {
Expand All @@ -242,7 +244,8 @@ class ComposeIrGenerationExtension(
idSignatureBuilder,
metrics,
mangler!!,
stabilityInferencer
stabilityInferencer,
featureFlags,
).lower(moduleFragment)
}

Expand All @@ -251,7 +254,8 @@ class ComposeIrGenerationExtension(
pluginContext,
symbolRemapper,
metrics,
stabilityInferencer
stabilityInferencer,
featureFlags,
).lower(moduleFragment)
}

Expand All @@ -262,7 +266,8 @@ class ComposeIrGenerationExtension(
metrics,
idSignatureBuilder,
stabilityInferencer,
decoysEnabled
decoysEnabled,
featureFlags,
).lower(moduleFragment)
}

Expand Down
Loading

0 comments on commit cdfe659

Please sign in to comment.