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-15447] Assertion failure: no generic environment provided for type with type parameters #57752

Closed
ahoppen opened this issue Nov 5, 2021 · 5 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 found by stress tester Flag: An issue found by the SourceKit stress tester

Comments

@ahoppen
Copy link
Contributor

ahoppen commented Nov 5, 2021

Previous ID SR-15447
Radar rdar://85067320
Original Reporter @ahoppen
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, FoundByStressTester
Assignee @AnthonyLatsis
Priority Medium

md5: 5a803ec79d258c0383eef5a4d7f95843

Issue Description:

Type checking the following test case causes an assertion failure:

// RUN: %swift-frontend -typecheck %s

public extension Array {
    func chunked(into size: Int) -> [[Element]] {
        return stride(from: 0, to: count, by: size).map { elt in
            self[elt


public extension Array where Element == Item {
    mutating func toggle(item: Item) -> Bool {
        _ = contains(item)
    }
}

Stack trace:

Assertion failed: ((env || !type->hasTypeParameter()) && "no generic environment provided for type with type parameters"), function mapTypeIntoContext, file GenericEnvironment.cpp, line 91.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.  Program arguments: /Users/alex/swift-src/mbuild/Release+Asserts/swift-macosx-x86_64/bin/swift-frontend -module-cache-path /Users/alex/swift-src/mbuild/Release+Asserts/swift-macosx-x86_64/swift-test-results/x86_64-apple-macosx10.9/clang-module-cache -disable-objc-attr-requires-foundation-module -swift-version 4 -define-availability "SwiftStdlib 5.5:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0-frontend" -typecheck /Users/alex/swift-src/swift/test/Array.swift
1.  Swift version 5.6-dev (LLVM 3f1736177ffe15c, Swift 14be9e71fa4a958)
2.  Compiling with effective version 4.1.50
3.  While evaluating request TypeCheckSourceFileRequest(source_file "/Users/alex/swift-src/swift/test/Array.swift")
4.  While evaluating request TypeCheckFunctionBodyRequest(Array.(file).Array extension.chunked(into:).explicit closure discriminator=0.Array extension.toggle(item:)@/Users/alex/swift-src/swift/test/Array.swift:10:19)
5.  While type-checking statement at [/Users/alex/swift-src/swift/test/Array.swift:10:46 - line:12:5] RangeText="{
        _ = contains(item)
    "
6.  While type-checking expression at [/Users/alex/swift-src/swift/test/Array.swift:11:9 - line:11:26] RangeText="_ = contains(item"
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x00000001128c5d07 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  swift-frontend           0x00000001128c4c28 llvm::sys::RunSignalHandlers() + 248
2  swift-frontend           0x00000001128c6350 SignalHandler(int) + 288
3  libsystem_platform.dylib 0x00007ff81cd17e2d _sigtramp + 29
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603370097443312
5  libsystem_c.dylib        0x00007ff81cc4ed10 abort + 123
6  libsystem_c.dylib        0x00007ff81cc4e0be err + 0
7  swift-frontend           0x0000000112dfc161 swift::GenericEnvironment::mapTypeIntoContext(swift::GenericEnvironment*, swift::Type) (.cold.2) + 33
8  swift-frontend           0x000000010ec138f2 swift::GenericEnvironment::mapTypeIntoContext(swift::GenericEnvironment*, swift::Type) + 98
9  swift-frontend           0x000000010e856ce1 swift::TypeChecker::lookupUnqualified(swift::DeclContext*, swift::DeclNameRef, swift::SourceLoc, swift::OptionSet<swift::NameLookupFlags, unsigned int>) + 657
10 swift-frontend           0x000000010e79a92e swift::TypeChecker::resolveDeclRefExpr(swift::UnresolvedDeclRefExpr*, swift::DeclContext*, bool) + 1134
11 swift-frontend           0x000000010e79e662 (anonymous namespace)::PreCheckExpression::walkToExprPre(swift::Expr*) + 1154
12 swift-frontend           0x000000010eac1bb9 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 281
13 swift-frontend           0x000000010eac206a swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 1482
14 swift-frontend           0x000000010eac12f9 swift::Expr::walk(swift::ASTWalker&) + 73
15 swift-frontend           0x000000010e79d9da swift::constraints::ConstraintSystem::preCheckExpression(swift::Expr*&, swift::DeclContext*, bool) + 250
16 swift-frontend           0x000000010e7f4624 swift::TypeChecker::typeCheckExpression(swift::constraints::SolutionApplicationTarget&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 196
17 swift-frontend           0x000000010e7f44de swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::constraints::ContextualTypeInfo, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 78
18 swift-frontend           0x000000010e8ad285 (anonymous namespace)::StmtChecker::typeCheckASTNode(swift::ASTNode&) + 229
19 swift-frontend           0x000000010e8af25c swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 124
20 swift-frontend           0x000000010e8ae4b3 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 131
21 swift-frontend           0x000000010e8ada19 swift::TypeCheckFunctionBodyRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*) const + 937
22 swift-frontend           0x000000010ebbc19f llvm::Expected<swift::TypeCheckFunctionBodyRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckFunctionBodyRequest>(swift::TypeCheckFunctionBodyRequest const&) + 415
23 swift-frontend           0x000000010ebbbf3b llvm::Expected<swift::TypeCheckFunctionBodyRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckFunctionBodyRequest, (void*)0>(swift::TypeCheckFunctionBodyRequest const&) + 107
24 swift-frontend           0x000000010eb1c513 swift::TypeCheckFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType) + 35
25 swift-frontend           0x000000010e8dd558 swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 328
26 swift-frontend           0x000000010e8df280 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 416
27 swift-frontend           0x000000010e8df034 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckSourceFileRequest, (void*)0>(swift::TypeCheckSourceFileRequest const&) + 100
28 swift-frontend           0x000000010e8dd31f swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType) + 31
29 swift-frontend           0x000000010dbad89e swift::CompilerInstance::forEachFileToTypeCheck(llvm::function_ref<void (swift::SourceFile&)>) + 158
30 swift-frontend           0x000000010dbad74a swift::CompilerInstance::performSema() + 74
31 swift-frontend           0x000000010da3f9b0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 5984
32 swift-frontend           0x000000010da08a17 swift::mainEntry(int, char const**) + 503
33 dyld                     0x00000001283034fe start + 462
34 dyld                     000000000000000000 start + 18446744068740336848
35 swift-frontend           0x000000010d9e8000 __dso_handle + 0
/Users/alex/swift-src/mbuild/Release+Asserts/swift-macosx-x86_64/test-macosx-x86_64/Output/Array.swift.script: line 1: 49432 Abort trap: 6           '/Users/alex/swift-src/mbuild/Release+Asserts/swift-macosx-x86_64/bin/swift-frontend' -module-cache-path /Users/alex/swift-src/mbuild/Release+Asserts/swift-macosx-x86_64/swift-test-results/x86_64-apple-macosx10.9/clang-module-cache -disable-objc-attr-requires-foundation-module -swift-version 4 -define-availability 'SwiftStdlib 5.5:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0'-frontend -typecheck /Users/alex/swift-src/swift/test/Array.swift
@ahoppen
Copy link
Contributor Author

ahoppen commented Nov 5, 2021

CC @AnthonyLatsis

This seems to have been caused by #39898

@slavapestov
Copy link
Member

I would still prefer we keep Anthony's cleanup; this code is highly invalid with an extension nested inside of a function body, which violates numerous invariants, and we should try to avoid the assertion further upstream.

@AnthonyLatsis
Copy link
Collaborator

Thanks Alex! Looking into this..

@AnthonyLatsis
Copy link
Collaborator

#40082

@ahoppen
Copy link
Contributor Author

ahoppen commented Nov 9, 2021

Thanks for the quick fix @AnthonyLatsis!

@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 found by stress tester Flag: An issue found by the SourceKit stress tester
Projects
None yet
Development

No branches or pull requests

3 participants