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-2463] Assertion failed: (resultTy->hasUnresolvedType() && "Should have a selected member if we got a type") #45068

Closed
swift-ci opened this issue Aug 23, 2016 · 9 comments
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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-2463
Radar rdar://problem/27974638
Original Reporter Stiivi (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 3.0-dev (LLVM 17c4c6cf7a, Clang 4ca9e01a7c, Swift 31bbb2c)
Target: x86_64-apple-macosx10.9

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

md5: abe8fdb7709ac58a7d7b1005ed603ecc

Issue Description:

Compiling this library (requires ParserCombinator 0.1.4) results in compiler crash. It fails on Parser/Grammar.swift:95.

The project used to compile on one of earlier versions of swift this year, but I don't have them installed any more.

Crash output:

$ swift build
Compile Swift Module 'Parser' (6 sources)
Assertion failed: (resultTy->hasUnresolvedType() && "Should have a selected member if we got a type"), function applyMemberRefExpr, file /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/lib/Sema/CSApply.cpp, line 2518.
0  swift                    0x000000010645130b llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
1  swift                    0x0000000106450556 llvm::sys::RunSignalHandlers() + 70
2  swift                    0x0000000106451a5f SignalHandler(int) + 383
3  libsystem_platform.dylib 0x00007fff96b4352a _sigtramp + 26
4  swift                    0x000000010704b621 cmark_strbuf__initbuf + 74160
5  swift                    0x00000001064517ae abort + 14
6  swift                    0x0000000106451791 __assert_rtn + 81
7  swift                    0x0000000103f30ccf swift::ASTVisitor<(anonymous namespace)::ExprRewriter, swift::Expr*, void, void, void, void, void>::visit(swift::Expr*) + 25183
8  swift                    0x0000000103f22595 (anonymous namespace)::ExprRewriter::walkToExprPost(swift::Expr*) + 21
9  swift                    0x0000000103f263e3 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 19
10 swift                    0x00000001040d345b swift::Expr::walk(swift::ASTWalker&) + 123
11 swift                    0x0000000103f1ef6b swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::Expr*, swift::Type, bool, bool, bool) + 475
12 swift                    0x0000000103fcba6e swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 1070
13 swift                    0x0000000103f4671d (anonymous namespace)::FailureDiagnosis::typeCheckChildIndependently(swift::Expr*, swift::Type, swift::ContextualTypePurpose, swift::OptionSet<TCCFlags, unsigned int>, swift::ExprTypeCheckListener*) + 1101
14 swift                    0x0000000103f4d893 (anonymous namespace)::FailureDiagnosis::typeCheckArgumentChildIndependently(swift::Expr*, swift::Type, (anonymous namespace)::CalleeCandidateInfo const&, swift::OptionSet<TCCFlags, unsigned int>) + 1987
15 swift                    0x0000000103f571d1 (anonymous namespace)::FailureDiagnosis::visitApplyExpr(swift::ApplyExpr*) + 913
16 swift                    0x0000000103f41305 swift::ASTVisitor<(anonymous namespace)::FailureDiagnosis, bool, void, void, void, void, void>::visit(swift::Expr*) + 181
17 swift                    0x0000000103f3abb8 swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 104
18 swift                    0x0000000103f40d38 swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*) + 4056
19 swift                    0x0000000103fc52b5 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>) + 917
20 swift                    0x0000000103fcb9d8 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 920
21 swift                    0x0000000103f4671d (anonymous namespace)::FailureDiagnosis::typeCheckChildIndependently(swift::Expr*, swift::Type, swift::ContextualTypePurpose, swift::OptionSet<TCCFlags, unsigned int>, swift::ExprTypeCheckListener*) + 1101
22 swift                    0x0000000103f433a7 swift::ASTVisitor<(anonymous namespace)::FailureDiagnosis, bool, void, void, void, void, void>::visit(swift::Expr*) + 8535
23 swift                    0x0000000103f3abb8 swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 104
24 swift                    0x0000000103f40d38 swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*) + 4056
25 swift                    0x0000000103fc52b5 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>) + 917
26 swift                    0x0000000103fcb9d8 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 920
27 swift                    0x0000000103f4671d (anonymous namespace)::FailureDiagnosis::typeCheckChildIndependently(swift::Expr*, swift::Type, swift::ContextualTypePurpose, swift::OptionSet<TCCFlags, unsigned int>, swift::ExprTypeCheckListener*) + 1101
28 swift                    0x0000000103f4d893 (anonymous namespace)::FailureDiagnosis::typeCheckArgumentChildIndependently(swift::Expr*, swift::Type, (anonymous namespace)::CalleeCandidateInfo const&, swift::OptionSet<TCCFlags, unsigned int>) + 1987
29 swift                    0x0000000103f571d1 (anonymous namespace)::FailureDiagnosis::visitApplyExpr(swift::ApplyExpr*) + 913
30 swift                    0x0000000103f41305 swift::ASTVisitor<(anonymous namespace)::FailureDiagnosis, bool, void, void, void, void, void>::visit(swift::Expr*) + 181
31 swift                    0x0000000103f3abb8 swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 104
32 swift                    0x0000000103f40d38 swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*) + 4056
33 swift                    0x0000000103fc52b5 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>) + 917
34 swift                    0x0000000103fcb9d8 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 920
35 swift                    0x0000000103f4671d (anonymous namespace)::FailureDiagnosis::typeCheckChildIndependently(swift::Expr*, swift::Type, swift::ContextualTypePurpose, swift::OptionSet<TCCFlags, unsigned int>, swift::ExprTypeCheckListener*) + 1101
36 swift                    0x0000000103f4deaa (anonymous namespace)::FailureDiagnosis::typeCheckArgumentChildIndependently(swift::Expr*, swift::Type, (anonymous namespace)::CalleeCandidateInfo const&, swift::OptionSet<TCCFlags, unsigned int>) + 3546
37 swift                    0x0000000103f571d1 (anonymous namespace)::FailureDiagnosis::visitApplyExpr(swift::ApplyExpr*) + 913
38 swift                    0x0000000103f41305 swift::ASTVisitor<(anonymous namespace)::FailureDiagnosis, bool, void, void, void, void, void>::visit(swift::Expr*) + 181
39 swift                    0x0000000103f3abb8 swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 104
40 swift                    0x0000000103f40d38 swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*) + 4056
41 swift                    0x0000000103fc52b5 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>) + 917
42 swift                    0x0000000103fcb9d8 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 920
43 swift                    0x0000000103fccd4f swift::TypeChecker::typeCheckBinding(swift::Pattern*&, swift::Expr*&, swift::DeclContext*) + 367
44 swift                    0x0000000103fccf4a swift::TypeChecker::typeCheckPatternBinding(swift::PatternBindingDecl*, unsigned int) + 298
45 swift                    0x0000000103fddec6 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 262
46 swift                    0x0000000103fdddac swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 156
47 swift                    0x0000000104000f8a swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int) + 1434
48 swift                    0x0000000103c9dc0c swift::CompilerInstance::performSema() + 3916
49 swift                    0x0000000103792171 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3185
50 swift                    0x0000000103752320 main + 2544
51 libdyld.dylib            0x00007fff8c2365ad start + 1
52 libdyld.dylib            0x0000000000000029 start + 1943837309
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-08-18-a.xctoolchain/usr/bin/swift -frontend -c /Users/stefanu/Developer/sepro/Sources/Parser/AST.swift /Users/stefanu/Developer/sepro/Sources/Parser/CharacterSets.swift -primary-file /Users/stefanu/Developer/sepro/Sources/Parser/Grammar.swift /Users/stefanu/Developer/sepro/Sources/Parser/Lexer.swift /Users/stefanu/Developer/sepro/Sources/Parser/Operators.swift /Users/stefanu/Developer/sepro/Sources/Parser/Parser.swift -target x86_64-apple-macosx10.10 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -I /Users/stefanu/Developer/sepro/.build/debug -F /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -enable-testing -g -module-cache-path /Users/stefanu/Developer/sepro/.build/debug/ModuleCache -D SWIFT_PACKAGE -emit-module-doc-path /Users/stefanu/Developer/sepro/.build/debug/Parser.build/Grammar~partial.swiftdoc -Onone -parse-as-library -module-name Parser -emit-module-path /Users/stefanu/Developer/sepro/.build/debug/Parser.build/Grammar~partial.swiftmodule -emit-dependencies-path /Users/stefanu/Developer/sepro/.build/debug/Parser.build/Grammar.d -emit-reference-dependencies-path /Users/stefanu/Developer/sepro/.build/debug/Parser.build/Grammar.swiftdeps -num-threads 8 -o /Users/stefanu/Developer/sepro/.build/debug/Parser.build/Grammar.swift.o
1.  While type-checking declaration 0x7fcafc83f9f8 at /Users/stefanu/Developer/sepro/Sources/Parser/Grammar.swift:94:1
2.  While type-checking expression at [/Users/stefanu/Developer/sepro/Sources/Parser/Grammar.swift:95:9 - line:96:98] RangeText="target_type + option(op(".") *> %"slot") => { target in ModifierTarget(target.0, target.1) }
        || %"slot"                               => { symbol in ModifierTarget(TargetType.This, symbol)}"
3.  While type-checking expression at [/Users/stefanu/Developer/sepro/Sources/Parser/Grammar.swift:95:9 - line:95:100] RangeText="target_type + option(op(".") *> %"slot") => { target in ModifierTarget(target.0, target.1) }"
4.  While type-checking expression at [/Users/stefanu/Developer/sepro/Sources/Parser/Grammar.swift:95:53 - line:95:100] RangeText="{ target in ModifierTarget(target.0, target.1) }"
5.  While type-checking expression at [/Users/stefanu/Developer/sepro/Sources/Parser/Grammar.swift:95:65 - line:95:98] RangeText="ModifierTarget(target.0, target.1)"
6.  While type-checking expression at [/Users/stefanu/Developer/sepro/Sources/Parser/Grammar.swift:95:80 - line:95:87] RangeText="target.0"
<unknown>:0: error: unable to execute command: Illegal instruction: 4
<unknown>:0: error: compile command failed due to signal (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
error: exit(1): /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-08-18-a.xctoolchain/usr/bin/swift-build-tool -f /Users/stefanu/Developer/sepro/.build/debug.yaml
@belkadan
Copy link
Contributor

Possibly related to SE-0110. Does the closure really take one argument that's a tuple, or is it supposed to take two arguments?

@belkadan
Copy link
Contributor

(We shouldn't crash regardless.)

@swift-ci
Copy link
Collaborator Author

Comment by Stefan Urbanek (JIRA)

The + operator is producing a parser that returns a tuple of two elements, this one at line 55 seems to be fine. When I change the closure to: (a,b) in ModifierTarget(a, b) I get:

/Users/stefanu/Developer/sepro/Sources/Parser/Grammar.swift:95:55: error: contextual closure type '(_) -> _' expects 1 argument, but 2 were used in closure body
        target_type + option(op(".") *> %"slot") => { (a,b) in ModifierTarget(a, b) }
                                                      ^

Edit 2: Here is the function behind +: func then<T,A,B> (_ p: Parser<T,A>, _ q: Parser<T,B>) -> Parser<T,(A,B)>

@belkadan
Copy link
Contributor

Okay, thanks for clarifying that.

@rudkx
Copy link
Member

rudkx commented Aug 23, 2016

Despite the example at line 55, I don't believe a tuple is expected here at all.

This assert is basically saying that we didn't expect to determine a type when the member reference is invalid, but we did. That would be a fine assert except we're hitting this code on a path where we are attempting to emit a diagnostic, and I suspect we have a type because it's the one we've substituted in to attempt to solve the system (the type we're using here is the one expected by the call to ModifierTarget, in this case a TargetType).

Line 96, just below, has another closure that attempts to construct a ModifierTarget using TargetType.This and the closure parameter.

If I remove the assert I get the rather unhelpful:

  /Users/mark_lacey/src/sepro/Sources/Parser/Grammar.swift:95:87: error: type of expression is ambiguous without more context
        target_type + option(op(".") *> %"slot") => { target in ModifierTarget(target.0, target.1) }
                                                                               ~~~~~~~^

@swift-ci
Copy link
Collaborator Author

Comment by Stefan Urbanek (JIRA)

Line 96 contains recognizer that returns a parser which generates just a single object of type Symbol. Operator % is recognizer symbol from line 25.

In line 95 the + can be written as function: then(target_type, xthen(option(op("."), symbol("slot")))) and the function then returns Parser<T,(A,B)> (see link in my previous comment), therefore I assume that the closure is getting a tuple (A,B) which in this case is (TargetType, Symbol). This produces the same error.

Edit: replaced all the operators in the rewrite example with functions.

@rudkx
Copy link
Member

rudkx commented Aug 24, 2016

Yes, you're right. I dug into this further and the thing that gets us to this point is that ModifierTarget's init() isn't public, so it's inaccessible from this file.

We should emit a useful diagnostic for that, but hopefully this will allow you to work around the lack of diagnostic (and current assert in debug builds).

@swift-ci
Copy link
Collaborator Author

Comment by Stefan Urbanek (JIRA)

Thank you @rudkx for the investigation. Indeed making the method public (and also adding explicit public init for Modifier) solved the problem and the module compiles. Works for me for now.

Interesting that it compiled with older versions of swift.

You are right, better diagnostic would be helpful.

Thanks a lot.

@belkadan
Copy link
Contributor

belkadan commented Mar 4, 2017

Looks like Swift 3.1 has the good diagnostic and everything.

@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
Projects
None yet
Development

No branches or pull requests

4 participants