Skip to content

CPP #includes may result in nonsensical SrcSpans

Consider the following code in compiler/prelude/PrimOp.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

primOpInfo IndexSmallArrayOp = mkGenPrimOp (fsLit "indexSmallArray#") [alphaTyVar] [mkSmallArrayPrimTy alphaTy, intPrimTy] ((mkTupleTy Unboxed [alphaTy]))

The SrcSpans 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.

Trac metadata
Trac field Value
Version 8.4.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information