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-13766] Index store does not correctly relate variable type #56163

Closed
swift-ci opened this issue Oct 22, 2020 · 7 comments · Fixed by #38883
Closed

[SR-13766] Index store does not correctly relate variable type #56163

swift-ci opened this issue Oct 22, 2020 · 7 comments · Fixed by #38883
Labels
compiler The Swift compiler in itself feature A feature request or implementation indexing Area → source tooling: AST indexing properties Feature: properties source tooling Area: IDE support, SourceKit, and other source tooling

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-13766
Radar rdar://problem/70580256
Original Reporter Leitch (JIRA User)
Type New Feature
Status Resolved
Resolution Done
Environment

Apple Swift version 5.3.1 (swiftlang-1200.0.41 clang-1200.0.32.8)
Target: x86_64-apple-darwin19.6.0

Additional Detail from JIRA
Votes 0
Component/s Source Tooling
Labels New Feature
Assignee Leitch (JIRA)
Priority Medium

md5: 13adb7e503bedbfaa01d84ad75c17d0f

Issue Description:

class MyClass1 {}

public class MyClass2 {
    var someVar: MyClass1?
}

The index store contains an occurrence for `MyClass1` with a `reference` role, however said occurrence does not have any associated relations that tie it to `someVar`. The occurrence is therefore "dangling" or "toplevel", however you want to call it.

The full dependency graph is as follows:

Declaration(class, 'MyClass1', explicit, internal, [], 's:17RetentionFixtures8MyClass1C', testClassRetainedByUnusedInstanceVariable.swift:3:7)
··Declaration(function.constructor, 'init()', explicit, internal, [], 's:17RetentionFixtures8MyClass1CACycfc', testClassRetainedByUnusedInstanceVariable.swift:3:7)

Reference(class, 'MyClass1', 's:17RetentionFixtures8MyClass1C', nil, testClassRetainedByUnusedInstanceVariable.swift:6:18)

Declaration(class, 'MyClass2', explicit, public, [public], 's:17RetentionFixtures8MyClass2C', testClassRetainedByUnusedInstanceVariable.swift:5:14)
··Declaration(var.instance, 'someVar', explicit, internal, [], 's:17RetentionFixtures8MyClass2C7someVarAA0C6Class1CSgvp', testClassRetainedByUnusedInstanceVariable.swift:6:9)
··Declaration(function.constructor, 'init()', explicit, internal, [], 's:17RetentionFixtures8MyClass2CACycfc', testClassRetainedByUnusedInstanceVariable.swift:5:14)

Declaration(function.accessor.getter, 'getter:someVar', explicit, internal, [], 's:17RetentionFixtures8MyClass2C7someVarAA0C6Class1CSgvg', testClassRetainedByUnusedInstanceVariable.swift:6:9)
··Reference(var.instance, 'someVar', 's:17RetentionFixtures8MyClass2C7someVarAA0C6Class1CSgvp', nil, testClassRetainedByUnusedInstanceVariable.swift:6:9)

Declaration(function.accessor.setter, 'setter:someVar', explicit, internal, [], 's:17RetentionFixtures8MyClass2C7someVarAA0C6Class1CSgvs', testClassRetainedByUnusedInstanceVariable.swift:6:9)
··Reference(var.instance, 'someVar', 's:17RetentionFixtures8MyClass2C7someVarAA0C6Class1CSgvp', nil, testClassRetainedByUnusedInstanceVariable.swift:6:9)

I'm expecting the dependency graph for 'MyClass2' to be as follows:

Declaration(class, 'MyClass2', explicit, public, [public], 's:17RetentionFixtures8MyClass2C', testClassRetainedByUnusedInstanceVariable.swift:5:14)
··Declaration(var.instance, 'someVar', explicit, internal, [], 's:17RetentionFixtures8MyClass2C7someVarAA0C6Class1CSgvp', testClassRetainedByUnusedInstanceVariable.swift:6:9)
····Reference(class, 'MyClass1', 's:17RetentionFixtures8MyClass1C', nil, testClassRetainedByUnusedInstanceVariable.swift:6:18)
··Declaration(function.constructor, 'init()', explicit, internal, [], 's:17RetentionFixtures8MyClass2CACycfc', testClassRetainedByUnusedInstanceVariable.swift:5:14)
@swift-ci
Copy link
Collaborator Author

Comment by Ian Leitch (JIRA)

/cc @benlangmuir

@benlangmuir
Copy link
Member

What is your use case for this new relation? Keep in mind it would not be sufficient for determining the type of the variable in general, because we do not have a representation of structured types in the index.

For example, the following all reference Int inside of types, but it doesn't tell you much about the type of the variable.

var a: (Int, String)
var b: (Int) -> ()
var c: Array<Int>
var d: Int?

@akyrtzi
Copy link
Member

akyrtzi commented Oct 22, 2020

It should have 'container' relationship with the property. This is what clang is doing.

@akyrtzi
Copy link
Member

akyrtzi commented Oct 22, 2020

Though @benlangmuir's point still stands that even with 'container' relationship it's not enough to determine the actual type.

@swift-ci
Copy link
Collaborator Author

Comment by Ian Leitch (JIRA)

My use case is detecting unused code. I'm not interested in the type information so much, I just need to know that `someVar` references `MyClass1`, which isn't currently possible since the reference isn't contained under the `someVar` declaration.

@benlangmuir
Copy link
Member

@swift-ci create

@swift-ci
Copy link
Collaborator Author

swift-ci commented Aug 6, 2021

Comment by Ian Leitch (JIRA)

I've started a discussion on the forums regarding this issue: https://forums.swift.org/t/why-isnt-patternbindingdecl-scoped-within-vardecl/50994

@benlangmuir @akyrtzi perhaps you've some thoughts to share?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler in itself feature A feature request or implementation source tooling Area: IDE support, SourceKit, and other source tooling indexing Area → source tooling: AST indexing properties Feature: properties and removed new feature labels Feb 25, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself feature A feature request or implementation indexing Area → source tooling: AST indexing properties Feature: properties source tooling Area: IDE support, SourceKit, and other source tooling
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants