Skip to content

Latest commit

 

History

History
84 lines (72 loc) · 4.68 KB

WIP.md

File metadata and controls

84 lines (72 loc) · 4.68 KB

Work In Progress

This package is a work in progress, and many details are subject to change.

Here is a long yet still very incomplete list of things we would like to do or improve:

  • Expressivity gaps:
    • Translate Java exceptions into Swift and vice versa
    • Expose Swift types to Java
    • Figure out when to promote from the local to the global heap
    • Automatically turn get/set method pairs into Swift properties?
    • Implement a global registry that lets us find the Swift type corresponding to a canonical Java class name (e.g., java.net.URL -> JavaKitNetwork.URL)
    • Introduce overloads of is and as on the Swift projections so that conversion to any implemented interface or extended superclass returns non-optional.
    • Figure out how to express the equivalent of super.foo() that calls the superclass's method from the subclass method.
    • Recognize Java's enum classes and map them into Swift well
    • Translate Java constants into Swift constants
    • Support nested classes
    • Streamline the definition of "main" code in Swift
    • Figure out how to subclass a Java class from Swift
  • Tooling
    • Extract documentation comments from Java and put them in the Swift projections
    • SwiftPM build plugin to generate the Swift projections from Java as part of the build
    • Figure out how to launch the Java runtime from Swift code so we don't need to always start via java
    • Figure out how to unit-test this framework using Swift Testing
    • Add a "Jar mode" to Java2Swift that translates all classes in the given Jar file.
    • Generate Swift projections for more common Java types into JavaKit libraries to make it easier to get started
    • Teach Java2Swift when to create extensions of already-translated types that pick up any members that couldn't be translated because of missing types. See, for example, how JavaKitReflection adds extensions to JavaClass based on types like Method and Parameter
  • Performance:
    • Cache method/field IDs when we can
    • Investigate noncopyable types to remove excess copies
    • Investigate "unbridged" variants of String, Array, etc.
    • Investigate the new Foreign Function & Memory API (aka Project Panama) for exposing Swift APIs to Java.

jextract-swift

Separate todo list for the jextract / panama side of the project:

Calling convention:

  • Call swift methods, take parameters, return values
  • How to call a throwing Swift function from Java
  • How to call a generic Swift function from Java
    • How to pass "call me back" (Callable, Runnable) to Swift, and make an up-call
  • How to support passing a struct inout SwiftValue to Swift so that Java side sees change

Bridges:

  • Java Optional / Swift Optional - depends on generics (!)
  • Efficient String / SwiftString wrappers and converters
  • Handle byte buffers and pointers properly
  • Converters for Array
  • Converters for List and common collections?
  • expose Swift collections as some bridged type implementing java.util.Collection?
  • Import Swift enums

Importer:

  • import global functions into the Module.theFunction on Java side
  • import functions with parameters
  • import functions return values
  • HACK: use dylib to find mangled names of methods
  • HACK: use dylib to find mangled names of initializers
  • HACK: use dylib to find mangled names of imported types (TYPE_METADATA_NAME)
  • import instance member functions using "wrapper" pattern
  • handle types like [any Thing]?, we can't parse them right now even
  • support nested types in Swift
  • handle types like any Thing, importer does not understand any or some

Programming model:

  • Which style of ownership for Java class wrapping a Swift Class
    • __allocating_init, how to release/destroy from Java
    • Offer explicit swift_release / swift_retain functions
    • Offer some way to make Immortal class instance
    • SwiftArena which retains/destroys underlying Swift class?
  • How to create a Swift struct

Swift Compiler work:

  • Expose mangled names of types and methods in .swiftinterface
  • Expose @layout of class, struct etc. types in .swiftinterface
  • Expose demangle function to human-readable text; it'd be good for usability

Build:

  • Gradle build for Java parts of samples and "SwiftKit" utilities
  • Build Swift dependencies when building Java samples automatically
  • JMH benchmarks