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

Command CompileSwift failed with a nonzero exit code when accessing mutable dictionary of generics with associated types #63751

Closed
mohurwitzmusic opened this issue Feb 17, 2023 · 7 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself crash Bug: A crash, i.e., an abnormal termination of software duplicate Resolution: Duplicates another issue existential member accesses Feature → existentials: existential member accesses existentials Feature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased values swift 5.9 type checker Area → compiler: Semantic analysis

Comments

@mohurwitzmusic
Copy link

mohurwitzmusic commented Feb 17, 2023

Description

This fails to compile with error "Command CompileSwift failed with a nonzero exit code"

import Foundation

public protocol WidgetDictionary<T>: AnyObject {
    associatedtype T
    var widgets: [Int : T] { get set } // <--- Remove `set` and this will compile
}

class WidgetController {
    func getSimpleWidget(index: Int) -> SimpleWidget? {
        store.simpleWidgets.widgets[index] // <-- This is the line that causes the error
    }
    let store: WidgetStore
    init(store: WidgetStore) {
        self.store = store
    }
}

public protocol WidgetStore: AnyObject {
    var simpleWidgets: any SimpleWidgetDictionary { get }
}

public protocol SimpleWidget: AnyObject { }

public protocol SimpleWidgetDictionary: WidgetDictionary where T : SimpleWidget { }

Steps to reproduce

Remove set declaration to make the dictionary read-only and the code will compile successfully.

Environment

  • Swift compiler version info: Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
  • Xcode version info: Xcode 14.2 Build version 14C18
  • Deployment target: iOS v15

Dump
Stack dump:

0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file "/Users/moh/Developer/Temp Dev/GenericsBug/Sources/GenericsBug/GenericsBug.swift" -emit-dependencies-path /Users/moh/Library/Developer/Xcode/DerivedData/GenericsBug-exkgqdjwvgvzwdgutvaksddeqtoj/Build/Intermediates.noindex/GenericsBug.build/Debug-iphoneos/GenericsBug.build/Objects-normal/arm64/GenericsBug.d -emit-reference-dependencies-path /Users/moh/Library/Developer/Xcode/DerivedData/GenericsBug-exkgqdjwvgvzwdgutvaksddeqtoj/Build/Intermediates.noindex/GenericsBug.build/Debug-iphoneos/GenericsBug.build/Objects-normal/arm64/GenericsBug.swiftdeps -serialize-diagnostics-path /Users/moh/Library/Developer/Xcode/DerivedData/GenericsBug-exkgqdjwvgvzwdgutvaksddeqtoj/Build/Intermediates.noindex/GenericsBug.build/Debug-iphoneos/GenericsBug.build/Objects-normal/arm64/GenericsBug.dia -target arm64-apple-ios15.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.2.sdk -I /Users/moh/Library/Developer/Xcode/DerivedData/GenericsBug-exkgqdjwvgvzwdgutvaksddeqtoj/Build/Products/Debug-iphoneos -I /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib -F /Users/moh/Library/Developer/Xcode/DerivedData/GenericsBug-exkgqdjwvgvzwdgutvaksddeqtoj/Build/Products/Debug-iphoneos -F /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks -F /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.2.sdk/Developer/Library/Frameworks -no-color-diagnostics -enable-testing -g -module-cache-path /Users/moh/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -empty-abi-descriptor -Xcc -working-directory -Xcc "/Users/moh/Developer/Temp Dev/GenericsBug" -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -I/Users/moh/Library/Developer/Xcode/DerivedData/GenericsBug-exkgqdjwvgvzwdgutvaksddeqtoj/Build/Intermediates.noindex/GenericsBug.build/Debug-iphoneos/GenericsBug.build/swift-overrides.hmap -Xcc -I/Users/moh/Library/Developer/Xcode/DerivedData/GenericsBug-exkgqdjwvgvzwdgutvaksddeqtoj/Build/Products/Debug-iphoneos/include -Xcc -I/Users/moh/Library/Developer/Xcode/DerivedData/GenericsBug-exkgqdjwvgvzwdgutvaksddeqtoj/Build/Intermediates.noindex/GenericsBug.build/Debug-iphoneos/GenericsBug.build/DerivedSources-normal/arm64 -Xcc -I/Users/moh/Library/Developer/Xcode/DerivedData/GenericsBug-exkgqdjwvgvzwdgutvaksddeqtoj/Build/Intermediates.noindex/GenericsBug.build/Debug-iphoneos/GenericsBug.build/DerivedSources/arm64 -Xcc -I/Users/moh/Library/Developer/Xcode/DerivedData/GenericsBug-exkgqdjwvgvzwdgutvaksddeqtoj/Build/Intermediates.noindex/GenericsBug.build/Debug-iphoneos/GenericsBug.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -module-name GenericsBug -frontend-parseable-output -disable-clang-spi -target-sdk-version 16.2 -parse-as-library -o /Users/moh/Library/Developer/Xcode/DerivedData/GenericsBug-exkgqdjwvgvzwdgutvaksddeqtoj/Build/Intermediates.noindex/GenericsBug.build/Debug-iphoneos/GenericsBug.build/Objects-normal/arm64/GenericsBug.o -index-unit-output-path /GenericsBug.build/Debug-iphoneos/GenericsBug.build/Objects-normal/arm64/GenericsBug.o -index-store-path /Users/moh/Library/Developer/Xcode/DerivedData/GenericsBug-exkgqdjwvgvzwdgutvaksddeqtoj/Index.noindex/DataStore -index-system-modules
1.	Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
2.	Compiling with the current language version
3.	While evaluating request TypeCheckSourceFileRequest(source_file "/Users/moh/Developer/Temp Dev/GenericsBug/Sources/GenericsBug/GenericsBug.swift")
4.	While evaluating request TypeCheckFunctionBodyRequest(GenericsBug.(file).WidgetController.getSimpleWidget(index:)@/Users/moh/Developer/Temp Dev/GenericsBug/Sources/GenericsBug/GenericsBug.swift:10:10)
5.	While type-checking statement at [/Users/moh/Developer/Temp Dev/GenericsBug/Sources/GenericsBug/GenericsBug.swift:10:55 - line:12:5] RangeText="{
        store.simpleWidgets.widgets[index] // <-- This is the line that causes the error
    "
6.	While type-checking statement at [/Users/moh/Developer/Temp Dev/GenericsBug/Sources/GenericsBug/GenericsBug.swift:11:9 - line:11:42] RangeText="store.simpleWidgets.widgets[index"
7.	While type-checking expression at [/Users/moh/Developer/Temp Dev/GenericsBug/Sources/GenericsBug/GenericsBug.swift:11:9 - line:11:42] RangeText="store.simpleWidgets.widgets[index"
8.	While type-checking-target starting at /Users/moh/Developer/Temp Dev/GenericsBug/Sources/GenericsBug/GenericsBug.swift:11:36
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           0x0000000108d175b0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000108d165b4 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000108d17c34 SignalHandler(int) + 344
3  libsystem_platform.dylib 0x000000019ca1b4a4 _sigtramp + 56
4  swift-frontend           0x0000000104e3db34 (anonymous namespace)::ExprRewriter::coerceToType(swift::Expr*, swift::Type, swift::constraints::ConstraintLocatorBuilder, llvm::Optional<swift::Pattern*>) + 16868
5  swift-frontend           0x0000000104e3c8c4 (anonymous namespace)::ExprRewriter::coerceToType(swift::Expr*, swift::Type, swift::constraints::ConstraintLocatorBuilder, llvm::Optional<swift::Pattern*>) + 12148
6  swift-frontend           0x0000000104e605e4 (anonymous namespace)::ExprRewriter::closeExistential(swift::Expr*&, swift::constraints::ConstraintLocatorBuilder, bool) + 340
7  swift-frontend           0x0000000104e587bc (anonymous namespace)::ExprRewriter::buildMemberRef(swift::Expr*, swift::SourceLoc, swift::constraints::SelectedOverload, swift::DeclNameLoc, swift::constraints::ConstraintLocatorBuilder, swift::constraints::ConstraintLocatorBuilder, bool, swift::AccessSemantics) + 11204
8  swift-frontend           0x0000000104e45f4c swift::ASTVisitor<(anonymous namespace)::ExprRewriter, swift::Expr*, void, void, void, void, void>::visit(swift::Expr*) + 8156
9  swift-frontend           0x0000000104e40d54 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 24
10 swift-frontend           0x0000000105498650 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 632
11 swift-frontend           0x0000000104e36a74 (anonymous namespace)::ExprWalker::rewriteTarget(swift::constraints::SolutionApplicationTarget) + 376
12 swift-frontend           0x0000000104e365e8 swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::constraints::SolutionApplicationTarget) + 5852
13 swift-frontend           0x000000010509e100 swift::TypeChecker::typeCheckTarget(swift::constraints::SolutionApplicationTarget&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 688
14 swift-frontend           0x000000010509dde0 swift::TypeChecker::typeCheckExpression(swift::constraints::SolutionApplicationTarget&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 400
15 swift-frontend           0x000000010517d0fc swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 6116
16 swift-frontend           0x000000010517b88c bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::Stmt>(swift::Stmt*&) + 300
17 swift-frontend           0x0000000105178484 (anonymous namespace)::StmtChecker::typeCheckASTNode(swift::ASTNode&) + 80
18 swift-frontend           0x000000010517ba60 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 328
19 swift-frontend           0x000000010517a53c bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 300
20 swift-frontend           0x0000000105179388 swift::TypeCheckFunctionBodyRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*) const + 1276
21 swift-frontend           0x0000000105572e60 llvm::Expected<swift::TypeCheckFunctionBodyRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckFunctionBodyRequest>(swift::TypeCheckFunctionBodyRequest const&) + 588
22 swift-frontend           0x0000000105505e60 swift::TypeCheckFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType) + 116
23 swift-frontend           0x00000001051b5dac swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 792
24 swift-frontend           0x00000001051b895c llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 576
25 swift-frontend           0x00000001051b5a40 swift::performTypeChecking(swift::SourceFile&) + 120
26 swift-frontend           0x00000001043d6a60 bool llvm::function_ref<bool (swift::SourceFile&)>::callback_fn<swift::CompilerInstance::performSema()::$_6>(long, swift::SourceFile&) + 16
27 swift-frontend           0x00000001043d1158 swift::CompilerInstance::forEachFileToTypeCheck(llvm::function_ref<bool (swift::SourceFile&)>) + 164
28 swift-frontend           0x00000001043d1078 swift::CompilerInstance::performSema() + 148
29 swift-frontend           0x0000000104364180 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4364
30 swift-frontend           0x0000000104305294 swift::mainEntry(int, char const**) + 3940
31 dyld                     0x000000010b42908c start + 520

Tracked by rdar://104230391

@mohurwitzmusic mohurwitzmusic added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Feb 17, 2023
@xedin
Copy link
Contributor

xedin commented Feb 17, 2023

/cc @angela-laar I think we already have a radar for this, the "opened" base here is @lvalue type.

@xedin xedin added type checker Area → compiler: Semantic analysis compiler crash and removed triage needed This issue needs more specific labels labels Feb 17, 2023
@AnthonyLatsis
Copy link
Collaborator

AnthonyLatsis commented Feb 24, 2023

Simplified:

protocol P {}

protocol Q {
  associatedtype T: P
  var t: T { get set }
}

do {
  var qq: any Q
  let _: P = qq.t
}

This spun off from SE-0309.

@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler itself crash Bug: A crash, i.e., an abnormal termination of software existentials Feature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased values swift 5.9 labels Feb 24, 2023
@AnthonyLatsis AnthonyLatsis self-assigned this Feb 24, 2023
@angela-laar
Copy link
Contributor

angela-laar commented Feb 27, 2023

/cc @angela-laar I think we already have a radar for this, the "opened" base here is @lvalue type.

We do, added the radar to description 👍

@angela-laar
Copy link
Contributor

@AnthonyLatsis would you like to continue working on this?

@AnthonyLatsis
Copy link
Collaborator

I would, thanks for asking! But I'm open to collaboration if you'd like to as well. This is a part of SE-0309 that's yet to be implemented.

@angela-laar
Copy link
Contributor

Ok, I'll leave the bug to you! I'm happy to weigh in on the review once you've got a fix!

@AnthonyLatsis AnthonyLatsis added existential member accesses Feature → existentials: existential member accesses duplicate Resolution: Duplicates another issue labels Apr 14, 2023
@AnthonyLatsis
Copy link
Collaborator

Duplicate of #62219

@AnthonyLatsis AnthonyLatsis marked this as a duplicate of #62219 Apr 14, 2023
@AnthonyLatsis AnthonyLatsis closed this as not planned Won't fix, can't repro, duplicate, stale Apr 14, 2023
@AnthonyLatsis AnthonyLatsis removed their assignment Jul 5, 2024
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 itself crash Bug: A crash, i.e., an abnormal termination of software duplicate Resolution: Duplicates another issue existential member accesses Feature → existentials: existential member accesses existentials Feature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased values swift 5.9 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants