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-11079] swiftc hang probably related to non-hashable subscript index in keypath #53471

Open
mayoff opened this issue Jul 8, 2019 · 2 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 key paths Feature: key paths (both native and Objective-C) type checker Area → compiler: Semantic analysis

Comments

@mayoff
Copy link

mayoff commented Jul 8, 2019

Previous ID SR-11079
Radar None
Original Reporter @mayoff
Type Bug
Environment

macOS Catalina beta 3 (10.15 Beta (19A501i))

Xcode 11 beta 3 (Version 11.0 beta 3 (11M362v))

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

md5: 588c5ee0915d4b9a964418b23bcc1156

Issue Description:

Here's the test case:

import SwiftUI
func f<Doodad>(_ type: Doodad.Type) {
    let kp = \EnvironmentValues.[doodadFor: type]
} 

When I compile this on Catalina beta 3 (10.15 Beta (19A501i)) with the swiftc from Xcode 11 beta 3 (Version 11.0 beta 3 (11M362v)), the compiler hangs:

:; time xcrun swiftc -c hang.swift
^C

real    0m15.842s
user    0m15.542s
sys 0m0.270s 

I tried to simplify the test case by removing the use of SwiftUI as follows:

extension Int {
    subscript<Doodad>(doodadFor type: Doodad.Type) -> Void { () }
}
func f<Doodad>(_ type: Doodad.Type) {
    let kp = \Int.[doodadFor: type]
} 

But this doesn't make swiftc hang. Instead it emits an error and exits:

:; time swiftc -c Doodad.swift 
Doodad.swift:8:19: error: subscript index of type 'Doodad.Type' in a key path must be Hashable
    let kp = \Int.[doodadFor: type]
                  ^

real    0m0.219s
user    0m0.065s
sys 0m0.145s 

This leads me to believe that the hang is triggered in some way by Doodad.Type's lack of conformance to Hashable, but I don't know what's special about EnvironmentValues.

Note also that in the hanging case, I don't actually have to define subscript(doodadFor🙂 to make swiftc hang. Defining it doesn't lead swiftc to terminate.

@belkadan
Copy link
Contributor

belkadan commented Jul 8, 2019

@xedin, @jckarter, does this sound familiar?

@xedin
Copy link
Member

xedin commented Jul 11, 2019

Hm, from the constraint system output it looks like we are trying to bind result of a keypath and constantly failing while trying to produce diagnostics. You are right about missing conformance to Hashable though, that's what the problem is here.

@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
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 key paths Feature: key paths (both native and Objective-C) type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants