-
Notifications
You must be signed in to change notification settings - Fork 29
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
Split out AST and Parser libraries from GHC #56
base: main
Are you sure you want to change the base?
Conversation
This makes the diff easier to read with (crude, bad for prose) line-based diffing.
AST parser libs history
subsections not bullets
A (failed 🥲) attempt to suggest that perhaps part of the problem of depending on |
But it's built in, isn't it? You can't not have it on your Haskell system. |
Additionally, the library must be "reinstallable" (if I'm interpreting the term correctly), i.e. it should not be tied to the
I'm not too intimately familiar with Hadrian, and I'm not saying this is a trivial or easy change to it, but it should definitely be possible to express dependencies at the cross-package module level, i.e. if only |
this is it, the key motivation for ghc-lib-parser. from https://github.com/digital-asset/ghc-lib: e.g. the most recent ghc-lib-parser consists of ghc-9.6.1 source and so HLint can be built with compiler versions in the range [9.2.2, 9.6.1]. |
Here's a comment I wrote on the GHC issue tracker that covers this a bit: https://gitlab.haskell.org/ghc/ghc/-/issues/14409#note_506489 Excerpting:
Let me elaborate on that a bit. Suppose you want to use
Of course, this is only true because the GHC parser tends to be backwards-compatible, so you can get away with using the latest version. If you want to rename, typecheck, etc. a program, then you really do want to mimic the GHC that the user has so you really do want an exactly matching However, I will say that I don't know of any other tool apart from HLS that relies on anything past parsing. I think there's a simple reason for that: parsing can be done (mostly) standalone, whereas to go much further you actually need a proper GHC session with a package database and so on. Getting that all set up is pretty non-trivial and is the whole raison d'etre of I think it's worth emphasizing that basically all the "big" tools for working with Haskell source are now using
|
Another thing: it seems to me that the current situation with
And since lots of tools now rely on In contrast, a GHC parser package maintained by the GHC team is going to be robustly tested, maintained by the right people, and probably just much less work overall. |
Thanks! Co-authored-by: David Thrane Christiansen <[email protected]>
This is the intent of the proposal. There should be no major downsides; no new submodules to bump, and still loading everything in a single
I indeed don't' want the HF to write a blank check.
I think the answer is "yes" --- we definitely want a parser we can resuse. That said, I do not know the Parser parts as well as I know the AST parts.
I don't think I am the right person to answer this; I have song strong biases towards modularity but this gets myself and the GHC devs into "we agree to disagree" territory. I hope everyone else in this thread will be able to find a resolution here without me. I will say this: there are a number of build system and other "dev ops" issues with The |
Thanks for the responses above. I now better understand why we want this: we want a Haskell program built with (say) GHC 9.2 to be able to parse Haskell files that use syntax from (say) GHC 9.6. Good. I'm on board with that bit of motivation, otherwise known as making the library reinstallable. I also understand that one problem with the existing Regarding downsides: I remain unconvinced about build times. My read of this proposal is that the new parser would live in the same repo as GHC (not in a submodule) but would be its own Haskell package, with its own cabal file. My best understanding of our build tools suggests that changing a file in one cabalized package requires a rebuild of the package, which would then require rebuilds of other packages that depend on the first one. Maybe these dependencies are at the module level, not the package level? But I'd need someone to assert that pretty clearly. (Note: this is not at all about repo organization or anything involving git.) |
Yay!
I am not sure that is actually less work. But happy to discuss the next bit first before returning to this. (IMO adding new CI steps (like e.g. the linting ones ;)) often annoys developers when there is this extra "gotcha" step they didn't notice during local development. But just...refactoring the code so the extraction step is superfluous will get us to a new local maxima cleanly with no extra gotcha steps.)
With "vanilla" Cabal and cabal-install, what you say is true. These things invoke Hadrian (and GHC's old make build system) are different however, they invoke GHC in one-shot mode, so there is one process per Haskell module. They do not force all downstream packages to be rebuilt, at least last I heard. You can try this out by modifying a file of The |
Another point here - we've talked a bit about reinstallable
If we keep pushing on the modularity we can get to a better place with plain cabal build times also. Conceptually, most of GHC shouldn't depend on the parser, only the driver that puts it all together. So if you have the driver as a separate component that depends on the parser, typechecker etc, then changing the parser should mean rebuilding only the driver component.
I think it would help, but I do think a significant part of the problem is that it's not being maintained by the GHC devs. If the GHC devs want to adopt and maintain |
Thanks again. I'm becoming more convinced. For me the story runs like this:
Is that an accurate telling of the story? This story need not be what inspires you (for any definition of "you"), but if it's an accurate story, then it might be what inspires me. (Specifically, some people have a great desire for more modularity. That motivation speaks to them. But, on its own, it does not speak to me, other than as an aesthetic "nice to have".) |
quick comment on ghc-lib vs ghc-lib-parser. ghc-lib re-exports ghc-lib-parser and adds in the rest of the GHC API such that you can produce GHC core from haskell source. ghc-lib-parser (~400 modules) was split from ghc-lib (~400 modules) in an effort to achieve install times for HLint users as reasonable as they could be. |
@goldfirere That's exactly right! For me personally modularity is very exciting, but I indeed there is not yet enough evidence that other people care enough for that to motivate an HF proposal on alone --- I knew I couldn't just write a GHC modularity in its entirely HF proposal and expect it to go through. I turned to
And the official goal the proposal is (3), while also making the library hopefully also better than it was before, helping out (2). Any modularity benefits are just icing on the cake we need not worry about if folks don't really care for icing :). |
(Once could state that I am cynically laundering modularity work under something more popular. I prefer to state that I am trying to demonstrate modularity being useful to help solve existing problems, problems that (at least as I understand it) can't very well be solved any other way. Modularity is part of the means but not the end of the proposal.) (edit the rendered link was wrong, so changes since the initial version did not appear. it is fixed now.) |
I think you're scoping out work that has benefits across a number of different axes! |
Thanks! Co-authored-by: David Thrane Christiansen <[email protected]>
I certainly hope so! But some of the more abstract ones are hard to argue in an ironclad objective way. I'm fine with leaving them out of it and hoping the main more concrete enough ones are enough to carry the day. If this goes as well as I hope, it will provide useful a shared experience to ground discussing those other things, and other modularity projects that relate to them. But until then those conversations are rather unmoored and I'm OK waiting. |
I was asked to comment here as a maintainer of Ormolu, a tool that depends on
Which is telling. I'm not very familiar with the way GHC is developed, so I won't express any strong opinions. On the whole, the idea of having the parser as a "normal" Haskell library which nevertheless would continue to live in the GHC source tree seems to be a good one in the sense that it would reduce build times for end users without making GHC development harder. |
It use `ghc` directly.
As a maintainer of Fourmolu, I don't have much to contribute beyond what @mrkkrp said. As Fourmolu is a fork of Ormolu, we mostly inherit ghc-lib-parser from Ormolu and don't interact with that dependency a ton. But as a maintainer of tasty-autocollect, I can't use ghc-lib-parser because it's a compiler plugin, so I have to use ghc directly. So I do use CPP to provide a common interface that's implemented by each GHC version. Even if ghc-lib/ghc-lib-parser could be reused, I'd probably avoid it anyway because 1) long build time and 2) my usecase is small enough that manually writing shims isn't too much work. But if there were a library broken out that can be used for plugins + provides a compatible interface for multiple versions of GHC + is prebuilt/doesnt have a huge build time, it would be useful for tasty-autocollect |
I happened to glance at shakespeare and noted this comment:
Maybe @snoyberg you would like to comment or more likely point us to someone who is a potential maintainer of shakespeare for their opinion on if this work would be of value? |
As a maintainer of |
Problem
The community lacks AST and Parser libraries for Haskell that are both self-contained and up-to-date. Experience has shown that there is only way one way to meet each criterion:
However, no library has so far done both, nor met meet both criteria.
Solution
The purpose of this proposal is to make that library finally exist. The Haskell Foundation will finance the completion of the existing "Trees that grow" project, decoupling GHC's AST and parser from the rest of the compiler so they can be moved to separate libraries. Those libaries will be "normal" haskell libraries, without any weird dependencies or build process, and published on Hackage. Those libraries will be used by GHC, ensuring they are maintained.
Rendered