wickwirew/Runtime

Swift 5.0 metadata build errors

noahemmet opened this issue · 11 comments

Getting some build errors in Swift 5, in Metadata.swift and TypeInfo.swift:

    var typeInfoConvertible: TypeInfoConvertible
    
    switch kind {
    case .struct:
        typeInfoConvertible = StructMetadata(type: type) // error: Missing argument for parameter 'metadata' in call

(Those errors pop up for every case.)

That init is defined here: https://github.com/wickwirew/Runtime/blob/master/Sources/Runtime/Metadata/MetadataType.swift#L61

extension MetadataType {
    // ...
    init(type: Any.Type) {
        let base = metadataPointer(type: type)
        let metadata = base.advanced(by: valueWitnessTableOffset).raw.assumingMemoryBound(to: Layout.self)
        self.init(type: type, metadata: metadata, base: base)
    }
}

so I'm not sure why Swift 5 is refusing to see it…

Note this happens when building the project from scratch, or when building as an SPM dependency.

Troubleshooting notes:

  • I can resolve the "missing argument" errors if I change the inits to typeInfoConvertible = StructMetadata.init(type: type).
  • However, StructMetadata.swift fails with a error: reference to invalid associated type 'Layout' of type 'StructMetadata', on the init declaration itself.
  • Adding manual typealias Layout = FooMetadata declarations fixes those errors, and allowed me to remove the manual Foo.init(type: type)
  • but then I get our old friend
Undefined symbols for architecture x86_64:
  "_swift_getFieldAt", referenced from:
      closure #1 (Swift.Int) -> Runtime.PropertyInfo in Runtime.getProperties(of: Any.Type, offsets: [Swift.Int]) -> [Runtime.PropertyInfo] in GetFieldAt.o
ld: symbol(s) not found for architecture x86_64
  • Huh… swift build from the terminal completes just fine; is this only a problem in Xcode? Is there a problem with my deployment target? I've rebuilt the .xcodeproj with swift package generate-xcodeproj

Anywho, here's the branch if you wanna take a look: https://github.com/noahemmet/Runtime/tree/swift5

_swift_getFieldAt Is not available anymore. Here's HandyJSON fix as reference:

alibaba/HandyJSON@da72f29

Awesome thanks! I have a swift 5 branch locally. Hopefully will finish it up soon. Sorry for the wait.

@wickwirew Can you push the branch so I can help, if I can? I was able to make it work except for generics. @jckarter helped me with some directions:

swiftlang/swift#15565 (comment)

But I couldn't get it to work properly. How far were you able to get? Oh, and looks like stride has changed location as well.

@wickwirew Also, please check swiftlang/swift#15565 (comment). See if you have any ideas.

@paulofaria I’ll push soon. The latest OS update bricked my laptop so it may take a little time

@wickwirew any update? Would love to pitch in and help out if anything is left to do as well!

@robertjpayne made some good progress tonight! Got it reading from the FieldDescriptor now and it'll correctly get the field offset, name, and type. Gonna clean it up and push what I have tomorrow and see whats left to do.

Still have to workout getting the generic argument descriptor so we can pass the types to swift_getTypeByMangledNameInContext correctly.

Thought I would note that I'm seeing this error as well in Swift 4.2.

I setup a Vapor test project using Swift package manager with GraphQL as a dependency .

It looks like GraphQL has a dependency on Runtime and trying to build a generated Xcode project fails in the Runtime framework with the same error noted by the OP.

If it helps my Package.swift looks like this:

// swift-tools-version:4.0
import PackageDescription

let package = Package(
    name: "hello",
    products: [
        .library(name: "hello", targets: ["App"]),
    ],
    dependencies: [
        // 💧 A server-side Swift web framework.
        .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"),
        // 🔵 Swift ORM (queries, models, relations, etc) built on SQLite 3.
        .package(url: "https://github.com/vapor/fluent-sqlite.git", from: "3.0.0"),
        // Leaf
        .package(url: "https://github.com/vapor/leaf.git", from: "3.0.2"),
        // Realm
//        .package(url: "https://github.com/realm/realm-cocoa.git", from: "3.14.0"),
        // GraphQL
        .package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "0.9.0")
    ],
    targets: [
        .target(name: "App", dependencies: ["FluentSQLite", "Vapor", "Leaf", "GraphQL"]),
        .target(name: "Run", dependencies: ["App"]),
        .testTarget(name: "AppTests", dependencies: ["App"])
    ]
)

@paulofaria @robertjpayne pushed the swift5 branch. All of the tests pass for structs only currently. Going to start class support soon.

I was able to correctly get the generic argument vector, and pass that into swift_getTypeByMangledNameInContext for generic support as well. Let me know if you have any questions.

Just pushed a temp fix for class support. All tests pass. The class generic argument vector's offset is hard coded and not calculated like it should be. Still needs some clean up as well but should be hopefully enough to not block people from upgrading to swift 5

Swift 5 support has been merged and 2.0.0 has been released. Thank you for everyone's patience! If there are any more bugs with swift 5 please feel free to open a new issue 👍