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

Split swarm libraries #1069

Closed
wants to merge 12 commits into from
Closed

Split swarm libraries #1069

wants to merge 12 commits into from

Conversation

xsebek
Copy link
Member

@xsebek xsebek commented Jan 31, 2023


This is how our dependencies look like and the libraries should enforce that we keep everything well ordered:

find src -name '*.hs' | xargs graphmod -q -p | dot -Tsvg -o swarm.svg

swarm

On a high level, the libraries look like this:

graph TD;
    swarm-language --> swarm-util;
    swarm-language-server --> swarm-util;
    swarm-language-server --> swarm-language;
    swarm-game --> swarm-util;
    swarm-game --> swarm-language;
    swarm-tui --> swarm-util;
    swarm-tui --> swarm-language;
    swarm-tui --> swarm-game;
    swarm-tui --> swarm-version;
    swarm-app --> swarm-util;
    swarm-app --> swarm-language;
    swarm-app --> swarm-game;
    swarm-app --> swarm-version;
    swarm-app --> swarm-tui;
    swarm-exe --> swarm-app;
    swarm-exe --> swarm-language;
    swarm-exe --> swarm-language-server;
    swarm-exe --> swarm-version;
    swarm-exe --> swarm-tui;
Loading

@byorgey
Copy link
Member

byorgey commented Feb 1, 2023

We also need to make sure to update stack.yaml as well as the release action.

mergify bot pushed a commit that referenced this pull request Feb 9, 2023
- Move the Location module to Game
- Move Achievements modules to Game
- Move Render and Model modules to TUI
- split off from #1069
- part of #1043
mergify bot pushed a commit that referenced this pull request Feb 10, 2023
This avoids using `Brick.AttrName` and we can remove the `-fno-warn-orphans` from `Attr.hs`.

As a bonus, we can now specify a terrain attribute (`terrain_stone`) in a scenario along with the `default` attribute.

- split off from #1069
- part of #1043
mergify bot pushed a commit that referenced this pull request Feb 13, 2023
- remove the useless `DirInfo` type
- move the `Direction -> Heading` functions to the `Location` module
- split off from #1069
- part of #1043
- part of #707
@@ -11,7 +11,7 @@
--
-- These failures are often not fatal and serve
-- to create common infrastructure for logging.
module Swarm.TUI.Model.Failure where
module Swarm.Game.Util.Failure where
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kostmo FYI I had to move the module back to the Game just to compile, but the change in #1116 is better (no Util directory and less code in the Util module itself) so I will rebase once merged. 👍

It seems that I am also susceptible to making silly Util modules when desperate. 😅

Splitting the libraries with Cabal has been a great learning experience for me, so I hope not to repeat my mistake from #982 where I put this module in TUI in the first place. 🤦

swarm.cabal Outdated Show resolved Hide resolved
@@ -295,7 +625,7 @@ test-suite swarm-integration
benchmark benchmark
import: stan-config, common, ghc2021-extensions
main-is: Benchmark.hs
hs-source-dirs: bench
hs-source-dirs: test/bench
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@byorgey I moved the app and bench directories to src and test respectively.

Sometimes I forgot to recompile the benchmark until the CI told me, so I hope seeing it with other tests will remind me about it. 🙂

I did not save file before commit
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaking of CI, it looks like regenerating this file will get rid of GitHub warnings about deprecated actions. 🙂

Let's hope it will all work nicely. 🤞

@xsebek
Copy link
Member Author

xsebek commented Feb 20, 2023

@byorgey @kostmo this will be ready to merge after #1116, please take a look. 🙂

If there are any old PR you wish to resurrect that can not be rebased just because of this PR, I will happily rebase them myself rather than let this wait for all PRs to be slowly merged.

However, because this is almost purely moving modules into library folders, git rebase should handle most cases. 🤞

Copy link
Member

@byorgey byorgey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still mostly think that this is a good idea but I am still a bit concerned about the maintenance burden of managing package versions, doing releases, etc. What's our plan for updating the release action?

StrictData


library
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't this library have a name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did not before, it is simply swarm. I am not 100% clear about whether we need this or if swarm-app would be better or maybe if it could even merge with swarm-exe.

