haskell / haskell/cabal

Extend the grammar/semantics of `default:` to support boolean expressions

Open
#5,328 7 comments 2 reactions 0 assignees View on GitHub
cabal-install: solver Cabal: file format re: flag type: enhancement
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

This is expanded version [of this comment](https://github.com/haskell/cabal/issues/3072#issuecomment-174487089):

Currently, the grammar for the `default` field is limited to

```
default:
```

This is perfectly sufficient for properly used automatic flags (i.e. `manual: False` and used in a way which allows the solver to unique determine their value -- there's a separate feature request to have cabal detect "non-functional" uses of automatic flags); however, for manual flags the limitation of allowing only a constant boolean literal in `default:` is rather limiting.

Instead, starting with e.g. `cabal-version:3.0`, we should allow an enhanced version of `default`

```
default:
```

and where `` would be the expression we already support in `if` clauses which currently supports the

- the literals `True/0` and `False/0`,
- binary operator `&&/2`, `||/2`,
- the unary operator `!/1`,
- grouping via `(` and `)`, and the
- builtin predicates:
- `impl/1`
- `flag/1`
- `arch/1`
- `os/1`

Such expression can be statically determined, as the `impl/1`, `arch/1`, and `os/1` predicates are globally constant for a solver session.

The `flag/1` predicate however requires us to impose a limitation though, in order to keep the implementation simple (allow for referential checks during single-pass parsing) and avoid the issue of undecidable flags (e.g. via cyclic references). To that end, the following simple well-formedness rule needs to be added to the specification of `flag/1`

- `flag()` may only refer to a `` which is lexically visible, i.e. *completely* defined before their use-site (i.e. only *after* its `Flag` stanza ends, a flag is considered completely defined; this prefents direct self-referential uses of `flag/1` from within the same Flag stanza)

- Furthermore (as pointed out in https://github.com/haskell/cabal/issues/5328#issuecomment-389450253), a manual flag's default expression must not be refer to an automatic flag.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.