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-6799] Swift 4.1 regression: compiler crash after converting code to Swift 4.1 (cast<Ty>() argument of incompatible type) #49348

Closed
NachoSoto opened this issue Jan 20, 2018 · 6 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 regression swift 4.1 type checker Area → compiler: Semantic analysis

Comments

@NachoSoto
Copy link
Contributor

Previous ID SR-6799
Radar rdar://problem/36675083
Original Reporter @NachoSoto
Type Bug
Status Resolved
Resolution Done
Environment

Swift version 4.1-dev (LLVM ef53654946, Clang f7df1e5a04, Swift 831b78c)

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

md5: 690553db83ecc1c99445947a8e8e7171

Issue Description:

I started converting ReactiveCocoa to Swift 4.1 and it simply crashes the compiler. You can clone the branch on that exact state from my fork or download it directly from here.

Stack trace:

Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file /Users/buildnode/jenkins/workspace/oss-swift-4.1-package-osx/llvm/include/llvm/Support/Casting.h, line 255.
0  swift                    0x000000010f40eab8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x000000010f40da06 llvm::sys::RunSignalHandlers() + 86
2  swift                    0x000000010f40f07e SignalHandler(int) + 366
3  libsystem_platform.dylib 0x00007fff54770f5a _sigtramp + 26
4  libsystem_platform.dylib 0x000000011dde0570 _sigtramp + 3378968112
5  libsystem_c.dylib        0x00007fff5459b312 abort + 127
6  libsystem_c.dylib        0x00007fff54563368 basename_r + 0
7  swift                    0x000000010cc933ab swift::constraints::ConstraintSystem::simplifyKeyPathConstraint(swift::Type, swift::Type, swift::Type, swift::OptionSet<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int>, swift::constraints::ConstraintLocatorBuilder) + 1867
8  swift                    0x000000010cc96f50 swift::constraints::ConstraintSystem::simplifyConstraint(swift::constraints::Constraint const&) + 1776
9  swift                    0x000000010cc9a2c7 swift::constraints::ConstraintSystem::simplify(bool) + 151
10 swift                    0x000000010cc9d665 swift::constraints::ConstraintSystem::solveRec(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 53
11 swift                    0x000000010cca216d swift::constraints::DisjunctionChoice::solve(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 61
12 swift                    0x000000010cca177d swift::constraints::ConstraintSystem::solveSimplified(swift::constraints::Constraint*, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 2013
13 swift                    0x000000010cc9dd94 swift::constraints::ConstraintSystem::solveRec(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 1892
14 swift                    0x000000010cc9ca5f swift::constraints::ConstraintSystem::tryTypeVariableBindings(unsigned int, swift::TypeVariableType*, llvm::ArrayRef<swift::constraints::ConstraintSystem::PotentialBinding>, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 5247
15 swift                    0x000000010cca1036 swift::constraints::ConstraintSystem::solveSimplified(swift::constraints::Constraint*, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 150
16 swift                    0x000000010cc9dd94 swift::constraints::ConstraintSystem::solveRec(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 1892
17 swift                    0x000000010cca216d swift::constraints::DisjunctionChoice::solve(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 61
18 swift                    0x000000010cca177d swift::constraints::ConstraintSystem::solveSimplified(swift::constraints::Constraint*, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 2013
19 swift                    0x000000010cc9dd94 swift::constraints::ConstraintSystem::solveRec(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 1892
20 swift                    0x000000010cc9ca5f swift::constraints::ConstraintSystem::tryTypeVariableBindings(unsigned int, swift::TypeVariableType*, llvm::ArrayRef<swift::constraints::ConstraintSystem::PotentialBinding>, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 5247
21 swift                    0x000000010cca1036 swift::constraints::ConstraintSystem::solveSimplified(swift::constraints::Constraint*, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 150
22 swift                    0x000000010cc9dd94 swift::constraints::ConstraintSystem::solveRec(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 1892
23 swift                    0x000000010cca216d swift::constraints::DisjunctionChoice::solve(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 61
24 swift                    0x000000010cca177d swift::constraints::ConstraintSystem::solveSimplified(swift::constraints::Constraint*, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 2013
25 swift                    0x000000010cc9dd94 swift::constraints::ConstraintSystem::solveRec(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 1892
26 swift                    0x000000010cc9f0cd swift::constraints::ConstraintSystem::solve(swift::Expr*, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 109
27 swift                    0x000000010cca0db0 swift::constraints::ConstraintSystem::solve(swift::Expr*&, swift::Type, swift::ExprTypeCheckListener*, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 976
28 swift                    0x000000010cd2a364 swift::TypeChecker::solveForExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem&, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 52
29 swift                    0x000000010cd2d656 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 678
30 swift                    0x000000010cdb627e swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 542
31 swift                    0x000000010cdb53cb (anonymous namespace)::StmtChecker::typeCheckBody(swift::BraceStmt*&) + 27
32 swift                    0x000000010cdb59bc swift::TypeChecker::typeCheckClosureBody(swift::ClosureExpr*) + 252
33 swift                    0x000000010cc2414c swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::Expr*, swift::Type, bool, bool, bool) + 668
34 swift                    0x000000010cd2d726 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 886
35 swift                    0x000000010cdb627e swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 542
36 swift                    0x000000010cdb53cb (anonymous namespace)::StmtChecker::typeCheckBody(swift::BraceStmt*&) + 27
37 swift                    0x000000010cdb59bc swift::TypeChecker::typeCheckClosureBody(swift::ClosureExpr*) + 252
38 swift                    0x000000010cc2414c swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::Expr*, swift::Type, bool, bool, bool) + 668
39 swift                    0x000000010cd2d726 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 886
40 swift                    0x000000010cdb627e swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 542
41 swift                    0x000000010cdb53cb (anonymous namespace)::StmtChecker::typeCheckBody(swift::BraceStmt*&) + 27
42 swift                    0x000000010cdb4699 swift::TypeChecker::typeCheckFunctionBodyUntil(swift::FuncDecl*, swift::SourceLoc) + 233
43 swift                    0x000000010cdb508b swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 251
44 swift                    0x000000010cdd5cc9 typeCheckFunctionsAndExternalDecls(swift::TypeChecker&) + 185
45 swift                    0x000000010cdd6b69 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int) + 1849
46 swift                    0x000000010ca578cd swift::CompilerInstance::parseAndCheckTypes(swift::CompilerInstance::ImplicitImports const&) + 829
47 swift                    0x000000010ca57038 swift::CompilerInstance::performSema() + 520
48 swift                    0x000000010bfa06e5 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1781
49 swift                    0x000000010bf9f02a swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3210
50 swift                    0x000000010bf5fda0 main + 3360
51 libdyld.dylib            0x00007fff544ef115 start + 1
52 libdyld.dylib            0x0000000000000078 start + 2880507748

1.  While type-checking 'spec()' at /Users/nachosoto/dev/ios/ReactiveCocoa/ReactiveCocoaTests/BindingTargetSpec.swift:24:11
2.  While type-checking expression at [/Users/nachosoto/dev/ios/ReactiveCocoa/ReactiveCocoaTests/BindingTargetSpec.swift:115:3 - line:157:3] RangeText="describe("key path binding target") {
            it("should update the value") {
                let object = Object()
                expect(object.value) == 0

                let property = MutableProperty(1)
                object.reactive[\.value] <~ property
                expect(object.value) == 1

                property.value = 2
                expect(object.value) == 2
            }

            it("should update the value on the given scheduler") {
                let scheduler = TestScheduler()

                let object = Object()
                let property = MutableProperty(1)
                object.reactive[\.value, on: scheduler] <~ property
                expect(object.value) == 0

                scheduler.run()
                expect(object.value) == 1

                property.value = 2
                expect(object.value) == 1

                scheduler.run()
                expect(object.value) == 2
            }

            it("should work for native swift objects") {
                let object = NativeObject()
                expect(object.value) == 0

                let property = MutableProperty(1)
                object.reactive[\.value] <~ property
                expect(object.value) == 1

                property.value = 2
                expect(object.value) == 2
            }
        }"
3.  While type-checking expression at [/Users/nachosoto/dev/ios/ReactiveCocoa/ReactiveCocoaTests/BindingTargetSpec.swift:116:4 - line:126:4] RangeText="it("should update the value") {
                let object = Object()
                expect(object.value) == 0

                let property = MutableProperty(1)
                object.reactive[\.value] <~ property
                expect(object.value) == 1

                property.value = 2
                expect(object.value) == 2
            }"
4.  While type-checking expression at [/Users/nachosoto/dev/ios/ReactiveCocoa/ReactiveCocoaTests/BindingTargetSpec.swift:121:5 - line:121:33] RangeText="object.reactive[\.value] <~ p"

Note that this happens when compiling tests (Select the ReactiveCocoa-iOS target for example)

See also SR-6797 and SR-6800.

@slavapestov
Copy link
Member

@swift-ci create

@slavapestov
Copy link
Member

This could be a dupe of SR-6744, which was fixed on master by #13943

@jckarter
Copy link
Member

Looks like it, thanks @slavapestov. Here's a PR for 4.1: #14067

@jckarter
Copy link
Member

Merged. @NachoSoto, can you give this a try with the next snapshot?

@NachoSoto
Copy link
Contributor Author

Tried this with the January 22 snapshot and it's still failing in the same way.

@NachoSoto
Copy link
Contributor Author

Confirmed fixed in beta 2! 👍

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

No branches or pull requests

4 participants