CPP macros suitable for partial evaluation
- Dominant language
- Haskell
- Stars
- 1.7k
- Forks
- 750
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 28
Description
I looked into tools that could simplify my codebase by partially evaluating CPP conditionals.
E.g. if I have
```hs
#if __GLASGOW_HASKELL__ < 806
...
#if !MIN_VERSION_base(4,11,0)
...
```
and I no longer support GHC < 8.6 or base < 4.11 then I can get rid of some cruft by partially evaluating the conditions and throw away the conditional together with the branch that is now impossible..
I checked some tools that do some partial evaluation of CPP conditionals:
- `unifdef` (shipped on my system macOS): https://dotat.at/prog/unifdef/
- `cppp`: https://www.muppetlabs.com/~breadbox/software/cppp.html
- `coan`: https://coan2.sourceforge.net/index.php
These tools typically only support setting a symbol to a value, like `__GLASGOW_HASKELL__=806`. They do not accept predicates, i.e., I cannot set `MIN_VERSION_base(4,11,0)` to be true.
So if Cabal defined 3 separate symbols to specify a version, instead of a ternary predicate, this would be compatible with such tools.
```
MAJOR1_VERSION_base=4
MAJOR2_VERSION_base=11
MINOR_VERSION_base=0
```
This would be usable in Haskell code as such:
```hs
#if MAJOR1_VERSION_base >= 4 && MAJOR2_VERSION_base >= 11
...
```
(One could think of other macro names, like the triple `VERSION_EDITION_base`, `VERSION_MAJOR_base`, `VERSION_MINOR_base`---although the terminology _edition_ for the "major-major" version is not established.)
Contributor guide
Research direction
No source file or test is named. Start by tracing where Cabal defines MIN_VERSION_base and __GLASGOW_HASKELL__ macros, then compare the proposed version symbols with the stated unifdef, cppp, and coan constraints. Done means agreeing on a supported macro scheme and implementing it with coverage for the generated definitions.
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
- 30/100