ndmitchell / hlint

Haskell source code suggestions
Other
1.47k stars 196 forks source link

Error thrown on CPP in the `base` codebase #1075

Closed Kleidukos closed 4 years ago

Kleidukos commented 4 years ago

The CPP code block is :

#if defined(i386_HOST_ARCH)     
# define WINDOWS_CCONV stdcall  
#elif defined(x86_64_HOST_ARCH) 
# define WINDOWS_CCONV ccall    
#else                           
# error Unknown mingw32 arch    
#endif                          
shayne-fletcher commented 4 years ago

Perhaps adding --cpp-define x86_64_HOST_ARCH to the hlint invocation will help here?

Kleidukos commented 4 years ago

Perfect! I still get a rather peculiar message from hlint, but other than that, no problem whatsoever!

Warning: unknown directive #-}
in libraries/base/Unsafe/Coerce.hs  at line 311 col 1
No hints

This is the file in question: https://gitlab.haskell.org/ghc/ghc/-/blob/master/libraries/base/Unsafe/Coerce.hs#L303-311

shayne-fletcher commented 4 years ago

Perfect! I still get a rather peculiar message from hlint, but other than that, no problem whatsoever!

Awesome.

Warning: unknown directive #-}
in libraries/base/Unsafe/Coerce.hs  at line 311 col 1
No hints

This is the file in question: https://gitlab.haskell.org/ghc/ghc/-/blob/master/libraries/base/Unsafe/Coerce.hs#L303-311

Ha. That's a genuine problem. The C-preprocessor is being run over the file and it doesn't know what to make of a line that reads,

#-}

and that's where the warning is coming from. This is because the C-preprocessor interprets lines beginning with a # as being those with directives meant for it. Putting a space in front of the leading # will fix it.

If this were purely a language extension issue then potential fixes would include:

However, I'm not sure in this instance those things alone will do. I don't know if/how HLint can be told to not run CPP in general. @ndmitchell can you advise please?

Kleidukos commented 4 years ago

@shayne-fletcher Thanks for the fix! I'll be sure to document the hows and whys on the GHC side. Cheers!

ndmitchell commented 4 years ago

-XNoCpp turns off CPP entirely, --cpp-simple just strips lines with a leading # but otherwise ignores CPP markup. But in this case, with complex CPP, passing a valid set of CPP options as Shayne suggests is the right thing to do.