Skip to content
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

Xcode 10.2 and Swift 5 problem building #21

Open
linksmt opened this issue Mar 30, 2019 · 15 comments
Open

Xcode 10.2 and Swift 5 problem building #21

linksmt opened this issue Mar 30, 2019 · 15 comments

Comments

@linksmt
Copy link

linksmt commented Mar 30, 2019

Hi,

on Xcosw 10.2 and in particular with swift 5 there's a serious problem.
Here is:
Undefined symbols for architecture x86_64: "_swift_getFieldAt", referenced from: closure #1 (Swift.Int) -> (Swift.String, Any.Type) in (extension in Reflection):Reflection.NominalType.fieldNamesAndTypes(for: Any.Type) -> [(Swift.String, Any.Type)]? in NominalType.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

I've searched on google and found this blog post:

https://www.jishuwen.com/d/2Elq/zh-hk
alibaba/HandyJSON#307

Can you help?

Thanks.

@NSExceptional
Copy link

I'm fairly certain this repo isn't compatible with Swift 5 yet...

@mapo80
Copy link

mapo80 commented Apr 2, 2019

Any plan to support swift 5?

@tanner0101
Copy link

Easier said than done, although it seems like @paulofaria is working on it.

Anyone relying on Swift 4.2's metadata layout will have a lot more work in general moving to Swift 5's final layouts.

apple/swift#15565 (comment)

@mapo80
Copy link

mapo80 commented Apr 2, 2019

Let’s wait for a resolution

@mapo80
Copy link

mapo80 commented Apr 4, 2019

Hi all, here they found solution: wickwirew/Runtime#37

@NSExceptional
Copy link

@paulofaria is already over there too haha. Can't wait for this to be fixed 😄

@mapo80
Copy link

mapo80 commented Apr 11, 2019

No news?

@filbertasurion
Copy link

Any updates on this?

@robertjpayne
Copy link
Member

@filbertasurion @mapo80 @NSExceptional @tanner0101 I'd highly recommend migrating to wickwirew/Runtime as it's a maintained version of this lib and operates very similarly.

@filbertasurion
Copy link

@filbertasurion @mapo80 @NSExceptional @tanner0101 I'd highly recommend migrating to wickwirew/Runtime as it's a maintained version of this lib and operates very similarly.

I tried Runtime, but it's crashing when I'm trying to do the code below from Zewo/Reflection:

// Reflection can be extended for higher-level packages to do mapping and serializing.
// Here is a simple Mappable protocol that allows deserializing of arbitrary nested structures.

import Reflection

typealias MappableDictionary = [String : Any]

enum Error : ErrorProtocol {
case missingRequiredValue(key: String)
}

protocol Mappable {
init(dictionary: MappableDictionary) throws
}

extension Mappable {

init(dictionary: MappableDictionary) throws {
    self = try construct { property in
        if let value = dictionary[property.key] {
            if let type = property.type as? Mappable.Type, let value = value as? MappableDictionary {
                return try type.init(dictionary: value)
            } else {
                return value
            }
        } else {
            throw Error.missingRequiredValue(key: property.key)
        }
    }
}

}

struct Person : Mappable {
var firstName: String
var lastName: String
var age: Int
var phoneNumber: PhoneNumber
}

struct PhoneNumber : Mappable {
var number: String
var type: String
}

let dictionary = [
"firstName" : "Jane",
"lastName" : "Miller",
"age" : 54,
"phoneNumber" : [
"number" : "924-555-0294",
"type" : "work"
] as MappableDictionary
] as MappableDictionary

let person = try Person(dictionary: dictionary)

@filbertasurion
Copy link

Dang even Runtime has its own Xcode 10.2 issue, but at least Zewo/Reflection is able to load my nested structs.

Screen Shot 2019-05-02 at 6 35 48 PM

@wickwirew
Copy link
Contributor

@filbertasurion just tried the code above and it works for me in Xcode 10.2 with swift 5. Make sure you have the latest version installed. If it doesn't work feel free to open an issue 👍

@filbertasurion
Copy link

filbertasurion commented May 3, 2019

