-
Notifications
You must be signed in to change notification settings - Fork 37
move a bunch of types into dedicated modules #502
Conversation
src/Context/Type.hs
Outdated
|
||
import Hadrian.Package.Type | ||
import Stage.Type | ||
import Way |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably, this can be relaxed to import Way.Type
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in an upcoming commit.
@@ -0,0 +1,17 @@ | |||
module Expression.Type where | |||
|
|||
import Builder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, I think Builder.Type
is sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry, ignore the above comment, apparently there is no Builder.Type
. Or does it make sense to add it as well, for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at Stage
below, I think we should only add .Type
modules if they help resolve a cyclic import. So, let's not add Builder.Type
if it's not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed I didn't add .Type
modules that were not in @angerman's PR under src/Types/
, and the ones that were there presumably were there to resolve cyclic imports, so I think the PR effectively implements what you converged on in your last comment, doesn't it?
EDIT: looking at the comments below, looks like it doesn't just yet =)
src/Hadrian/Builder/Type.hs
Outdated
@@ -0,0 +1,26 @@ | |||
module Hadrian.Builder.Type where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit unhappy about this module: do we really need to separate the definition of builder modes and builder arguments? This looks very awkward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that's the only way forward, perhaps we can at least give this module a bit clearer name: Hadrian.Builder.Mode
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in an upcoming commit.
src/Stage/Type.hs
Outdated
@@ -0,0 +1,27 @@ | |||
module Stage.Type where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module doesn't seem to buy us anything. Is it here only for consistency? I think I'd prefer to keep everything simply in Stage
, as otherwise the latter looks really silly with a single stageString
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got rid of this module and put back everything into src/Stage.hs
, in an upcoming commit.
@@ -0,0 +1,45 @@ | |||
module Hadrian.Package.Type where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a quick look at Hadrian.Package
, it doesn't seem that this split is necessary. Or is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will be necessary shortly (as in, in a PR or two), and given that we're not really in a comparable situation as with the Stage
/Stage.Type
case (the .Package
module has several functions and the package-related types are likely going to be needed by "base" modules), I would personally suggest that we leave that one as-is, but it's your call of course :)
import Data.List | ||
import Data.Maybe | ||
import Development.Shake.Classes | ||
import Hadrian.Utilities |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, it seems that Hadrian.Utilities
is the only potential source of cyclic imports. But does it really cause a cyclic import? If not, perhaps we don't need this split?
@alpmestan Many thanks! I've left a few comments above. Most of the comments arise because it's unclear which I would argue that we need to introduce a |
Perhaps, some cyclic imports only become obvious in the |
@@ -12,25 +12,13 @@ module Context ( | |||
pkgConfFile, objectPath | |||
) where | |||
|
|||
import GHC.Generics | |||
import Context.Type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an example of the kind of comment I'm looking for:
-- The module "Context.Type" is used to break import cycles caused by "Oracles.Setting".
import Context.Type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt those comments will be of much use. They will document what the initial cycle that was broken was, but will ultimately bitrot pretty quickly. Any further refactoring or addition of code to hadrian that uses the .Type
modules will not see that there could have been a cycle without the .Type
module and subsequently not update the comment.
As such I believe the comment while it might be initially correct will be ultimately incorrect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree, these comments will likely get out-of-date quickly, and we probably don't want to keep changing the structure very often.
Instead it may be more useful to add a general comment somewhere in the overview document that explains the module structure. (We don't have such a document at the moment, so we don't need to do it now.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest we write such a description once we have integrated all of #445 as things will be in flux until we're done with that.
While I would have preferred to completely separate Data Types and logic in the reloc branch, I opted to only separate the ultimately necessary data types out. I don't think it would be a bad idea to follow this practice through though, as that will ultimately prevent some cycles from occuring in the first place. The occurance of cycles and GHCs inability to deal with them in the first place is rather sad though; however, as that is the current state of affairs, I believe that it's a good practice to separate data types from functions. As this PR tries to provide a rather self contained refactoring, without pulling in the changes that forced the cycle breaking, I wonder if we can try to review this from the point of view that this PR provides a better extension point to hadrian, that reduces the risk of cycles? |
@angerman Right, at the moment I'm bothered by two specific decisions:
|
In general I am fine with splitting all modules that we identify as High Risk for Import Cycles. These seem to be: These modules on the other hand are Low Risk: Does this sound reasonable? |
OK, I'll tweak the PR accordingly next week :) |
@alpmestan Thanks! I started to worry I scared you away with my avalanche of comments :-) |
No no, absolutely not. It's just that I have to interleave the hadrian work with some other tasks :) My work on this will resume on monday. |
It looks to me like one of the instances for @snowleopard I just pushed a commit addressing most of your feedback, let me know if that works for you or if you see other things that should be changed. :) |
@alpmestan Thanks! One last question: You renamed If |
@snowleopard Got rid of |
@alpmestan Thanks =) Merged now! Looking forward to more juicy PRs :-) |
Alright, it's show time.
This is the first PR extracted out of #445, hopefully addressing the feedback you (@snowleopard) gave in comments around here. Let me know what you think.