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

Make it easier to support other link disambiguation in the future #824

Merged
merged 3 commits into from
Feb 14, 2024

Conversation

d-ronnqvist
Copy link
Contributor

Bug/issue #, if applicable:

Summary

This handpicks some of the changes from #643 to make it easier to support other types of link disambiguation without adding any new link disambiguation.

Specifically, this wraps the path component disambiguation as its own type instead of storing the values directly on the path component. This means that in the future, if we added a new type of link disambiguation—like in #643—then all the places that process path component disambiguation would already be switching over the type of disambiguation.

A follow up PR will handpick some more changes from #643 to change how the path hierarchy internally stores its disambiguated elements.

Dependencies

None

Testing

Nothing in particular.

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • Added Updated tests
  • Ran the ./bin/test script and it succeeded
  • [ ] Updated documentation if necessary

@d-ronnqvist d-ronnqvist added the code cleanup Code cleanup *without* user facing changes label Feb 13, 2024

enum Disambiguation {
/// This path component uses a combination of kind and hash disambiguation
case kindAndHash(kind: Substring?, hash: Substring?)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to add kind and hash accessor functions or calculated properties in this enum that return Substring? That would allow you to further simplify the code that uses these values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe. I wouldn't want it to work against the goal of making it easier to add other types of link disambiguation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My goal is to break apart #643 into 3 pieces: this PR, a follow up PR that changes how disambiguated elements are stored in the path hierarchy, and finally the new link disambiguation syntax. The idea is that we can land the two refactor PRs without changing any behavior and that makes the 3rd (new feature) PR smaller and less likely to have complicated merge conflicts.

Comment on lines +413 to +422
var kind: String?
var hash: String?
switch disambiguation {
case .kindAndHash(kind: let maybeKind, hash: let maybeHash):
kind = maybeKind.map(String.init)
hash = maybeHash.map(String.init)
case nil:
kind = nil
hash = nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You could move this snippet from here into PathHierarchy.PathComponent.Disambiguation and separate it into two calculated properties. Then I think you could simplify this function even more.

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've already removed this code in the follow up change—for which I haven't opened a PR yet—that updates how the disambiguated elements are stored in the path hierarchy.

kind = nil
hash = nil
}

if let kind = kind {
Copy link
Contributor

Choose a reason for hiding this comment

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

For example this line here could just read if let kind = disambiguation.kind

guard name == component.name else {
return false
else if let symbol = symbol, let disambiguation = component.disambiguation {
switch disambiguation {
Copy link
Contributor

Choose a reason for hiding this comment

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

And here for example you might be able to avoid the switch statement and avoid referring to the enum case directly.

@d-ronnqvist
Copy link
Contributor Author

@swift-ci please test

@d-ronnqvist d-ronnqvist merged commit f0a3d7a into apple:main Feb 14, 2024
2 checks passed
@d-ronnqvist d-ronnqvist deleted the link-disambiguation-refactor-1 branch February 14, 2024 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code cleanup Code cleanup *without* user facing changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants