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

Add Suffix newtype and use in PPSuffixHandler #9484

Closed
wants to merge 1 commit into from

Conversation

sheaf
Copy link
Collaborator

@sheaf sheaf commented Nov 29, 2023

This commit adds a Suffix newtype to describe suffixes as handled by suffix handlers & preprocessors, and changes the PPSuffixHandler type synonym to use it.

It also moves some type definitions from Distribution.Simple.PreProcess to the new module Distribution.Simple.PreProcess.Types.

As this commit changes the definition of PPSuffixHandler, it will break custom Setup scripts which use the hookedPreProcessors functionality. As such, this PR should at least make mention of the breakage in a changelog; but as there isn't all that much payoff to the change it might be best to hold off entirely until we can get rid of Custom setups.

@sheaf sheaf marked this pull request as draft November 29, 2023 12:17
@andreabedini
Copy link
Collaborator

What is the point of a newtype wrapper if we export the constructor?

If the breaking change is

type PPSuffixHandler =
-  (String, BuildInfo -> LocalBuildInfo -> ComponentLocalBuildInfo -> PreProcessor)
+  (Suffix, BuildInfo -> LocalBuildInfo -> ComponentLocalBuildInfo -> PreProcessor)

I would expect Suffix to be significantly different from a String.

Actually, maybe the breaking change can be avoided entirely, the field

hookedPreProcessors :: [PPSuffixHandler]

gets passed to Cabal. If I am not mistaken, all we would need to do to keep compatibility is converting that String to a Suffix as we receive it.

@sheaf
Copy link
Collaborator Author

sheaf commented Dec 6, 2023

The intent was more of documentation than anything else:

  • using a different type rather than String makes it a lot easier to understand type signatures, especially those which have other String arguments,
  • using a newtype rather than a type synonym makes it so that one is less likely to make a silly mistake, and can help enforce the invariant that a suffix is something like "hs" and not ".hs".

However, I don't particular mind making it a type synonym if that's what we need to do to avoid breaking people's custom Setup scripts.

NB: I have a few additional changes involving Suffix that I hope to push to this MR.

@sheaf
Copy link
Collaborator Author

sheaf commented Dec 6, 2023

I would of course like to use a different type than String (which IMO should basically never be used), but Cabal needs to change the representation of filepaths that it uses for that change to make sense.

@philderbeast
Copy link
Collaborator

However, I don't particular mind making it a type synonym if that's what we need to do to avoid breaking people's custom Setup scripts.

From the docs on Custom setup scripts, these are compiled aren't they (I don't use them)? The change to a Suffix newtype would be flagged by a build failure but limited to packages with custom setups doing something with suffixes, wouldn't it? Do we have a build failure report for one of our test suites hitting this type mismatch already?

@andreabedini
Copy link
Collaborator

Ok, I am ok with a newtype. The breaking change is minimal after all.

@sheaf
Copy link
Collaborator Author

sheaf commented Dec 19, 2023

Do we have a build failure report for one of our test suites hitting this type mismatch already?

Yes, AutogenModulesToggling and CustomPreProcess ran into type-checking failures, which I solved without introducing CPP by enabling OverloadedStrings.

@sheaf sheaf marked this pull request as ready for review December 19, 2023 13:40
@alt-romes alt-romes force-pushed the wip/suffixes branch 2 times, most recently from 4a83d25 to c4ee262 Compare January 30, 2024 19:12
@alt-romes alt-romes force-pushed the wip/suffixes branch 3 times, most recently from 89dbaad to 33c97ff Compare February 16, 2024 07:37
This commit adds a Suffix newtype to describe suffixes as handled
by suffix handlers & preprocessors, and changes the PPSuffixHandler
type definition to use it.

It also moves some type definitions from Distribution.Simple.PreProcess
to the new module Distribution.Simple.PreProcess.Types.

As this commit changes the definition of PPSuffixHandler, it will
break custom Setup scripts which use the 'hookedPreProcessors'
functionality.
@Mikolaj
Copy link
Member

Mikolaj commented Mar 4, 2024

@Kleidukos: I know you are super-busy. Shall I dismiss your blocking review, optimistically assuming all concerns have been addressed?

Copy link
Member

@Kleidukos Kleidukos left a comment

Choose a reason for hiding this comment

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

Screenshot_20240222_131436

@alt-romes
Copy link
Collaborator

I addressed @Kleidukos' review.

@alt-romes alt-romes added the merge me Tell Mergify Bot to merge label Mar 4, 2024
@sheaf sheaf closed this Mar 4, 2024
@Kleidukos
Copy link
Member

@sheaf any reason why you closed the PR?

@sheaf
Copy link
Collaborator Author

sheaf commented Mar 4, 2024

This PR was already merged when merging #9543.

@Kleidukos
Copy link
Member

ok-thumbs-up

@mergify mergify bot added the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label Mar 6, 2024
@Mikolaj Mikolaj removed merge me Tell Mergify Bot to merge merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days labels Mar 12, 2024
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.

7 participants