Could you share the code on how these were written on Runtime? I've used Xcode 10.2 with swift 4.0 and I'm still getting Swift Compiler Error. Thanks!

@KrishnaKishore1992
Copy link

After all debugging & research with the help of alibaba/HandyJSON@da72f29

I changed _swift_getFieldAt with swift_getTypeByMangledNameInContext in Nominal.swift file @line 31.

@_silgen_name("swift_getFieldAt") ---> @_silgen_name("swift_getTypeByMangledNameInContext")

I am able to compile & test successfully with this small change.

Try this & share your feedback

mapo80 pushed a commit to linksmt/Reflection that referenced this issue Sep 30, 2019
Change from @_silgen_name("swift_getFieldAt") to @_silgen_name("swift_getTypeByMangledNameInContext")
@cyborch
Copy link

cyborch commented Dec 8, 2020

Annoyingly this now gives me a SEGFAULT:

1.	Apple Swift version 5.3.1 (swiftlang-1200.0.41 clang-1200.0.32.8)
2.	While evaluating request IRGenSourceFileRequest(IR Generation for file "[...]Reflection/Sources/Reflection/NominalType.swift")
3.	While emitting IR SIL function "@$s10Reflection11NominalTypePAAE18fieldNamesAndTypes3forSaySS_ypXptGSgypXp_tFSS_ypXptSiXEfU_".
 for expression at [[...]Reflection/Sources/Reflection/NominalType.swift:8:63 - line:18:9] RangeText="{ index in
            var context: (String, Any.Type) = ("", Any.self)
            getFieldAt(type, index, { name, type, context in
                let context = context.assumingMemoryBound(to: (String, Any.Type).self)
                context.pointee = (
                    String(cString: name),
                    unsafeBitCast(type, to: Any.Type.self)
                )
            }, &context)
            return context
        "
0  swift                    0x0000000104c35c15 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x0000000104c36332 SignalHandler(int) + 610
2  libsystem_platform.dylib 0x00007fff2037ed7d _sigtramp + 29
3  libsystem_platform.dylib 0x00007f913b894c00 _sigtramp + 18446743601721466528
4  swift                    0x0000000100673f63 swift::irgen::allocateForCoercion(swift::irgen::IRGenFunction&, llvm::Type*, llvm::Type*, llvm::Twine const&) + 67
5  swift                    0x000000010066aef5 swift::irgen::IRGenFunction::coerceValue(llvm::Value*, llvm::Type*, llvm::DataLayout const&) + 405
6  swift                    0x000000010066ded1 swift::irgen::CallEmission::emitToExplosion(swift::irgen::Explosion&, bool) + 3745
7  swift                    0x0000000100834f2b (anonymous namespace)::IRGenSILFunction::visitFullApplySite(swift::FullApplySite) + 4187
8  swift                    0x00000001008141e6 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8966
9  swift                    0x00000001006c4167 swift::irgen::IRGenerator::emitLazyDefinitions() + 1207
10 swift                    0x00000001007eecc0 performIRGeneration(swift::IRGenOptions const&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, swift::SourceFile*, llvm::GlobalVariable**, llvm::StringSet<llvm::MallocAllocator>*) + 1920
11 swift                    0x0000000100811c51 swift::SimpleRequest<swift::IRGenSourceFileRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenSourceFileRequest const&, swift::Evaluator&) + 97
12 swift                    0x00000001007f337c llvm::Expected<swift::IRGenSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenSourceFileRequest>(swift::IRGenSourceFileRequest const&) + 972
13 swift                    0x00000001007ef2fd swift::performIRGeneration(swift::IRGenOptions const&, swift::SourceFile&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**, llvm::StringSet<llvm::MallocAllocator>*) + 269
14 swift                    0x000000010044d822 performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 3042
15 swift                    0x000000010043d603 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 21363
16 swift                    0x00000001003be2c1 main + 1265
17 libdyld.dylib            0x00007fff20355631 start + 1
18 libdyld.dylib            0x0000000000000080 start + 18446603339975797328
error: Segmentation fault: 11 (in target 'Reflection' from project 'Pods')

Any clue how to work around this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants