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-3500] Compiler crash in extension with same-type constraint #46088

Closed
karwa opened this issue Dec 28, 2016 · 4 comments
Closed

[SR-3500] Compiler crash in extension with same-type constraint #46088

karwa opened this issue Dec 28, 2016 · 4 comments
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 SILGen Area → compiler: The SIL generation stage

Comments

@karwa
Copy link
Contributor

karwa commented Dec 28, 2016

Previous ID SR-3500
Radar rdar://problem/29960484
Original Reporter @karwa
Type Bug
Status Resolved
Resolution Done
Environment

Swift 474096b

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 3.1Regression, CompilerCrash, SILGen
Assignee @slavapestov
Priority Medium

md5: 4455e3eab37075beeeb65dd78cb6fe48

relates to:

  • SR-3326 Crash on master "SIL verification failed: substituted callee type does not match substitutions"

Issue Description:

The following code crashes the compiler on master (regression from 3.0.2). The issue seems to be with the lookup for the return type of A.doSomething (Coordinate.Stride); using a concrete return-type (such as Int) or replacing the constraint with a conformance constraint ("where Coordinate: SignedInteger", for instance) does not crash.

That's as far as I got with my investigation. I think it's related to the TODO in GenericSignature::getSubstitutionMap, but I'm not really familiar with substitution maps so somebody else is probably better-placed to resolve it.

protocol A {
  associatedtype Coordinate: Strideable
  func doSomething(_: Range<Coordinate>) -> Coordinate.Stride
}

extension A where Coordinate == Int {
  func extensionFunc(_ range: Range<Coordinate>) {
    _ = doSomething(range)
  }
}

Crash details:

0  swift                    0x00000001122eb0e6 SignalHandler(int) + 454
1  libsystem_platform.dylib 0x00007fffc5e18bba _sigtramp + 26
2  swift                    0x000000010fc27ca8 swift::TypeBase::getCanonicalType() + 24
3  swift                    0x000000010f76e105 (anonymous namespace)::SILTypeSubstituter::visitType(swift::CanType) + 277
4  swift                    0x000000010f76db3e swift::CanType swift::CanTypeVisitor<(anonymous namespace)::SILTypeSubstituter, swift::CanType>::visit<>(swift::CanType) + 94
5  swift                    0x000000010f768095 (anonymous namespace)::SILTypeSubstituter::visitSILFunctionType(swift::CanTypeWrapper<swift::SILFunctionType>, bool) + 277
6  swift                    0x000000010f76852f swift::SILFunctionType::substGenericArgs(swift::SILModule&, llvm::ArrayRef<swift::Substitution>) + 191
7  swift                    0x000000010f390a1f (anonymous namespace)::Callee::getAtUncurryLevel(swift::Lowering::SILGenFunction&, unsigned int) const + 3247
8  swift                    0x000000010f38cb76 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 1078
9  swift                    0x000000010f38c223 swift::Lowering::SILGenFunction::emitApplyExpr(swift::Expr*, swift::Lowering::SGFContext) + 51
10 swift                    0x000000010f3d5905 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 85
11 swift                    0x000000010f3d42f6 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 470
12 swift                    0x000000010f3d8685 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 11733
13 swift                    0x000000010f3d42f6 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 470
14 swift                    0x000000010f4276dd swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 653
15 swift                    0x000000010f427445 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
16 swift                    0x000000010f3e8ffe swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 462
17 swift                    0x000000010f386c28 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1::operator()(swift::SILFunction*) const + 216
18 swift                    0x000000010f37d3c0 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 640
19 swift                    0x000000010f42dba0 swift::ASTVisitor<SILGenExtension, void, void, void, void, void, void>::visit(swift::Decl*) + 208
20 swift                    0x000000010f42cf2b SILGenExtension::emitExtension(swift::ExtensionDecl*) + 59
21 swift                    0x000000010f42cee5 swift::Lowering::SILGenModule::visitExtensionDecl(swift::ExtensionDecl*) + 21
22 swift                    0x000000010f3836cb swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 747
23 swift                    0x000000010f384755 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 1029
24 swift                    0x000000010f384ba6 swift::performSILGeneration(swift::ModuleDecl*, swift::SILOptions&, bool, bool) + 38
25 swift                    0x000000010f1bffdc swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 12188
26 swift                    0x000000010f178771 main + 3025
@belkadan
Copy link
Contributor

@swift-ci create

@swift-ci
Copy link
Collaborator

swift-ci commented Mar 4, 2017

Comment by Steven Sheldon (JIRA)

Is this still on the roadmap to be fixed before 3.1 is released? It's the last regression we're experiencing.

I believe the line of code that's triggering the segfault for us used to produce a stack trace like the one in this ticket, but now it produces a different stack trace:

Assertion failed: (!substReplacement->hasError() && "substitution replacement failed"), function subst, file /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/lib/AST/Substitution.cpp, line 59.
0  swift                    0x000000010b2be0b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x000000010b2bd2d6 llvm::sys::RunSignalHandlers() + 86
2  swift                    0x000000010b2be709 SignalHandler(int) + 361
3  libsystem_platform.dylib 0x00007fffbc28fbba _sigtramp + 26
4  libsystem_platform.dylib 0x00000000b0097338 _sigtramp + 4091574168
5  libsystem_c.dylib        0x00007fffbc116420 abort + 129
6  libsystem_c.dylib        0x00007fffbc0dd893 basename_r + 0
7  swift                    0x0000000109135b15 swift::Substitution::subst(swift::ModuleDecl*, llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolType*)>) const + 1813
8  swift                    0x000000010914799c 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::ProtocolType*)>, swift::OptionSet<swift::SubstFlags, unsigned int>)::$_14>(long, swift::TypeBase*) + 972
9  swift                    0x00000001091448d6 swift::Type::transformRec(llvm::function_ref<llvm::Optional<swift::Type> (swift::TypeBase*)>) const + 166
10 swift                    0x0000000109143219 swift::Type::subst(llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolType*)>, swift::OptionSet<swift::SubstFlags, unsigned int>) const + 105
11 swift                    0x0000000108c60c19 (anonymous namespace)::SILTypeSubstituter::visitType(swift::CanType) + 265
12 swift                    0x0000000108c6066e swift::CanType swift::CanTypeVisitor<(anonymous namespace)::SILTypeSubstituter, swift::CanType>::visit<>(swift::CanType) + 94
13 swift                    0x0000000108c5af11 (anonymous namespace)::SILTypeSubstituter::visitSILFunctionType(swift::CanTypeWrapper<swift::SILFunctionType>, bool) + 641
14 swift                    0x0000000108c6074d swift::CanType swift::CanTypeVisitor<(anonymous namespace)::SILTypeSubstituter, swift::CanType>::visit<>(swift::CanType) + 317
15 swift                    0x0000000108c5ab45 swift::SILType::subst(swift::SILModule&, llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolType*)>) const + 69
16 swift                    0x00000001089ca1f0 swift::TypeSubstCloner<swift::SILInliner>::visitPartialApplyInst(swift::PartialApplyInst*) + 2000
17 swift                    0x00000001089bec13 swift::SILCloner<swift::SILInliner>::visitSILBasicBlock(swift::SILBasicBlock*) + 67
18 swift                    0x00000001089bf04d swift::SILCloner<swift::SILInliner>::visitSILBasicBlock(swift::SILBasicBlock*) + 1149
19 swift                    0x00000001089bf04d swift::SILCloner<swift::SILInliner>::visitSILBasicBlock(swift::SILBasicBlock*) + 1149
20 swift                    0x00000001089bf04d swift::SILCloner<swift::SILInliner>::visitSILBasicBlock(swift::SILBasicBlock*) + 1149
21 swift                    0x00000001089bf04d swift::SILCloner<swift::SILInliner>::visitSILBasicBlock(swift::SILBasicBlock*) + 1149
22 swift                    0x00000001089be625 swift::SILInliner::inlineFunction(swift::FullApplySite, llvm::ArrayRef<swift::SILValue>) + 1141
23 swift                    0x0000000108a4b2b1 runOnFunctionRecursively(swift::SILFunction*, swift::FullApplySite, swift::SILOptions::LinkingMode, llvm::DenseSet<swift::SILFunction*, llvm::DenseMapInfo<swift::SILFunction*> >&, llvm::ImmutableSet<swift::SILFunction*, llvm::ImutContainerInfo<swift::SILFunction*> >::Factory&, llvm::ImmutableSet<swift::SILFunction*, llvm::ImutContainerInfo<swift::SILFunction*> >, swift::ClassHierarchyAnalysis*) + 3153
24 swift                    0x0000000108a4a488 (anonymous namespace)::MandatoryInlining::run() + 392
25 swift                    0x00000001089e063b swift::SILPassManager::runModulePass(swift::SILModuleTransform*) + 1259
26 swift                    0x00000001089e1083 swift::SILPassManager::runOneIteration() + 1027
27 swift                    0x000000010831468b swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 187
28 swift                    0x00000001089e9725 swift::runSILDiagnosticPasses(swift::SILModule&) + 165
29 swift                    0x00000001081cf29c swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 12332
30 swift                    0x000000010818bd70 main + 3312
31 libdyld.dylib            0x00007fffbc082255 start + 1

@slavapestov
Copy link
Member

I submitted a targeted fix to the 3.1 branch: fda2ddb

Can you give the next development snapshot a try when it's released?

@swift-ci
Copy link
Collaborator

swift-ci commented Mar 6, 2017

Comment by Steven Sheldon (JIRA)

@slavapestov you were a step ahead of me 🙂 I just tried the 2017-03-05 snapshot and can confirm that our segfault was fixed. Thanks!

@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 SILGen Area → compiler: The SIL generation stage
Projects
None yet
Development

No branches or pull requests

5 participants