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-10217] Incorrect handling for Objective-C classes and protocols used as type arguments #52617

Open
swift-ci opened this issue Mar 28, 2019 · 12 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-10217
Radar rdar://problem/49380773
Original Reporter SvyatoslavScherbina (JIRA User)
Type Bug
Environment
Apple Swift version 5.0 (swiftlang-1001.0.69.5 clang-1001.0.46.3)
Target: x86_64-apple-darwin18.2.0
Additional Detail from JIRA
Votes 3
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 1dcc6034e3c7ec3532eba543e53f002c

Issue Description:

The compiler sometimes doesn't consider such a declarations to be used, as shown by the following examples crashing at runtime:

1.

import Accounts

class Base<T> {}
class Derived : Base<ACAccount> {}

Derived()

Accounts framework is not linked because not considered as used by the compiler. And then Swift runtime fails because it can't find the class from this framework.

2.

import Foundation

class Base<T> {}
class Derived : Base<NSURLDownloadDelegate> {}

Derived()

Foundation framework is linked, but protocols code is generated on demand, and NSURLDownloadDelegate hasn't been requested properly. So it can't be found at runtime and the application crashes with segmentation fault.

@swift-ci
Copy link
Collaborator Author

Comment by Svyatoslav Scherbina (JIRA)

(First reported in SR-10177).

@belkadan
Copy link
Contributor

Thank you!

@swift-ci
Copy link
Collaborator Author

Comment by Eric Yanush (JIRA)

This issue has caused an entire set of projects to crash at runtime when built with Xcode 10.2. This bug will prevent my organization from upgrading from Xcode 10.1 to 10.2 (& Swift 5.0).

In our case, we have a pure Swift dynamic framework that encapsulates all of our common base classes and other common functionality. Currently we know that at least one of the generic classes in our common framework, which inherits from a class in an external framework (GroupProcedure from ProcedureKit), is causing runtime crashes when a concrete subclass is defined outside of the common framework.

I've also noticed that the mangled name reported in the runtime crash, is not demangle-able by swift-demangle. I've included the mangled name reported (with proprietary names replaced with placeholders).

8CommonFramework10FetchGroupCyAA32DownloadSecuredResourceProcedureC5ProductFramework9APITicketVytAE0G10KitNetwork0K9OperationA2A0ekG0C0gJ006OutputG0HPyHC_AI19HTTPPayloadResponseVy10Foundation4DataVGAI0nO8ProtocolHPyHCHCg1_G

@belkadan
Copy link
Contributor

The workaround is to use the type somewhere in your program that's not a generic argument, even if you don't do anything with it. For the class case, you should be able to explicitly link the framework without any source changes as well, rather than relying on autolinking.

Replacing proprietary names by placeholders might mess up the mangled name, unfortunately, so we can't do anything with that. Can you share the original name with just Apple at https://bugreport.apple.com?

@swift-ci
Copy link
Collaborator Author

Comment by Eric Yanush (JIRA)

@belkadan Done! Submitted as problem 49391672, with code attached.

@belkadan
Copy link
Contributor

Reverted @bob-wilson's Radar change since that's a separate issue.

@belkadan
Copy link
Contributor

(Eric, I'm treating your Radar as being about the mangling; we can keep using this JIRA to track the "the compiler should link the framework" issue.)

@bob-wilson
Copy link

OK, sorry, I misunderstood. What about SR-10177? Is that also a separate issue?

@belkadan
Copy link
Contributor

Yep, that's about the diagnostic in the runtime. If we ever come up with a way to turn off autolinking (or if we have other bugs) that'll still be relevant.

@swift-ci
Copy link
Collaborator Author

Comment by Eric Yanush (JIRA)

An update to my issue:

I was able to identify a workaround, which is to specify the superclass type as the type parameter used in my sub-type declaration. For example:

class GenericOne<T> { }
class Other { }
class DerivedOne: GenericOne<Other> { }

class GenericTwo<T, U , V> { }

// This will cause a runtime error stating that the super class of ProblemClass cannot be demangled.
class ProblemClass: GenericTwo<DerivedOne, Int, String> { }

// This works
class ProblemClass: GenericTwo<GenericOne<Other>, Int, String> { }

@belkadan
Copy link
Contributor

This is starting to sound like a completely different issue from what Svyatoslav is describing. Is that what's in your Radar?

@swift-ci
Copy link
Collaborator Author

Comment by Eric Yanush (JIRA)

Yes it is.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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
Projects
None yet
Development

No branches or pull requests

3 participants