Skip to content

[SwiftLexicalLookup] Add dollar identifier, better extension handling and more ASTScope related fixes #2877

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

Conversation

MAJKFL
Copy link
Contributor

@MAJKFL MAJKFL commented Oct 9, 2024

This PR brings more ASTScope related fixes to SwiftLexicalLookup. Those include:

  • Prompting clients to lookup generic parameters of extended types inside extensions with LookupResult.lookInGenericParametersOfExtendedType.
  • Dollar identifier handling through LookupResult.mightIntroduceDollarIdentifiers result kind when looking up for identifier = nil and more explicit LookupName.dollarIdentifier when looking up for a particular dollar identifier.
  • Remove member and file scope handling to avoid confusion and incomplete member lookup.
  • Fix behavior of lookup from where clauses.
  • And more fine grained fixes.

@MAJKFL
Copy link
Contributor Author

MAJKFL commented Oct 9, 2024

@swift-ci Please test

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

Just a couple of minor comments, these are great improvements.

+ [.lookInGenericParametersOfExtendedType(self)]
+ defaultLookupImplementation(identifier, at: lookUpPosition, with: config, propagateToParent: false)
+ [.lookInMembers(self)]
+ lookupInParent(identifier, at: lookUpPosition, with: config)
Copy link
Member

Choose a reason for hiding this comment

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

That's a lot of array concatenation, but I like how it very clearly shows each of the necessary lookup steps in the appropriate order. (No action needed)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also like how it shows the steps, but I think we could try to improve readability here a bit. I think I’d like to try to rewrite it to some kind of result builder method at some point in the future when we have a good suite of integration and unit tests (I think I’ve mentioned it once during a meeting). I was thinking about something like this:

return lookupResult(identifier, at: lookupPosition, with: config)
  .implicitSelf()
  .lookInGenericParametersOfExtendedType()
  .defaultLookup()
  .lookInMembers()
  .lookupInParent()

Each of the methods could also take an optional if: bool parameter that would conditionally include that step. This way we could basically remove all those complicated if … else if … else statements from lookup methods. Additionally, we could try to enforce some pre/post conditions related to config in those functions (like LookupConfig.finishInSequentialScope being checked inside .lookupInParent() call for all sequential scopes).

Copy link
Member

Choose a reason for hiding this comment

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

That does look nice! I don't know whether it's "worth" the effort of doing (vs. other things we've talked about for this library), but the result would be cleaner code in this part of the library.

@DougGregor
Copy link
Member

@swift-ci please test Windows

@MAJKFL
Copy link
Contributor Author

MAJKFL commented Oct 10, 2024

@swift-ci Please test

@DougGregor
Copy link
Member

@swift-ci please test Windows

@DougGregor
Copy link
Member

@swift-ci please test Windows

@MAJKFL MAJKFL merged commit b47d442 into swiftlang:main Oct 14, 2024
3 checks passed
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.

2 participants