Open linksmt opened 5 years ago
I'm fairly certain this repo isn't compatible with Swift 5 yet...
Any plan to support swift 5?
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.
https://github.com/apple/swift/pull/15565#issuecomment-420734275
Let’s wait for a resolution
Hi all, here they found solution: https://github.com/wickwirew/Runtime/issues/37
@paulofaria is already over there too haha. Can't wait for this to be fixed 😄
No news?
Any updates on this?
@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 @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)
Dang even Runtime has its own Xcode 10.2 issue, but at least Zewo/Reflection is able to load my nested structs.
@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 👍
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!
After all debugging & research with the help of https://github.com/alibaba/HandyJSON/commit/da72f298f05cdc638fd63b92091404c5415c4586
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
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?
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:
Can you help?
Thanks.