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-4211] Extension That Refers Extended Class Within Itself Causes a Segmentation Fault: 11 #46794

Closed
swift-ci opened this issue Mar 10, 2017 · 3 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 serialization Area → compiler: Serialization & deserialization

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-4211
Radar None
Original Reporter Andy (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Version 8.2.1 (8C1002)

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

md5: ccaa656ef63b4551aabc5b9959952074

Issue Description:

Summary: When you create an extension for a class, and inside your extension you refer to the class you just extended, the compiler will crash with a segfault 11 error.

Description: I was thinking of possible ways to group a set of notifications that a module of my code can post, and I came up with something like this:

/// Set of notifications that can be sent by this manager
extension Notification.Name {
    /// Notifications that can be posted by the BLE code.
    class BLE {
        /// A notification posted when a new device has been discovered while scanning.
        static var discoveredDevice = Notification.Name("my_unique_notification name")
    }
}

To recreate, put this code at the top level of any Swift file and the compiler will segfault: 11 when you attempt to compile it.

For some reason, it doesn't seem to crash playgrounds.

@belkadan
Copy link
Contributor

With asserts, during the merge-module phase of building:

0.  Program arguments: /Volumes/Data/swift-public/build/ninja/swift-macosx-x86_64/bin/swift -frontend -emit-module /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/--1c73ed.swiftmodule -parse-as-library -target x86_64-apple-macosx10.9 -enable-objc-interop -sdk /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -g -emit-module-doc-path /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/main-23471f.swiftdoc -color-diagnostics -module-name main -o /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/main-23471f.swiftmodule 
1.  While reading from /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/--1c73ed.swiftmodule
2.  While deserializing extension of '<null>' (ExtensionDecl #&#8203;22) in 'main'
3.  While deserializing 'Name' (StructDecl #&#8203;23) in 'main'
4.  Cross-reference to module 'Foundation'
    ... NSNotification
    ... in an extension in module 'Foundation'
    ... Name
5.  /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSNotification.h:26:12: loading members for 'NSNotificationCreation'
6.  /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSNotification.h:28:1: importing 'NSNotificationCreation::notificationWithName:object:'
7.  /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSNotification.h:15:12: loading members for 'NSNotification'
8.  /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSNotification.h:17:47: importing 'NSNotification::name'
9.  /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSScriptObjectSpecifiers.h:107:12: loading members for 'NSScriptObjectSpecifiers'
10. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSScriptObjectSpecifiers.h:109:65: importing 'NSScriptObjectSpecifiers::objectSpecifier'
11. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSScriptClassDescription.h:104:12: loading members for 'NSScriptClassDescription'
12. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSScriptClassDescription.h:108:35: importing 'NSScriptClassDescription::classCode'
13. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjectScripting.h:12:12: loading members for 'NSScripting'
14. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjectScripting.h:25:58: importing 'NSScripting::scriptingProperties'
15. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSClassDescription.h:26:12: loading members for 'NSClassDescriptionPrimitives'
16. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSClassDescription.h:28:48: importing 'NSClassDescriptionPrimitives::classDescription'
17. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSPortCoder.h:27:12: loading members for 'NSDistributedObjects'
18. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSPortCoder.h:29:28: importing 'NSDistributedObjects::classForPortCoder'
19. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSArchiver.h:93:12: loading members for 'NSArchiverCallback'
20. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSArchiver.h:95:38: importing 'NSArchiverCallback::classForArchiver'
21. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSKeyedArchiver.h:211:12: loading members for 'NSKeyedArchiverObjectSubstitution'
22. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSKeyedArchiver.h:213:38: importing 'NSKeyedArchiverObjectSubstitution::classForKeyedArchiver'
23. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSKeyValueObserving.h:168:12: loading members for 'NSKeyValueObservingCustomization'
24. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSKeyValueObserving.h:186:28: importing 'NSKeyValueObservingCustomization::observationInfo'
25. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSKeyValueCoding.h:40:12: loading members for 'NSKeyValueCoding'
26. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSKeyValueCoding.h:45:34: importing 'NSKeyValueCoding::accessInstanceVariablesDirectly'
27. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:85:12: loading members for 'NSDiscardableContentProxy'
28. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:86:33: importing 'NSDiscardableContentProxy::autoContentAccessingProxy'
29. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:52:12: loading members for 'NSCoderMethods'
30. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:56:28: importing 'NSCoderMethods::classForCoder'
31. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/objc/NSObject.h:53:12: loading members for 'NSObject'
32. /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/objc/NSObject.h:69:1: importing 'NSObject::dealloc'
33. While deserializing 'BLE' (ClassDecl #&#8203;24) in 'main'

Obviously this is way more work than Swift should be doing—a known issue—but sometimes it comes back to bite us. Trying to load Every Dealloc Ever is at least one of the problem points here.

I have a Radar for this issue, which I'll find later.

@slavapestov
Copy link
Member

This has since been fixed.

@slavapestov
Copy link
Member

I'm adding a regression test.

@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
This issue was closed.
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 serialization Area → compiler: Serialization & deserialization
Projects
None yet
Development

No branches or pull requests

4 participants