swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.41k stars 10.34k forks source link

[SR-691] Swift crashes in MergeSwiftModules checking generics #43306

Closed swift-ci closed 3 years ago

swift-ci commented 8 years ago
Previous ID SR-691
Radar None
Original Reporter cortices (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment Xcode 7.3 beta (7D129n) Swift 2.2 Snapshot 2016-02-03 – 2.2-dev (LLVM ae2eb212e4, Clang ef4c02f431, Swift 634acb40a1)
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, CompilerCrash | |Assignee | cbuteau123 (JIRA) | |Priority | | md5: 2ce56a9ef02fd09ba730d8fed8c48679

Issue Description:

The source files compile fine on their own, but MergeSwiftModules segfaults with the following trace:

MergeSwiftModule normal x86_64  <Input files excluded for brevity>
0  swift                    0x000000011261427b llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
1  swift                    0x0000000112613536 llvm::sys::RunSignalHandlers() + 70
2  swift                    0x0000000112614922 SignalHandler(int) + 322
3  libsystem_platform.dylib 0x00007fff88b4452a _sigtramp + 26
4  libsystem_platform.dylib 0x00007fe28c004600 _sigtramp + 55312624
5  swift                    0x000000011078f4de swift::GenericParamList::addNestedArchetypes(swift::ArchetypeType*, llvm::SmallPtrSetImpl<swift::ArchetypeType*>&, llvm::SmallVectorImpl<swift::ArchetypeType*>&) + 30
6  swift                    0x000000011078f7a3 swift::GenericParamList::deriveAllArchetypes(llvm::ArrayRef<swift::GenericTypeParamDecl*>, llvm::SmallVectorImpl<swift::ArchetypeType*>&) + 355
7  swift                    0x00000001103e0b44 swift::ModuleFile::maybeReadGenericParams(swift::DeclContext*, llvm::BitstreamCursor&, swift::GenericParamList*) + 1748
8  swift                    0x00000001103d67a6 swift::ModuleFile::getDecl(llvm::Fixnum<31u, unsigned int>, llvm::Optional<swift::DeclContext*>) + 12054
9  swift                    0x0000000110404e69 swift::ModuleFile::lookupValue(swift::DeclName, llvm::SmallVectorImpl<swift::ValueDecl*>&) + 1017
10 swift                    0x00000001107c3549 swift::ModuleDecl::lookupValue(llvm::ArrayRef<std::__1::pair<swift::Identifier, swift::SourceLoc> >, swift::DeclName, swift::NLKind, llvm::SmallVectorImpl<swift::ValueDecl*>&) const + 89
11 swift                    0x00000001107d014c 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) + 380
12 swift                    0x00000001107cff35 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*> >) + 1317
13 swift                    0x00000001107d7252 swift::DeclContext::lookupQualified(swift::Type, swift::DeclName, unsigned int, swift::LazyResolver*, llvm::SmallVectorImpl<swift::ValueDecl*>&) const + 2338
14 swift                    0x00000001103e1a65 swift::ModuleFile::resolveCrossReference(swift::ModuleDecl*, unsigned int) + 1109
15 swift                    0x00000001103d62c8 swift::ModuleFile::getDecl(llvm::Fixnum<31u, unsigned int>, llvm::Optional<swift::DeclContext*>) + 10808
16 swift                    0x00000001103dcb75 swift::ModuleFile::getType(llvm::Fixnum<31u, unsigned int>) + 3029
17 swift                    0x00000001103dc463 swift::ModuleFile::getType(llvm::Fixnum<31u, unsigned int>) + 1219
18 swift                    0x00000001103dc776 swift::ModuleFile::getType(llvm::Fixnum<31u, unsigned int>) + 2006
19 swift                    0x00000001103dcd23 swift::ModuleFile::getType(llvm::Fixnum<31u, unsigned int>) + 3459
20 swift                    0x00000001103da992 swift::ModuleFile::getDecl(llvm::Fixnum<31u, unsigned int>, llvm::Optional<swift::DeclContext*>) + 28930
21 swift                    0x00000001103e155c swift::ModuleFile::readMembers(llvm::SmallVectorImpl<swift::Decl*>&) + 268
22 swift                    0x00000001103e4865 swift::ModuleFile::loadAllMembers(swift::Decl*, unsigned long long) + 245
23 swift                    0x00000001107a1d2b swift::IterableDeclContext::loadAllMembers() const + 91
24 swift                    0x000000011079001c swift::NominalTypeDecl::getMembers(bool) const + 28
25 swift                    0x00000001107d8dea swift::NominalTypeDecl::lookupDirect(swift::DeclName, bool) + 90
26 swift                    0x00000001103e2634 swift::ModuleFile::resolveCrossReference(swift::ModuleDecl*, unsigned int) + 4132
27 swift                    0x00000001103d62c8 swift::ModuleFile::getDecl(llvm::Fixnum<31u, unsigned int>, llvm::Optional<swift::DeclContext*>) + 10808
28 swift                    0x00000001103dc99c swift::ModuleFile::getType(llvm::Fixnum<31u, unsigned int>) + 2556
29 swift                    0x00000001103de73f swift::ModuleFile::getType(llvm::Fixnum<31u, unsigned int>) + 10143
30 swift                    0x00000001103d85d3 swift::ModuleFile::getDecl(llvm::Fixnum<31u, unsigned int>, llvm::Optional<swift::DeclContext*>) + 19779
31 swift                    0x00000001103e0a5d swift::ModuleFile::maybeReadGenericParams(swift::DeclContext*, llvm::BitstreamCursor&, swift::GenericParamList*) + 1517
32 swift                    0x00000001103d67a6 swift::ModuleFile::getDecl(llvm::Fixnum<31u, unsigned int>, llvm::Optional<swift::DeclContext*>) + 12054
33 swift                    0x0000000110407a0a swift::ModuleFile::getTopLevelDecls(llvm::SmallVectorImpl<swift::Decl*>&) + 666
34 swift                    0x00000001107c45cc swift::ModuleDecl::getTopLevelDecls(llvm::SmallVectorImpl<swift::Decl*>&) const + 44
35 swift                    0x00000001101e89bf swift::ClassHierarchyAnalysis::init() + 79
36 swift                    0x00000001101ddbb9 swift::createClassHierarchyAnalysis(swift::SILModule*) + 153
37 swift                    0x000000011027ea60 swift::SILPassManager::SILPassManager(swift::SILModule*, llvm::StringRef) + 320
38 swift                    0x000000011028a56a swift::runSILDiagnosticPasses(swift::SILModule&) + 122
39 swift                    0x000000010fecd517 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 6087
40 swift                    0x000000010fec7df9 main + 2905
41 libdyld.dylib            0x00007fff8d8295ad start + 1
42 libdyld.dylib            0x0000000000000069 start + 1920821949
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-2.2-SNAPSHOT-2016-02-03-a.xctoolchain/usr/bin/swift -frontend -emit-module <Arguments excluded for brevity>
1.  While reading from /Users/sparky/Library/Developer/Xcode/DerivedData/Lustre-axemxpphadxsaodpiitxnbrgcemb/Build/Intermediates/Lustre.build/Debug-iphonesimulator/Lustre.build/Objects-normal-asan/x86_64/ParameterState~partial.swiftmodule
2.  While deserializing decl #&#8203;22 (STRUCT_DECL)
3.  While deserializing 'ParameterType' (GenericTypeParamDecl #&#8203;1) 
4.  While deserializing decl #&#8203;28 (XREF)
5.  Cross-reference to module 'Lustre'
    ... ParameterProtocol
    ... VType
6.  While loading members for 'ParameterProtocol' at <invalid loc>
7.  While deserializing 'restoreFromState' (FuncDecl #&#8203;76) 
8.  While deserializing decl #&#8203;119 (XREF)
9.  Cross-reference to module 'Lustre'
    ... ParameterState
10. While reading from /Users/sparky/Library/Developer/Xcode/DerivedData/Lustre-axemxpphadxsaodpiitxnbrgcemb/Build/Intermediates/Lustre.build/Debug-iphonesimulator/Lustre.build/Objects-normal-asan/x86_64/ParameterState~partial.swiftmodule
11. While deserializing decl #&#8203;22 (STRUCT_DECL)

Note: Seems to be same issue as rdar://22205712 (https://openradar.appspot.com/22205712).

CodaFi commented 7 years ago

The original crash is resolved on master. Does this still happen for you? Would you mind sharing the original code that caused the crash for you?

tkrajacic commented 6 years ago

In a playground (Swift 4.1), this has a fixit for the where clause

protocol P {
    associatedtype T
}

enum E<F : P where F.T == E<F>> {
    indirect case Roll(F.T)
}

Which then produces

protocol P {
    associatedtype T
}

enum E<F : P> where F.T == E<F> {
    indirect case Roll(F.T)
}

which produces the error:

Playground execution failed:

error: bugs.playground:1:28: error: generic enum 'E' references itself
enum E<F : P> where F.T == E<F> {
                           ^

bugs.playground:1:6: note: type declared here
enum E<F : P> where F.T == E<F> {

So I guess this can be closed? This will not compile like in the original bugreport

CodaFi commented 3 years ago

This was resolved with better diagnostics in Swift 3.1