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

Cabal solver shall consider *-extensions #2644

Closed
hvr opened this issue Jun 4, 2015 · 12 comments
Closed

Cabal solver shall consider *-extensions #2644

hvr opened this issue Jun 4, 2015 · 12 comments

Comments

@hvr
Copy link
Member

hvr commented Jun 4, 2015

I thought I had seen this feature request filed ages ago, but couldn't find it (the closest related side-comment I did find was #335 (comment)). In any case, here it is (again) explicitly:

It's possible (and afaik recommended) to list used language extensions in the .cabal file. However, that information is currently used too late, after the cabal solver has already locked into an install-plan.

Instead, the Cabal solver should regard the declared {default,other}-extensions as a dependency, and integrate that information with the solving algorithm, thereby allowing to backtrack to other package-versions/install-plans if the current compiler is known not to provide the requested language extensions

/cc @dcoutts

@23Skidoo
Copy link
Member

23Skidoo commented Jun 5, 2015

Is the problem that extensions can be conditionally enabled by flags? Otherwise this could be implemented by just not considering such packages in the first place.

@hvr
Copy link
Member Author

hvr commented Jun 5, 2015

@23Skidoo yeah, that's exactly why this can't be implemented as a trivial pre-filtering step...

@kosmikus
Copy link
Contributor

kosmikus commented Jun 5, 2015

Yes, interesting suggestion. So this isn't quite as easy as it sounds, because the solver uses its own simplified index format right now, and discards the extensions information during an initial conversion step. So the implementation of this would have to extend the solver-specific index format with extension information. Then we'd need a mapping from GHC versions to supported extensions. Is this available somewhere already? Can one query GHC for this easily? Once we have the supported extensions available as an input to the solver, and the extended index info mentioned above, the actual filtering should be very easy.

@hvr
Copy link
Member Author

hvr commented Jun 5, 2015

@hvr
Copy link
Member Author

hvr commented Jun 5, 2015

PS: Here's the cabal configure check against the required *-language: and *-extensions specifications Cabal performs currently (after cabal solving):

-- check languages and extensions
let langlist = nub $ catMaybes $ map defaultLanguage
(allBuildInfo pkg_descr)
let langs = unsupportedLanguages comp langlist
when (not (null langs)) $
die $ "The package " ++ display (packageId pkg_descr0)
++ " requires the following languages which are not "
++ "supported by " ++ display (compilerId comp) ++ ": "
++ intercalate ", " (map display langs)
let extlist = nub $ concatMap allExtensions (allBuildInfo pkg_descr)
let exts = unsupportedExtensions comp extlist
when (not (null exts)) $
die $ "The package " ++ display (packageId pkg_descr0)
++ " requires the following language extensions which are not "
++ "supported by " ++ display (compilerId comp) ++ ": "
++ intercalate ", " (map display exts)

@kosmikus
Copy link
Contributor

kosmikus commented Jun 5, 2015

Ok great. Then this part is easy. So I think this makes this a relatively easy (but not quite trivial), to work on for someone who wanted to gain a little bit of understanding on how the solver works.

@dcoutts
Copy link
Contributor

dcoutts commented Jun 5, 2015

Yes, I think ultimately the solver should be extended to cover several other kinds of dependency in addition to libraries: build tools, language extensions, C libs etc.

For language extensions we need to know which extensions are supported by the current compiler, which we already have infrastructure for. So then once the solver is extended to accept the set of supported extensions then it's easy to plug together.

The main challenge is extending the solver to cope with multiple different kinds of dependency. For some, like build-tools they're very similar to build libs in that there is something you can install to satisfy the dependency. With language extensions (and there's some others in this category) we can treat them as fixed and so there's nothing you can install to satisfy them. This makes them a bit simpler.

@kosmikus
Copy link
Contributor

kosmikus commented Jun 5, 2015

Yes, let's not make this ticket more complicated than it is. For language extensions, it's a simple yes/no check, which makes this a rather low hanging fruit.

@kosmikus
Copy link
Contributor

I'm working on this now.

@phadej
Copy link
Collaborator

phadej commented Sep 10, 2015

Should we formulate some guidelines for default-extensions and other-extensions fields. As they are soon used by solver. E.g. I use DefaultSignatures but the usage is often guarded by cpp, should I put it in other-extensions or not?

@hvr
Copy link
Member Author

hvr commented Sep 10, 2015

@phadej fwiw, other-extensions and default-extensions are already used right now, it's just that they're checked too late (after the solver ran) by Cabal. However, there's a ticket #1517 about documenting {other,default}-extensions. I usually mirror the CPP-conditional which guards language pragmas inside the .cabal file via Cabal conditionals.

hvr added a commit to hvr/cabal that referenced this issue Nov 17, 2015
This emulates what GHC>=8 will do on its own for older GHC versions.

This is particularly useful in combination with haskell#2644 allowing the
solver to toggle flags depending on the availability of
`-XTemplateHaskell`.

For instance, cross-compilers and/or unregisterised GHC builds often
don't have TemplateHaskell support. Having support for toggling flags
based on availability of `-XTemplateHaskell` allows `cabal` to
support such environments with less manual intervention.
hvr pushed a commit to ghc/ghc that referenced this issue Nov 18, 2015
`-XTemplateHaskell` requires GHCi; don't show it in
`--supported-extensions` if it's not supported.

Together with haskell/cabal#2644
this allows to finally fix a long-standing annoyance in cabal
of not being able to detect availability of TH in build-plans.

Fixes #11102

See also haskell/cabal#2930 which provides
emulation of this feature for older GHCs.

Reviewed By: bgamari

Differential Revision: https://phabricator.haskell.org/D1484
@23Skidoo
Copy link
Member

Fixed by #2873.

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

Successfully merging a pull request may close this issue.

5 participants