BangPatterns bang is silently removed #116

Closed
opened 2018-01-22 18:12:46 +01:00 by lspitzner · 1 comment
lspitzner commented 2018-01-22 18:12:46 +01:00 (Migrated from github.com)

I think I saw this in do-notation. This is rather serious, as this kind of error will not be detected, but the code will behave differently.

I think I saw this in do-notation. This is rather serious, as this kind of error will not be detected, but the code will behave differently.
lspitzner commented 2018-02-13 23:00:56 +01:00 (Migrated from github.com)

I'll document a bit how I approach this issue for anyone interested.

First thing I noticed is that this does not appear in ghc-8.0. But in ghc-8.2.* a failing testcase would be

{-# LANGUAGE BangPatterns #-}
func = do
  let !abc = def
  pure ()

Looking at the parse trees via --dump-ast-full, they are indeed a good bit different. Just for the !abc = def part above, we have:

  • 8.0

    PatBind
      A Just (Ann (DP (0,0)) [] [] [((G AnnBang),DP (0,0))] Nothing Nothing)
        BangPat
          A Just (Ann (DP (0,0)) [] [] [((G AnnVal),DP (0,0))] Nothing Nothing)
            VarPat
              A Nothing
                Unqual {OccName: abc}
      GRHSs
        [ A Just (Ann (DP (0,-1)) [] [] [] Nothing Nothing)
            GRHS
              []
              A Just (Ann (DP (0,1)) [] [] [] Nothing Nothing)
                HsVar
                  A Just (Ann (DP (0,0)) [] [] [((G AnnVal),DP (0,0))] Nothing Nothing)
                    Unqual {OccName: def}
        ]
        A (Nothing) EmptyLocalBinds
      PlaceHolder
      PlaceHolder
      (,) [] []
    
  • 8.2

    FunBind
      A Just (Ann (DP (0,0)) [] [] [((G AnnVal),DP (0,0))] Nothing Nothing)
        Unqual {OccName: abc}
      MG
        A Nothing
          [ A Just (Ann (DP (0,0)) [] [] [((G AnnBang),DP (0,0)),((G AnnEqual),DP (0,1))] Nothing Nothing)
              Match
                FunRhs
                  A Just (Ann (DP (0,0)) [] [] [((G AnnVal),DP (0,0))] Nothing Nothing)
                    Unqual {OccName: abc}
                  Prefix
                  SrcStrict
                []
                Nothing
                GRHSs
                  [ A Just (Ann (DP (0,-1)) [] [] [] Nothing Nothing)
                      GRHS
                        []
                        A Just (Ann (DP (0,1)) [] [] [] Nothing Nothing)
                          HsVar
                            A Just (Ann (DP (0,0)) [] [] [((G AnnVal),DP (0,0))] Nothing Nothing)
                              Unqual
                                {OccName: def}
                  ]
                  A (Nothing) EmptyLocalBinds
          ]
        []
        PlaceHolder
        FromSource
      WpHole
      PlaceHolder
      []
    

As brittany currently ignores the first argument of Match we ignore the only trace of the bang, namely SrcStrict.

I'll write a fix next.

I'll document a bit how I approach this issue for anyone interested. First thing I noticed is that this does not appear in ghc-8.0. But in ghc-8.2.* a failing testcase would be ~~~~.hs {-# LANGUAGE BangPatterns #-} func = do let !abc = def pure () ~~~~ --- Looking at the parse trees via --dump-ast-full, they are indeed a good bit different. Just for the `!abc = def` part above, we have: - 8.0 ~~~~ PatBind A Just (Ann (DP (0,0)) [] [] [((G AnnBang),DP (0,0))] Nothing Nothing) BangPat A Just (Ann (DP (0,0)) [] [] [((G AnnVal),DP (0,0))] Nothing Nothing) VarPat A Nothing Unqual {OccName: abc} GRHSs [ A Just (Ann (DP (0,-1)) [] [] [] Nothing Nothing) GRHS [] A Just (Ann (DP (0,1)) [] [] [] Nothing Nothing) HsVar A Just (Ann (DP (0,0)) [] [] [((G AnnVal),DP (0,0))] Nothing Nothing) Unqual {OccName: def} ] A (Nothing) EmptyLocalBinds PlaceHolder PlaceHolder (,) [] [] ~~~~ - 8.2 ~~~~ FunBind A Just (Ann (DP (0,0)) [] [] [((G AnnVal),DP (0,0))] Nothing Nothing) Unqual {OccName: abc} MG A Nothing [ A Just (Ann (DP (0,0)) [] [] [((G AnnBang),DP (0,0)),((G AnnEqual),DP (0,1))] Nothing Nothing) Match FunRhs A Just (Ann (DP (0,0)) [] [] [((G AnnVal),DP (0,0))] Nothing Nothing) Unqual {OccName: abc} Prefix SrcStrict [] Nothing GRHSs [ A Just (Ann (DP (0,-1)) [] [] [] Nothing Nothing) GRHS [] A Just (Ann (DP (0,1)) [] [] [] Nothing Nothing) HsVar A Just (Ann (DP (0,0)) [] [] [((G AnnVal),DP (0,0))] Nothing Nothing) Unqual {OccName: def} ] A (Nothing) EmptyLocalBinds ] [] PlaceHolder FromSource WpHole PlaceHolder [] ~~~~ As `brittany` currently ignores the first argument of `Match` we ignore the only trace of the bang, namely `SrcStrict`. I'll write a fix next.
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#116
There is no content yet.