Facility for declaring optional language extensions
- Dominant language
- Haskell
- Stars
- 1.7k
- Forks
- 750
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 28
Description
A common pattern I've seen (and used myself) is
```
-- ...
library
other-extensions: CPP
if impl(ghc>=7.2)
other-extensions: Safe, Trustworthy
-- ...
```
and then in the code this is then enabled via
``` hs
{-# LANGUAGE CPP #-}
#if __GLASGOW_HASKELL__ >= 702
{-# LANGUAGE Trustworthy #-}
#endif
-- ...
```
I.e. I have to know which compiler versions have support for a certain language extension, even though Cabal does possesses this knowledge. This might be tolerable for the current situation when there is only one major compiler as GHC which implements a certain language extension, but it doesn't scale well when multiple compilers support a certain extension.
Therefore I propose the following extensions to the Cabal format:
1. an `extension()` predicate in the style of `impl()`, i.e.
```
-- ...
library
other-extensions: CPP
if extension(Trustworthy)
other-extensions: Trustworthy
cpp-options: -DHAVE_EXTENSION_Trustworthy
if extension(Safe)
other-extensions: Safe
cpp-options: -DHAVE_EXTENSION_Safe
-- ...
```
and maybe also
1. For convenience, have a new field `optional-extensions` that captures the pattern in 1. and makes the intention more explicit; i.e. the following example would be semantically equivalent to the example from 1.:
```
-- ...
library
other-extensions: CPP
optional-extensions: Trustworthy, Safe
-- ...
```
Contributor guide
Research direction
Start by reviewing Cabal format conditionals in the library stanza, especially the existing impl() predicate and other-extensions field. Determine how an extension() predicate and optional-extensions should interact with conditional other-extensions and cpp-options, then define tests for supported and unsupported extensions and confirm the proposed examples behave as intended.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100