Formatting removes key program components in custom data structures #368

Open
opened 2022-03-22 01:26:45 +01:00 by L0neGamer · 3 comments
L0neGamer commented 2022-03-22 01:26:45 +01:00 (Migrated from github.com)

See below of the before and after of running brittany --config-file=brittany.yaml --write-mode=inplace $(git ls-files '*.hs') using the default config on versions 0.14.0.0, and 0.14.0.2.

before
after

As is evident, the code produced is completely unable to compile.

See below of the before and after of running `brittany --config-file=brittany.yaml --write-mode=inplace $(git ls-files '*.hs')` using the default config on versions 0.14.0.0, and 0.14.0.2. ![before](https://user-images.githubusercontent.com/10566848/159384098-3f23d8a3-8519-47c7-b6fc-25a89093ebb6.jpg) ![after](https://user-images.githubusercontent.com/10566848/159384111-4ed2f882-63d4-4dcc-8aaa-f5be80ba12d8.jpg) As is evident, the code produced is completely unable to compile.
tfausak commented 2022-03-22 02:36:23 +01:00 (Migrated from github.com)

Dang, that's a gnarly bug! Unfortunately Brittany only barely supports GADTs. See #217, #242, and #261 for some other examples.

Dang, that's a gnarly bug! Unfortunately Brittany only barely supports GADTs. See #217, #242, and #261 for some other examples.
L0neGamer commented 2022-03-22 11:25:25 +01:00 (Migrated from github.com)

I managed to resist putting "catastrophic reformatting on data structures" as the title, cause yeah this is bad lol.

Is there anywhere in particular in the code where this could be solved? I'm not familiar with formatters.

I managed to resist putting "catastrophic reformatting on data structures" as the title, cause yeah this is bad lol. Is there anywhere in particular in the code where this could be solved? I'm not familiar with formatters.
prikhi commented 2022-06-14 19:48:38 +02:00 (Migrated from github.com)

This is currently preventing us from using brittany after we upgrade to LTS-19, so I did a little digging...

GADTs trigger this formatting line in Internal.Layouters.DataDecl.layoutDataDecl:

  _ -> briDocByExactNoComment ltycl

so I thought maybe this was an issue in ghc-exactprint, made a little harness that uses exactprint to parse & print a GADT but I get the proper output back:

doIt :: FilePath -> IO ()
doIt fp = do
    raw <- readFile fp
    putStr raw
    putStrLn $ replicate 80 '-'
    (anns, res) <- either (error . show . bagToList) return =<< parseModule fp
    putStrLn $ exactPrint res anns
λ: :l ExactPrintHarness.hs 
[1 of 1] Compiling ExactPrintHarness ( ExactPrintHarness.hs, interpreted )
Ok, one module loaded.
λ: doIt "GadtFormatting.hs"
{-# LANGUAGE GADTs #-}
module GadtFormatting where

data MyGadt a where
    MyInt :: Int -> MyGadt Int
--------------------------------------------------------------------------------
{-# LANGUAGE GADTs #-}
module GadtFormatting where

data MyGadt a where
    MyInt :: Int -> MyGadt Int

logging out the ltycl in that case branch(with briDocByExactNoComment $ traceShow (showSDocUnsafe $ ppr ltycl) $ ltycl via new test file I wrote) gives us:

data Stuff a\n  where\n    AnInt :: Int -> Stuff Int\n    AString :: String -> Stuff String

So I'm inclined to believe the problem lies somewhere within briDocByExactNoComment, but I haven't dug much further than that yet.

This is currently preventing us from using brittany after we upgrade to LTS-19, so I did a little digging... GADTs trigger this formatting line in `Internal.Layouters.DataDecl.layoutDataDecl`: ``` _ -> briDocByExactNoComment ltycl ``` so I thought maybe this was an issue in `ghc-exactprint`, made a little harness that uses exactprint to parse & print a GADT but I get the proper output back: ```haskell doIt :: FilePath -> IO () doIt fp = do raw <- readFile fp putStr raw putStrLn $ replicate 80 '-' (anns, res) <- either (error . show . bagToList) return =<< parseModule fp putStrLn $ exactPrint res anns ``` ``` λ: :l ExactPrintHarness.hs [1 of 1] Compiling ExactPrintHarness ( ExactPrintHarness.hs, interpreted ) Ok, one module loaded. λ: doIt "GadtFormatting.hs" {-# LANGUAGE GADTs #-} module GadtFormatting where data MyGadt a where MyInt :: Int -> MyGadt Int -------------------------------------------------------------------------------- {-# LANGUAGE GADTs #-} module GadtFormatting where data MyGadt a where MyInt :: Int -> MyGadt Int ``` logging out the `ltycl` in that case branch(with `briDocByExactNoComment $ traceShow (showSDocUnsafe $ ppr ltycl) $ ltycl` via new test file I wrote) gives us: ``` data Stuff a\n where\n AnInt :: Int -> Stuff Int\n AString :: String -> Stuff String ``` So I'm inclined to believe the problem lies somewhere within `briDocByExactNoComment`, but I haven't dug much further than that yet.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: hexagoxel/brittany#368
There is no content yet.