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

Pretty-print RecordField comments #2021

Merged
merged 1 commit into from
Sep 10, 2020

Conversation

sjakobi
Copy link
Collaborator

@sjakobi sjakobi commented Sep 2, 2020

Context: #145

dhall/tests/Dhall/Test/QuickCheck.hs Outdated Show resolved Hide resolved
dhall/src/Dhall/Pretty/Internal.hs Outdated Show resolved Hide resolved
@Gabriella439
Copy link
Collaborator

@sjakobi: Thank you for doing this! 🙂

Would you like me to begin reviewing or do you want to wait until the PR is out of draft status?

@sjakobi
Copy link
Collaborator Author

sjakobi commented Sep 2, 2020

Would you like me to begin reviewing or do you want to wait until the PR is out of draft status?

The actual code still needs a lot of work and is probably not worth reviewing yet. If you have feedback on the test output though, I can try to incorporate that.

@sjakobi
Copy link
Collaborator Author

sjakobi commented Sep 2, 2020

Some normalization logic seems to need updating:

    isNormalized should be consistent with normalize:                                                                          FAIL
      *** Failed! Falsified (after 22 tests and 4 shrinks):
      RecordLit (fromList [("",RecordField {recordFieldSrc0 = Nothing, recordFieldValue = Var (V "" 0), recordFieldSrc1 = Nothing, recordFieldSrc2 = Just ()})])
      True /= False
      Use --quickcheck-replay=139332 to reproduce.

@sjakobi
Copy link
Collaborator Author

sjakobi commented Sep 2, 2020

I've been staring it this part of isNormalized but didn't understand how it would report the wrong thing!

RecordLit kvs -> Dhall.Map.isSorted kvs && all decide kvs
where
decide (RecordField Nothing exp' Nothing Nothing) = loop exp'
decide _ = False

The issue is that isNormalized applies denote first:

isNormalized e0 = loop (Syntax.denote e0)

How about removing this denote step?!

@sjakobi
Copy link
Collaborator Author

sjakobi commented Sep 2, 2020

How about removing this denote step?!

That would probably make pattern matching on Exprs like in this part much more complex:

App f a -> loop f && loop a && case App f a of
App (Lam _ _) _ -> False
App (App (App (App NaturalFold (NaturalLit _)) _) _) _ -> False
App NaturalBuild _ -> False
App NaturalIsZero (NaturalLit _) -> False
App NaturalEven (NaturalLit _) -> False
App NaturalOdd (NaturalLit _) -> False
App NaturalShow (NaturalLit _) -> False
App (App NaturalSubtract (NaturalLit _)) (NaturalLit _) -> False
App (App NaturalSubtract (NaturalLit 0)) _ -> False
App (App NaturalSubtract _) (NaturalLit 0) -> False
App (App NaturalSubtract x) y -> not (Eval.judgmentallyEqual x y)
App NaturalToInteger (NaturalLit _) -> False
App IntegerNegate (IntegerLit _) -> False
App IntegerClamp (IntegerLit _) -> False
App IntegerShow (IntegerLit _) -> False
App IntegerToDouble (IntegerLit _) -> False
App DoubleShow (DoubleLit _) -> False
App (App ListBuild _) _ -> False
App (App (App (App (App (App ListFold _) (ListLit _ _)) _) _) _) _ -> False
App (App ListLength _) (ListLit _ _) -> False
App (App ListHead _) (ListLit _ _) -> False
App (App ListLast _) (ListLit _ _) -> False
App (App ListIndexed _) (ListLit _ _) -> False
App (App ListReverse _) (ListLit _ _) -> False
App TextShow (TextLit (Chunks [] _)) ->

@Gabriella439
Copy link
Collaborator

@sjakobi: Not necessarily. You could still do the ViewPatterns trick where you do something like:

App (shallowDenote -> App (shallowDenote -> 

… possibly with a short-hand synonym for shallowDenote to save characters.

Comment on lines +628 to +630
-- Dhall.Core.isNormalized ignores 'Note's and other annotations.
-- So we do the same when checking the result of 'normalize'.
return $ isNormalized === (nf == denotedExpression)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I went with this simple test fix in order to keep the focus on the pretty-printer changes.

@sjakobi sjakobi force-pushed the sjakobi/145-pretty-record-field-comments branch from 4dc37ac to f3a24ce Compare September 4, 2020 10:29
@sjakobi sjakobi changed the title [WIP] Pretty-print RecordField comments Pretty-print RecordField comments Sep 4, 2020
@sjakobi sjakobi marked this pull request as ready for review September 4, 2020 10:34
@sjakobi
Copy link
Collaborator Author

sjakobi commented Sep 4, 2020

BTW, note that I'll be mostly AFK during the weekend. I expect to be able to address any review feedback on Monday.

Feel free to take over the PR if you would like to merge it sooner.

@sjakobi
Copy link
Collaborator Author

sjakobi commented Sep 9, 2020

The output is worth another look at this stage. I'm pretty happy with it.

The code still needs a bit of cleanup though.

@sjakobi
Copy link
Collaborator Author

sjakobi commented Sep 9, 2020

@Gabriel439 Could you review?

@TristanCacqueray
Copy link
Collaborator

I guess preserving and pretty-printing comment for Union type is out of scope, but will those changes also facilitate such addition?

@sjakobi
Copy link
Collaborator Author

sjakobi commented Sep 9, 2020

I guess preserving and pretty-printing comment for Union type is out of scope, but will those changes also facilitate such addition?

Definitely. The pretty-printer will be well-prepared after this PR. What remains to be done is updating the parser and updating the code in response to the necessary Expr changes.

Copy link
Collaborator

@german1608 german1608 left a comment

Choose a reason for hiding this comment

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

My only concern with the implementation is that it confuses me a little the difference between render and pretty in some functions (prettyComment and renderComment for example) but I don't have better names for those.

I believe that the output of the formatter is OK as I'm not too opinionated about the result. Making dhall format not delete comment it's the main goal from my POV

dhall/src/Dhall/Pretty/Internal.hs Show resolved Hide resolved
dhall/src/Dhall/Pretty/Internal.hs Outdated Show resolved Hide resolved
@sjakobi sjakobi force-pushed the sjakobi/145-pretty-record-field-comments branch from 3e17684 to 8108411 Compare September 10, 2020 08:47
@sjakobi
Copy link
Collaborator Author

sjakobi commented Sep 10, 2020

Thanks for the review @german1608! :)

Copy link
Collaborator

@Gabriella439 Gabriella439 left a comment

Choose a reason for hiding this comment

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

Thank you for doing this! 🙂

Also:
* Use tasty-silver for format tests
* Ignore annotations in isNormalizedIsConsistentWithNormalize
@sjakobi sjakobi force-pushed the sjakobi/145-pretty-record-field-comments branch from 8108411 to 948988b Compare September 10, 2020 15:17
@mergify mergify bot merged commit b453abf into master Sep 10, 2020
@mergify mergify bot deleted the sjakobi/145-pretty-record-field-comments branch September 10, 2020 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants