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

Swift: Add and use AbstractFunctionDecl.hasGlobalName predicate. #11034

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

geoffw0
Copy link
Contributor

@geoffw0 geoffw0 commented Oct 28, 2022

This allows us to concisely match a non-member function. At the moment its only used in one place but I expect there will be a lot more of this in future.

@geoffw0 geoffw0 added no-change-note-required This PR does not need a change note Swift labels Oct 28, 2022
@geoffw0 geoffw0 requested a review from a team as a code owner Oct 28, 2022
d10c
d10c previously approved these changes Oct 29, 2022
Copy link
Contributor

@d10c d10c left a comment

LGTM 👍

I was considering adding a GlobalFunctionDecl class (AbstractFunctionDecl minus MethodDecl), but I guess this predicate will subsume most of the usefulness of that class.

@MathiasVP
Copy link
Contributor

MathiasVP commented Oct 30, 2022

Is "global" the right terminology in a language that uses modules? After all, the function isn't global in the same sense that it's global in C/C++ since the function has an (implicit) enclosing module.

@d10c
Copy link
Contributor

d10c commented Oct 30, 2022

You're right. Another name for non-methods could be "free" functions instead of "global". But f.hasFreeName(...) sounds awkward, so another way to phrase it could be f.(FreeFunctionDecl).hasName(...)

@geoffw0
Copy link
Contributor Author

geoffw0 commented Oct 31, 2022

f.hasFreeName(...) sounds awkward, so another way to phrase it could be f.(FreeFunctionDecl).hasName(...)

I'm happy with either. @MathiasVP which do you prefer?

@MathiasVP
Copy link
Contributor

MathiasVP commented Oct 31, 2022

I'm happy with either. @MathiasVP which do you prefer?

I think I like f.(FreeFunctionDecl).hasName(...) more. We should really have such a function anyway so if it also makes the ergonomics easier in this case I think it's a strong argument for choosing this one 👍.

@geoffw0
Copy link
Contributor Author

geoffw0 commented Oct 31, 2022

Updated. And fixed the merge conflict. And I've added a bit more qldoc, though I'm not expecting to win any awards for:

/**
 * A function.
 */

Copy link
Contributor

@MathiasVP MathiasVP left a comment

😂. Yeah, we should revisit that QLDoc and provide proper examples. But the code LGTM, at least!

@geoffw0
Copy link
Contributor Author

geoffw0 commented Oct 31, 2022

("A function" is actually not saying nothing in this case; it's saying "Yeah, don't worry about that funky name AbstractFunctionDecl, this really is the class you want to represent a function")

@MathiasVP
Copy link
Contributor

MathiasVP commented Oct 31, 2022

("A function" is actually not saying nothing in this case; it's saying "Yeah, don't worry about that funky name AbstractFunctionDecl, this really is the class you want to represent a function")

Good point. That name should be changed eventually as well, though.

Labels
no-change-note-required This PR does not need a change note Swift
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants