Add -fdefer-ffi-errors flag
Currently when I do:
foreign import javascript unsafe
"foo()"
foo :: IO ()
I understandably get:
• The `javascript' calling convention is unsupported on this platform
• When checking declaration:
foreign import javascript unsafe "static foo()" foo :: IO ()
However when I am developing with GHCJS I still want to use all my typical GHC tooling, a lot of which is not supported on GHCJS. So I need GHC to be able to compile my code even though I don't actually run it, currently I often have to do:
#ifdef __GHCJS__
foreign import javascript unsafe
"foo()"
foo :: IO ()
#else
foo :: IO ()
foo = error "GHCJS required to use foo"
#endif
Which is really noisy and annoying code to write, and it also does not help me with compiling external library code that does not do the above. It also pins me specifically to GHCJS and any future compiler that supports JS to any degree will need the code changed.
The easiest solution to the problem seems to me to be a -fdefer-ffi-errors
flag which replaces any unsupported ffi declaration with a runtime error
call that gives a similar error message to the one currently given at compile time. I would also like a -fdefer-ffi-errors-no-warn
flag to avoid my tooling complaining / emitting a bunch of warnings that don't actually help me much.
This is not a very exciting request, but it would be a huge quality of life improvement for front end Haskell web development, and it does not seem overly difficult or dangerous to implement.
Trac metadata
Trac field | Value |
---|---|
Version | 8.2.1 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |