confundus icon indicating copy to clipboard operation
confundus copied to clipboard

Investigate multiplatform

Open JakeWharton opened this issue 5 years ago • 2 comments

Obviously this exists for Kotlin/JS already, but do we need this for Kotlin/Native too? If so, migrate the runtime to MPP and restore the IR-based compiler plugin.

Actually, we should probably restore the IR compiler anyway...

JakeWharton avatar Mar 09 '20 20:03 JakeWharton

In LLVM IR...

nullable!!:

  %8 = icmp eq %struct.ObjHeader* %7, null
  br i1 %8, label %when_case, label %when_exit

when_case:                                        ; preds = %call_success
  invoke void @ThrowNullPointerException()
          to label %call_success1 unwind label %cleanup_landingpad

nonNull as OtherType:

  %8 = call i1 @IsInstance(%struct.ObjHeader* %7, %struct.TypeInfo* @"ktype:kotlin.String")
  %9 = xor i1 %8, true
  br i1 %9, label %label_1, label %label_

label_1:                                          ; preds = %call_success
  invoke void @ThrowClassCastException(%struct.ObjHeader* %7, i8* bitcast (%struct.TypeInfo* @"ktype:kotlin.String" to i8*))
          to label %call_success2 unwind label %cleanup_landingpad

nullable as OtherType:

%8 = icmp eq %struct.ObjHeader* %7, null
  br i1 %8, label %when_case, label %when_next

when_case:                                        ; preds = %call_success
  invoke void @"kfun:kotlin.native.internal.ThrowTypeCastException()kotlin.Nothing"()
          to label %call_success1 unwind label %cleanup_landingpad

when_next:                                        ; preds = %call_success
  %9 = call i1 @IsInstance(%struct.ObjHeader* %7, %struct.TypeInfo* @"ktype:kotlin.String")
  %10 = xor i1 %9, true
  br i1 %10, label %label_2, label %label_

label_2:                                          ; preds = %when_next
  invoke void @ThrowClassCastException(%struct.ObjHeader* %7, i8* bitcast (%struct.TypeInfo* @"ktype:kotlin.String" to i8*))
          to label %call_success3 unwind label %cleanup_landingpad

JakeWharton avatar Mar 10 '20 02:03 JakeWharton

Restoring the IR transformer was easy. But even ignoring that, I immediately wanted to use unsafeCast in Okio common even if it only applied to the JVM. So perhaps that is a good first step for multiplatform support: just the API which is erased on native, delegates to stdlib on JS, and compiler plugin for JVM.

JakeWharton avatar Mar 10 '20 15:03 JakeWharton