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

[hls-explicit-record-fields-plugin] Expand used fields only #3386

Merged
merged 20 commits into from
Dec 19, 2022

Conversation

ozkutuk
Copy link
Collaborator

@ozkutuk ozkutuk commented Dec 7, 2022

This is a follow-up PR to #3304, which makes record wildcard expansion code action to only expand fields that are used.

How it works?

Since the plugin already operates on RenamedSource, we have access to all the Names that GHC has resolved for us. We utilize this information by first collecting all the Names within the source file by a syb traversal, and then for every field of the record to be expanded we check if the Name of the field exists within this collected list of Names (except for the field itself).

(@santiweight: you might be interested in this approach)

Copy link
Collaborator

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

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

Nice!

-- to 'Name' referring to the same entity is considered equal. In order
-- to ensure that no false-positive is reported (in the case where the
-- 'name' itself is part of the given list), the inequality of source
-- locations is also checked.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps an example? I couldn't quite figure out why this matters, and tbh it seems rather weird to have a match on the unique but not on the srcspan?

@@ -212,8 +273,13 @@ renderRecordInfo (RecordInfoCon ss expr) = RenderedRecordInfo ss <$> showRecordC
-- as we want to print the records in their fully expanded form.
-- Here `rec_dotdot` is set to `Nothing` so that fields are printed without
-- such post-processing.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this comment could do with some tweaks. It suggests that this is primarily about printing the records which makes it sounds like you always print them as they are, but now you're adding some additional logic to print something else depending on the fields in use.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have revised this and a bunch of other comments, can you take another look to see if it looks better?

Copy link
Collaborator

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

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

great stuff!

@michaelpj michaelpj added the merge me Label to trigger pull request merge label Dec 19, 2022
@mergify mergify bot merged commit b83ceb4 into haskell:master Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Label to trigger pull request merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants