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-5286] Protocols with circular associated types constraints does not compile when definitions are in different files(works within one file) #47861

Closed
swift-ci opened this issue Jun 22, 2017 · 6 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-5286
Radar None
Original Reporter kacperh (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode 9 Beta 2, Swift 4.0

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

md5: 88e6dcd62f1028b82f4a7166bea38631

Issue Description:

I'm using associated types constraints in following way:

protocol CharacteristicType {
    associatedtype D: DescriptorType where Self.D.C == Self
}

protocol DescriptorType {
    associatedtype C: CharacteristicType
}

Everything works well when protocols are defined within the single file. This feature started working in Swift 4.
When divided into two files(there are more protocols in our production code so it has to be that way) - compiler fails. I'm attaching project in which this behavior is happening.

Also, please look at the log:

*** DESERIALIZATION FAILURE (please include this section in any bug report) ***
top-level value not found
Cross-reference to module 'SampleCrash'
... CharacteristicType

0  swift                    0x000000010c1e231a PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x000000010c1e1756 SignalHandler(int) + 662
2  libsystem_platform.dylib 0x00007fffbce4eb3a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fff570c08c0 _sigtramp + 2586254752
4  libsystem_c.dylib        0x00007fffbccd3420 abort + 129
5  swift                    0x00000001098f4d61 swift::ModuleFile::fatal(llvm::Error) + 1569
6  swift                    0x00000001098ff443 swift::ModuleFile::getDeclChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 41507
7  swift                    0x00000001098f51e4 swift::ModuleFile::getDecl(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 84
8  swift                    0x000000010990202a swift::ModuleFile::getTypeChecked(llvm::PointerEmbeddedInt<unsigned int, 31>) + 1898
9  swift                    0x00000001098fffe8 swift::ModuleFile::readGenericRequirements(llvm::SmallVectorImpl<swift::Requirement>&, llvm::BitstreamCursor&) + 200
10 swift                    0x00000001098fbca1 swift::ModuleFile::getDeclChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 27265
11 swift                    0x000000010999622a swift::SerializedASTFile::lookupValue(llvm::ArrayRef<std::__1::pair<swift::Identifier, swift::SourceLoc> >, swift::DeclName, swift::NLKind, llvm::SmallVectorImpl<swift::ValueDecl*>&) const + 1066
12 swift                    0x0000000109da796d void lookupInModule<llvm::SmallSet<swift::CanType, 4u, (anonymous namespace)::SortCanType>, swift::namelookup::lookupInModule(swift::ModuleDecl*, llvm::ArrayRef<std::__1::pair<swift::Identifier, swift::SourceLoc> >, swift::DeclName, llvm::SmallVectorImpl<swift::ValueDecl*>&, swift::NLKind, swift::namelookup::ResolutionKind, swift::LazyResolver*, swift::DeclContext const*, llvm::ArrayRef<std::__1::pair<llvm::ArrayRef<std::__1::pair<swift::Identifier, swift::SourceLoc> >, swift::ModuleDecl*> >)::$_0>(swift::ModuleDecl*, llvm::ArrayRef<std::__1::pair<swift::Identifier, swift::SourceLoc> >, llvm::SmallVectorImpl<swift::ValueDecl*>&, swift::namelookup::ResolutionKind, bool, swift::LazyResolver*, llvm::SmallDenseMap<std::__1::pair<llvm::ArrayRef<std::__1::pair<swift::Identifier, swift::SourceLoc> >, swift::ModuleDecl*>, llvm::TinyPtrVector<swift::ValueDecl*>, 32u, llvm::DenseMapInfo<std::__1::pair<llvm::ArrayRef<std::__1::pair<swift::Identifier, swift::SourceLoc> >, swift::ModuleDecl*> >, llvm::detail::DenseMapPair<std::__1::pair<llvm::ArrayRef<std::__1::pair<swift::Identifier, swift::SourceLoc> >, swift::ModuleDecl*>, llvm::TinyPtrVector<swift::ValueDecl*> > >&, swift::DeclContext const*, bool, llvm::ArrayRef<std::__1::pair<llvm::ArrayRef<std::__1::pair<swift::Identifier, swift::SourceLoc> >, swift::ModuleDecl*> >, swift::namelookup::lookupInModule(swift::ModuleDecl*, llvm::ArrayRef<std::__1::pair<swift::Identifier, swift::SourceLoc> >, swift::DeclName, llvm::SmallVectorImpl<swift::ValueDecl*>&, swift::NLKind, swift::namelookup::ResolutionKind, swift::LazyResolver*, swift::DeclContext const*, llvm::ArrayRef<std::__1::pair<llvm::ArrayRef<std::__1::pair<swift::Identifier, swift::SourceLoc> >, swift::ModuleDecl*> >)::$_0) + 333
13 swift                    0x0000000109da77e3 swift::namelookup::lookupInModule(swift::ModuleDecl*, llvm::ArrayRef<std::__1::pair<swift::Identifier, swift::SourceLoc> >, swift::DeclName, llvm::SmallVectorImpl<swift::ValueDecl*>&, swift::NLKind, swift::namelookup::ResolutionKind, swift::LazyResolver*, swift::DeclContext const*, llvm::ArrayRef<std::__1::pair<llvm::ArrayRef<std::__1::pair<swift::Identifier, swift::SourceLoc> >, swift::ModuleDecl*> >) + 1267
14 swift                    0x0000000109db05ce swift::DeclContext::lookupQualified(swift::Type, swift::DeclName, swift::NLOptions, swift::LazyResolver*, llvm::SmallVectorImpl<swift::ValueDecl*>&) const + 1438
15 swift                    0x0000000109906baa swift::ModuleFile::resolveCrossReference(swift::ModuleDecl*, unsigned int) + 874
16 swift                    0x00000001098f8cb5 swift::ModuleFile::getDeclChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 14997
17 swift                    0x000000010990294d swift::ModuleFile::getTypeChecked(llvm::PointerEmbeddedInt<unsigned int, 31>) + 4237
18 swift                    0x00000001098fad27 swift::ModuleFile::getDeclChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 23303
19 swift                    0x00000001098f51e4 swift::ModuleFile::getDecl(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 84
20 swift                    0x000000010990202a swift::ModuleFile::getTypeChecked(llvm::PointerEmbeddedInt<unsigned int, 31>) + 1898
21 swift                    0x0000000109901ff9 swift::ModuleFile::getTypeChecked(llvm::PointerEmbeddedInt<unsigned int, 31>) + 1849
22 swift                    0x00000001099001c9 swift::ModuleFile::readGenericRequirements(llvm::SmallVectorImpl<swift::Requirement>&, llvm::BitstreamCursor&) + 681
23 swift                    0x00000001098fbca1 swift::ModuleFile::getDeclChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 27265
24 swift                    0x000000010992e6ae swift::ModuleFile::getTopLevelDecls(llvm::SmallVectorImpl<swift::Decl*>&) + 1982
25 swift                    0x00000001095dc3c0 swift::SILPassManager::SILPassManager(swift::SILModule*, llvm::StringRef) + 1504
26 swift                    0x00000001095e2a3f swift::runSILDiagnosticPasses(swift::SILModule&) + 143
27 swift                    0x0000000108baec10 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 13696
28 swift                    0x0000000108ba9e24 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7332
29 swift                    0x0000000108b5fab8 main + 12248
30 libdyld.dylib            0x00007fffbcc3f235 start + 1
Stack dump:
0.  Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -emit-module /Users/kacperharasim/Library/Developer/Xcode/DerivedData/SampleCrash-cnomijadbqzflbdsknshrdenwvfd/Build/Intermediates.noindex/SampleCrash.build/Debug-iphonesimulator/SampleCrash.build/Objects-normal/x86_64/CharacteristicType~partial.swiftmodule /Users/kacperharasim/Library/Developer/Xcode/DerivedData/SampleCrash-cnomijadbqzflbdsknshrdenwvfd/Build/Intermediates.noindex/SampleCrash.build/Debug-iphonesimulator/SampleCrash.build/Objects-normal/x86_64/DescriptorType~partial.swiftmodule -parse-as-library -target x86_64-apple-ios11.0 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.0.sdk -I /Users/kacperharasim/Library/Developer/Xcode/DerivedData/SampleCrash-cnomijadbqzflbdsknshrdenwvfd/Build/Products/Debug-iphonesimulator -F /Users/kacperharasim/Library/Developer/Xcode/DerivedData/SampleCrash-cnomijadbqzflbdsknshrdenwvfd/Build/Products/Debug-iphonesimulator -enable-testing -g -import-underlying-module -module-cache-path /Users/kacperharasim/Library/Developer/Xcode/DerivedData/ModuleCache -swift-version 4 -D DEBUG -serialize-debugging-options -Xcc -I/Users/kacperharasim/Library/Developer/Xcode/DerivedData/SampleCrash-cnomijadbqzflbdsknshrdenwvfd/Build/Intermediates.noindex/SampleCrash.build/Debug-iphonesimulator/SampleCrash.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/kacperharasim/Library/Developer/Xcode/DerivedData/SampleCrash-cnomijadbqzflbdsknshrdenwvfd/Build/Intermediates.noindex/SampleCrash.build/Debug-iphonesimulator/SampleCrash.build/SampleCrash-generated-files.hmap -Xcc -I/Users/kacperharasim/Library/Developer/Xcode/DerivedData/SampleCrash-cnomijadbqzflbdsknshrdenwvfd/Build/Intermediates.noindex/SampleCrash.build/Debug-iphonesimulator/SampleCrash.build/SampleCrash-own-target-headers.hmap -Xcc -I/Users/kacperharasim/Library/Developer/Xcode/DerivedData/SampleCrash-cnomijadbqzflbdsknshrdenwvfd/Build/Intermediates.noindex/SampleCrash.build/Debug-iphonesimulator/SampleCrash.build/SampleCrash-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/kacperharasim/Library/Developer/Xcode/DerivedData/SampleCrash-cnomijadbqzflbdsknshrdenwvfd/Build/Intermediates.noindex/SampleCrash.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/kacperharasim/Library/Developer/Xcode/DerivedData/SampleCrash-cnomijadbqzflbdsknshrdenwvfd/Build/Intermediates.noindex/SampleCrash.build/Debug-iphonesimulator/SampleCrash.build/SampleCrash-project-headers.hmap -Xcc -I/Users/kacperharasim/Library/Developer/Xcode/DerivedData/SampleCrash-cnomijadbqzflbdsknshrdenwvfd/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/kacperharasim/Library/Developer/Xcode/DerivedData/SampleCrash-cnomijadbqzflbdsknshrdenwvfd/Build/Intermediates.noindex/SampleCrash.build/Debug-iphonesimulator/SampleCrash.build/DerivedSources/x86_64 -Xcc -I/Users/kacperharasim/Library/Developer/Xcode/DerivedData/SampleCrash-cnomijadbqzflbdsknshrdenwvfd/Build/Intermediates.noindex/SampleCrash.build/Debug-iphonesimulator/SampleCrash.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -ivfsoverlay -Xcc /Users/kacperharasim/Library/Developer/Xcode/DerivedData/SampleCrash-cnomijadbqzflbdsknshrdenwvfd/Build/Intermediates.noindex/SampleCrash.build/Debug-iphonesimulator/SampleCrash.build/unextended-module-overlay.yaml -Xcc -working-directory/Users/kacperharasim/Downloads/SampleCrash -emit-module-doc-path /Users/kacperharasim/Library/Developer/Xcode/DerivedData/SampleCrash-cnomijadbqzflbdsknshrdenwvfd/Build/Intermediates.noindex/SampleCrash.build/Debug-iphonesimulator/SampleCrash.build/Objects-normal/x86_64/SampleCrash.swiftdoc -module-name SampleCrash -emit-objc-header-path /Users/kacperharasim/Library/Developer/Xcode/DerivedData/SampleCrash-cnomijadbqzflbdsknshrdenwvfd/Build/Intermediates.noindex/SampleCrash.build/Debug-iphonesimulator/SampleCrash.build/Objects-normal/x86_64/SampleCrash-Swift.h -o /Users/kacperharasim/Library/Developer/Xcode/DerivedData/SampleCrash-cnomijadbqzflbdsknshrdenwvfd/Build/Intermediates.noindex/SampleCrash.build/Debug-iphonesimulator/SampleCrash.build/Objects-normal/x86_64/SampleCrash.swiftmodule 
1.  While reading from /Users/kacperharasim/Library/Developer/Xcode/DerivedData/SampleCrash-cnomijadbqzflbdsknshrdenwvfd/Build/Intermediates.noindex/SampleCrash.build/Debug-iphonesimulator/SampleCrash.build/Objects-normal/x86_64/CharacteristicType~partial.swiftmodule
2.  While deserializing 'CharacteristicType' (ProtocolDecl #&#8203;1) in 'SampleCrash'
3.  While deserializing 'D' (AssociatedTypeDecl #&#8203;2) in 'SampleCrash'
4.  While deserializing decl #&#8203;5 (XREF) in 'SampleCrash'
5.  Cross-reference to module 'SampleCrash'
    ... DescriptorType
6.  While reading from /Users/kacperharasim/Library/Developer/Xcode/DerivedData/SampleCrash-cnomijadbqzflbdsknshrdenwvfd/Build/Intermediates.noindex/SampleCrash.build/Debug-iphonesimulator/SampleCrash.build/Objects-normal/x86_64/DescriptorType~partial.swiftmodule
7.  While deserializing 'DescriptorType' (ProtocolDecl #&#8203;1) in 'SampleCrash'
8.  While deserializing 'C' (AssociatedTypeDecl #&#8203;2) in 'SampleCrash'
@belkadan
Copy link
Contributor

Very invasive workaround: turn on whole-module optimization.

@swift-ci
Copy link
Collaborator Author

Comment by KacperHarasim (JIRA)

@belkadanIt works![]( It'll help us a lot during the development of the new architecture for the library. Thank you)

@belkadan
Copy link
Contributor

I'll warn you that this isn't likely to be fixed in the Swift 4 timeframe, though—it's been a known issue for a while and if there were an easy solution I would have put it in already. :-(

@swift-ci
Copy link
Collaborator Author

Comment by KacperHarasim (JIRA)

Oh, okay, I understand 🙂 Good luck with fixing this! Is it possible to fit this fix in the 4.X release or Swift 5 is more realistic? Asking just in order to plan future releases.

@belkadan
Copy link
Contributor

Can't really say that far out. Still finishing 4.0.

@slavapestov
Copy link
Member

@DougGregor fixed this on master recently: #12253

@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