-
Notifications
You must be signed in to change notification settings - Fork 6.1k
[KT-48068] Add opt-in support for NSEnum for Kotlin Native iOS via an annotation #5539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
/test-private |
|
Failed to process command due to an unexpected exception. |
native/objcexport-header-generator/src/org/jetbrains/kotlin/backend/konan/objcexport/stubs.kt
Outdated
Show resolved
Hide resolved
native/objcexport-header-generator/src/org/jetbrains/kotlin/backend/konan/objcexport/stubs.kt
Outdated
Show resolved
Hide resolved
native/native.tests/testData/framework/objcexport/nativeEnum.kt
Outdated
Show resolved
Hide resolved
kotlin-native/runtime/src/main/kotlin/kotlin/native/Annotations.kt
Outdated
Show resolved
Hide resolved
...-generator/impl/k1/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportTranslator.kt
Show resolved
Hide resolved
...-generator/impl/k1/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportTranslator.kt
Outdated
Show resolved
Hide resolved
...-generator/impl/k1/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportTranslator.kt
Show resolved
Hide resolved
...er/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportCodeSpec.kt
Outdated
Show resolved
Hide resolved
...bjcexport-header-generator/src/org/jetbrains/kotlin/backend/konan/objcexport/StubRenderer.kt
Outdated
Show resolved
Hide resolved
|
The K2 (Analysis API, aka AA) implementation is missing, which makes the new test fail in this mode. ./gradlew :native:objcexport-header-generator:testAnalysisApi --tests "org.jetbrains.kotlin.backend.konan.tests.ObjCExportHeaderGeneratorTest"to reproduce. Related code: Line 54 in f90cbf3
|
|
Another thing to fix: adding a declaration to stdlib requires updating the ABI dump. |
I have added this, but AA emits the a comment about the annotation whereas K1 does not... Any suggestions how to resolve this? Current state is the AA output |
...end.native/src/org/jetbrains/kotlin/backend/konan/llvm/objcexport/ObjCExportCodeGenerator.kt
Outdated
Show resolved
Hide resolved
...end.native/src/org/jetbrains/kotlin/backend/konan/llvm/objcexport/ObjCExportCodeGenerator.kt
Outdated
Show resolved
Hide resolved
...end.native/src/org/jetbrains/kotlin/backend/konan/llvm/objcexport/ObjCExportCodeGenerator.kt
Outdated
Show resolved
Hide resolved
...er/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportCodeSpec.kt
Outdated
Show resolved
Hide resolved
...er/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportCodeSpec.kt
Outdated
Show resolved
Hide resolved
...-generator/impl/k1/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportTranslator.kt
Outdated
Show resolved
Hide resolved
...-generator/impl/k1/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportTranslator.kt
Show resolved
Hide resolved
...-generator/impl/k1/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportTranslator.kt
Outdated
Show resolved
Hide resolved
native/objcexport-header-generator/src/org/jetbrains/kotlin/backend/konan/objcexport/stubs.kt
Show resolved
Hide resolved
...-generator/impl/k1/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportTranslator.kt
Show resolved
Hide resolved
native/objcexport-header-generator/src/org/jetbrains/kotlin/backend/konan/objcexport/stubs.kt
Outdated
Show resolved
Hide resolved
...-generator/impl/k1/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportTranslator.kt
Outdated
Show resolved
Hide resolved
...er/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportCodeSpec.kt
Outdated
Show resolved
Hide resolved
native/native.tests/testData/framework/objcexport/nativeEnum.swift
Outdated
Show resolved
Hide resolved
kotlin-native/runtime/src/main/kotlin/kotlin/native/Annotations.kt
Outdated
Show resolved
Hide resolved
| enum class Foo { | ||
| // Note that the order is not alphabetic on purpose, ensuring that tests fail if we can't rely on the | ||
| // order to be preserved for the ordinal value. | ||
| ALPHA, COPY, BAR_FOO, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no test checking how having @ObjCName on enum class or its entries affects the generated NS_ENUM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a few more cases here -- let me know if I should add any additional specific one...
I tried adding @ObjCName on the literal itself, but that's broken for AA in general, even for "regular" enum literals, and the output won't match, so I can't even document the error easily.
I'll file a bug for this separately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KT-82838 @ObjCName for enum literals inconsistent in AnalysisApi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried adding @ObjCName on the literal itself, but that's broken for AA in general, even for "regular" enum literals, and the output won't match, so I can't even document the error easily.
Ah, I see. Thanks!
What can be done: a separate @Test fun can be added to ObjCExportHeaderGeneratorTest for this case and marked with @TodoAnalysisApi. This way, the test will be muted when checking the AA implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added annotations to the smaller test and disabled aa there -- I think for the meantime AA is covered by the larger test with enum annotations sufficiently?
...eader-generator/impl/k1/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportNamer.kt
Outdated
Show resolved
Hide resolved
...eader-generator/impl/k1/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportNamer.kt
Outdated
Show resolved
Hide resolved
...der-generator/impl/analysis-api/src/org/jetbrains/kotlin/objcexport/translateToObjCHeader.kt
Outdated
Show resolved
Hide resolved
...bjcexport-header-generator/src/org/jetbrains/kotlin/backend/konan/objcexport/StubRenderer.kt
Outdated
Show resolved
Hide resolved
SvyatoslavScherbina
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think the implementation is good now. But there are a few more things to be done to actually get it merged:
- Rebase it to
master, squash the commits and write a commit message as recommended here. - Because of KT-82670, an unrelated test has to be adjusted:
--- a/analysis/low-level-api-fir/testData/lazyResolveStdlibSources/wrappedInt.txt
+++ b/analysis/low-level-api-fir/testData/lazyResolveStdlibSources/wrappedInt.txt
@@ -824,7 +824,7 @@ FILE: [ResolvedTo(BODY_RESOLVE)] TypeReference.kt
}
public open override [ResolvedTo(BODY_RESOLVE)] fun hashCode(): R|kotlin/Int| {
- ^hashCode this@R|kotlin/jvm/internal/TypeReference|.R|kotlin/jvm/internal/TypeReference.classifier|.R|kotlin/Any.hashCode|().R|kotlin/Int.times|(Int(31)).R|kotlin/Int.plus|(this@R|kotlin/jvm/internal/TypeReference|.R|kotlin/jvm/internal/TypeReference.arguments|.R|kotlin/Any.hashCode|()).R|kotlin/Int.times|(Int(31)).R|kotlin/Int.plus|(this@R|kotlin/jvm/internal/TypeReference|.R|kotlin/jvm/internal/TypeReference.flags|.R|kotlin/Int.hashCode|())
+ ^hashCode this@R|kotlin/jvm/internal/TypeReference|.R|kotlin/jvm/internal/TypeReference.classifier|.R|kotlin/Any.hashCode|().R|kotlin/Int.times|(Int(31)).R|kotlin/Int.plus|(this@R|kotlin/jvm/internal/TypeReference|.R|kotlin/jvm/internal/TypeReference.arguments|.R|kotlin/Any.hashCode|()).R|kotlin/Int.times|(Int(31)).R|kotlin/Int.plus|(this@R|kotlin/jvm/internal/TypeReference|.R|kotlin/jvm/internal/TypeReference.flags|.R|kotlin/Any.hashCode|())
}
public open override [ResolvedTo(BODY_RESOLVE)] fun toString(): R|kotlin/String| {- I'll run the required tests after that. Hopefully, nothing more will require fixing.
- We'll also need some approvals from the codeowners for the changes in stdlib. I'll request them.
I think I have rebased the fork successfully but would like to confirm that I won't screw up the branch with the wrong git command.... (I mainly use perforce for work... O:) Can you confirm that a valid option to squash is to run |
It seems that you actually merged the master branch, not rebased to master.
That won't work because of the merge. git rebase -i 5952e77c40174e23afb9b2606d3ee3dded3b4b9fAnd then you can replace "pick" with "squash" (or "fixup"). |
...der-generator/test/org/jetbrains/kotlin/backend/konan/tests/ObjCExportHeaderGeneratorTest.kt
Outdated
Show resolved
Hide resolved
native/objcexport-header-generator/testData/headers/enumClassWithObjCEnum/Foo.kt
Outdated
Show resolved
Hide resolved
…Native iOS via an annotation Addresses KT-48068 If not specified otherwise via @ObjCEnum, the NSEnum type name will match the Kotlin Enum ObjC / Swift name with "NSEnum" appended. The new type is accesible via the "nsEnum" property (the same way as the ordinal value via "ordinal")
4305d7b to
99127a7
Compare
| package kotlin.experimental | ||
|
|
||
| /** | ||
| * This annotation marks the experimental [ObjCEnum][kotlin.native.ObjCEnum] annotation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a description of what this status entails.
Also, is there a path to stabilization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have expanded the explanation based on the documentation for ExperimentalNativeApi
Not sure about the stabilization path, I'd expect something along the lines that this would lose experimental status if no issues are observed for a certain amount of time and there is significant usage, but I don't see something similar elsewere...
e709855
…Annotations.kt Co-authored-by: Filipp Zhinkin <filipp.zhinkin@gmail.com>
Basically implementing the feature suggested here: https://youtrack.jetbrains.com/issue/KT-48068