[GHC] #15279: CPP #includes may result in nonsensical SrcSpans

GHC ghc-devs at haskell.org
Sun Jun 17 13:05:25 UTC 2018


#15279: CPP #includes may result in nonsensical SrcSpans
-------------------------------------+-------------------------------------
           Reporter:  wz1000         |             Owner:  (none)
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.4.3
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  Other
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 Consider the following code in `compiler/prelude/PrimOp.hs`
 {{{#!hs
 primOpInfo :: PrimOp -> PrimOpInfo
 #include "primop-primop-info.hs-incl"
 primOpInfo _ = error "primOpInfo: unknown primop" -- line 175 in PrimOp.hs
 }}}
 The MatchGroup for primOpInfo includes the `SrcSpan`

 `compiler/stage2/build/primop-primop-info.hs-incl:(1,1)-(175,49)`

 Here is line 175 in `primop-primop-info.hs-incl`
 {{{#!hs
 primOpInfo IndexSmallArrayOp = mkGenPrimOp (fsLit "indexSmallArray#")
 [alphaTyVar] [mkSmallArrayPrimTy alphaTy, intPrimTy] ((mkTupleTy Unboxed
 [alphaTy]))
 }}}

 The `SrcSpan`s end is somewhere in the middle of that line.

 I guess this occurs because `combineSrcSpans` doesn't take the file into
 account.

 I can think of multiple ways to fix this:

 1. Make `combineSrcSpans` output an `UnhelpfulSrcSpan` if the files don't
 match(quick and easy)
 2. Extend SrcSpan to properly support things spanning multiple files
 3. Don't fix: People who use CPP get what they deserve.

 Option 3 is not unreasonable as options 1 and 2 will incur some
 performance penalty.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15279>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list