Native: add an option to disable exported Swift member name mangling
This commit supports `objcExportDisableSwiftMemberNameMangling=true` binary option, which disables mangling for Swift names in generated Objective-C headers, but keeps mangling for Objective-C names. Enabling it might cause issues in some cases with actual clashes. ^KT-53638 Fixed
This commit is contained in:
committed by
Space Team
parent
1b016d0bce
commit
e2640b4afa
Executable → Regular
+27
@@ -1564,6 +1564,33 @@ __attribute__((swift_name("Person.WorkerContractor")))
|
||||
@property (readonly) int32_t id __attribute__((swift_name("id")));
|
||||
@end
|
||||
|
||||
__attribute__((swift_name("SwiftNameManglingI1")))
|
||||
@protocol KtSwiftNameManglingI1
|
||||
@required
|
||||
- (int32_t)clashingMethod __attribute__((swift_name("clashingMethod()")));
|
||||
- (int32_t)clashingMethodWithObjCNameInI1 __attribute__((swift_name("swiftClashingMethodWithObjCNameInI1()")));
|
||||
- (int32_t)swiftClashingMethodWithObjCNameInI2 __attribute__((swift_name("swiftClashingMethodWithObjCNameInI2()")));
|
||||
- (int32_t)clashingMethodWithObjCNameInBoth __attribute__((swift_name("swiftClashingMethodWithObjCNameInBoth()")));
|
||||
@property (readonly) int32_t clashingProperty __attribute__((swift_name("clashingProperty")));
|
||||
@end
|
||||
|
||||
__attribute__((swift_name("SwiftNameManglingI2")))
|
||||
@protocol KtSwiftNameManglingI2
|
||||
@required
|
||||
- (id)clashingMethod __attribute__((swift_name("clashingMethod()")));
|
||||
- (id)swiftClashingMethodWithObjCNameInI1 __attribute__((swift_name("swiftClashingMethodWithObjCNameInI1()")));
|
||||
- (id)clashingMethodWithObjCNameInI2 __attribute__((swift_name("swiftClashingMethodWithObjCNameInI2()")));
|
||||
- (id)clashingMethodWithObjCNameInBoth __attribute__((swift_name("swiftClashingMethodWithObjCNameInBoth()")));
|
||||
@property (readonly) id clashingProperty __attribute__((swift_name("clashingProperty")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("SwiftNameManglingKt")))
|
||||
@interface KtSwiftNameManglingKt : KtBase
|
||||
+ (id<KtSwiftNameManglingI1>)i1 __attribute__((swift_name("i1()")));
|
||||
+ (id<KtSwiftNameManglingI2>)i2 __attribute__((swift_name("i2()")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("ThrowableAsError")))
|
||||
@interface KtThrowableAsError : KtKotlinThrowable
|
||||
|
||||
@@ -1499,6 +1499,33 @@ __attribute__((swift_name("Person.WorkerContractor")))
|
||||
@property (readonly) int32_t id __attribute__((swift_name("id")));
|
||||
@end
|
||||
|
||||
__attribute__((swift_name("SwiftNameManglingI1")))
|
||||
@protocol KtSwiftNameManglingI1
|
||||
@required
|
||||
- (int32_t)clashingMethod __attribute__((swift_name("clashingMethod()")));
|
||||
- (int32_t)clashingMethodWithObjCNameInI1 __attribute__((swift_name("swiftClashingMethodWithObjCNameInI1()")));
|
||||
- (int32_t)swiftClashingMethodWithObjCNameInI2 __attribute__((swift_name("swiftClashingMethodWithObjCNameInI2()")));
|
||||
- (int32_t)clashingMethodWithObjCNameInBoth __attribute__((swift_name("swiftClashingMethodWithObjCNameInBoth()")));
|
||||
@property (readonly) int32_t clashingProperty __attribute__((swift_name("clashingProperty")));
|
||||
@end
|
||||
|
||||
__attribute__((swift_name("SwiftNameManglingI2")))
|
||||
@protocol KtSwiftNameManglingI2
|
||||
@required
|
||||
- (id)clashingMethod __attribute__((swift_name("clashingMethod()")));
|
||||
- (id)swiftClashingMethodWithObjCNameInI1 __attribute__((swift_name("swiftClashingMethodWithObjCNameInI1()")));
|
||||
- (id)clashingMethodWithObjCNameInI2 __attribute__((swift_name("swiftClashingMethodWithObjCNameInI2()")));
|
||||
- (id)clashingMethodWithObjCNameInBoth __attribute__((swift_name("swiftClashingMethodWithObjCNameInBoth()")));
|
||||
@property (readonly) id clashingProperty __attribute__((swift_name("clashingProperty")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("SwiftNameManglingKt")))
|
||||
@interface KtSwiftNameManglingKt : KtBase
|
||||
+ (id<KtSwiftNameManglingI1>)i1 __attribute__((swift_name("i1()")));
|
||||
+ (id<KtSwiftNameManglingI2>)i2 __attribute__((swift_name("i2()")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("ThrowableAsError")))
|
||||
@interface KtThrowableAsError : KtKotlinThrowable
|
||||
|
||||
@@ -1499,6 +1499,33 @@ __attribute__((swift_name("Person.WorkerContractor")))
|
||||
@property (readonly) int32_t id __attribute__((swift_name("id")));
|
||||
@end
|
||||
|
||||
__attribute__((swift_name("SwiftNameManglingI1")))
|
||||
@protocol KtSwiftNameManglingI1
|
||||
@required
|
||||
- (int32_t)clashingMethod __attribute__((swift_name("clashingMethod()")));
|
||||
- (int32_t)clashingMethodWithObjCNameInI1 __attribute__((swift_name("swiftClashingMethodWithObjCNameInI1()")));
|
||||
- (int32_t)swiftClashingMethodWithObjCNameInI2 __attribute__((swift_name("swiftClashingMethodWithObjCNameInI2()")));
|
||||
- (int32_t)clashingMethodWithObjCNameInBoth __attribute__((swift_name("swiftClashingMethodWithObjCNameInBoth()")));
|
||||
@property (readonly) int32_t clashingProperty __attribute__((swift_name("clashingProperty")));
|
||||
@end
|
||||
|
||||
__attribute__((swift_name("SwiftNameManglingI2")))
|
||||
@protocol KtSwiftNameManglingI2
|
||||
@required
|
||||
- (id)clashingMethod __attribute__((swift_name("clashingMethod()")));
|
||||
- (id)swiftClashingMethodWithObjCNameInI1 __attribute__((swift_name("swiftClashingMethodWithObjCNameInI1()")));
|
||||
- (id)clashingMethodWithObjCNameInI2 __attribute__((swift_name("swiftClashingMethodWithObjCNameInI2()")));
|
||||
- (id)clashingMethodWithObjCNameInBoth __attribute__((swift_name("swiftClashingMethodWithObjCNameInBoth()")));
|
||||
@property (readonly) id clashingProperty __attribute__((swift_name("clashingProperty")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("SwiftNameManglingKt")))
|
||||
@interface KtSwiftNameManglingKt : KtBase
|
||||
+ (id<KtSwiftNameManglingI1>)i1 __attribute__((swift_name("i1()")));
|
||||
+ (id<KtSwiftNameManglingI2>)i2 __attribute__((swift_name("i2()")));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("ThrowableAsError")))
|
||||
@interface KtThrowableAsError : KtKotlinThrowable
|
||||
|
||||
@@ -29,8 +29,10 @@ private func testVar() throws {
|
||||
|
||||
private func testTwoProperties() throws {
|
||||
let t = KT38641.TwoProperties()
|
||||
#if !DISABLE_MEMBER_NAME_MANGLING
|
||||
try assertEquals(actual: t.description_, expected: "description")
|
||||
try assertEquals(actual: t.description__, expected: "description_")
|
||||
#endif
|
||||
}
|
||||
|
||||
private func testOverrideVal() throws {
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
@file:OptIn(kotlin.experimental.ExperimentalObjCName::class)
|
||||
|
||||
package swiftNameMangling
|
||||
|
||||
interface SwiftNameManglingI1 {
|
||||
val clashingProperty: Int
|
||||
|
||||
fun clashingMethod(): Int
|
||||
|
||||
@ObjCName(swiftName = "swiftClashingMethodWithObjCNameInI1")
|
||||
fun clashingMethodWithObjCNameInI1(): Int
|
||||
|
||||
fun swiftClashingMethodWithObjCNameInI2(): Int
|
||||
|
||||
@ObjCName(swiftName = "swiftClashingMethodWithObjCNameInBoth")
|
||||
fun clashingMethodWithObjCNameInBoth(): Int
|
||||
}
|
||||
|
||||
fun i1() = object : SwiftNameManglingI1 {
|
||||
override val clashingProperty: Int
|
||||
get() = 1
|
||||
|
||||
override fun clashingMethod(): Int = 2
|
||||
|
||||
override fun clashingMethodWithObjCNameInI1(): Int = 3
|
||||
|
||||
override fun swiftClashingMethodWithObjCNameInI2(): Int = 4
|
||||
|
||||
override fun clashingMethodWithObjCNameInBoth(): Int = 5
|
||||
}
|
||||
|
||||
interface SwiftNameManglingI2 {
|
||||
val clashingProperty: Any
|
||||
|
||||
fun clashingMethod(): Any
|
||||
|
||||
fun swiftClashingMethodWithObjCNameInI1(): Any
|
||||
|
||||
@ObjCName(swiftName = "swiftClashingMethodWithObjCNameInI2")
|
||||
fun clashingMethodWithObjCNameInI2(): Any
|
||||
|
||||
@ObjCName(swiftName = "swiftClashingMethodWithObjCNameInBoth")
|
||||
fun clashingMethodWithObjCNameInBoth(): Any
|
||||
}
|
||||
|
||||
fun i2() = object : SwiftNameManglingI2 {
|
||||
override val clashingProperty: Any
|
||||
get() = "one"
|
||||
|
||||
override fun clashingMethod(): Any = "two"
|
||||
|
||||
override fun swiftClashingMethodWithObjCNameInI1(): Any = "three"
|
||||
|
||||
override fun clashingMethodWithObjCNameInI2(): Any = "four"
|
||||
|
||||
override fun clashingMethodWithObjCNameInBoth(): Any = "five"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import Kt
|
||||
|
||||
private func test1() throws {
|
||||
let i1 = SwiftNameManglingKt.i1()
|
||||
let i2 = SwiftNameManglingKt.i2()
|
||||
|
||||
#if DISABLE_MEMBER_NAME_MANGLING
|
||||
try assertEquals(actual: i1.clashingProperty, expected: 1)
|
||||
try assertEquals(actual: i1.clashingMethod(), expected: 2)
|
||||
try assertEquals(actual: i1.swiftClashingMethodWithObjCNameInI1(), expected: 3)
|
||||
try assertEquals(actual: i1.swiftClashingMethodWithObjCNameInI2(), expected: 4)
|
||||
try assertEquals(actual: i1.swiftClashingMethodWithObjCNameInBoth(), expected: 5)
|
||||
|
||||
try assertEquals(actual: i2.clashingProperty as! String, expected: "one")
|
||||
try assertEquals(actual: i2.clashingMethod() as! String, expected: "two")
|
||||
try assertEquals(actual: i2.swiftClashingMethodWithObjCNameInI1() as! String, expected: "three")
|
||||
try assertEquals(actual: i2.swiftClashingMethodWithObjCNameInI2() as! String, expected: "four")
|
||||
try assertEquals(actual: i2.swiftClashingMethodWithObjCNameInBoth() as! String, expected: "five")
|
||||
#endif
|
||||
}
|
||||
|
||||
class SwiftNameManglingTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Test1", test1)
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,12 @@ private func testPropertiesInDifferentFilesAreNotMangled() throws {
|
||||
|
||||
private func testFunctionsInSameFileAreMangled() throws {
|
||||
try assertEquals(actual: TopLevelManglingAKt.sameNumber(value: Int32(1)), expected: 1)
|
||||
try assertEquals(actual: TopLevelManglingAKt.sameNumber(value_: Int64(2)), expected: 2)
|
||||
#if DISABLE_MEMBER_NAME_MANGLING
|
||||
let sameNumberLong = TopLevelManglingAKt.sameNumber(value: Int64(2))
|
||||
#else
|
||||
let sameNumberLong = TopLevelManglingAKt.sameNumber(value_: Int64(2))
|
||||
#endif
|
||||
try assertEquals(actual: sameNumberLong, expected: 2)
|
||||
}
|
||||
|
||||
class TopLevelManglingTests : SimpleTestProvider {
|
||||
|
||||
@@ -726,8 +726,11 @@ func testClashes() throws {
|
||||
let test2: TestClashes2 = test
|
||||
|
||||
try assertEquals(actual: 1, expected: test1.clashingProperty)
|
||||
|
||||
#if !DISABLE_MEMBER_NAME_MANGLING
|
||||
try assertEquals(actual: 1, expected: test2.clashingProperty_ as! Int32)
|
||||
try assertEquals(actual: 2, expected: test2.clashingProperty__ as! Int32)
|
||||
#endif
|
||||
}
|
||||
|
||||
func testInvalidIdentifiers() throws {
|
||||
@@ -742,7 +745,9 @@ func testInvalidIdentifiers() throws {
|
||||
|
||||
try assertEquals(actual: TestInvalidIdentifiers.CompanionS()._42, expected: 42)
|
||||
|
||||
#if !DISABLE_MEMBER_NAME_MANGLING
|
||||
try assertEquals(actual: Set([test.__, test.___]), expected: Set(["_".utf16.first, "_".utf16.first]))
|
||||
#endif
|
||||
}
|
||||
|
||||
class ImplementingHiddenSubclass : TestDeprecation.ImplementingHidden {
|
||||
|
||||
Reference in New Issue
Block a user