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-13756] Abort: 6 when type checking an array expression that contains tuples of implicit enum instances. #56153

Closed
swift-ci opened this issue Oct 20, 2020 · 6 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-13756
Radar rdar://problem/70488315
Original Reporter roydaw (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)
Target: x86_64-apple-darwin19.6.0

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

md5: a7630044c526c1ecdaff2240ef721db2

duplicates:

  • SR-13364 keypath missing optional crashes compiler: "Inactive constraints left over?"

Issue Description:

The below Swift code causes Abort: 6

enum Enum {
    case one, two, three, four, five
}

var include: [Enum] = [
    (.one, true),
    (.two, false),
    (.three, true),
    (.four, false),
    (.five, false)
].filter(\.1).map(\.0)

Here is the output from running `swiftc`

Score: 2 0 0 0 0 0 0 0 0 1 0 5 0 0
Contextual Type: [Enum] at [main.swift:5:14 - line:5:19]
Type Variables:
  $T20 [noescape allowed] as [$T50] @ locator@0x7fadb9c8c910 [Array@main.swift:5:23]
  $T21 [lvalue allowed] [noescape allowed] as (($T50) throws -> Bool) throws -> [$T50] @ locator@0x7fadb9c8cd48 [UnresolvedDot@main.swift:11:3 -> member]
  $T22 as Any @ locator@0x7fadb9c8ce10 [KeyPath@main.swift:11:10 -> key path root]
  $T23 [lvalue allowed] [noescape allowed] as Bool @ locator@0x7fadb9c8ceb8 [KeyPath@main.swift:11:10 -> key path component #​0 -> key path component result]
  $T24 [noescape allowed] as Bool @ locator@0x7fadb9c8cf80 [KeyPath@main.swift:11:10 -> key path value]
  $T25 [noescape allowed] as ($T50) throws -> Bool @ locator@0x7fadb9c8d040 [KeyPath@main.swift:11:10 -> key path type]
  $T26 [noescape allowed] as [$T50] @ locator@0x7fadb9c8d158 [Call@main.swift:11:3 -> function result]
  $T27 [lvalue allowed] [noescape allowed] as (($T22) throws -> $T53) throws -> [$T53] @ locator@0x7fadb9c8d280 [UnresolvedDot@main.swift:11:15 -> member]
  $T28 [noescape allowed] equivalent to $T22 @ locator@0x7fadb9c8d340 [KeyPath@main.swift:11:19 -> key path root]
  $T30 as Enum @ locator@0x7fadb9c8d4b0 [KeyPath@main.swift:11:19 -> key path value]
  $T31 [noescape allowed] as ($T22) throws -> $T53 @ locator@0x7fadb9c8d570 [KeyPath@main.swift:11:19 -> key path type]
  $T32 [noescape allowed] as [$T53] @ locator@0x7fadb9ca5ec8 [Call@main.swift:11:15 -> function result]
  $T50 equivalent to $T22 @ locator@0x7fadb9ca6168 [Array@main.swift:5:23 -> generic parameter 'Element']
  $T51 as [$T50] @ locator@0x7fadb9ca67d0 [UnresolvedDot@main.swift:11:3 -> member -> generic parameter 'Self']
  $T52 as [$T22] @ locator@0x7fadb9d9d670 [UnresolvedDot@main.swift:11:15 -> member -> generic parameter 'Self']
  $T53 equivalent to $T30 @ locator@0x7fadb9d9d6d0 [UnresolvedDot@main.swift:11:15 -> member -> generic parameter 'T']

Active Constraints:

Inactive Constraints:
  $T25 key path from $T22 -> $T24 [[locator@0x7fadb9c8ce30 [KeyPath@main.swift:11:10]]];
Resolved overloads:
  selected overload set choice [$T50].filter: $T21 == (($T51.Element) throws -> Bool) throws -> $T51
  selected overload set choice [$T22].map: $T27 == (($T52.Element) throws -> $T53) throws -> [$T53]


Opened types:
  locator@0x7fadb9c8cd48 [UnresolvedDot@main.swift:11:3 -> member] opens τ_0_0 -> $T51
  locator@0x7fadb9c8d280 [UnresolvedDot@main.swift:11:15 -> member] opens τ_1_0 -> $T53, τ_0_0 -> $T52

Defaulted constraints: locator@0x7fadb9c8c910 [Array@main.swift:5:23]
Fixes:
  [fix: define missing member named '0' based on its use] @ locator@0x7fadb9c8d3c8 [KeyPath@main.swift:11:19 -> key path component #​0]
  [fix: define missing member named '1' based on its use] @ locator@0x7fadb9c8ce98 [KeyPath@main.swift:11:10 -> key path component #​0]
<unknown>:0: error: fatal error encountered during compilation; please file a bug report with your project and the crash log
<unknown>:0: note: Inactive constraints left over?
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file main.swift -target x86_64-apple-darwin19.6.0 -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -target-sdk-version 10.15.6 -module-name main -o /var/folders/pj/b_26vq4x44ggt2xxfv06bks00000gn/T/main-b1efd5.o 
1.  Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)
2.  While evaluating request TypeCheckSourceFileRequest(source_file "main.swift")
3.  While type-checking statement at [main.swift:5:1 - line:11:22] RangeText="var include: [Enum] = [
    (.one, true),
    (.two, false),
    (.three, true),
    (.four, false),
    (.five, false)
].filter(\.1).map(\.0"
4.  While type-checking declaration 0x7fadba0e5bd0 (at main.swift:5:1)
5.  While type-checking expression at [main.swift:5:23 - line:11:22] RangeText="[
    (.one, true),
    (.two, false),
    (.three, true),
    (.four, false),
    (.five, false)
].filter(\.1).map(\.0"
0  swift                    0x000000011382e865 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x000000011382d865 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x000000011382ee1f SignalHandler(int) + 111
3  libsystem_platform.dylib 0x00007fff6f6f75fd _sigtramp + 29
4  libsystem_platform.dylib 0x00007ffee090b020 _sigtramp + 18446744071312587328
5  libsystem_c.dylib        0x00007fff6f5cd808 abort + 120
6  swift                    0x000000010f39663f swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*)::$_1::__invoke(void*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool) + 1151
7  swift                    0x00000001137adc4a llvm::report_fatal_error(llvm::Twine const&, bool) + 234
8  swift                    0x00000001137adb52 llvm::report_fatal_error(char const*, bool) + 50
9  swift                    0x000000011010a0fa swift::constraints::ComponentStep::take(bool) + 5802
10 swift                    0x00000001100f8974 swift::constraints::ConstraintSystem::solveImpl(llvm::SmallVectorImpl<swift::constraints::Solution>&) + 356
11 swift                    0x000000011017b169 swift::constraints::ConstraintSystem::salvage() + 185
12 swift                    0x00000001100fafad swift::constraints::ConstraintSystem::solve(swift::constraints::SolutionApplicationTarget&, swift::FreeTypeVariableBinding) + 1821
13 swift                    0x00000001102389ef swift::TypeChecker::typeCheckExpression(swift::constraints::SolutionApplicationTarget&, bool&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 799
14 swift                    0x000000011023a167 swift::TypeChecker::typeCheckBinding(swift::Pattern*&, swift::Expr*&, swift::DeclContext*, swift::Type, swift::PatternBindingDecl*, unsigned int) + 151
15 swift                    0x000000011023a350 swift::TypeChecker::typeCheckPatternBinding(swift::PatternBindingDecl*, unsigned int, swift::Type) + 256
16 swift                    0x000000011028f755 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 5237
17 swift                    0x000000011031da97 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 8695
18 swift                    0x000000011031947a bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 314
19 swift                    0x0000000110319645 swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 261
20 swift                    0x0000000110356648 swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 792
21 swift                    0x00000001103594a9 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 953
22 swift                    0x00000001103561a4 swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType) + 164
23 swift                    0x000000010f4d13b7 swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 6439
24 swift                    0x000000010f3922fd swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6845
25 swift                    0x000000010f316c07 main + 1255
26 libdyld.dylib            0x00007fff6f4fecc9 start + 1
<unknown>:0: error: unable to execute command: Abort trap: 6
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)

Expected behavior:
It's not clear to me whether Swift should be able to compile this kind of expression. Currently, it is easy enough to modify the code to give Swift enough context to compile it by prefixing the value in the first tuple with `Enum`

enum Enum {
    case one, two, three, four, five
}

var include: [Enum] = [
    (Enum.one, true),
    (.two, false),
    (.three, true),
    (.four, false),
    (.five, false)
].filter(\.1).map(\.0)
@typesanitizer
Copy link

@swift-ci create

@xedin
Copy link
Member

xedin commented Oct 21, 2020

@hamishknight Would you like to take a look at this one?

@LucianoPAlmeida
Copy link
Collaborator

@xedin It is this somehow similar to SR-13364? Seems like in both cases a KeyPath constraint is left unsolved ...

@LucianoPAlmeida
Copy link
Collaborator

Right, just by a quick test seems like similar to SR-13364 delaying the binding of key path type until root and base value are bounded fixes it, but it was only a quick test while working on another issue, so not sure if thats a good solution(or even a solution) but maybe this can help 🙂

@xedin
Copy link
Member

xedin commented Oct 23, 2020

Yeah, it looks like a dupe, I think the root cause here is that we keep re-introducing key path constraint (probably because not all of the references have been resolved) which ends up biting us at the end.

@hamishknight
Copy link
Collaborator

Yeah this is a dupe

@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
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

5 participants