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-3186] Crash when capture list references parameter of outer single-expression closure #45774

Closed
weissi opened this issue Nov 11, 2016 · 8 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 type checker Area → compiler: Semantic analysis

Comments

@weissi
Copy link
Member

weissi commented Nov 11, 2016

Previous ID SR-3186
Radar rdar://problem/65155671
Original Reporter @weissi
Type Bug
Status Resolved
Resolution Done

Attachment: Download

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

md5: 4641f79d35f3a301584735972998360c

is duplicated by:

  • SR-5870 Crash when capture list references parameter of outer single-expression closure
  • SR-7717 Compiler SegFaults when weak reference is captured in a closure from another closure with a strong reference

Issue Description:

Description

Compiling the following program

/* from http://stackoverflow.com/a/30523286/55925 */
func recursive<T, U>(_ f: (@escaping (@escaping (T) -> U) -> ((T) -> U))) -> ((T) -> U) {
    return { x in return f(recursive(f))(x) }
}

class Foo {
    init() {
        let v = recursive { f in { [unowned self, f] x in x != 1000 ? f(x + 1) : "success" } }(0)
        print("\(v)")
    }
}

results in the following crashes

macOS

0  swift                    0x000000010c6e9a3d PrintStackTraceSignalHandler(void*) + 45
1  swift                    0x000000010c6e9466 SignalHandler(int) + 470
2  libsystem_platform.dylib 0x00007fff991bbbba _sigtramp + 26
3  libsystem_platform.dylib 0x00007fff561db0e0 _sigtramp + 3171022144
4  swift                    0x000000010a46c12e swift::NominalTypeDecl::hasFixedLayout() const + 14
5  swift                    0x000000010a062f40 (anonymous namespace)::LowerType::visitAnyStructType(swift::CanType, swift::StructDecl*) + 48
6  swift                    0x000000010a061f90 swift::Lowering::TypeConverter::getTypeLoweringForUncachedLoweredType(swift::Lowering::TypeConverter::TypeKey) + 80
7  swift                    0x000000010a0615f4 swift::Lowering::TypeConverter::getTypeLowering(swift::Lowering::AbstractionPattern, swift::Type, unsigned int) + 3412
8  swift                    0x0000000109c85d76 swift::Lowering::SILGenFunction::emitInitializationForVarDecl(swift::VarDecl*) + 838
9  swift                    0x0000000109c88595 swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 85
10 swift                    0x0000000109c3f90d swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Decl*) + 125
11 swift                    0x0000000109cf8ce9 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 4169
12 swift                    0x0000000109c7c3ac swift::Lowering::SILGenFunction::emitClassConstructorInitializer(swift::ConstructorDecl*) + 3932
13 swift                    0x0000000109c38aff swift::Lowering::SILGenModule::emitConstructor(swift::ConstructorDecl*) + 5807
14 swift                    0x0000000109cffbf4 (anonymous namespace)::SILGenType::emitType() + 1028
15 swift                    0x0000000109cff77e swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 30
16 swift                    0x0000000109c411e3 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 1795
17 swift                    0x0000000109c42e9d swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 1629
18 swift                    0x0000000109a96bb9 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 19513
19 swift                    0x0000000109a8ff70 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 17856
20 swift                    0x0000000109a4c93e main + 8302
21 libdyld.dylib            0x00007fff98fae255 start + 1
22 libdyld.dylib            0x000000000000000d start + 1728388537
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file test.swift -target x86_64-apple-macosx10.9 -enable-objc-interop -color-diagnostics -module-name test -o /var/folders/k8/7d0p_dxx2ll8vnw5mt5__ddc0000gn/T/test-1614d0.o 
1.  While silgen constructor initializer SIL function @_TFC4test3FoocfT_S0_ for 'init' at test.swift:7:5
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: compile command failed due to signal (use -v to see invocation)

for

$ swiftc -version
Apple Swift version 3.0.1 (swiftlang-800.0.58.6 clang-800.0.42.1)
Target: x86_64-apple-macosx10.9

Linux

$ swiftc test.swift 
swift: /home/swift/swift-3.0-branch/swift-source/swift/include/swift/AST/ExprNodes.def:69: virtual std::pair<bool, Expr *> (anonymous namespace)::Verifier::walkToExprPre(swift::Expr *): Assertion `(HadError || !M.is<SourceFile*>() || M.get<SourceFile*>()->ASTStage < SourceFile::TypeChecked) && "OverloadedDeclRef" "in wrong phase"' failed.
0  swift           0x00000000035c3ec8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift           0x00000000035c4627
2  libpthread.so.0 0x00007f7445b303e0
3  libc.so.6       0x00007f744425e428 gsignal + 56
4  libc.so.6       0x00007f744426002a abort + 362
5  libc.so.6       0x00007f7444256bd7
6  libc.so.6       0x00007f7444256c82
7  swift           0x00000000010dd483
8  swift           0x00000000010fbabb
9  swift           0x00000000010f999d
10 swift           0x00000000010fa0ad
11 swift           0x00000000010fb646
12 swift           0x00000000010fa7e9
13 swift           0x00000000010fb646
14 swift           0x00000000010f995f
15 swift           0x00000000010fbb21
16 swift           0x00000000010f999d
17 swift           0x00000000010fbacf
18 swift           0x00000000010f999d
19 swift           0x00000000010f9618
20 swift           0x00000000010fbe08
21 swift           0x00000000010fdf54
22 swift           0x00000000010f92d6
23 swift           0x00000000010fda64
24 swift           0x00000000010f92c2
25 swift           0x00000000010f91e4 swift::Decl::walk(swift::ASTWalker&) + 20
26 swift           0x000000000119d5fe swift::SourceFile::walk(swift::ASTWalker&) + 174
27 swift           0x00000000010dcf24 swift::verify(swift::SourceFile&) + 52
28 swift           0x0000000000f54ff9 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int) + 1481
29 swift           0x0000000000cc7466 swift::CompilerInstance::performSema() + 3542
30 swift           0x00000000007e6c36
31 swift           0x00000000007e5b41 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2737
32 swift           0x00000000007ab253 main + 2787
33 libc.so.6       0x00007f7444249830 __libc_start_main + 240
34 swift           0x00000000007a88f9 _start + 41
Stack dump:
0.  Program arguments: /usr/local/swift/swift-dev/usr/bin/swift -frontend -c -primary-file test.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -color-diagnostics -module-name test -o /tmp/test-2393d8.o 
1.  While walking into decl 'Foo' at test.swift:6:1
2.  While walking into body of 'init' at test.swift:7:5
3.  While walking into initializer for declaration 0x6975bf8 at test.swift:8:9
<unknown>:0: error: unable to execute command: Aborted
<unknown>:0: error: compile command failed due to signal (use -v to see invocation)

for

$ swiftc -version
Swift version 3.0.2-dev (LLVM 6a11c7d78f, Clang 18b736028f, Swift 32d170d48c)
Target: x86_64-unknown-linux-gnu
@belkadan
Copy link
Contributor

   Assertion failed: ((HadError || !M.is<SourceFile*>() || M.get<SourceFile*>()->ASTStage < SourceFile::TypeChecked) && "OverloadedDeclRef" "in wrong phase"), function walkToExprPre, file /Volumes/Data/swift-public/swift/include/swift/AST/ExprNodes.def, line 69.
Stack dump:
0.  Program arguments: /Volumes/Data/swift-public/build/ninja/swift-macosx-x86_64/bin/swift -frontend -c -primary-file - -target x86_64-apple-macosx10.12 -enable-objc-interop -sdk /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -g -emit-module-doc-path /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/--aeed5b.swiftdoc -color-diagnostics -module-name main -emit-module-path /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/--aeed5b.swiftmodule -o /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/--aeed5b.o 
1.  While walking into decl 'Foo' at <stdin>:6:1
2.  While walking into body of 'init' at <stdin>:7:5
3.  While walking into initializer for declaration 0x7f845880c848 at <stdin>:8:9

@weissi
Copy link
Member Author

weissi commented Jul 13, 2017

still crashes in very recent Swift 4

$ ~/devel/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/bin/swiftc cc.swift 
Assertion failed: ((HadError || !M.is<SourceFile*>() || M.get<SourceFile*>()->ASTStage < SourceFile::TypeChecked) && "OverloadedDeclRef" "in wrong phase"), function walkToExprPre, file /Users/johannes/devel/swift/include/swift/AST/ExprNodes.def, line 77.
0  swift                    0x000000010a1a1a18 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x000000010a1a0976 llvm::sys::RunSignalHandlers() + 86
2  swift                    0x000000010a1a1fde SignalHandler(int) + 366
3  libsystem_platform.dylib 0x00007fff8857ff5a _sigtramp + 26
4  libsystem_platform.dylib 0x00007fcc2c81a590 _sigtramp + 2754192976
5  libsystem_c.dylib        0x00007fff883aad56 abort + 127
6  libsystem_c.dylib        0x00007fff88372dac basename_r + 0
7  swift                    0x0000000108074b01 (anonymous namespace)::Verifier::walkToExprPre(swift::Expr*) + 753
8  swift                    0x00000001080895f4 (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr*) + 36
9  swift                    0x0000000108087de1 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 9969
10 swift                    0x0000000108088c87 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 13719
11 swift                    0x00000001080860df swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 2543
12 swift                    0x0000000108088c87 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 13719
13 swift                    0x00000001080877c8 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 8408
14 swift                    0x00000001080896a3 (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr*) + 211
15 swift                    0x0000000108089626 (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr*) + 86
16 swift                    0x0000000108085281 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 1057
17 swift                    0x0000000108089aeb swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Stmt*) + 507
18 swift                    0x000000010808c08c (anonymous namespace)::Traversal::visitAbstractFunctionDecl(swift::AbstractFunctionDecl*) + 668
19 swift                    0x0000000108084fb3 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 339
20 swift                    0x000000010808bd9b (anonymous namespace)::Traversal::visitNominalTypeDecl(swift::NominalTypeDecl*) + 443
21 swift                    0x0000000108084fa6 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 326
22 swift                    0x0000000108084e4b swift::Decl::walk(swift::ASTWalker&) + 27
23 swift                    0x000000010811278a swift::SourceFile::walk(swift::ASTWalker&) + 170
24 swift                    0x000000010807419b swift::verify(swift::SourceFile&) + 59
25 swift                    0x0000000107ff4dad swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int) + 2141
26 swift                    0x0000000107b489ef swift::CompilerInstance::performSema() + 3535
27 swift                    0x000000010714642a performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1450
28 swift                    0x0000000107144f96 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3494
29 swift                    0x0000000107106b50 main + 3312
30 libdyld.dylib            0x00007fff88300639 start + 1
31 libdyld.dylib            0x000000000000000d start + 2010118613
Stack dump:
0.  Program arguments: /Users/johannes/devel/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/bin/swift -frontend -c -primary-file cc.swift -target x86_64-apple-macosx10.9 -enable-objc-interop -color-diagnostics -module-name cc -o /var/folders/k8/7d0p_dxx2ll8vnw5mt5__ddc0000gn/T/cc-494c28.o 
1.  While walking into decl 'Foo' at cc.swift:5:1
2.  While walking into body of 'init()' at cc.swift:6:5
3.  While walking into initializer for declaration 0x7fcc2b009e90 at cc.swift:7:9
<unknown>:0: error: unable to execute command: Abort trap: 6
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)

version is

$ ~/devel/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/bin/swiftc --version
Swift version 4.0-dev (LLVM 2c7b572db2, Clang 54c8e38855, Swift 51eac53c4a)
Target: x86_64-apple-macosx10.9

checkout is from this week.

@rudkx
Copy link
Member

rudkx commented Jul 13, 2017

I'm not seeing that particular assert with this test case, but I do see this: Assertion failed: (hasInterfaceType() && "No interface type was set"), function getInterfaceType

@rudkx
Copy link
Member

rudkx commented Jul 13, 2017

@swift-ci create

@rudkx
Copy link
Member

rudkx commented Jul 13, 2017

Here's a reduction:

func r(_ fn: ((Int) -> Int)->Int) {}

func test() {
  let _ = r {
    f in { [f] _ in f(1) }
  }
}

@slavapestov
Copy link
Member

See the discussion in https://bugs.swift.org/browse/SR-5870 for details.

@DougGregor
Copy link
Member

@swift-ci create

@slavapestov
Copy link
Member

Doug merged the fix: #33116

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

6 participants