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-11769] Crash when attempting to assign an unbound method from a protocol #54176

Closed
swift-ci opened this issue Nov 12, 2019 · 3 comments
Closed
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

@swift-ci
Copy link
Collaborator

Previous ID SR-11769
Radar rdar://problem/57176569
Original Reporter Alvae (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

macOS 10.14.6
Apple Swift version 5.1.2 (swiftlang-1100.0.278 clang-1100.0.33.9)
Target: x86_64-apple-darwin18.7.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Crash, Generics, TypeChecker
Assignee Alvae (JIRA)
Priority Medium

md5: ca3f5f0da607d96f6ed538ca5e76bb34

duplicates:

  • SR-75 Referencing a protocol function crashes the compiler

Issue Description:

The following code will crash the compiler (Swift 5.1.2):

protocol S {
}
extension S {
  func a() {}
}
let f = S.a

Of course, this would work perfectly if `S` was a struct (or class) rather than a protocol. If the same behavior is not meant to be supported, then the compiler should issue an error message at line 6.

Here's my stack dump:

Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret main.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name main 
0  swift                    0x0000000109c4ea13 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x0000000109c4e1e6 SignalHandler(int) + 358
2  libsystem_platform.dylib 0x00007fff6836fb5d _sigtramp + 29
3  libsystem_platform.dylib 0x0000000000000001 _sigtramp + 2546533569
4  swift                    0x0000000105d066aa swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 58794
5  swift                    0x0000000105cf86bc swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 1468
6  swift                    0x0000000105cf95e3 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 5347
7  swift                    0x0000000105d0c876 void llvm::function_ref<void (swift::Expr*)>::callback_fn<swift::Lowering::RValue swift::Lowering::SILGenFunction::emitOpenExistentialExpr<swift::Lowering::RValue, (anonymous namespace)::RValueEmitter::visitOpenExistentialExpr(swift::OpenExistentialExpr*, swift::Lowering::SGFContext)::$_15>(swift::OpenExistentialExpr*, (anonymous namespace)::RValueEmitter::visitOpenExistentialExpr(swift::OpenExistentialExpr*, swift::Lowering::SGFContext)::$_15)::'lambda'(swift::Expr*)>(long, swift::Expr*) + 38
8  swift                    0x0000000105d0cb8d swift::Lowering::SILGenFunction::emitOpenExistentialExprImpl(swift::OpenExistentialExpr*, llvm::function_ref<void (swift::Expr*)>) + 685
9  swift                    0x0000000105cff974 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 30836
10 swift                    0x0000000105cf7f23 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, llvm::Optional<swift::SILLocation>) + 131
11 swift                    0x0000000105ceb31c swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 268
12 swift                    0x0000000105c9221d swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Decl*) + 93
13 swift                    0x0000000105c949af swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 1087
14 swift                    0x0000000105c93806 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 1238
15 swift                    0x0000000105c952b1 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) + 1313
16 swift                    0x0000000105899795 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 30885
17 swift                    0x000000010588e6e4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6820
18 swift                    0x000000010581bbe3 main + 1219
19 libdyld.dylib            0x00007fff681843d5 start + 1
20 libdyld.dylib            0x000000000000000a start + 2548546614
Segmentation fault: 11
mipha-1:Algo alvae$ swift --version
Apple Swift version 5.1.2 (swiftlang-1100.0.278 clang-1100.0.33.9)
Target: x86_64-apple-darwin18.7.0
@beccadax
Copy link
Contributor

Reproduced in master. As far as I know, it's legal to get an unbound method from a protocol existential, which means this code should be valid.

