-
Notifications
You must be signed in to change notification settings - Fork 68
Data declaration for newtype and records #259
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
Conversation
|
👀 I'll review this soon. I glanced over the test cases and liked what I saw! |
tfausak
left a comment
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 started reading layoutDataDecl but I can't really grok it. No fault of yours though! I'm not familiar enough with this codebase to do a thorough code review. Is there anything in particular you'd like me to look at?
| | ColBindStmt | ||
| | ColDoLet -- the non-indented variant | ||
| | ColRec | ||
| | ColRecUpdate -- used for both RecCon and RecUpd. TODO: refactor to reflect? |
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.
What would be the benefit of differentiating between record construction and record update? I thought they were always formatted the same.
|
I fully approve of the idea of getting this merged. I started working on supporting the older ghcs, and with this commit it compiles with both ghc-8.4 and ghc-8.6. Unfortunately, the tests on 8.4 do not pass. One failure case is some whitespace problem that I have not investigated but that is probably relatively easy to fix. The more annoying issue is that 8.4 does not have should do the trick. (this might point towards the question if we want to reduce the number of supported compiler versions, but I think I want this feature regardless; it seems it would be required again in the future even if we only supported two versions at a time.) I plan to keep working on this when I find the time, in small pieces. If anyone else works on this over more than an evening, you might want to leave a note so that we don't conflict / do redundant work. This advice applies to myself, too. |
|
@lspitzner The big blocker in my mind right now is comments. They are something that could precipitate a lot of change in this code (though maybe they won't 🤷♂️) If you have the time I might recommend doing some research on what that might look like instead of attacking multi version support. 100% agree on committing early and often and keeping the lines of communication going so we don't have redundant work. |
|
I have started on supporting comments, will push something this night. |
|
I did a bit of fiddling with it, but didn't get anywhere. I'd love to have a brain dump from you on how |
src-literatetests/10-tests.blt
Outdated
| data Foo = Bar | ||
| { foo :: Baz | ||
| , bars :: Bizzz | ||
| } | ||
| -- a | ||
| deriving --b | ||
| ( -- c | ||
| ToJSON -- d | ||
| , -- e | ||
| FromJSON --f | ||
| ) -- g | ||
| via -- h | ||
| ( -- i | ||
| SomeType --j | ||
| , -- k | ||
| ABC --l | ||
| ) |
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.
Yeah, that is a lot of fun!
Maybe something like this:
-- a
deriving --b
( -- c
ToJSON -- d
, -- e
FromJSON --f
) -- g
via -- h
( -- i
SomeType --j
, -- k
ABC --l
)The alignment with deriving would then be dropped in align left and replaced with a single indent.
-- a
deriving --b
( -- c
ToJSON -- d
, -- e
FromJSON --f
) -- g
via -- h
( -- i
SomeType --j
, -- k
ABC --l
)|
@lspitzner I've updated the branch to build with all supported GHC versions. There are a number of test failures that will need to be picked off. One specific issue is literate tests that use syntax that is not available in earlier versions, like We'll likely need a mechanism to disable certain tests depending on the GHC version. |
|
great work, I'll have a look later. I think one set of errors comes down to one trivial mistake that causes duplication of offsets/comments in front of a data-def. That, together with the deriving-via fix you mentioned, I think 8.4 is clean already. |
|
All green! nice. I still need to review the last few commits, and I want to test this on one or two larger codebases. |
|
Nice work on the |
|
I'm only seeing one issue. Interstitial comments are getting de-indented one level too much. data CurrentLevel = CurrentLevel
{ clLevel :: FreckleTextLevel
- -- ^ Either the last Snapshot or Starting/Overridden level
+-- ^ Either the last Snapshot or Starting/Overridden level
, clStartingLevel :: FreckleTextLevel
- -- ^ Specifically the Starting/Overridden level
+-- ^ Specifically the Starting/Overridden level
, clOverridden :: Bool
- -- ^ True if level has been Overridden
+-- ^ True if level has been Overridden
}
deriving Show |
|
I ran this branch over ITProTV's medium sized (72 KLOC) simple codebase and only ran into one bona fide problem: data EnterpriseGrantsForCompanyResponse = EnterpriseGrantsForCompanyResponse Types.Company [ EnterpriseGrantResponse
](We have data EnterpriseGrantsForCompanyResponse
= EnterpriseGrantsForCompanyResponse Types.Company [EnterpriseGrantResponse]
data EnterpriseGrantsForCompanyResponse = EnterpriseGrantsForCompanyResponse
Types.Company
[EnterpriseGrantResponse]
data EnterpriseGrantsForCompanyResponse
= EnterpriseGrantsForCompanyResponse
Types.Company
[EnterpriseGrantResponse] |
|
This would be consistent with how data EnterpriseGrantsForCompanyResponse = EnterpriseGrantsForCompanyResponse
Types.Company
[EnterpriseGrantResponse] |
|
@tfausak I added some tests and layouting for that situation. |
|
@lspitzner I'll need your help with the comment issue. |
|
Awesome, thanks for the quick fix! I re-ran Brittany at 393bdb0 against my codebase and everything worked. I'm also seeing the comment problem, but everything builds properly after formatting. |
|
My notes from testing on some non-public code:
Will add test-cases/examples for the above later. I plan to write some documentation to explain the processing of comments. I'll also look into this particular comment problem; the |
|
I re-ran 09da6d4 against ITProTV's code base and everything looks great! Most of our record data declarations were written with |
The choice to put them on a new line sacrifices one vertical line for consistency in the current GHC world where |
|
Ah, I found a problem. Trying to format a data declaration like this: data T = C {}Returns a syntactically invalid result: data T =I think it should probably keep the empty braces around, but as far as I know that's the same as not taking any arguments. I'd be fine with either of these: data T = C
data T = C {} |
|
@tfausak I've added a test and corrected that bug. |
|
Awesome, thanks! |
|
@lspitzner do you have an examples of these two?
|
The `Makefile` includes `stack test` configurations to support building versions of `brittany` with supported versions of `ghc`. Each version uses a separate `.stack-work` directory to allow minimal compilation on each change.
`docWrapNodePrior` caused duplication of offset of `data` keyword and of comments connected to it.
Only single line formatting of normal records was being supported. For records with long names we need multi line formatting. This also needs to support both multi and left indentation policies.
Add tests for nullary prefix data types and nullary record data types.
- Fix bug in BackendUtil/lowest level of brittany about alignment being ignored after a comment, - Properly layout large (more than single-line) types in record fields and in data decl rhs arguments, - Properly layout data decl constructors with large "heads" (forall, constraints), - Add a config flag to control single-line layout of record definition,
|
☝️ pushed up conflict fixes. Please |
|
@tfausak great, thanks. @eborden thanks for the rebase. I have found one glitch in a special case that I have not had time to look at in the last few days. Will have a look now. If it has a simple fix I'd like to include it, otherwise I'll merge this and release. Will hopefully get back to you in the next hour or so. |
|
@lspitzner I'm not necessarily pushing for a release. I'm just pushing for merging to |
|
But once it is on master, we cannot make releases without this feature. And I'd like to make a new release with the regression fixes that are on master asap. I'll just make a patch release 0.12.1.1 and merge this immediately after. I am not happy with my latest commit (had to add another Bool to the BriDoc datatype..) but it passes all tests now. I am pretty certain that this only affects rather special cases. |
|
Thanks again @eborden . I have just released 0.12.1.1 without this feature, but we will definitely include it in the next release. I really think this is ready for publication even when it does not cover mulitple constructors yet; I just wanted to get the bugfixes out without having to organize the announcement that we should have with the new feature release. |
|
Thanks @lspitzner. My current plan is working on sums next, which I'll follow with GADTs. Let me know if this conflicts with any of your initiatives. |
My intent with this PR is to take stock of the status of the
datadeclbranch and to push for an in progress merge. This work has been pending with sporadic changes for a long time. I believe that is because of the monolithic nature of the work. An all or none strategy has not worked and is counter tobrittany's basic design on top of exact print (to be able to incrementally support new features). As well most incremental progress has been put towards refreshing the branch with each sporadic effort. This bit-rotting has been a time suck.Instead I would like to see the current work (pending a few updates) merged with the goal of providing layout for
newtypeand record styledatatypes.Current Status
Supported
Blockers
CPPfor olderghcversionsDeferred