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-11652] Extension of generic Obj-C type with @objc method crashes the compiler #54063

Open
lilyball mannequin opened this issue Oct 22, 2019 · 4 comments
Open

[SR-11652] Extension of generic Obj-C type with @objc method crashes the compiler #54063

lilyball mannequin opened this issue Oct 22, 2019 · 4 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

Comments

@lilyball
Copy link
Mannequin

lilyball mannequin commented Oct 22, 2019

Previous ID SR-11652
Radar None
Original Reporter @lilyball
Type Bug
Environment

Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7)
Target: x86_64-apple-darwin19.0.0

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

md5: da7d5242311cc91d2247bffdb21794bb

relates to:

  • SR-11651 Extension of generic Obj-C type has confusing note about adding @objc

Issue Description:

If I try to extend a generic Obj-C type from Swift with a new method, I get an error about how generic parameters aren't available at runtime. If I add the @objc attribute this error goes away, but instead I get a compiler crash.

import Foundation
extension NSHashTable {
    @objc func foo(_ x: ObjectType) {}
}
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file foo.swift -target x86_64-apple-darwin19.0.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name foo -o /var/folders/nq/dmc1zzf938163pj2rm8tcrbr0000gn/T/foo-8e6b0c.o 
1.  While emitting IR SIL function "@$sSo11NSHashTableC3fooEACyyxF".
 for 'foo(_:)' (at foo.swift:3:11)
0  swift                    0x000000010da26eb3 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x000000010da26686 SignalHandler(int) + 358
2  libsystem_platform.dylib 0x00007fff6e5d3b1d _sigtramp + 29
3  swift                    0x00000001098802bd swift::Type llvm::function_ref<swift::Type (swift::SubstitutableType*)>::callback_fn<swift::irgen::TypeConverter::getExemplarType(swift::CanType)::$_0>(long, swift::SubstitutableType*) + 221
4  swift                    0x0000000109905ed5 emitDirectTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanType, swift::irgen::DynamicMetadataRequest) + 197
5  swift                    0x000000010990a7c5 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType, swift::irgen::DynamicMetadataRequest) + 149
6  swift                    0x00000001098d92d3 void llvm::function_ref<void (swift::CanType)>::callback_fn<(anonymous namespace)::IRGenSILFunction::bindArchetypes(swift::Type)::'lambda'(swift::CanType)>(long, swift::CanType) + 67
7  swift                    0x000000010976729d bool llvm::function_ref<bool (swift::CanType)>::callback_fn<swift::CanType::visit(llvm::function_ref<void (swift::CanType)>) const::'lambda'(swift::Type)>(long, swift::CanType) + 13
8  swift                    0x000000010a61851e swift::Type::findIf(llvm::function_ref<bool (swift::Type)>) const::Walker::walkToTypePre(swift::Type) + 14
9  swift                    0x00000001098d257b (anonymous namespace)::IRGenSILFunction::bindArchetypes(swift::Type) + 235
10 swift                    0x00000001098cdd20 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 90240
11 swift                    0x00000001098b512a swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 9866
12 swift                    0x0000000109761700 swift::irgen::IRGenerator::emitGlobalTopLevel() + 1712
13 swift                    0x0000000109891e85 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**) + 1189
14 swift                    0x000000010967e5aa performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 36682
15 swift                    0x0000000109671e54 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6820
16 swift                    0x00000001095ff3c3 main + 1219
17 libdyld.dylib            0x00007fff6e3d2405 start + 1
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: compile command failed due to signal 11 (use -v to see invocation)
@lilyball
Copy link
Mannequin Author

lilyball mannequin commented Oct 22, 2019

If the method instead looks like @objc func foo(_ x: Int) {} there is no crash.

@belkadan
Copy link
Contributor

Crashes on master and in Xcode 10.2 as well. @jckarter, @DougGregor, do you remember how this was supposed to work, or what rule was supposed to ban it?

@jckarter
Copy link
Member

An @objc method in an extension is supposed to avoid trying to reify the erased generic arguments of the ObjC class. It looks like we're generating some code that tries to reify them anyway.

@swift-ci
Copy link
Collaborator

Comment by Alberto Lagos (JIRA)

Hi, I’m new in the community and I looked this ticket and i thought that maybe i can help and try to fix it. Can someone give me some directions on where I need too look in the code? Thanks!

@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
Projects
None yet
Development

No branches or pull requests

4 participants