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-6225] Swift compiler crashes if two protocols refer the type of each other spreat around diffenrent files. #48777

Open
swift-ci opened this issue Oct 26, 2017 · 1 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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-6225
Radar None
Original Reporter stephan.rehfeld (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, Serialization
Assignee None
Priority Medium

md5: ae38afb98c00dbcabdb1188942d6933a

relates to:

  • SR-1445 Recursive protocol constraints

Issue Description:

Let's consider you want to write a library for units, and let's assume your base protocol for a unit looks like:

public protocol Unit \{
static var symbol : String \{ get}
static var name : String \{ get}
static var exponent : UInt \{ get}
``}

Next, lets consider you want to have one derived protocol for length units and one for area units. As you want to use generic implementation of the * and / operators, a length unit must know corresponding AreaUnit and the AreaUnit must know its Length Unit.

public protocol LengthUnit : Unit \{
associatedtype AreaType : AreaUnit
``}

public protocol AreaUnit : Unit \{
associatedtype LengthType: LengthUnit
``}

The code compiles if all three protocols are defines in the same file. If all three are defined in different files the Swift compiler crashes.

The compiler prints the followig information:

*** DESERIALIZATION FAILURE (please include this section in any bug report) ***
top-level value not found
Cross-reference to module 'ThroughputTest'
... AreaUnit``0 swift 0x0000000108931dba PrintStackTraceSignalHandler(void*) + 42
1 swift 0x00000001089311f6 SignalHandler(int) + 662
2 libsystem_platform.dylib 0x00007fff72661f5a _sigtramp + 26
3 libsystem_platform.dylib 0x00007ffeea9cc0a8 _sigtramp + 2016846184
4 libsystem_c.dylib 0x00007fff7248d32a abort + 127
5 swift 0x000000010602dbd1 swift::ModuleFile::fatal(llvm::Error) + 1569
6 swift 0x000000010603848a swift::ModuleFile::getDeclChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 41978
7 swift 0x000000010602e054 swift::ModuleFile::getDecl(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 84
8 swift 0x000000010603b00c swift::ModuleFile::getTypeChecked(llvm::PointerEmbeddedInt<unsigned int, 31>) + 1836
9 swift 0x0000000106039008 swift::ModuleFile::readGenericRequirements(llvm::SmallVectorImpl<swift::Requirement>&, llvm::BitstreamCursor&) + 200
10 swift 0x0000000106034ac9 swift::ModuleFile::getDeclChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 27193
11 swift 0x00000001060d04ea swift::SerializedASTFile::lookupValue(llvm::ArrayRef<std::__1::pair<swift::Identifier, swift::SourceLoc> >, swift::DeclName, swift::NLKind, llvm::SmallVectorImpl<swift::ValueDecl*>&) const + 1082
12 swift 0x00000001064efb7d 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 0x00000001064ef9f3 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 0x00000001064f86de swift::DeclContext::lookupQualified(swift::Type, swift::DeclName, swift::NLOptions, swift::LazyResolver*, llvm::SmallVectorImpl<swift::ValueDecl*>&) const + 1470
15 swift 0x000000010603fa3a swift::ModuleFile::resolveCrossReference(swift::ModuleDecl*, unsigned int) + 874
16 swift 0x0000000106031a85 swift::ModuleFile::getDeclChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 14837
17 swift 0x000000010603b913 swift::ModuleFile::getTypeChecked(llvm::PointerEmbeddedInt<unsigned int, 31>) + 4147
18 swift 0x0000000106033b2a swift::ModuleFile::getDeclChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 23194
19 swift 0x000000010602e054 swift::ModuleFile::getDecl(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 84
20 swift 0x000000010603b00c swift::ModuleFile::getTypeChecked(llvm::PointerEmbeddedInt<unsigned int, 31>) + 1836
21 swift 0x0000000106039008 swift::ModuleFile::readGenericRequirements(llvm::SmallVectorImpl<swift::Requirement>&, llvm::BitstreamCursor&) + 200
22 swift 0x0000000106034ac9 swift::ModuleFile::getDeclChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 27193
23 swift 0x0000000106067f9e swift::ModuleFile::getTopLevelDecls(llvm::SmallVectorImpl<swift::Decl*>&) + 1998
24 swift 0x0000000105cf85f0 swift::SILPassManager::SILPassManager(swift::SILModule*, llvm::StringRef) + 1712
25 swift 0x0000000105cfec8f swift::runSILDiagnosticPasses(swift::SILModule&) + 175
26 swift 0x00000001052a4534 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 13844
27 swift 0x000000010529f6b4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7716
28 swift 0x00000001052545d8 main + 12248
29 libdyld.dylib 0x00007fff723e1145 start + 1
30 libdyld.dylib 0x000000000000003c start + 2378297080
Stack dump:
0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -emit-module /Users/stephan.rehfeld/Library/Developer/Xcode/DerivedData/ThroughputTest-fncirewswnhfibgvxibvxrrourcj/Build/Intermediates.noindex/ThroughputTest.build/Debug-iphonesimulator/ThroughputTest.build/Objects-normal/x86_64/CompilerCrash~partial.swiftmodule /Users/stephan.rehfeld/Library/Developer/Xcode/DerivedData/ThroughputTest-fncirewswnhfibgvxibvxrrourcj/Build/Intermediates.noindex/ThroughputTest.build/Debug-iphonesimulator/ThroughputTest.build/Objects-normal/x86_64/CompilerCrash3~partial.swiftmodule /Users/stephan.rehfeld/Library/Developer/Xcode/DerivedData/ThroughputTest-fncirewswnhfibgvxibvxrrourcj/Build/Intermediates.noindex/ThroughputTest.build/Debug-iphonesimulator/ThroughputTest.build/Objects-normal/x86_64/CompilerCrash2~partial.swiftmodule /Users/stephan.rehfeld/Library/Developer/Xcode/DerivedData/ThroughputTest-fncirewswnhfibgvxibvxrrourcj/Build/Intermediates.noindex/ThroughputTest.build/Debug-iphonesimulator/ThroughputTest.build/Objects-normal/x86_64/ViewController~partial.swiftmodule /Users/stephan.rehfeld/Library/Developer/Xcode/DerivedData/ThroughputTest-fncirewswnhfibgvxibvxrrourcj/Build/Intermediates.noindex/ThroughputTest.build/Debug-iphonesimulator/ThroughputTest.build/Objects-normal/x86_64/AppDelegate~partial.swiftmodule -parse-as-library -target x86_64-apple-ios10.3 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.0.sdk -I /Users/stephan.rehfeld/Library/Developer/Xcode/DerivedData/ThroughputTest-fncirewswnhfibgvxibvxrrourcj/Build/Products/Debug-iphonesimulator -F /Users/stephan.rehfeld/Library/Developer/Xcode/DerivedData/ThroughputTest-fncirewswnhfibgvxibvxrrourcj/Build/Products/Debug-iphonesimulator -enable-testing -g -module-cache-path /Users/stephan.rehfeld/Library/Developer/Xcode/DerivedData/ModuleCache -swift-version 3 -enforce-exclusivity=checked -D DEBUG -serialize-debugging-options -Xcc -I/Users/stephan.rehfeld/Library/Developer/Xcode/DerivedData/ThroughputTest-fncirewswnhfibgvxibvxrrourcj/Build/Intermediates.noindex/ThroughputTest.build/Debug-iphonesimulator/ThroughputTest.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/stephan.rehfeld/Library/Developer/Xcode/DerivedData/ThroughputTest-fncirewswnhfibgvxibvxrrourcj/Build/Intermediates.noindex/ThroughputTest.build/Debug-iphonesimulator/ThroughputTest.build/ThroughputTest-generated-files.hmap -Xcc -I/Users/stephan.rehfeld/Library/Developer/Xcode/DerivedData/ThroughputTest-fncirewswnhfibgvxibvxrrourcj/Build/Intermediates.noindex/ThroughputTest.build/Debug-iphonesimulator/ThroughputTest.build/ThroughputTest-own-target-headers.hmap -Xcc -I/Users/stephan.rehfeld/Library/Developer/Xcode/DerivedData/ThroughputTest-fncirewswnhfibgvxibvxrrourcj/Build/Intermediates.noindex/ThroughputTest.build/Debug-iphonesimulator/ThroughputTest.build/ThroughputTest-all-target-headers.hmap -Xcc -iquote -Xcc /Users/stephan.rehfeld/Library/Developer/Xcode/DerivedData/ThroughputTest-fncirewswnhfibgvxibvxrrourcj/Build/Intermediates.noindex/ThroughputTest.build/Debug-iphonesimulator/ThroughputTest.build/ThroughputTest-project-headers.hmap -Xcc -I/Users/stephan.rehfeld/Library/Developer/Xcode/DerivedData/ThroughputTest-fncirewswnhfibgvxibvxrrourcj/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/stephan.rehfeld/Library/Developer/Xcode/DerivedData/ThroughputTest-fncirewswnhfibgvxibvxrrourcj/Build/Intermediates.noindex/ThroughputTest.build/Debug-iphonesimulator/ThroughputTest.build/DerivedSources/x86_64 -Xcc -I/Users/stephan.rehfeld/Library/Developer/Xcode/DerivedData/ThroughputTest-fncirewswnhfibgvxibvxrrourcj/Build/Intermediates.noindex/ThroughputTest.build/Debug-iphonesimulator/ThroughputTest.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/stephan.rehfeld/Documents/repos/ThroughputTest -emit-module-doc-path /Users/stephan.rehfeld/Library/Developer/Xcode/DerivedData/ThroughputTest-fncirewswnhfibgvxibvxrrourcj/Build/Intermediates.noindex/ThroughputTest.build/Debug-iphonesimulator/ThroughputTest.build/Objects-normal/x86_64/ThroughputTest.swiftdoc -module-name ThroughputTest -emit-objc-header-path /Users/stephan.rehfeld/Library/Developer/Xcode/DerivedData/ThroughputTest-fncirewswnhfibgvxibvxrrourcj/Build/Intermediates.noindex/ThroughputTest.build/Debug-iphonesimulator/ThroughputTest.build/Objects-normal/x86_64/ThroughputTest-Swift.h -o /Users/stephan.rehfeld/Library/Developer/Xcode/DerivedData/ThroughputTest-fncirewswnhfibgvxibvxrrourcj/Build/Intermediates.noindex/ThroughputTest.build/Debug-iphonesimulator/ThroughputTest.build/Objects-normal/x86_64/ThroughputTest.swiftmodule
1. While reading from 'ThroughputTest'
2. While deserializing 'AreaUnit' (ProtocolDecl #&#8203;1) in 'ThroughputTest'
3. While deserializing 'LengthType' (AssociatedTypeDecl #&#8203;2) in 'ThroughputTest'
4. While deserializing decl #&#8203;5 (XREF) in 'ThroughputTest'
5. Cross-reference to module 'ThroughputTest'
... LengthUnit
6. While reading from 'ThroughputTest'
7. While deserializing 'LengthUnit' (ProtocolDecl #&#8203;1) in 'ThroughputTest'
8. While deserializing 'AreaType' (AssociatedTypeDecl #&#8203;2) in 'ThroughputTest'

@belkadan
Copy link
Contributor

Yep, recursive protocol references aren't supported in general in Swift 4.0, but they're especially broken across file boundaries. We've made some progress on the master branch, though; would you mind trying with a recent "development snapshot" from https://swift.org/download/ ?

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

No branches or pull requests

3 participants