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

[SR-10200] NSForwarding: warning: object 0x102408108 of class 'Module.NonGenericFinalSwiftClass' does not implement methodSignatureForSelector: -- trouble ahead #52600

Open
DevAndArtist mannequin opened this issue Mar 27, 2019 · 12 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution

Comments

@DevAndArtist
Copy link
Mannequin

DevAndArtist mannequin commented Mar 27, 2019

Previous ID SR-10200
Radar None
Original Reporter @DevAndArtist
Type Bug
Environment

Apple Swift version 5.0 (swiftlang-1001.0.69.5 clang-1001.0.46.3)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, RunTimeCrash
Assignee None
Priority Medium

md5: 1b7b3667a0b982abf12099be628faeff

Issue Description:

I cannot post the exact code, this issue started top pop up randomly with the Swift 5 compiler in Swift 4.2 mode. It worked perfectly fine with the old compiler.

extension GenericCoreClass {
  func start() {
    // Ensure proper synchronization.
    preconditionIsOnQueue()
    switch self {
    case let core as GenericCoreClass<InterfaceAsStruct>: // crashes here
      ...
    default:
      break
    }
  }
}

Part of the stack trace:

#&#8203;0  0x00000001bf362ec8 in _class_initialize ()
#&#8203;1  0x00000001bf36c8f8 in lookUpImpOrForward ()
#&#8203;2  0x00000001bf379098 in _objc_msgSend_uncached ()
#&#8203;3  0x00000001c01967dc in ___forwarding___ ()
#&#8203;4  0x00000001c019848c in _CF_forwarding_prep_0 ()
#&#8203;5  0x00000001bf35d024 in CALLING_SOME_+initialize_METHOD ()
#&#8203;6  0x00000001bf362f84 in _class_initialize ()
#&#8203;7  0x00000001bf36c8f8 in lookUpImpOrForward ()
#&#8203;8  0x00000001bf379098 in _objc_msgSend_uncached ()
#&#8203;9  0x00000001029d6b4c in swift_dynamicCastObjCClassMetatype ()
#&#8203;10 0x000000010298ab30 in swift_dynamicCastMetatypeImpl(swift::TargetMetadata<swift::InProcess> const*, swift::TargetMetadata<swift::InProcess> const*) ()
#&#8203;11 0x00000001029ae394 in swift::_checkGenericRequirements(llvm::ArrayRef<swift::TargetGenericRequirementDescriptor<swift::InProcess> >, std::__1::vector<void const*, std::__1::allocator<void const*> >&, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) ()
#&#8203;12 0x00000001029ab410 in (anonymous namespace)::DecodedMetadataBuilder::createBoundGenericType(swift::TargetContextDescriptor<swift::InProcess> const*, llvm::ArrayRef<swift::TargetMetadata<swift::InProcess> const*>, swift::TargetMetadata<swift::InProcess> const*) const ()
#&#8203;13 0x00000001029aaac4 in swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&) ()
#&#8203;14 0x00000001029aa100 in swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&) ()
#&#8203;15 0x00000001029a99e8 in swift_getTypeByMangledNodeImpl(swift::MetadataRequest, swift::Demangle::Demangler&, swift::Demangle::Node*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) ()
#&#8203;16 0x00000001029a97a8 in swift::swift_getTypeByMangledNode(swift::MetadataRequest, swift::Demangle::Demangler&, swift::Demangle::Node*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) ()
#&#8203;17 0x00000001029a9d18 in swift_getTypeByMangledNameImpl(swift::MetadataRequest, llvm::StringRef, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) ()
#&#8203;18 0x00000001029a8110 in swift::swift_getTypeByMangledName(swift::MetadataRequest, llvm::StringRef, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) ()
#&#8203;19 0x000000010299f114 in getSuperclassMetadata(swift::TargetClassMetadata<swift::InProcess>*, bool) ()
#&#8203;20 0x0000000102999df4 in _swift_initClassMetadataImpl(swift::TargetClassMetadata<swift::InProcess>*, swift::ClassLayoutFlags, unsigned long, swift::TypeLayout const* const*, unsigned long*, bool) ()
#&#8203;21 0x000000010237b988 in type metadata completion function for GenericCoreClass ()
#&#8203;22 0x00000001029a0e24 in swift::MetadataCacheEntryBase<(anonymous namespace)::GenericCacheEntry, void const*>::doInitialization(swift::ConcurrencyControl&, swift::MetadataCompletionQueueEntry*, swift::MetadataRequest) ()
#&#8203;23 0x0000000102998168 in swift_getGenericMetadata ()
#&#8203;24 0x000000010237a58c in type metadata accessor for GenericCoreClass ()
#&#8203;25 0x000000010230173c in type metadata accessor for GenericCoreClass<InterfaceAsStruct> ()
#&#8203;26 0x00000001023c29f0 in GenericCoreClass.start() at file_where_code_is_executed.swift:16
#&#8203;27 0x000000010237b9d4 in partial apply for GenericCoreClass.start() ()
#&#8203;28 0x0000000102337174 in thunk for @escaping @callee_guaranteed () -> () ()
#&#8203;29 0x00000001032b7824 in _dispatch_call_block_and_release ()
#&#8203;30 0x00000001032b8dc8 in _dispatch_client_callout ()
#&#8203;31 0x00000001032c0e6c in _dispatch_lane_serial_drain ()
#&#8203;32 0x00000001032c1b60 in _dispatch_lane_invoke ()
#&#8203;33 0x00000001032cbbfc in _dispatch_workloop_worker_thread ()
#&#8203;34 0x00000001bfdad0dc in _pthread_wqthread ()
#&#8203;35 0x00000001bfdafcec in start_wqthread ()

The code is running on a custom serial queue.

Edit:

New similar crash on a similar subtype:

extension OtherGenericCoreClass {
  func start() {
    // Ensure sync.
    preconditionIsOnQueue()
    if let core = self as? OtherGenericCoreClass<InterfaceAsStruct> { // crashes here
      ...
    }
  }
}
#&#8203;0  0x00000001dbf676cc in initObjCClass(swift::TargetClassMetadata<swift::InProcess>*, unsigned long, swift::TypeLayout const* const*, unsigned long*) ()
#&#8203;1  0x00000001dbf627e0 in _swift_initClassMetadataImpl(swift::TargetClassMetadata<swift::InProcess>*, swift::ClassLayoutFlags, unsigned long, swift::TypeLayout const* const*, unsigned long*, bool) ()
#&#8203;2  0x000000010299531c in type metadata completion function for DrivingUnleashedStorage ()
#&#8203;3  0x00000001dbf6a1c4 in swift::MetadataCacheEntryBase<(anonymous namespace)::SingletonMetadataCacheEntry, int>::doInitialization(swift::ConcurrencyControl&, swift::MetadataCompletionQueueEntry*, swift::MetadataRequest) ()
#&#8203;4  0x00000001dbf65d10 in swift::resumeMetadataCompletion(swift::MetadataCompletionQueueEntry*) ()
#&#8203;5  0x00000001dbf6a550 in swift::MetadataCacheEntryBase<(anonymous namespace)::SingletonMetadataCacheEntry, int>::doInitialization(swift::ConcurrencyControl&, swift::MetadataCompletionQueueEntry*, swift::MetadataRequest) ()
#&#8203;6  0x00000001dbf60820 in swift_getSingletonMetadata ()
#&#8203;7  0x00000001029788d0 in type metadata accessor for UnleashedStorage ()
#&#8203;8  0x00000001dbf73808 in (anonymous namespace)::DecodedMetadataBuilder::createBoundGenericType(swift::TargetContextDescriptor<swift::InProcess> const*, llvm::ArrayRef<swift::TargetMetadata<swift::InProcess> const*>, swift::TargetMetadata<swift::InProcess> const*) const ()
#&#8203;9  0x00000001dbf72c94 in swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&) ()
#&#8203;10 0x00000001dbf72428 in swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&) ()
#&#8203;11 0x00000001dbf71d10 in swift_getTypeByMangledNodeImpl(swift::MetadataRequest, swift::Demangle::Demangler&, swift::Demangle::Node*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) ()
#&#8203;12 0x00000001dbf71ad0 in swift::swift_getTypeByMangledNode(swift::MetadataRequest, swift::Demangle::Demangler&, swift::Demangle::Node*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) ()
#&#8203;13 0x00000001dbf72044 in swift_getTypeByMangledNameImpl(swift::MetadataRequest, llvm::StringRef, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) ()
#&#8203;14 0x00000001dbf70450 in swift::swift_getTypeByMangledName(swift::MetadataRequest, llvm::StringRef, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) ()
#&#8203;15 0x00000001dbf66d84 in swift_getAssociatedTypeWitnessSlowImpl(swift::MetadataRequest, swift::TargetWitnessTable<swift::InProcess>*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolRequirement<swift::InProcess> const*, swift::TargetProtocolRequirement<swift::InProcess> const*) ()
#&#8203;16 0x00000001dbf65340 in swift_getAssociatedTypeWitness ()
#&#8203;17 0x00000001dbf730a0 in swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&) ()
#&#8203;18 0x00000001dbf72428 in swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&) ()
#&#8203;19 0x00000001dbf7297c in swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&) ()
#&#8203;20 0x00000001dbf72428 in swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&) ()
#&#8203;21 0x00000001dbf71d10 in swift_getTypeByMangledNodeImpl(swift::MetadataRequest, swift::Demangle::Demangler&, swift::Demangle::Node*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) ()
#&#8203;22 0x00000001dbf71ad0 in swift::swift_getTypeByMangledNode(swift::MetadataRequest, swift::Demangle::Demangler&, swift::Demangle::Node*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) ()
#&#8203;23 0x00000001dbf72044 in swift_getTypeByMangledNameImpl(swift::MetadataRequest, llvm::StringRef, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) ()
#&#8203;24 0x00000001dbf70450 in swift::swift_getTypeByMangledName(swift::MetadataRequest, llvm::StringRef, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) ()
#&#8203;25 0x00000001dbf6743c in getSuperclassMetadata(swift::TargetClassMetadata<swift::InProcess>*, bool) ()
#&#8203;26 0x00000001dbf62088 in _swift_initClassMetadataImpl(swift::TargetClassMetadata<swift::InProcess>*, swift::ClassLayoutFlags, unsigned long, swift::TypeLayout const* const*, unsigned long*, bool) ()
#&#8203;27 0x0000000102a214b0 in type metadata completion function for OtherGenericCoreClass ()
#&#8203;28 0x00000001dbf69164 in swift::MetadataCacheEntryBase<(anonymous namespace)::GenericCacheEntry, void const*>::doInitialization(swift::ConcurrencyControl&, swift::MetadataCompletionQueueEntry*, swift::MetadataRequest) ()
#&#8203;29 0x00000001dbf603f8 in swift_getGenericMetadata ()
#&#8203;30 0x0000000102a18424 in type metadata accessor for OtherGenericCoreClass ()
#&#8203;31 0x00000001029ec0b8 in type metadata accessor for OtherGenericCoreClass<InterfaceAsStruct> ()
#&#8203;32 0x0000000102a18b00 in OtherGenericCoreClass.start() at FILE_NAME.swift:56
#&#8203;33 0x0000000102a236e0 in partial apply for OtherGenericCoreClass.start() ()
#&#8203;34 0x00000001029a7174 in thunk for @escaping @callee_guaranteed () -> () ()
#&#8203;35 0x0000000102d576f0 in _dispatch_call_block_and_release ()
#&#8203;36 0x0000000102d58c74 in _dispatch_client_callout ()
#&#8203;37 0x0000000102d60bf4 in _dispatch_lane_serial_drain ()
#&#8203;38 0x0000000102d618b4 in _dispatch_lane_invoke ()
#&#8203;39 0x0000000102d6b77c in _dispatch_workloop_worker_thread ()
#&#8203;40 0x00000001ae631114 in _pthread_wqthread ()
#&#8203;41 0x00000001ae633cd4 in start_wqthread ()
@DevAndArtist
Copy link
Mannequin Author

DevAndArtist mannequin commented Mar 27, 2019

cc @slavapestov

@slavapestov
Copy link
Member

What OS version is this? CC @mikeash

@DevAndArtist
Copy link
Mannequin Author

DevAndArtist mannequin commented Mar 27, 2019

Xcode running on 10.14.3 (18D109) - project compiled with minimal deployment target iOS 10.3, and executed on an iPhone 6 Plus 12.1.1 (16C50). The crash happens randomly when I compile and run the project. I just have seen it the second time today. Working on the project the whole day without any issues, but this start appear now. (I have not working on the codebase that cases the crash.)

@mikeash
Copy link
Contributor

mikeash commented Mar 27, 2019

Looks like it's failing to find the `+initialize` method on the class. `SwiftObject` has an empty `+initialize` so I'd guess that the superclass pointer isn't set up properly. Given that it's inconsistent, maybe there's a race. If you re-run without recompiling after a crash, does it reliably crash again, or is it still inconsistent? (This would distinguish between some intermittent compiler error and an intermittent runtime error.)

@DevAndArtist
Copy link
Mannequin Author

DevAndArtist mannequin commented Mar 27, 2019

I tried to run the project without re-compiling, it did crash on the first time I tried. I'm trying to see if I can obtain any crash logs. Then I tried running the project like 20 times and it did not crash so far. I don't really know what to to say. We cannot use thread sanitizer as the project and the code requires bluetooth, which the iOS simulator does not support.

