Skip to content

Commit

Permalink
Fix that replaced visibility was not correctly applied to the entire …
Browse files Browse the repository at this point in the history
…override hierarchy.
  • Loading branch information
FilipDolnik committed May 17, 2024
1 parent 5a12834 commit 1327638
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion SKIE/acceptance-tests
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ annotation class SkieVisibility {
* The declaration will be visible from external modules, but it will be:
* - marked as `swift-private` (Xcode will not include it in autocomplete suggestions.),
* - renamed in Swift by adding the `__` prefix (Obj-C name remains the same)
*
* The `__` prefix will be added to all overrides of the declaration even if they have different visibility.
*/
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY)
Expand All @@ -41,6 +43,8 @@ annotation class SkieVisibility {
/**
* The declaration will be visible only for declarations within the Kotlin module (including custom Swift code bundled by SKIE).
* Additionally, the declaration will be renamed in Swift by adding the `__` prefix (Obj-C name remains the same)
*
* The `__` prefix will be added to all overrides of the declaration even if they have different visibility.
*/
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ object SkieVisibility : ConfigurationKey.Enum<co.touchlab.skie.configuration.Ski
* The declaration will be visible from external modules, but it will be:
* - marked as `swift-private` (Xcode will not include it in autocomplete suggestions.),
* - renamed in Swift by adding the `__` prefix (Obj-C name remains the same); constructors are not affected.
*
* The `__` prefix will be added to all overrides of the declaration even if they have different visibility.
*/
PublicButReplaced(SkieVisibility.PublicButReplaced::class),

Expand All @@ -36,6 +38,8 @@ object SkieVisibility : ConfigurationKey.Enum<co.touchlab.skie.configuration.Ski
/**
* The declaration will be visible only for declarations within the Kotlin module (including custom Swift code bundled by SKIE).
* Additionally, the declaration will be renamed in Swift by adding the `__` prefix (Obj-C name remains the same); constructors are not affected.
*
* The `__` prefix will be added to all overrides of the declaration even if they have different visibility.
*/
InternalAndReplaced(SkieVisibility.InternalAndReplaced::class),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import co.touchlab.skie.sir.element.SirExtension
import co.touchlab.skie.sir.element.SirProperty
import co.touchlab.skie.sir.element.SirSimpleFunction
import co.touchlab.skie.sir.element.SirTypeDeclaration
import co.touchlab.skie.sir.element.applyToEntireOverrideHierarchy

/**
* Prefixes all isReplaced declarations with the appropriate prefix and sets all isReplaced to false.
* Unifies the configuration across all overrides.
*
* This phase ensures that SKIE can use isReplaced internally without having to worry about the declarations already being replaced.
* (For example, isReplaced is used by CreateSirMembersPhase to implement isRefinedInSwift and user-configurable SkieVisibility.)
Expand Down Expand Up @@ -38,15 +40,33 @@ object CommitSirIsReplacedPropertyPhase : SirPhase {
}

private fun SirSimpleFunction.commitIsReplaced() {
this.identifier = this.identifierAfterVisibilityChange
// Already processed by some member of the override hierarchy.
if (!this.isReplaced) {
return
}

this.isReplaced = false
this.applyToEntireOverrideHierarchy {
isReplaced = true

identifier = identifierAfterVisibilityChange

isReplaced = false
}
}

private fun SirProperty.commitIsReplaced() {
this.identifier = this.identifierAfterVisibilityChange
// Already processed by some member of the override hierarchy.
if (!this.isReplaced) {
return
}

this.isReplaced = false
this.applyToEntireOverrideHierarchy {
isReplaced = true

identifier = identifierAfterVisibilityChange

isReplaced = false
}
}

private fun SirTypeDeclaration.commitIsReplaced() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ sealed interface SirDeclarationWithVisibility : SirDeclaration {

/**
* If true, the "__" will be added to the name.
*
* Must be consistent across all overrides.
*/
val isReplaced: Boolean

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package co.touchlab.skie.sir.element

import co.touchlab.skie.kir.util.BaseOverridableDeclaration
import co.touchlab.skie.util.pop

sealed interface SirOverridableDeclaration<T : SirOverridableDeclaration<T>> : SirCallableDeclaration {
Expand Down

0 comments on commit 1327638

Please sign in to comment.