I do not think we need to do anything about this right now.

@@ -79,12 +80,113 @@ common ghc2021-extensions
-- Not GHC2021, but until we get \cases we use \case a lot
LambdaCase

library

library boolexpr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's our plan for boolexpr? I don't think we can have an internal library called boolexpr when there is already a package on Hackage with that name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out we can... at least until we try to publish it on Hackage. 😄

Do we want to rename it swarm-boolexpr and support it indefinitely @kostmo?

I like that it is a separate package so we at least know that it does not have any Swarm dependency and could be upstreamed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kostmo @byorgey let's discuss this in #934 👀

@xsebek
Copy link
Member Author

xsebek commented Feb 20, 2023

@byorgey the release action can stay exactly as it is. All commands it uses stay the same, just as you can still use the same Stack/Cabal commands as before.

I am still a bit concerned about the maintenance burden of managing package versions, doing releases

  • package versions: once we thin out swarm-util the lowest library can set the package version range and the dependent libraries can remove them - this will result in two kinds of dependencies:
    • common to basically all (base)
    • specific to one package (unification-fd, brick)
  • we can use tooling like packdeps or cabal-bounds to ease the pain
  • we can now rely on -Wunused-packages to keep things minimal
  • ultimately we will not make changes too often
  • releases stay the same (write CHANGELOG entry, bump Cabal version, push git tag 🏖️ 🍹 )

@byorgey
Copy link
Member

byorgey commented Feb 20, 2023

OHHHH, I just realized what my confusion was. I thought by doing this we were going to have to upload a bunch of separate packages to Hackage, like swarm-language, swarm-game, etc. But we can still just upload the one swarm package to Hackage, which happens to have a bunch of internal library components... right?

If that's true, then none of my concerns are valid (e.g. version number management, release tooling, and what we will do with boolexpr)!

@xsebek
Copy link
Member Author

xsebek commented Feb 20, 2023

But we can still just upload the one swarm package to Hackage, which happens to have a bunch of internal library components... right?

First, yes. Second, I am not sure.

The Hackage release is still just $CABAL v2-sdist and we let haskell-actions/hackage-publish@v1 handle it.

But I think it will actually publish the libraries separately and also publish swarm. Think about it like the distinction between optics-core and optics. This means that I should probably use the reexported-modules field in swarm.cabal. It looks like Hackage displays the reexported modules now:
https://hackage.haskell.org/package/optics

@byorgey
Copy link
Member

byorgey commented Feb 20, 2023

But I think it will actually publish the libraries separately and also publish swarm. Think about it like the distinction between optics-core and optics.

But optics-core and optics each have their own separate .cabal file. There is absolutely no way that publishing something with a single .cabal file could actually cause multiple separate packages to be uploaded to Hackage. How would each one get a version number? Would they all have the same .cabal file? etc.

@byorgey
Copy link
Member

byorgey commented Feb 20, 2023

This means that I should probably use the reexported-modules field in swarm.cabal.

Yes, probably so. We want someone who depends on the swarm package to be able to use any of the modules from any of our internal packages (possibly except for a few "internal/private" ones).

@byorgey
Copy link
Member

byorgey commented Feb 20, 2023

We should probably try running Haddock on this locally to make sure that it produces something reasonable.

@xsebek
Copy link
Member Author

xsebek commented Feb 20, 2023

@byorgey I tested it with Haddock and it showed all modules. 🙂

Feel free to test it yourself and with Stack. Otherwise, I will have to download Stack to test it myself. 😄

@byorgey
Copy link
Member

byorgey commented Feb 20, 2023

I tried it with stack, and the first thing that happens is it prints this concerning message:

SubLibrary dependency is not supported, this will almost certainly fail

...and then it proceeds to build everything perfectly. 🤷

@xsebek xsebek closed this Jun 4, 2023
@kostmo kostmo mentioned this pull request Sep 7, 2023
mergify bot pushed a commit that referenced this pull request Sep 7, 2023
Also:
* adds a script to view locally-generated Haddocks.
* Describes module organization as per #1069 (comment) in the toplevel cabal package description
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Split Swarm components into libraries
2 participants