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-2672] Implement tuple conversion #45277

Closed
swift-ci opened this issue Sep 16, 2016 · 5 comments
Closed

[SR-2672] Implement tuple conversion #45277

swift-ci opened this issue Sep 16, 2016 · 5 comments

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Sep 16, 2016

Previous ID SR-2672
Radar rdar://problem/12340004
Original Reporter paul.eipper (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 8 (8A218a)
Apple Swift version 3.0 (swiftlang-800.0.46.2 clang-800.0.38)
Build Target iOS SDK 10

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

md5: e5d8c9bdc5d4c9319a3d61409edd7d54

is duplicated by:

  • SR-4745 for (index, (a, b)) in dict.enumerated() produces an error
  • SR-6027 "cannot express tuple conversion" dealing with IUOs
  • SR-6263 Inconsistent assignability of tuple & functional types
  • SR-9051 Cannot call a protocol method returning Self in a tuple type on an existential
  • SR-10160 Seg Fault 11: Attempting to Implicitly convert Tuples

Issue Description:

Compiler crashes when trying to compile the following code:

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // this works:
        let tapAction: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(optionTapped(_:)))
        let items: [(String, UIGestureRecognizer)] = [("Action", tapAction)]
        dump(tapAction)
        dump(items)
    }
    
    // this works
    let items1: [(String, UIGestureRecognizer)] = {
        let tapAction: UIGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(optionTapped(_:)))
        let items = [("Action", tapAction)]
        return items
    }()

    // this causes segfault
    let items2: [(String, UIGestureRecognizer)] = {
        let tapAction: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(optionTapped(_:)))
        let items = [("Action", tapAction)]
        return items
    }()
    
    func optionTapped(_ sender: UIGestureRecognizer?) {
        dump(sender)
    }

}

This is the segfault output:

<unknown>:0: error: cannot express tuple conversion '(String, UITapGestureRecognizer)' to '(String, UIGestureRecognizer)'
0  swift                    0x000000010cc7ab6d PrintStackTraceSignalHandler(void*) + 45
1  swift                    0x000000010cc7a5b6 SignalHandler(int) + 470
2  libsystem_platform.dylib 0x00007fff9576e52a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fff55bdbd48 _sigtramp + 3225868344
4  swift                    0x000000010a9ed02e swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 5438
5  swift                    0x000000010a8f1eac swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 3020
6  swift                    0x000000010a973bb2 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 6114
7  swift                    0x000000010a972516 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 326
8  swift                    0x000000010a97667b swift::TypeChecker::typeCheckClosureBody(swift::ClosureExpr*) + 267
9  swift                    0x000000010a8f1a1b swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 1851
10 swift                    0x000000010a8f3fdc swift::TypeChecker::typeCheckBinding(swift::Pattern*&, swift::Expr*&, swift::DeclContext*) + 300
11 swift                    0x000000010a8f4903 swift::TypeChecker::typeCheckPatternBinding(swift::PatternBindingDecl*, unsigned int) + 579
12 swift                    0x000000010a9023a2 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 3938
13 swift                    0x000000010a90294b (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 5387
14 swift                    0x000000010a91dbf4 swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 180
15 swift                    0x000000010a92935a swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int) + 1866
16 swift                    0x000000010a5dfaab swift::CompilerInstance::performSema() + 5643
17 swift                    0x000000010a08c00d performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 2765
18 swift                    0x000000010a089265 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 17029
19 swift                    0x000000010a04682d main + 8685
20 libdyld.dylib            0x00007fff881b65ad start + 1
Stack dump:
(...)
1.  While type-checking 'ViewController' at SwiftCrash/ViewController.swift:11:1
2.  While type-checking expression at [SwiftCrash/ViewController.swift:31:51 - line:35:7] RangeText="{
        let tapAction: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(optionTapped(_:)))
        let items = [("Action", tapAction)]
        return items
    }()"
3.  While type-checking expression at [SwiftCrash/ViewController.swift:34:16 - line:34:16] RangeText="i"
@belkadan
Copy link
Contributor

belkadan commented Sep 17, 2016

@rudkx, this is the "tuples don't convert covariantly" crash. Do you have the dup?

@rudkx
Copy link
Member

rudkx commented Sep 17, 2016

@belkadan Is https://bugs.swift.org/browse/SR-2585 what you're looking for?

@slavapestov
Copy link
Member

slavapestov commented Dec 23, 2016

This one is different – we need a new kind of Expr for "top-level" tuple-to-tuple conversions, eg (Int, Int) to (Any, Any) etc. I'm taking this since the bulk of the work will be in SILGen.

@rudkx
Copy link
Member

rudkx commented Dec 24, 2016

Yeah I looked at this at one point. It also seemed like we could do element-wise conversions by extracting and then repacking the data and using the existing Exprs, and I suspect we'll end up with the same (post-optimized) LLVM IR, but I haven't given it that much thought.

@slavapestov
Copy link
Member

slavapestov commented Apr 1, 2019

#23612

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants