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

Conditional of conflicting pragmas #108

Open
jan-christiansen opened this issue Dec 10, 2024 · 2 comments
Open

Conditional of conflicting pragmas #108

jan-christiansen opened this issue Dec 10, 2024 · 2 comments

Comments

@jan-christiansen
Copy link
Contributor

I don't have a solution to this problem and it is a rare corner case. However, I would like to record the information somewhere. When parsing ekmett/lens modules https://github.com/ekmett/lens/blob/0ef83b761a820826aa729bf0e1c2c361ce8e198c/src/Control/Lens/Internal/FieldTH.hs#L9 and https://github.com/ekmett/lens/blob/0ef83b761a820826aa729bf0e1c2c361ce8e198c/src/Control/Lens/Internal/TH.hs#L4 fail because the cpp conditional activates either Safe or Trustworthy. As the library collects all pragmas in a conditional the extraction fails with ModuleSafeHaskellConflict.

@tomjaguarpaw
Copy link
Collaborator

I see. Perhaps the solution is to run CPP first, before parsing with this library?

@jan-christiansen
Copy link
Contributor Author

Running CPP for all modules causes some warnings, mostly due to the fact that #-} is recognized as directive if a line starts with #-}. There are rare cases were the warning is not caused by a comment but by some other construct that causes a line to start with #.

I am not currently running CPP first, but only if extensions yields an error. This is fine in my use case.

Because extensions parses CPP directives in general, we might in the future consider, whether this counterexample could be handled as well. For example, we know that there is in fact no ModuleSafeHaskellConflict because the branches of the directive can never be both enabled. I think it boils down to the fact that using the union of the pragmas in the branches of a conditional is an overapproximation. Perhaps using a kind of least upper bound would be more appropriate.

While implementing an approach is probably too much work for this rare case, keeping this information here will help others to know the limits of the current implementation.

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

No branches or pull requests

2 participants