Skip to content

[Sema] Consolidate logic for whether a decl has a curried self or parameter list #25170

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

Merged
merged 10 commits into from
Jun 18, 2019

Conversation

hamishknight
Copy link
Contributor

This PR adds ValueDecl::hasCurriedSelf and ValueDecl::hasParameterList that return whether a given declaration has a curried self parameter in its interface type and whether it has a parameter list, respectively. These members are then used in a couple of places where this logic is duplicated, as well as to fix a code completion bug.

In addition, this PR tweaks isDeclAsSpecializedAs so that it could compare decls that differ by curry level if it needed to. This case doesn't currently come up though, so this should be NFC.

Finally, this PR has a couple of straightforward NFC cleanups.

Resolves SR-10795.

Use this function to replace various places where the logic is
duplicated.

In addition, isolate the logic where subscripts are treated as having
curried self parameters to CalleeCandidateInfo, as their interface types
don't have a curried self, but get curried with self by
CalleeCandidateInfo. Ideally we'd fix this by having a subscript's
interface type be curried with self, but given that most of this CSDiag
logic should be going away, this may not be necessary.
While it's currently not possible for `isDeclAsSpecializedAs` to compare
decls that differ by having a curried self or having a parameter list,
tweak the logic slightly so it could handle that case if it needed to.

If one decl has a parameter list and the other doesn't, then just
compare their self types. If one decl is curried and the other isn't,
then add a curried self to the other and compare as normal.
@xedin xedin self-requested a review May 31, 2019 17:19
@slavapestov
Copy link
Contributor

Cool!

Is it worth using this in SILDeclRef::getParameterListCount()?

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you! I have left a small comment inline.

@hamishknight
Copy link
Contributor Author

@slavapestov Good idea! I actually just noticed that we're duplicating the logic for how many curry levels a decl has in a bunch of places, so added ValueDecl::getNumCurryLevels.

@slavapestov
Copy link
Contributor

@hamishknight Thanks!

Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great

@slavapestov
Copy link
Contributor

@swift-ci Please test

@slavapestov
Copy link
Contributor

@swift-ci Please test source compatibility

@swift-ci
Copy link
Contributor

swift-ci commented Jun 1, 2019

Build failed
Swift Test Linux Platform
Git Sha - 71eb43a

@swift-ci
Copy link
Contributor

swift-ci commented Jun 1, 2019

Build failed
Swift Test OS X Platform
Git Sha - 71eb43a

@hamishknight
Copy link
Contributor Author

LLDB failure for OS X looks unrelated, also observed in https://ci.swift.org/job/swift-PR-osx/13822/.

@slavapestov
Copy link
Contributor

@swift-ci Please smoke test macOS

@hamishknight
Copy link
Contributor Author

Just found a 5.1 regression (SR-10843) related to this logic, so pushed a fix (I'll also open a 5.1 PR in a bit). Could you please re-run the CI when it comes back up?

- Add a precondition on `doesDeclRefApplyCurriedSelf` to expect
a member decl, and rename it to make the precondition explicit.

- Don't assume that not having a base type means this isn't a member
reference, as member references to static operators don't have base
types.

Resolves SR-10843.
@hamishknight hamishknight force-pushed the a-couple-of-tangents branch from 277f9b2 to 356b3b4 Compare June 6, 2019 16:04
@hamishknight
Copy link
Contributor Author

Opened a 5.1 PR for SR-10843: #25288.

hamishknight added a commit to hamishknight/swift that referenced this pull request Jun 13, 2019
@xedin
Copy link
Contributor

xedin commented Jun 13, 2019

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 623a6ad

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 277f9b222c21218833d0d4be1ecce1202d0df729

@hamishknight
Copy link
Contributor Author

Linux failure appears to be unrelated

@xedin
Copy link
Contributor

xedin commented Jun 13, 2019

@swift-ci please test Linux platform

@xedin
Copy link
Contributor

xedin commented Jun 18, 2019

@swift-ci please smoke test and merge

1 similar comment
@xedin
Copy link
Contributor

xedin commented Jun 18, 2019

@swift-ci please smoke test and merge

@hamishknight
Copy link
Contributor Author

Had to resolve a merge conflict with #25359, could you please try again?

@xedin
Copy link
Contributor

xedin commented Jun 18, 2019

@swift-ci please smoke test and merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants