Add more hooks for overriding name lookup in the DebuggerClient#23031
Add more hooks for overriding name lookup in the DebuggerClient#23031bgogul merged 7 commits intoswiftlang:masterfrom
Conversation
davidungar
left a comment
There was a problem hiding this comment.
This is a great goal! And I think I see that you are trying to pass the distinction about which lookupQualifed function was called into the debug client. But, I think there is likely a more readable way to do it. And I'm involved in refactoring lookup these days, so I have strong feelings about the readability here.
Here's why I think the code could be clearer: When I read the finishLookupIn* functions this PR adds, I had trouble figuring out 1. Why they were file-static, rather than members of the DeclContext or the debug client, and 2. What their purpose was. (A comment in front of each would have helped, but...)
Also, finishLookupIn* are names at the wrong level of abstraction for best readability because they are about the mechanics of the computation rather than what a user might think about.
It seems to me that each of these routines exists only to forward to an appropriate DebugClient routine. So, having criticized this factoring, what do I suggest? (Wait a moment while I scratch my head:)
First, I would rename the existing finishLookup to pruneResultSet, since that is what the comment says it does. But you don't have to do that if you don't want to.
When I look at, for instance, finishLookupInModule, I see that is first, pruning the results (by calling finishLookup), and then allowing the debug client to do something mysterious to the results--adding?, pruning??, replacing??--the name finishLookupInModule offers no clue. So, while I usually love factoring, in this case I cannot find a sensible abstraction for such a routine. Without more knowledge, I would suggest just open-coding the three functions at their call sites. On the other hand, if the debug client functions are pruning, then I would handle that by: renaming the existing finishLookup to pruneResults and adding a function parameter to pruneResults that would be the call into the debugger.
Does this make sense to you? I hope that together, we can figure out how to make this code as clear as possible. Thanks!
|
Thanks for the review, @davidungar!
Yes, I wanted the debugger client to have the context about what kind of qualified lookup is being processed. I considered adding a single interface hook with an appropriate set of arguments, but it seemed cleaner to have three distinct hooks.
I will be happy to make the changes needed to make it more readable. :)
Yes, that is its sole purpose.
Good idea. Done.
I have moved the body of these functions into the corresponding lookups. Given that the signature allows the debug client to do anything with
Yes. Thanks. |
|
@davidungar I have addressed your comments and suggestions. Can you take a look when you get a chance, please? |
include/swift/AST/NameLookup.h
Outdated
| @@ -369,8 +369,8 @@ void forAllVisibleModules(const DeclContext *DC, const Fn &fn) { | |||
|
|
|||
| /// Only name lookup has gathered a set of results, perform any necessary | |||
There was a problem hiding this comment.
Is there a typo? "Only" should be "Once"?
There was a problem hiding this comment.
You are right! It should be "Once". Fixed it now.
davidungar
left a comment
There was a problem hiding this comment.
Sorry I didn't see your ping earlier. (Feel free to email me directly next time.) Looks fine to me now, thanks! I did spot one typo in a comment--nothing you wrote, though. Not critical, but would be nice to fix it if you agree.
|
Thanks, @davidungar ! I fixed the typo and this PR is all set to be merged in, but I don't have permissions. Can you trigger tests and merge it in, please? |
|
@swift-ci please smoke test |
|
@davidungar, can I go ahead and merge this PR? |
Currently, lldb's REPL mode does not work well with extensions. Specifically, we cannot redefine an extension. Consider the following LLDB repl session:
As you can see redefining a function in an extension causes an ambiguous use diagnostic. This PR adds additional hooks into the DebuggerClient based on the discussion on the swift forum.
See apple/swift-lldb#1340 for how it is used in lldb.