Code Monkey home page Code Monkey logo

Comments (10)

rubik avatar rubik commented on May 26, 2024

Nice work! It could be that Argon is setting extensions in a wrong way and impliedXFlags is never called.
The link to the GHC source is super useful! 👍

from argon.

rubik avatar rubik commented on May 26, 2024

Got it! Argon should use setExtensionFlag' instead of xopt_set. The former is exactly what we need:
https://github.com/ghc/ghc/blob/master/compiler/main/DynFlags.hs#L4175
because it calls impliedXFlags automatically.

The problem is.... it isn't exported 😧 And we cannot even implement it ourselves, because neither impliedXFlags is exported. We would then have to copy everything, but I really dislike this solution as implied extensions can change between different GHC versions.

The odd thing is that setGeneralFlags' is exported. It really seems like they forgot to export setExtensionFlag'.

from argon.

meditans avatar meditans commented on May 26, 2024

That is unfortunate, indeed. So, the copying solution is ugly, but is probably the only thing we can hope to have before lobbying for an export of that function in ghc, and then it would be only compilable with the latest ghc in any case.

A question comes to mind, though: doesn't cabal have the same problem? How does it do it? Is there a way to use a more high level exported function from the ghc library, letting it doing the work?

from argon.

rubik avatar rubik commented on May 26, 2024

That's an interesting point, I'll check the Cabal source to see if I can find something.

EDIT: Cabal does not seem to use the GHC API. They define their own type to represetn an extension:
https://github.com/haskell/cabal/blob/master/Cabal/Language/Haskell/Extension.hs#L96
which, incidentally, is what Argon uses when the Cabal file is parsed.
However, I just found that the DynFlag module exports some functions which might be of help:
https://www.stackage.org/haddock/lts-6.3/ghc-7.10.3/DynFlags.html#g:5
I haven't checked them all, but at a first glance they seem relevant. Still, creating an ad-hoc command line would be pretty ugly.

from argon.

meditans avatar meditans commented on May 26, 2024

Which functions in particular could be of help in the dynflags module? Are the correct extensions invoked in, e.g., parseDynamicFlagsCmdLine?

from argon.

rubik avatar rubik commented on May 26, 2024

Yes, I belive parseDynamicFlagsCmdLine could work. It's just a wrapper

parseDynamicFlagsCmdLine = parseDynamicFlagsFull flagsAll True

but flagsAll contains the flags related to the extensions as well. I just have to test it.

from argon.

rubik avatar rubik commented on May 26, 2024

Hooray! I finally got around to trying it and I confirm that using parseDynamicFlagsCmdLine works! It's a pretty ugly hack though, there has to be a better solution...

Can you try it?

from argon.

meditans avatar meditans commented on May 26, 2024

It seems that the modification works; in the end, I invoke the program on hint (and I get no errors) with:

argon --cabal-macros $(stack path --dist-dir)/build/autogen/cabal_macros.h --cabal-file hint.cabal src

I saw the commit, it doesn't seem too bad. Why do you feel it's pretty ugly? The better solution would probably be the export of the setExtensionFlag' function, right? If that's indeed the case, I checked with the folks in the #ghc channel and they proposed me to attach the proposed patch to a trac ticket for ghc.

I put that on hold since you were testing parseDynamicFlagCommandLine, but do you feel that that modification would be still useful/lead to better code?

from argon.

rubik avatar rubik commented on May 26, 2024

Well I find that the current solution has both some advantages and disadvantages. The main advantage I see is that since we're building a command line, the behaviour will always be the same as the GHC binary.

Still, I don't think it's the right way to proceed. Compare the current solution:

(dflags1,_,_) <- GHC.parseDynamicFlagsCmdLine dflags0
    [GHC.L GHC.noSrcSpan ("-X" ++ e) | e <- exts conf]

with

let dflags1 = foldr setExtensionFlag' dflags0 $ exts conf  -- not tested, but you get the point

In the first case we're doing useless work that will be undone by GHC. Instead, if setExtensionFlag' becomes part of the public API, it will be pretty much guaranteed that it will not break randomly at some point. Moreover, I just don't see why setGeneralFlag' is exported and setExtensionFlag' is not.

Finally, if setExtensionFlag' is exported, there will always be the problem of previous GHC releases, as you've noted. We cannot do anything about this, and probably would have to resort to conditional compilation (Yay!).

What do you think?

from argon.

meditans avatar meditans commented on May 26, 2024

The right thing to do is exporting setExtensionFlag' in ghc. Our long game would be introducing it when we don't need to support the old versions anymore (a very long game).

I'll try to write a patch later. For now, I have other questions on the code, but I'll open a new issue :)

from argon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.