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-3915] 3.1 compiler crashes during deserialization in merge module step #46500

Closed
swift-ci opened this issue Feb 10, 2017 · 8 comments
Closed
Assignees
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-3915
Radar rdar://problem/30472071
Original Reporter chengyin (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Apple Swift version 3.1-dev (LLVM 3887fe8485, Clang f9a0f935a5, Swift 59037e9)
Target: x86_64-apple-macosx10.9

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, 3.1Regression, CompilerCrash, Serialization
Assignee @belkadan
Priority Medium

md5: f5e1786b01effe41efff918d590478b6

Issue Description:

We found this issue in a library of ours. After some very interesting investigation, we were able to reduce it down to a small reproducible case.

This bug can be reproduced using Xcode 8.3b2 or swift-DEVELOPMENT-SNAPSHOT-2017-02-09-a. It couldn't be reproduced with Xcode 8.2.1.

In the test case we have two files:

A.swift

enum A {}

extension A {
  enum B {}
}

B.swift

extension A.B {
  enum A {}
}

extension A.B.A {}

Compile these two files will yield an crash:

$ /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2017-02-09-a.xctoolchain/usr/bin/swiftc A.swift B.swift -module-name EnumTest -emit-module

0  swift                    0x000000010910cdd8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x000000010910bff6 llvm::sys::RunSignalHandlers() + 86
2  swift                    0x000000010910d429 SignalHandler(int) + 361
3  libsystem_platform.dylib 0x00007fffce5d0bba _sigtramp + 26
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 832762976
5  swift                    0x0000000106f2d2f1 swift::NominalTypeDecl::computeType() + 129
6  swift                    0x0000000106b7c8db swift::ModuleFile::getDecl(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 18603
7  swift                    0x0000000106b801d7 swift::ModuleFile::getType(llvm::PointerEmbeddedInt<unsigned int, 31>) + 2087
8  swift                    0x0000000106b7bd49 swift::ModuleFile::getDecl(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 15641
9  swift                    0x0000000106bafcf8 swift::ModuleFile::loadExtensions(swift::NominalTypeDecl*) + 728
10 swift                    0x0000000106bfea61 swift::SerializedModuleLoader::loadExtensions(swift::NominalTypeDecl*, unsigned int) + 49
11 swift                    0x0000000106e8c09f swift::ASTContext::loadExtensions(swift::NominalTypeDecl*, unsigned int) + 63
12 swift                    0x0000000106f2d90a swift::NominalTypeDecl::getExtensions() + 74
13 swift                    0x0000000106b87113 swift::ModuleFile::resolveCrossReference(swift::ModuleDecl*, unsigned int) + 4803
14 swift                    0x0000000106b7b42d swift::ModuleFile::getDecl(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 13309
15 swift                    0x0000000106b801d7 swift::ModuleFile::getType(llvm::PointerEmbeddedInt<unsigned int, 31>) + 2087
16 swift                    0x0000000106b7bd49 swift::ModuleFile::getDecl(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 15641
17 swift                    0x0000000106bb15a5 swift::ModuleFile::getTopLevelDecls(llvm::SmallVectorImpl<swift::Decl*>&) + 1221
18 swift                    0x0000000106f62f6f swift::ModuleDecl::getTopLevelDecls(llvm::SmallVectorImpl<swift::Decl*>&) const + 63
19 swift                    0x00000001067ab68e swift::ClassHierarchyAnalysis::init() + 78
20 swift                    0x000000010679ed09 swift::createClassHierarchyAnalysis(swift::SILModule*) + 153
21 swift                    0x000000010685b8cc swift::SILPassManager::SILPassManager(swift::SILModule*, llvm::StringRef) + 460
22 swift                    0x0000000106866eca swift::runSILDiagnosticPasses(swift::SILModule&) + 138
23 swift                    0x000000010605ae7c swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 12332
24 swift                    0x0000000106017a00 main + 3312
25 libdyld.dylib            0x00007fffce3c3255 start + 1
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2017-02-09-a.xctoolchain/usr/bin/swift -frontend -emit-module /var/folders/18/g1ghk3z51476sy22xdf2m4100000gn/T/A-5af2a3.swiftmodule /var/folders/18/g1ghk3z51476sy22xdf2m4100000gn/T/B-dec568.swiftmodule -parse-as-library -target x86_64-apple-macosx10.9 -enable-objc-interop -emit-module-doc-path EnumTest.swiftdoc -color-diagnostics -module-name EnumTest -o EnumTest.swiftmodule
1.  While reading from /var/folders/18/g1ghk3z51476sy22xdf2m4100000gn/T/B-dec568.swiftmodule
2.  While deserializing extension of '<null>' (ExtensionDecl #&#8203;1)in 'EnumTest'
3.  While deserializing 'B' (EnumDecl #&#8203;2)in 'EnumTest'
4.  Cross-reference to module 'EnumTest'
    ... A
    ... in an extension in module 'EnumTest'
    ... B
5.  If you're seeing a crash here, try passing -Xfrontend -disable-serialization-nested-type-lookup-table
6.  While reading from /var/folders/18/g1ghk3z51476sy22xdf2m4100000gn/T/B-dec568.swiftmodule
7.  While deserializing extension of '<null>' (ExtensionDecl #&#8203;4)in 'EnumTest'
8.  While deserializing 'A' (EnumDecl #&#8203;3)in 'EnumTest'
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: merge-module command failed due to signal 11 (use -v to see invocation)

This also fails using an Xcode project. The flag -Xfrontend -disable-serialization-nested-type-lookup-table did not change the result.

Unsurprisingly, merging the two files fixed the issue.

What's fascinating is that if we change A.B.A to something different, such as Z.B.Z, it may compile successfully. We included this test case too with GoodA.swift and GoodB.swift files. We discovered other letters/words that led to crash or success. We also found other failed cases that are a little more complicated during our investigation. We can provide those if needed.

This might be related to SR-3707. As far as I could tell, the commit that fixes SR-3707 was already included in the snapshot I used to test.

@swift-ci
Copy link
Collaborator Author

Comment by Chengyin Liu (JIRA)

@belkadan Sorry to directly ping you, but since you owns SR-3707, this might be interesting to you too.

@belkadan
Copy link
Contributor

Hm. Thanks, Chengyin.

@swift-ci create

@swift-ci
Copy link
Collaborator Author

Comment by Chengyin Liu (JIRA)

I just edited the issue and the files to remove `public` modifiers. It doesn't affect this bug so I wanted to remove the distraction.

@belkadan
Copy link
Contributor

Looks like the extension table in modules is keyed by name, so nested types with the same name would cause more deserialization than needed. In this case that leads to a circularity issue. I'll think about whether there's an easy and non-intrusive way to fix this; even if having a nested type that matches a top-level type is rare, having nested types across multiple classes with the same name is incredibly common.

@belkadan
Copy link
Contributor

The Z.B.Z case is likely the hashing being perturbed enough to deserialize things coincidentally in the right order.

@belkadan
Copy link
Contributor

#7397

@belkadan
Copy link
Contributor

3.1: #7434

@belkadan
Copy link
Contributor

Merged in 03d9562. It might still take a while for this to get into an official Xcode release, so if you want to test this sooner you can grab a development snapshot from https://swift.org/download/#snapshots.

@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

3 participants