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-6906] KeyPath to an element of an optional tuple crashes the compiler #49455

Closed
tcldr opened this issue Feb 2, 2018 · 6 comments
Closed
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 key paths Feature: key paths (both native and Objective-C)

Comments

@tcldr
Copy link

tcldr commented Feb 2, 2018

Previous ID SR-6906
Radar rdar://problem/37160546
Original Reporter @tcldr
Type Bug
Status Resolved
Resolution Done
Environment

Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)

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

md5: 42963eb9b8cc02205f6606b795b91fbc

Issue Description:

I understand that this isn't yet supported, but a KeyPath to an element of an optional tuple currently crashes the compiler:

struct Foo {
    let bar: (Int, Int)?
}

let kp = \Foo.bar?.0 // crash
0  swift                    0x000000010d13636a PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x000000010d1357a6 SignalHandler(int) + 662
2  libsystem_platform.dylib 0x00007fff7dcb6f5a _sigtramp + 26
3  swift                    0x000000010ad113b4 swift::Type::transformRec(llvm::function_ref<llvm::Optional<swift::Type> (swift::TypeBase*)>) const + 148
4  swift                    0x000000010aa2e769 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 25
5  swift                    0x000000010ab4bd90 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 1584
6  swift                    0x000000010ab4ecbe swift::TypeChecker::typeCheckBinding(swift::Pattern*&, swift::Expr*&, swift::DeclContext*, bool) + 366
7  swift                    0x000000010ab4f27c swift::TypeChecker::typeCheckPatternBinding(swift::PatternBindingDecl*, unsigned int, bool) + 188
8  swift                    0x000000010ab5e507 validatePatternBindingEntries(swift::TypeChecker&, swift::PatternBindingDecl*) + 1111
9  swift                    0x000000010ab62348 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 1272
10 swift                    0x000000010abd187d swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 13805
11 swift                    0x000000010abd43ac swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 220
12 swift                    0x000000010abf0a75 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int) + 1861
13 swift                    0x000000010a7199c4 swift::CompilerInstance::performSema() + 4628
14 swift                    0x0000000109a8ffbb performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1371
15 swift                    0x0000000109a8e1f4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7716
16 swift                    0x0000000109a42e78 main + 12248
17 libdyld.dylib            0x00007fff7da35115 start + 1
18 libdyld.dylib            0x000000000000000f start + 2187112187

(Also, should I post an improvement request for this feature?)

@belkadan
Copy link
Contributor

belkadan commented Feb 2, 2018

Reproduces on master:

Assertion failed: (is<T>() && "Invalid accessor called"), function get, file /Volumes/Data/swift-public/llvm/include/llvm/ADT/PointerUnion.h, line 136.
0  swift                    0x0000000112524768 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x00000001125236b6 llvm::sys::RunSignalHandlers() + 86
2  swift                    0x0000000112524d2e SignalHandler(int) + 366
3  libsystem_platform.dylib 0x00007fff77faaf5a _sigtramp + 26
4  libsystem_malloc.dylib   0x00007fff77ed2384 tiny_malloc_from_free_list + 431
5  libsystem_c.dylib        0x00007fff77dd5312 abort + 127
6  libsystem_c.dylib        0x00007fff77d9d368 basename_r + 0
7  swift                    0x000000010fdfeb34 swift::ASTVisitor<(anonymous namespace)::ExprRewriter, swift::Expr*, void, void, void, void, void>::visit(swift::Expr*) + 33348
8  swift                    0x000000010fdec2a9 (anonymous namespace)::ExprRewriter::walkToExprPost(swift::Expr*) + 25
9  swift                    0x000000010fdf1816 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 22
10 swift                    0x00000001101ead36 swift::Expr::walk(swift::ASTWalker&) + 118
11 swift                    0x000000010fde8fb3 swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::Expr*, swift::Type, bool, bool, bool) + 595
12 swift                    0x000000010ff003e6 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 982
13 swift                    0x000000010ff044ed swift::TypeChecker::typeCheckBinding(swift::Pattern*&, swift::Expr*&, swift::DeclContext*, bool) + 461
14 swift                    0x000000010ff04869 swift::TypeChecker::typeCheckPatternBinding(swift::PatternBindingDecl*, unsigned int, bool) + 345
15 swift                    0x000000010ff1dc68 validatePatternBindingEntries(swift::TypeChecker&, swift::PatternBindingDecl*) + 872
16 swift                    0x000000010ff18008 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 504
17 swift                    0x000000010ff17dfc swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 124
18 swift                    0x000000010ff8be5f swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 431
19 swift                    0x000000010ff8b6f9 swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 153
20 swift                    0x000000010ffae2f5 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int) + 1701
21 swift                    0x000000010fc19983 swift::CompilerInstance::parseAndTypeCheckMainFile(swift::PersistentParserState&, swift::DelayedParsingCallbacks*, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>) + 531
22 swift                    0x000000010fc1871c swift::CompilerInstance::parseAndCheckTypes(swift::CompilerInstance::ImplicitImports const&) + 780
23 swift                    0x000000010fc17f57 swift::CompilerInstance::performSema() + 567
24 swift                    0x000000010f141d21 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1697
25 swift                    0x000000010f140769 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3273
26 swift                    0x000000010f1008e0 main + 3328
27 libdyld.dylib            0x00007fff77d29115 start + 1
28 libdyld.dylib            0x000000000000000f start + 2284678907
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-darwin17.4.0 -enable-objc-interop -sdk /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -color-diagnostics -module-name main -o /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/--960510.o 
1.  While type-checking declaration 0x7fe6ef85af68 at <stdin>:5:1
2.  While type-checking expression at [<stdin>:5:10 - line:5:20] RangeText="\Foo.bar?.0"

@jckarter?

@jckarter
Copy link
Member

jckarter commented Feb 2, 2018

We should at least diagnose here. (Or just support this, it'd be really easy.) Thanks!

@jckarter
Copy link
Member

jckarter commented Feb 2, 2018

@swift-ci create

@tcldr
Copy link
Author

tcldr commented Mar 17, 2019

This one is also still failing for me on latest Xcode beta (10.2b4):

Apple Swift version 5.0 (swiftlang-1001.0.69 clang-1001.0.45.2)

Target: x86_64-apple-darwin18.2.0

@theblixguy
Copy link
Collaborator

This no longer crashes in 5.1 as tuple key paths are now supported.

@xedin
Copy link
Member

xedin commented Jun 6, 2021

@tcldr This no longer crashes on main or 5.5 branch, @theblixguy reported that this was fixed in 5.1, please use the latest snapshot of either main or 5.5 branch from swift.org to verify and close.

@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 key paths Feature: key paths (both native and Objective-C)
Projects
None yet
Development

No branches or pull requests

6 participants