Skip to content

test(ios): automated Swift DCE verification for #if !DISABLE_* guards #211

Closed

Description

@kirich1409

Goal

Add an automated test that proves the Swift compiler eliminates code guarded by #if !DISABLE_* from release binaries, mirroring featured-shrinker-tests for Android R8.

Context

The Gradle plugin generates FeatureFlags.generated.xcconfig with SWIFT_ACTIVE_COMPILATION_CONDITIONS = $(inherited) DISABLE_<FLAG_KEY> for each local flag whose defaultValue = false:

Today there is no automated verification that Swift DCE actually strips the guarded branches from the release binary — the equivalent of featured-shrinker-tests/src/test/kotlin/dev/androidbroadcast/featured/shrinker/R8BooleanFlagEliminationTest.kt is missing for iOS.

Approach

  • Add a featured-swift-dce-tests Gradle module (skipped on non-macOS hosts).
  • Generate xcconfig via the existing plugin task.
  • Compile a small Swift fixture (swiftc -O -D DISABLE_X) — bypass full Xcode to keep the test fast.
  • Read symbols from the resulting object/binary (nm or swift demangle) and assert that symbols from the disabled branch are absent.
  • Verify the opposite case (no -D DISABLE_X) keeps the symbol present.

Definition of Done

  • New test module wiring xcconfig generation
  • Test compiles a Swift fixture with -O and asserts symbol stripping
  • CI job runs the test on the macOS runner (existing iOS build job already runs there)
  • Wiki page iOS — xcconfig DCE references the test
  • CHANGELOG.md [Unreleased] entry

Related

Activity

  1. kirich1409 commented on Nov 6, 2026

    @kirich1409
    ContributorAuthor

    Backlog: Bugfix FEA-2.

  2. kirich1409 commented on Nov 6, 2026

    @kirich1409
    ContributorAuthor

    Decided: proof is a small Swift fixture compiled with the generated DISABLE_ condition, not the sample iosApp. Task FEA-2.

  3. kirich1409 commented on Nov 6, 2026

    @kirich1409
    ContributorAuthor

    Closed from the generated-condition proof in #313, merged as 14436c4.

    :featured-swift-dce-tests compiles a symbol guarded by #if !DISABLE_* with the plugin-generated DISABLE_* condition, not a hand-written one and not iosApp. The check fails if that condition is missing or does not match the flag. On this machine the compile ran and the guarded symbol was absent when default = false. CI Build iOS passed with -PrequireSwiftDce=true, so a skipped Swift compile was not treated as a pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    gradle-pluginfeatured-gradle-plugin workiosiOS-specific worktestingTests and coverage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions