swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.57k stars 10.36k forks source link

Swift 6 index store missing related references for overriding decls #76628

Open ileitch opened 1 month ago

ileitch commented 1 month ago

Description

Index stores produced by Swift 6 are missing related references for overridden external declarations.

This is a problematic change for Periphery and potentially other tools as it makes it harder to determine whether the overriding function overrides a function declared elsewhere in a project or one that is external.

Reproduction

Given the following snippet:

import UIKit

class ViewController: UIViewController {
    override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
        super.traitCollectionDidChange(previousTraitCollection)
    }
}

With Swift 6, the related reference for the overridden function is missing:

Declaration(class, 'ViewController', explicit, internal, [], [], [], [c:@M@PeripheryExample@objc(cs)ViewController], ViewController.swift:3:7)
··Related(function.method.instance, 'traitCollectionDidChange(_:)', 'c:objc(pl)UITraitEnvironment(im)traitCollectionDidChange:', ViewController.swift:3:7)
··Declaration(function.method.instance, 'traitCollectionDidChange(_:)', explicit, internal, [override], [], [], [c:@M@PeripheryExample@objc(cs)ViewController(im)traitCollectionDidChange:], ViewController.swift:4:19)
····Reference(class, 'UITraitCollection', 'c:objc(cs)UITraitCollection', ViewController.swift:4:71)

Expected behavior

Swift 5.10 produces a related reference for the overridden function contained by the overriding function:

Declaration(class, 'ViewController', explicit, internal, [], [], [], [c:@M@PeripheryExample@objc(cs)ViewController], ViewController.swift:3:7)
··Related(function.method.instance, 'traitCollectionDidChange(_:)', 'c:objc(pl)UITraitEnvironment(im)traitCollectionDidChange:', ViewController.swift:3:7)
··Declaration(function.method.instance, 'traitCollectionDidChange(_:)', explicit, internal, [override], [], [], [c:@M@PeripheryExample@objc(cs)ViewController(im)traitCollectionDidChange:], ViewController.swift:4:19)
····Related(function.method.instance, 'traitCollectionDidChange(_:)', 'c:objc(pl)UITraitEnvironment(im)traitCollectionDidChange:', ViewController.swift:4:19)
····Reference(class, 'UITraitCollection', 'c:objc(cs)UITraitCollection', ViewController.swift:4:71)

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4) Target: arm64-apple-macosx14.0

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2) Target: arm64-apple-macosx14.0

Additional information

No response

ileitch commented 5 days ago

@bnbarham Maybe this is of interest to you?

bnbarham commented 4 days ago

Ah, thanks for the ping @ileitch. I'm fairly sure this is https://github.com/swiftlang/swift/issues/67446 - traitCollectionDidChange is defined in @protocol UITraitEnvironment. Though I'm somewhat surprised it worked in 5.10 since that issue was filed before 5.10 branched. Would you be able to confirm a recent main snapshot fixes things for you?