Skip to content

WIP: use prettyprinter rather than ghc-source-gen#522

Draft
TeofilC wants to merge 1 commit intogoogle:masterfrom
TeofilC:wip/prettyprinter
Draft

WIP: use prettyprinter rather than ghc-source-gen#522
TeofilC wants to merge 1 commit intogoogle:masterfrom
TeofilC:wip/prettyprinter

Conversation

@TeofilC
Copy link
Copy Markdown

@TeofilC TeofilC commented Dec 31, 2025

No description provided.

@google-cla
Copy link
Copy Markdown

google-cla bot commented Dec 31, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@TeofilC
Copy link
Copy Markdown
Author

TeofilC commented Dec 31, 2025

I have created a shim that uses prettyprinter to reimplement the bits of the ghc-source-gen interface we use. It's currently horribly broken but stuff compiles so that's a start! Then I will work to get rid of this shim.



module' :: Maybe ModuleNameStr -> Maybe [IE'] -> [ImportDecl'] -> [HsDecl'] -> HsModule'
module' (Just nm) (mexports) imports decls =

Check warning

Code scanning / HLint

Redundant bracket Warning

proto-lens-protoc/app/Prettyprinter/GHC.hs:109:19-28: Warning: Redundant bracket
  
Found:
  (mexports)
  
Perhaps:
  mexports
Right fs -> preamble & #file .~
[ defMessage
& #name .~ outputName
& #name .~ (traceShowId outputName)

Check notice

Code scanning / HLint

Redundant bracket Note

proto-lens-protoc/app/protoc-gen-haskell.hs:76:25-48: Suggestion: Redundant bracket
  
Found:
  #name . (traceShowId outputName)
  
Perhaps:
  #name . traceShowId outputName
@blackgnezdo
Copy link
Copy Markdown
Collaborator

I have created a shim that uses prettyprinter to reimplement the bits of the ghc-source-gen interface we use. It's currently horribly broken but stuff compiles so that's a start! Then I will work to get rid of this shim.

Good start! I see that ghc-9.10 can compile the PR, the older versions still need more work.

@TeofilC TeofilC force-pushed the wip/prettyprinter branch from 5b96e63 to c52a71e Compare January 1, 2026 22:07
@TeofilC
Copy link
Copy Markdown
Author

TeofilC commented Jan 1, 2026

Good spot. They changed the module names in a recent version. I'll switch back to the old names so that the versions from those snapshots will work.

@TeofilC TeofilC force-pushed the wip/prettyprinter branch from c52a71e to b2554e3 Compare January 4, 2026 21:18
pretty ImportDecl{..} =
hsep $
["import"]
++ (if isSource then ["{-# SOURCE #-}"] else [])

Check notice

Code scanning / HLint

Use list comprehension Note

proto-lens-protoc/app/Prettyprinter/GHC.hs:102:11-53: Suggestion: Use list comprehension
  
Found:
  if isSource then ["{-# SOURCE #-}"] else []
  
Perhaps:
  ["{-# SOURCE #-}" | isSource]
hsep $
["import"]
++ (if isSource then ["{-# SOURCE #-}"] else [])
++ (if isQualified then ["qualified"] else [])

Check notice

Code scanning / HLint

Use list comprehension Note

proto-lens-protoc/app/Prettyprinter/GHC.hs:103:11-51: Suggestion: Use list comprehension
  
Found:
  if isQualified then ["qualified"] else []
  
Perhaps:
  ["qualified" | isQualified]
++ (if isQualified then ["qualified"] else [])
++ [pretty ideclName]
++ es
++ (maybe [] (\as -> ["as", pretty as]) ideclAs)

Check notice

Code scanning / HLint

Redundant bracket Note

proto-lens-protoc/app/Prettyprinter/GHC.hs:106:10-54: Suggestion: Redundant bracket
  
Found:
  es ++ (maybe [] (\ as -> ["as", pretty as]) ideclAs)
  
Perhaps:
  es ++ maybe [] (\ as -> ["as", pretty as]) ideclAs
unit = "()"

if' :: Doc' -> Doc' -> Doc' -> Doc'
if' c y n = "if" <+> c <+> "then" <+> (nest 2 (line <> y) <> line) <+> "else" <+> (nest 2 (line <> n))

Check notice

Code scanning / HLint

Redundant bracket Note

proto-lens-protoc/app/Prettyprinter/GHC.hs:277:83-102: Suggestion: Redundant bracket
  
Found:
  "else" <+> (nest 2 (line <> n))
  
Perhaps:
  "else" <+> nest 2 (line <> n)
strict :: Doc' -> Doc'
strict x = "!" <> parens x

tyApp lhs rhs = lhs <+> "@" <> (parens rhs)

Check notice

Code scanning / HLint

Redundant bracket Note

proto-lens-protoc/app/Prettyprinter/GHC.hs:284:32-43: Suggestion: Redundant bracket
  
Found:
  "@" <> (parens rhs)
  
Perhaps:
  "@" <> parens rhs
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.

3 participants