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

Implement boolean assertion "statement" #3072

Open
hvr opened this issue Jan 24, 2016 · 8 comments
Open

Implement boolean assertion "statement" #3072

hvr opened this issue Jan 24, 2016 · 8 comments

Comments

@hvr
Copy link
Member

hvr commented Jan 24, 2016

I hereby propose to add a new property/field

assert: <boolean-expression>

which would effectively provide syntax sugar for the following construct:

if !(<boolean-expression>)
    build-depends: base<0

(or instead of base<0 we could use an unbuildable package)

This would allow us to write things like

assert: impl(ghc >= 7.0 && < 8.0)

Or e.g. specify in platform specific packages such as Win32:

assert: os(win32)

Or even specify an unconditional assert: False for a broken package release.

The benefit of having a distinct form as opposed to the if/build-depends construct is that Cabal can recognise such forms easier, and provide better solver error messages. Moreover, the cabal edit validation in Hackage would be allowed to edit assert-properties, and be easier to implement robustly.
(currently you are not allowed to edit add/remove/change if-conditionals, and it's not trivial to specify under which circumstances such an edit would be safe)

/cc @kosmikus @dcoutts @bergmark @phadej

@23Skidoo
Copy link
Member

Sounds like a good idea to me (modulo bikeshedding).

@grayjay
Copy link
Collaborator

grayjay commented Jan 24, 2016

Should the desugared conditional negate the boolean expression?

@phadej
Copy link
Collaborator

phadej commented Jan 25, 2016

btw we have buildable: True and buildable: False; we could extend it to support

buildable: impl(ghc >= 7.0 && < 8.0)

(or optionally, introdice buildable-if:)

as assert: impl(ghc >= 7.0 && < 8.0) looks like

if !impl(ghc >= 7.0 && < 8.0)
  buildable: False

@hvr
Copy link
Member Author

hvr commented Jan 25, 2016

@grayjay you're right! I've updated the description accordingly

@hvr
Copy link
Member Author

hvr commented Jan 25, 2016

@phadej that makes sense, but I'd consider that a separate issue feature-request; I'd also like the default: <bool-value> property of flag definitions to be generalised to statically determinable boolean-expressions

@grayjay
Copy link
Collaborator

grayjay commented Feb 7, 2016

Related issue: #393

EDIT: #393 also suggests adding a field to warn that a configuration is sub-optimal.

@phadej
Copy link
Collaborator

phadej commented Feb 12, 2018

After two years, I still like buildable: <bool expression> more than a new field.

@hvr
Copy link
Member Author

hvr commented Feb 12, 2018

@phadej the main problem with buildable is that it'd conflate component activation with a constraint... isn't it? I.e. currently

buildable: False

has a different meaning/effect than

build-depends: base<0

afaik, or is the plan to make it mean the same thing?

regardless, I still think that more descriptive fail: <message> (as suggested in #393) would allow us to describe the failure better to users... so e.g. if you have

if !os(linux)
  fail: This package will only ever support linux; maybe there is package foo-<otheros>

it's more helpful than merely

buildable: os(linux)

Or for hackage revisions, an unconditional

fail: this package is broken and is therefore blacklisted; see <issue-tracker-url> for more details

instead of build-depends: base<0 would also be able to provide better UX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants