-
Notifications
You must be signed in to change notification settings - Fork 52
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 components into libraries #1043
Comments
Makes sense to me, as long as we continue to have everything in a single repository. |
@byorgey repository definitely stays the same. 🙂 The simple idea is to make directories directly in |
If you're going to start on this, I wonder if we could please merge #873 in a partially-complete state first, since the merge conflicts would probably be massive. |
@kostmo good point. I think we can try another approach first. I will take file content changes out of the PR and merge them separately. If I am patient enough with that, then the final PR will be only moving files into subdirectories and the cabal file. |
@byorgey not at all! 🙂 It was simply taking time to rebase the PR, given that it moved around lot of code. I think this is a good thing ™️ to do, but needs a concrete immediate use-case. For example deciding that LSP client/Doc generator or some other part should be moved into a separate executable and depend on "swarm the language" library. Then the short term annoyance of investigating what could be broken by this change should get outweighed by the benefits. 😅 |
Would it be more feasible (with regard to rebasing) to tackle one sub-library at time (i.e. peel off one library per PR)? For starters, perhaps just the |
Yes, that sounds very reasonable to me. |
Towards #1043 This is the first of potentially more granular sub-library splits.
Towards #1043 Creates a new sub-library for the web service. Also moved the `Swarm.App` module from the `swarm` library to the `swarm` executable.
Towards #1043 Extracts `Swarm.Game.*` modules to their own sublibrary. There was already pretty good separation along this boundary; just had to move three functions into a new module `Swarm.Util.Content`.
Towards #1715 and #1043. This refactoring step is a prerequisite for #1719 to extricate references to the `CESK` module from the base `RobotR` definition. In this PR: * `Swarm.Game.CESK` is imported qualified to more easily track usages * A new `RobotMachine` type family is added to parameterize the `_machine` field. * `CESK` is a new parameter to `addTRobot`
Towards #1715 and #1043 Creates a new `swarm-scenario` sublibrary intended for scenario data that is independent of game state. # Planned follow-ups This PR is already pretty large, but there is still more that can be done regarding sublibrary reorganization/splitting. * May want to pare-down a sublibrary exclusively for world-generation without all the other baggage of scenarios. * `Swarm.Game.ScenarioInfo`, `Swarm.Game.Tick`, and `Swarm.Game.Scenario.Status` could probably be moved from `swarm-scenario` to `swarm-engine`.
Towards #1043. The eventual goal of this sublibrary split is to have a self contained library that can compose 2D grids of arbitrary content (perhaps colored pixels, or boolean values). This could be useful outside of the `swarm` game. I would also like to write unit tests for the structure recognizer that are independent of the `Entity` type. # Major Changes ## Direction module * Moved `Swarm.Language.Syntax.Direction` to `swarm-util`, since both `swarm-lang` and `swarm-topology` depend on it, but not on each other. * Removed the re-export of direction things from `Swarm.Language.Syntax` ## Structure module The `Swarm.Game.Scenario.Topography.Structure` module has been split into two: * `Swarm.Game.Scenario.Topography.Structure` * `Swarm.Game.Scenario.Topography.Structure.Type` The former retains the YAML parsing logic. The latter is agnostic of `Enitiy` type and the palette . At some future point, I might want to move the YAML parsing to this sublibrary while still retaining independence of `Entity` type. ## Structure recognizer The structure recognizer is independent of the content of Cells (i.e. it does not need to know what an `Entity` is), except: 1. during initialization 2. when retrieving the original cell content after recognition Type parameters for three kinds of data have been added to the recognizer: 1. `Cell`/`PCell` 2. `Entity` 3. `EntityName` Eventually it may be possible to eliminate one or two of these type parameters, with some refactoring.
I propose we split the sources into Cabal libraries.
Practical problem: compilation
When I run tests after changing some
Swarm.Language
modules, every Swarm source file (60+) is recompiled.However, we do not need to compile LSP or TUI or Web API, because we do not test them.
Theoretical problem: dependencies
We mostly* avoided using TUI or Web dependencies in the code for language and game logic.
In theory, we could switch the dependencies for new ones or add another UI without changing the game or language code.
Left unchecked, the dependencies could slowly leak and make future experiments less viable.
At least it would be easier to see which dependencies are needed for what part of the Swarm application.
Solution
In my mind, Swarm code is split like this in order of dependency:
Swarm.Language
Swarm.Language.LSP
(move to its own directory?)Swarm.Game
Swarm.DocGen
(not really required in the final application)Swarm.TUI
Swarm.Web
Swarm.App
is just a small module to neatly initialise everything in order.There is also
Swarm.Version
, which has a failure type that we use in TUI to show it nicely.We could split off the failure type and use the network call and Git polling only in App.
*) except for Brick
AttrName
inSwarm.Game.Display
.The text was updated successfully, but these errors were encountered: