[K/N] Opt-in for meaningful names for in "objc2kotlin" bridges
It is hard to run FileCheck tests over generated ObjC bridges because
they share the same name ("objc2kotlin"). To overcome this hurdle,
this commit introduces a compiler flag that appends function name to
"objc2_kotlin". This change might be useful for end-users, for example,
it makes stacktraces more readable. But it will require additional
testing and polishing which is out of the scope of this change.
This commit is contained in:
@@ -391,6 +391,7 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
})
|
||||
putIfNotNull(RUNTIME_LOGS, arguments.runtimeLogs)
|
||||
putIfNotNull(BUNDLE_ID, parseBundleId(arguments, outputKind, configuration))
|
||||
put(MEANINGFUL_BRIDGE_NAMES, arguments.meaningfulBridgeNames)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -361,6 +361,9 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
|
||||
@Argument(value = "-Xruntime-logs", valueDescription = "<tag1=level1,tag2=level2,...>", description = "Enable logging for runtime with tags.")
|
||||
var runtimeLogs: String? = null
|
||||
|
||||
@Argument(value = "-Xmeaningful-bridge-names", description = "(Unstable) Produce meaningful names for reverse bridges. Useful only for compiler tests.")
|
||||
var meaningfulBridgeNames: Boolean = false
|
||||
|
||||
@Argument(value = "-Xlazy-ir-for-caches", valueDescription = "{disable|enable}", description = "Use lazy IR for cached libraries")
|
||||
var lazyIrForCaches: String? = null
|
||||
|
||||
|
||||
+1
@@ -171,6 +171,7 @@ class KonanConfigKeys {
|
||||
val LLVM_VARIANT: CompilerConfigurationKey<LlvmVariant?> = CompilerConfigurationKey.create("llvm variant")
|
||||
val RUNTIME_LOGS: CompilerConfigurationKey<String> = CompilerConfigurationKey.create("enable runtime logging")
|
||||
val LAZY_IR_FOR_CACHES: CompilerConfigurationKey<Boolean> = CompilerConfigurationKey.create("use lazy IR for cached libraries")
|
||||
val MEANINGFUL_BRIDGE_NAMES: CompilerConfigurationKey<Boolean> = CompilerConfigurationKey.create("enable meaningful bridge names")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+15
-2
@@ -238,6 +238,13 @@ internal class ObjCExportCodeGenerator(
|
||||
generateContinuationToRetainedCompletionConverter(blockGenerator)
|
||||
}
|
||||
|
||||
fun meaningfulBridgeNameOrNull(irFunction: IrFunction?): String? {
|
||||
if (!context.config.configuration.getBoolean(KonanConfigKeys.MEANINGFUL_BRIDGE_NAMES)) {
|
||||
return null
|
||||
}
|
||||
return irFunction?.name?.asString()
|
||||
}
|
||||
|
||||
fun FunctionGenerationContext.genSendMessage(
|
||||
returnType: LlvmParamType,
|
||||
parameterTypes: List<LlvmParamType>,
|
||||
@@ -863,10 +870,12 @@ private fun ObjCExportFunctionGenerationContextBuilder.setupBridgeDebugInfo() {
|
||||
private inline fun ObjCExportCodeGenerator.generateObjCImpBy(
|
||||
methodBridge: MethodBridge,
|
||||
debugInfo: Boolean = false,
|
||||
suffix: String? = null,
|
||||
genBody: ObjCExportFunctionGenerationContext.() -> Unit
|
||||
): LLVMValueRef {
|
||||
val functionType = objCFunctionType(context, methodBridge)
|
||||
val result = functionGenerator(functionType, "objc2kotlin") {
|
||||
val functionName = "objc2kotlin" + (suffix?.let { "_$it" } ?: "")
|
||||
val result = functionGenerator(functionType, functionName) {
|
||||
if (debugInfo) {
|
||||
this.setupBridgeDebugInfo()
|
||||
}
|
||||
@@ -926,7 +935,11 @@ private fun ObjCExportCodeGenerator.generateObjCImp(
|
||||
resultLifetime: Lifetime,
|
||||
exceptionHandler: ExceptionHandler
|
||||
) -> LLVMValueRef?
|
||||
): LLVMValueRef = generateObjCImpBy(methodBridge, debugInfo = isDirect /* see below */) {
|
||||
): LLVMValueRef = generateObjCImpBy(
|
||||
methodBridge,
|
||||
debugInfo = isDirect /* see below */,
|
||||
suffix = meaningfulBridgeNameOrNull(baseMethod)
|
||||
) {
|
||||
// Considering direct calls inlinable above. If such a call is inlined into a bridge with no debug information,
|
||||
// lldb will not decode the inlined frame even if the callee has debug information.
|
||||
// So generate dummy debug information for bridge in this case.
|
||||
|
||||
Reference in New Issue
Block a user