@mikeash
Copy link
Contributor

mikeash commented Mar 27, 2019

Crash logs would be great. If they contain anything sensitive, please feel free to file a Radar on bugreport.apple.com, attach them, and post the number here. If by any chance you can share a test case there, that would be nice too (but I understand that's not always possible).

@DevAndArtist
Copy link
Mannequin Author

DevAndArtist mannequin commented Mar 27, 2019

Okay I can confirm that it crashed, but that is unrelated crash where a project internal precondition triggered.

@DevAndArtist
Copy link
Mannequin Author

DevAndArtist mannequin commented Mar 27, 2019

I'll see if I find some time in the next week to reduce the sample to a small snippet that I can share, I cannot promise that it will reproduce the issue. It will at least give you an idea what I'm doing and where this exploded.

@slavapestov
Copy link
Member

Is the failure non-deterministic? @rjmccall fixed something similar recently but maybe there's another case that was not fixed.

@DevAndArtist
Copy link
Mannequin Author

DevAndArtist mannequin commented Mar 27, 2019

It seems so, I changed some code in the main app (where this code is inside a custom framework we build), re-compiled and run and it crashed randomly two times today. Second time happened a few hours later.

@DevAndArtist
Copy link
Mannequin Author

DevAndArtist mannequin commented Mar 27, 2019

Can there be any differences if I run the project in Swift 4.2 mode compared to an updated project in Swift 5 mode?

@DevAndArtist
Copy link
Mannequin Author

DevAndArtist mannequin commented Mar 28, 2019

Added another crash to the issue, it seems to crash on the dynamic cast. What I do here is cast `self` (which is a generic class) to a specific version where the generic type parameter is specified. In other words I want to do something like this `let this = self as? Self where T == SomeInterface`.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution
Projects
None yet
Development

No branches or pull requests

3 participants