brent@broyalgordon /V/D/C/o/swift a-link-to-the-past-5.1> /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-11-01-a.xctoolchain/usr/bin/swift sr-11769.swift
not existential
UNREACHABLE executed at /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/lib/SILGen/SILGenConvert.cpp:987!
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-11-01-a.xctoolchain/usr/bin/swift -frontend -interpret sr-11769.swift -enable-objc-interop -sdk /Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name main 
1.  Apple Swift version 5.1.1-dev (Swift 74328cdda2)
0  swift                    0x000000011214fc35 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x000000011214eee5 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x0000000112150218 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff624abb1d _sigtramp + 29
4  swift                    0x000000011331f1de llvm::itanium_demangle::PixelVectorType::printLeft(llvm::itanium_demangle::OutputStream&) const (.cold.1) + 254014
5  libsystem_c.dylib        0x00007fff62381a08 abort + 120
6  swift                    0x00000001132d293e llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) + 462
7  swift                    0x000000010e88fcc3 swift::Lowering::SILGenFunction::emitOpenExistential(swift::SILLocation, swift::Lowering::ManagedValue, swift::SILType, swift::AccessKind) + 1203
8  swift                    0x000000010e8ae85a swift::Lowering::SILGenFunction::emitOpenExistentialExprImpl(swift::OpenExistentialExpr*, llvm::function_ref<void (swift::Expr*)>) + 314
9  swift                    0x000000010e8bed35 swift::Lowering::RValue swift::Lowering::SILGenFunction::emitOpenExistentialExpr<swift::Lowering::RValue, (anonymous namespace)::RValueEmitter::visitOpenExistentialExpr(swift::OpenExistentialExpr*, swift::Lowering::SGFContext)::$_16>(swift::OpenExistentialExpr*, (anonymous namespace)::RValueEmitter::visitOpenExistentialExpr(swift::OpenExistentialExpr*, swift::Lowering::SGFContext)::$_16) + 69
10 swift                    0x000000010e8b0b37 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 4695
11 swift                    0x000000010e8a2c6f swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, llvm::Optional<swift::SILLocation>) + 303
12 swift                    0x000000010e8949af swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 335
13 swift                    0x000000010e894a8d swift::Lowering::SILGenFunction::visitPatternBindingDecl(swift::PatternBindingDecl*) + 45
14 swift                    0x000000010e84a492 swift::Lowering::SILGenModule::visitTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 498
15 swift                    0x000000010e84a9b3 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 915
16 swift                    0x000000010e84b959 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions&, swift::FileUnit*) + 393
17 swift                    0x000000010e84bd21 swift::performSILGeneration(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions&) + 17
18 swift                    0x000000010e553cd0 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 7808
19 swift                    0x000000010e550ed6 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3046
20 swift                    0x000000010e4f62d9 main + 729
21 libdyld.dylib            0x00007fff622aa325 start + 1
22 libdyld.dylib            0x000000000000000a start + 2648005862

emitOpenExistential() is trying to lower this node:

(open_existential_expr implicit type='(S) -> () -> ()' location=sr-11769.swift:6:9 range=[sr-11769.swift:6:9 - line:6:11]
  (opaque_value_expr implicit type='(S).Type' location=sr-11769.swift:6:9 range=[sr-11769.swift:6:9 - line:6:9] @ 0x1100e0520)
  (type_expr type='S.Protocol' location=sr-11769.swift:6:9 range=[sr-11769.swift:6:9 - line:6:9] typerepr='S')
  (dot_syntax_base_ignored type='(S) -> () -> ()' location=sr-11769.swift:6:9 range=[sr-11769.swift:6:9 - line:6:11]
    (metatype_conversion_expr implicit type='S.Protocol' location=sr-11769.swift:6:9 range=[sr-11769.swift:6:9 - line:6:9]
      (opaque_value_expr implicit type='(S).Type' location=sr-11769.swift:6:9 range=[sr-11769.swift:6:9 - line:6:9] @ 0x1100e0520))
    (declref_expr type='(S) -> () -> ()' location=sr-11769.swift:6:11 range=[sr-11769.swift:6:11 - line:6:11] decl=main.(file).S extension.a()@sr-11769.swift:4:8 [with (substitution_map generic_signature=<Self where Self : S> (substitution Self -> S))] function_ref=unapplied)))

That AST smells funny to me. @xedin?

@beccadax
Copy link
Contributor

@swift-ci create

@jckarter
Copy link
Member

Dup of SR-75.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added CompilerCrash and removed generics Feature: generic declarations and types labels Sep 17, 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

4 participants