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-9015] Code completion assertion failure: (D->hasValidSignature()), function getType, file swift/lib/Sema/ConstraintSystem.h #51518

Closed
nathawes opened this issue Oct 16, 2018 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. code completion Area → source tooling: code completion compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software source tooling Area: IDE support, SourceKit, and other source tooling

Comments

@nathawes
Copy link
Collaborator

Previous ID SR-9015
Radar rdar://problem/45313700
Original Reporter @nathawes
Type Bug
Status Resolved
Resolution Done

Attachment: Download

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

md5: d0a4cce3ff8d444b486ed453327006cf

duplicates:

  • SR-4812 swiftc crash in swift::Lowering::SILGenFunction::emitClosureValue

Issue Description:

To reproduce:

$ git clone https://github.com/mac-cain13/R.swift.git
$ cd R.swift
$ git checkout -f f96758593573d3d1d9ae8084721033ab0bf392f6
$ xcrun swift package generate-xcodeproj --xcconfig-overrides RswiftConfig.xcconfig 
$ open rswift.xcodeproj

Then in Xcode:

  1. Select the October 3 dev snapshot toolchain

  2. Navigate to AggregatedStructGenerator.swift

  3. Replace its contents with attached "AggregatedStructGenerator-modified.swift" file

  4. Invoke code completion immediately before the "=" in "if let internalStruct = result.internalStruct" on line 19 of the modified file to get the trace below:

    Application Specific Information:
    dyld2 mode
    Stack dump:
    0.  While walking into decl 'AggregatedStructGenerator' at /Users/nathanhawes/workspace/open-swift-source-compat-suite-master/project_cache/R.swift/Sources/RswiftCore/Generators/AggregatedStructGenerator.swift:3:1
    1.  While type-checking statement at [/Users/nathanhawes/workspace/open-swift-source-compat-suite-master/project_cache/R.swift/Sources/RswiftCore/Generators/AggregatedStructGenerator.swift:10:113 - line:39:3] RangeText="{
        let structName: SwiftIdentifier = "R"
        let qualifiedName = structName
        let internalStructName: SwiftIdentifier = "_R"
     
        let collectedResult = subgenerators
          .compactMap {
            let result = $0.generatedStructs(at: externalAccessLevel, prefix: qualifiedName)
            if result.externalStruct.isEmpty { return nil }
            if let internalStruct 
    Assertion failed: (D->hasValidSignature()), function getType, file /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/lib/Sema/ConstraintSystem.h, line 1683.
    
    Thread 3 Crashed:
    0   libsystem_kernel.dylib          0x00007fff7443bb86 __pthread_kill + 10
    1   libsystem_pthread.dylib         0x00007fff744f1c50 pthread_kill + 285
    2   libsystem_c.dylib               0x00007fff743a5268 __abort + 144
    3   libsystem_c.dylib               0x00007fff743a51d8 abort + 142
    4   libsystem_c.dylib               0x00007fff7436d868 __assert_rtn + 320
    5   com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103d6d197 swift::constraints::ConstraintSystem::getType(swift::VarDecl const*, bool) const + 135
    6   com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103d65ee0 swift::TypeChecker::getUnopenedTypeOfReference(swift::VarDecl*, swift::Type, swift::DeclContext*, llvm::function_ref<swift::Type (swift::VarDecl*)>, swift::DeclRefExpr const*, bool) + 32
    7   com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103d66833 swift::constraints::ConstraintSystem::getTypeOfReference(swift::ValueDecl*, swift::FunctionRefKind, swift::constraints::ConstraintLocatorBuilder, swift::DeclContext*, swift::DeclRefExpr const*) + 819
    8   com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103d68ced swift::constraints::ConstraintSystem::resolveOverload(swift::constraints::ConstraintLocator*, swift::Type, swift::constraints::OverloadChoice, swift::DeclContext*) + 1085
    9   com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103cf8017 swift::ASTVisitor<(anonymous namespace)::ConstraintGenerator, swift::Type, void, void, void, void, void>::visit(swift::Expr*) + 19911
    10  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103cfb87f (anonymous namespace)::ConstraintWalker::walkToExprPost(swift::Expr*) + 415
    11  com.apple.SourceKitService.4.2.2018100301_osx   0x000000010404626c swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 300
    12  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000104046877 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 1847
    13  com.apple.SourceKitService.4.2.2018100301_osx   0x00000001040489df (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr*) + 207
    14  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000104045af4 swift::Expr::walk(swift::ASTWalker&) + 84
    15  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103cf1e62 swift::constraints::ConstraintSystem::generateConstraints(swift::Expr*) + 418
    16  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103d2755c swift::constraints::ConstraintSystem::solveImpl(swift::Expr*&, swift::Type, swift::ExprTypeCheckListener*, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 476
    17  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103d2711f swift::constraints::ConstraintSystem::solve(swift::Expr*&, swift::Type, swift::ExprTypeCheckListener*, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 31
    18  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103dc6037 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 951
    19  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103dcb055 swift::TypeChecker::typeCheckBinding(swift::Pattern*&, swift::Expr*&, swift::DeclContext*, bool) + 357
    20  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103dcb331 swift::TypeChecker::typeCheckPatternBinding(swift::PatternBindingDecl*, unsigned int, bool) + 273
    21  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103de1505 validatePatternBindingEntries(swift::TypeChecker&, swift::PatternBindingDecl*) + 757
    22  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103ddd50e swift::TypeChecker::validateDecl(swift::ValueDecl*) + 2606
    23  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103dc57e7 findNonMembers(swift::TypeChecker&, llvm::ArrayRef<swift::LookupResultEntry>, swift::DeclRefKind, bool, llvm::SmallVectorImpl<swift::ValueDecl*>&, llvm::function_ref<bool (swift::ValueDecl*)>) + 215
    24  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103dc346a swift::TypeChecker::resolveDeclRefExpr(swift::UnresolvedDeclRefExpr*, swift::DeclContext*) + 650
    25  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103dcfc6a (anonymous namespace)::PreCheckExpression::walkToExprPre(swift::Expr*) + 442
    26  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000104046207 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 199
    27  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000104045af4 swift::Expr::walk(swift::ASTWalker&) + 84
    28  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103dc5dc7 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 327
    29  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103dcb668 swift::TypeChecker::typeCheckCondition(swift::Expr*&, swift::DeclContext*) + 184
    30  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103dcb7a5 swift::TypeChecker::typeCheckStmtCondition(llvm::MutableArrayRef<swift::StmtConditionElement>&, swift::DeclContext*, swift::Diag<>) + 245
    31  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103e53d17 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 2135
    32  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103e56108 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::Stmt>(swift::Stmt*&) + 136
    33  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103e535b7 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 247
    34  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103e527f8 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 136
    35  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103e525ac swift::TypeChecker::typeCheckClosureBody(swift::ClosureExpr*) + 268
    36  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103ca627b swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::Expr*, swift::Type, bool, bool) + 555
    37  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103dc60ec swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 1132
    38  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103dcb055 swift::TypeChecker::typeCheckBinding(swift::Pattern*&, swift::Expr*&, swift::DeclContext*, bool) + 357
    39  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103dcb331 swift::TypeChecker::typeCheckPatternBinding(swift::PatternBindingDecl*, unsigned int, bool) + 273
    40  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103de1505 validatePatternBindingEntries(swift::TypeChecker&, swift::PatternBindingDecl*) + 757
    41  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103dd99f4 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 884
    42  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103dd9676 swift::TypeChecker::typeCheckDecl(swift::Decl*) + 38
    43  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103e53683 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 451
    44  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103e527f8 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 136
    45  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103e51394 swift::TypeChecker::typeCheckFunctionBodyUntil(swift::FuncDecl*, swift::SourceLoc) + 260
    46  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103e74df2 swift::typeCheckAbstractFunctionBodyUntil(swift::AbstractFunctionDecl*, swift::SourceLoc) + 1186
    47  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103626e8c (anonymous namespace)::CodeCompletionCallbacksImpl::typeCheckContext(swift::DeclContext*) + 188
    48  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103626e09 (anonymous namespace)::CodeCompletionCallbacksImpl::typeCheckContext(swift::DeclContext*) + 57
    49  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103620aac (anonymous namespace)::CodeCompletionCallbacksImpl::doneParsing() + 2700
    50  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103f96420 (anonymous namespace)::ParseDelayedFunctionBodies::walkToDeclPre(swift::Decl*) + 288
    51  com.apple.SourceKitService.4.2.2018100301_osx   0x000000010404609b (anonymous namespace)::Traversal::doIt(swift::Decl*) + 171
    52  com.apple.SourceKitService.4.2.2018100301_osx   0x000000010404b40b (anonymous namespace)::Traversal::visitNominalTypeDecl(swift::NominalTypeDecl*) + 459
    53  com.apple.SourceKitService.4.2.2018100301_osx   0x00000001040460c8 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 216
    54  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000104045fdb swift::Decl::walk(swift::ASTWalker&) + 27
    55  com.apple.SourceKitService.4.2.2018100301_osx   0x00000001040fb54a swift::SourceFile::walk(swift::ASTWalker&) + 170
    56  com.apple.SourceKitService.4.2.2018100301_osx   0x00000001040fa05f swift::ModuleDecl::walk(swift::ASTWalker&) + 95
    57  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103f8dfe7 swift::performDelayedParsing(swift::DeclContext*, swift::PersistentParserState&, swift::CodeCompletionCallbacksFactory*) + 215
    58  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103610d09 swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t) + 841
    59  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000103610238 swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 616
    60  com.apple.SourceKitService.4.2.2018100301_osx   0x000000010347e89f swiftCodeCompleteImpl(SourceKit::SwiftLangSupport&, llvm::MemoryBuffer*, unsigned int, (anonymous namespace)::SwiftCodeCompletionConsumer&, llvm::ArrayRef<char const*>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) + 2511
    61  com.apple.SourceKitService.4.2.2018100301_osx   0x000000010347de63 SourceKit::SwiftLangSupport::codeComplete(llvm::MemoryBuffer*, unsigned int, SourceKit::CodeCompletionConsumer&, llvm::ArrayRef<char const*>) + 131
    62  com.apple.SourceKitService.4.2.2018100301_osx   0x00000001034dac32 handleSemanticRequest(sourcekitd::RequestDict, std::__1::function<void (void*)>, sourcekitd_uid_s*, llvm::Optional<llvm::StringRef>, llvm::Optional<llvm::StringRef>, llvm::ArrayRef<char const*>) + 818
    63  com.apple.SourceKitService.4.2.2018100301_osx   0x00000001034da87e void SourceKit::WorkQueue::DispatchData::callAndDelete<handleRequestImpl(void*, std::__1::function<void (void*)>)::$_4>(void*) + 142
    64  libdispatch.dylib               0x00007fff742aedcb _dispatch_client_callout + 8
    65  libdispatch.dylib               0x00007fff742b1b68 _dispatch_block_invoke_direct + 260
    66  com.apple.SourceKitService.4.2.2018100301_osx   0x0000000105f8251f executeBlock(void*) + 15
    67  com.apple.SourceKitService.4.2.2018100301_osx   0x000000010359d5cd ExecuteOnThread_Dispatch(void*) + 13
    68  libsystem_pthread.dylib         0x00007fff744ef33d _pthread_body + 126
    69  libsystem_pthread.dylib         0x00007fff744f22a7 _pthread_start + 70
    70  libsystem_pthread.dylib         0x00007fff744ee425 thread_start + 13
@nathawes
Copy link
Collaborator Author

@swift-ci create

@rintaro
Copy link
Mannequin

rintaro mannequin commented Oct 24, 2018

Reproduced without code-completion:

private struct Collector {
  init() {}

  func appending(_ result: Int) -> Collector {
    return self
  }
}

func testing(ary: [String]) {
  let result1 = ary 
    .compactMap { _ in
      result2.foo
    }
    .reduce(Collector()) { collector, result in collector.appending(result) }

  let result2 = result1.foobar
}

Probably, `result1` and `result2` are cross referencing.

@slavapestov
Copy link
Member

I incorrectly duped this to the other radar. It's a different issue.

@slavapestov
Copy link
Member

#25848

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added crash Bug: A crash, i.e., an abnormal termination of software compiler The Swift compiler in itself labels Dec 12, 2022
@AnthonyLatsis AnthonyLatsis added the source tooling Area: IDE support, SourceKit, and other source tooling label Feb 6, 2023
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. code completion Area → source tooling: code completion compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software source tooling Area: IDE support, SourceKit, and other source tooling
Projects
None yet
Development

No branches or pull requests

3 participants