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-9225] Compiler Crash with protocol conformance, associated types and multiple files #51714

Closed
nsalmoria opened this issue Nov 12, 2018 · 4 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself conformances Feature → protocol: protocol conformances crash Bug: A crash, i.e., an abnormal termination of software multiple files Flag: An issue whose reproduction requires multiple files

Comments

@nsalmoria
Copy link
Contributor

Previous ID SR-9225
Radar rdar://problem/46031080
Original Reporter @nsalmoria
Type Bug
Status Resolved
Resolution Done
Environment

macOS 10.14.1, Xcode 10.1 both with default toolchain and with development snapshot 2018-11-01.

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, MultiFile, ProtocolConformance
Assignee @slavapestov
Priority Medium

md5: f49501a729183a52337fbf6a11e4f898

Issue Description:

This crash happens only when the source is split over two files.

I cannot reduce it more than this.

In main.swift:

protocol P1 {
    associatedtype P1_T1
    associatedtype P1_T2: Collection where P1_T2.Element == P1_T1
}

protocol P2 {
    associatedtype P2_T
}

protocol P3: P1, P2 {
    associatedtype P3_T: P1 where P3_T.P1_T2 == Range<P2_T>
}

in a separate file:

struct S1: P1 {
    typealias P1_T1 = Int
    typealias P1_T2 = Range<Int>
}

struct S2<P1_T1>: P1, P3 {
    typealias P1_T2 = [P1_T1]
    typealias P2_T = Int
    typealias P3_T = S1
}

The crash only happens when compiling the Debug build. Release compiles fine.

With the default toolchain, this is the crash dump:

0  swift                    0x00000001059e659a PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x00000001059e5d4e SignalHandler(int) + 302
2  libsystem_platform.dylib 0x00007fff5ab79b3d _sigtramp + 29
3  libsystem_platform.dylib 0x00007fbab2e07460 _sigtramp + 1479072064
4  swift                    0x0000000101df0b6e swift::irgen::IRGenModule::emitSILWitnessTable(swift::SILWitnessTable*) + 1310
5  swift                    0x0000000101d38e2b swift::irgen::IRGenerator::emitGlobalTopLevel(bool) + 2491
6  swift                    0x0000000101e37386 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**, unsigned int) + 1382
7  swift                    0x0000000101c77980 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 46928
8  swift                    0x0000000101c68d35 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7717
9  swift                    0x0000000101c0e965 main + 1349
10 libdyld.dylib            0x00007fff5a99008d start + 1

error: Segmentation fault: 11

and with development snapshot 2018-11-01:

Assertion failed: (hasConformanceInSignature(reqs, rootType, conformingProto) && "missing explicit conformance in signature"), function buildConformanceAccessPath, file /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/lib/AST/GenericSignature.cpp, line 964.

...

1.  While emitting witness table for type 'S2<P1_T1>' (declared at [/Users/nicolasalmoria/Documents/bugReportCompilerCrash/CompilerCrash/file.swift:6:1 - line:10:1] RangeText="struct S2<P1_T1>: P1, P3 {
    typealias P1_T2 = [P1_T1]
    typealias P2_T = Int
    typealias P3_T = S1
")
2.  While ...conforming to 'P3' at /Users/nicolasalmoria/Documents/bugReportCompilerCrash/CompilerCrash/main.swift:10:1
0  swift                    0x0000000112dbbef8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x0000000112dbb175 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x0000000112dbc502 SignalHandler(int) + 258
3  libsystem_platform.dylib 0x00007fff5ab79b3d _sigtramp + 29
4  swift                    0x00000001105c1f19 substType(swift::Type, llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolDecl*)>, swift::SubstOptions) + 281
5  libsystem_c.dylib        0x00007fff5aa381c9 abort + 127
6  libsystem_c.dylib        0x00007fff5aa00868 basename_r + 0
7  swift                    0x000000011053899a swift::GenericSignature::buildConformanceAccessPath(llvm::SmallVectorImpl<std::__1::pair<swift::Type, swift::ProtocolDecl*> >&, llvm::ArrayRef<swift::Requirement>, void const*, swift::ProtocolDecl*, swift::Type, swift::ProtocolDecl*) + 1978
8  swift                    0x0000000110539075 swift::GenericSignature::getConformanceAccessPath(swift::Type, swift::ProtocolDecl*) + 725
9  swift                    0x00000001105b355e swift::SubstitutionMap::lookupConformance(swift::CanType, swift::ProtocolDecl*) const + 494
10 swift                    0x00000001105c1bfd getMemberForBaseType(llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolDecl*)>, swift::Type, swift::Type, swift::AssociatedTypeDecl*, swift::Identifier, swift::SubstOptions) + 1069
11 swift                    0x00000001105c763f llvm::Optional<swift::Type> llvm::function_ref<llvm::Optional<swift::Type> (swift::TypeBase*)>::callback_fn<substType(swift::Type, llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolDecl*)>, swift::SubstOptions)::$_15>(long, swift::TypeBase*) + 943
12 swift                    0x00000001105c3ba8 swift::Type::transformRec(llvm::function_ref<llvm::Optional<swift::Type> (swift::TypeBase*)>) const + 216
13 swift                    0x00000001105c1f19 substType(swift::Type, llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolDecl*)>, swift::SubstOptions) + 281
14 swift                    0x00000001105bc066 swift::Type::subst(swift::SubstitutionMap, swift::SubstOptions) const + 118
15 swift                    0x00000001105a9391 swift::ProtocolConformanceRef::getAssociatedType(swift::Type, swift::Type, swift::LazyResolver*) const + 481
16 swift                    0x00000001105aa557 swift::ProtocolConformance::getAssociatedType(swift::Type, swift::LazyResolver*) const + 279
17 swift                    0x000000010f35caa0 swift::SILWitnessVisitor<(anonymous namespace)::WitnessTableBuilder>::visitProtocolDecl(swift::ProtocolDecl*) + 656
18 swift                    0x000000010f355076 swift::irgen::IRGenModule::emitSILWitnessTable(swift::SILWitnessTable*) + 1190
19 swift                    0x000000010f2cc7cd swift::irgen::IRGenerator::emitGlobalTopLevel(bool) + 1053
20 swift                    0x000000010f397a0b performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**) + 1067
21 swift                    0x000000010f397f46 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, llvm::GlobalVariable**) + 86
22 swift                    0x000000010f2274a1 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 13697
23 swift                    0x000000010f222e8d swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3021
24 swift                    0x000000010f1d4e5e main + 686
25 libdyld.dylib            0x00007fff5a99008d start + 1
error: Abort trap: 6
@slavapestov
Copy link
Member

The problem is the missing constraint that P2_T is Strideable. This should not crash, however, so there's something for us to fix.

@nsalmoria
Copy link
Contributor Author

But is it technically true that the Strideable conformance should be explicitly requested? In other contexts, such conformances are implicitly inferred. Also, note that if you put everything into a single file the code compiles fine.

@slavapestov
Copy link
Member

You're right that the behavior is inconsistent. However in the multi-file case it's not inferring the constraint at all.

@slavapestov
Copy link
Member

This was fixed at some point so I'm just adding a regression test - #29714

@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 conformances Feature → protocol: protocol conformances crash Bug: A crash, i.e., an abnormal termination of software multiple files Flag: An issue whose reproduction requires multiple files
Projects
None yet
Development

No branches or pull requests

3 participants