[GHC] #13366: addCStub doesn't allow control over compiler flags or source file file

#13366: addCStub doesn't allow control over compiler flags or source file file -------------------------------------+------------------------------------- Reporter: bgamari | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Currently if you pass a C source file on the GHC command line you can control whether the compiler treats it as C or C++ via the it's extension: GCC will treat a file ending in `.c` as C, whereas `.cpp` is treated as C++. However, we currently have no means of controlling what language a stub added with in Template Haskell with `addCStub` will be treated as. Consequently it is currently impossible to compile a C++ source file with `addCStub` without using `-optc`. Moreover, you can't have mixed C/C++ stubs at all. It really seems like this interface should be amended to fix this before we release it in 8.2. Perhaps `addCStub` should accept both the source and a set of compiler flags which will be added to the usual flags (allowing one to pass `-x c++` to the compiler when compiling C++ files)? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13366 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13366: addCStub doesn't allow control over compiler flags or source file file -------------------------------------+------------------------------------- Reporter: bgamari | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by facundo.dominguez): In the current implementation all stubs go into the same file as the C stubs. This means that multiple calls of `addCStub` have visibility of the the definitions that have been inserted earlier (actually I'm not sure of the order but this could be arranged). We could send each stub to a different file certainly. And ask for forward declarations.
Moreover, you can't have mixed C/C++ stubs at all.
Not even doing {{{ addCStub "extern \"C\" { ... }" }}} ? BTW, what's wrong with using `-optc`? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13366#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13366: addCStub doesn't allow control over compiler flags or source file file -------------------------------------+------------------------------------- Reporter: bgamari | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari):
Perhaps a dumb question: What's wrong with using -optc?
It very well may break other stubs, who expect to be compiled with a C compiler (and therefore will break with C++ name mangling). These users include GHC itself, which uses C stubs for static pointers and profiler initialization. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13366#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13366: addCStub doesn't allow control over compiler flags or source file file -------------------------------------+------------------------------------- Reporter: bgamari | Owner: bitonic Type: bug | Status: new Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bitonic): * owner: (none) => bitonic -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13366#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13366: addCStub doesn't allow control over compiler flags or source file file -------------------------------------+------------------------------------- Reporter: bgamari | Owner: bitonic Type: bug | Status: new Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mboes): I'm not convinced there is any bug here. inline-c snippets really are stubs, and C ones at that, no different from the ones produced by the `capi` calling convention and foreign exports. So it makes sense to treat them as such. And even to include the inline-c snippets in the same stubs file as the other stubs, since any compiler options should apply equally to both. Now, should we furthermore support C++? I'm unconvinced that this should be done as part of `addCStub`. After all, C++ is an entirely separate language. It so happens that a large subset of C is included in C++, but that's incidental. In fact C++ is so different that name mangling is different, and not understood by GHC at all. So I think that if users want not just C stubs but also C++ stubs, that it makes sense to have `addCppStubs`, which ideally would take into account Cabal's `cpp-options`, just as `addCStubs` takes into account `cc- options`. And why not, in the future `addJavaStubs`, `addCsharpStubs` etc. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13366#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13366: addCStub doesn't allow control over compiler flags or source file file -------------------------------------+------------------------------------- Reporter: bgamari | Owner: bitonic Type: bug | Status: new Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mboes): Argh forget what I said about `cpp-options`... That's CPP as in the preprocessor obviously. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13366#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13366: addCStub doesn't allow control over compiler flags or source file file -------------------------------------+------------------------------------- Reporter: bgamari | Owner: bitonic Type: bug | Status: new Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bitonic): The situation is that right now `addCStubs` streams content to the same file that is used for Haskell-from-C exports and `capi` calls, which I think is very fragile. This file includes imports and CPP macros outside the control of the person using `addCStub`, and thus code using `addCStub` might very well break if we change how that file is generated of simply if the C code conflicts with the content that is already in the stubs file. Moreover, if we want to add multi-language support, we needed to generate multiple files anyway. So me, rwbarton, and bgamari concluded that it would be better to just let the user emit an arbitrary number of files that will be compiled and linked with the current module. This is well-suited to `inline-c` since we can collect all the stubs and emit them at once with `addModFinalizer`. Hopefully this makes the motivation for the change clearer. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13366#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13366: addCStub doesn't allow control over compiler flags or source file file -------------------------------------+------------------------------------- Reporter: bgamari | Owner: bitonic Type: feature request | Status: new Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3280 Wiki Page: | -------------------------------------+------------------------------------- Changes (by rwbarton): * differential: => Phab:D3280 * type: bug => feature request -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13366#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13366: addCStub doesn't allow control over compiler flags or source file file -------------------------------------+------------------------------------- Reporter: bgamari | Owner: bitonic Type: feature request | Status: new Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3280 Wiki Page: | -------------------------------------+------------------------------------- Comment (by facundo.dominguez): Is this addressed after merging Phab:D3280? IIUC, it is ok to use `-optc` to affect all stubs in a module as long as `-x lang` is not given. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13366#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13366: addCStub doesn't allow control over compiler flags or source file file -------------------------------------+------------------------------------- Reporter: bgamari | Owner: bitonic Type: feature request | Status: new Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3280 Wiki Page: | -------------------------------------+------------------------------------- Comment (by bitonic): Yes, this is solved by D3280, since `addForeignFile` gives the user specific support for languages other than C. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13366#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13366: addCStub doesn't allow control over compiler flags or source file file -------------------------------------+------------------------------------- Reporter: bgamari | Owner: bitonic Type: feature request | Status: closed Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3280 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bitonic): * status: new => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13366#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13366: addCStub doesn't allow control over compiler flags or source file file -------------------------------------+------------------------------------- Reporter: bgamari | Owner: bitonic Type: feature request | Status: closed Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3280 Wiki Page: | -------------------------------------+------------------------------------- Comment (by bitonic): Actually, I realized now that the scope of the ticket is a bit wider -- since it's regarding any compilation flag. It would be easy to extend `addForeignFile` to accept other flags, but I don't think is as critical (at least it isn't for my use cases). I'll leave the decision to bgamari. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13366#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13366: addCStub doesn't allow control over compiler flags or source file file -------------------------------------+------------------------------------- Reporter: bgamari | Owner: (none) Type: feature request | Status: new Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3280 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bitonic): * owner: bitonic => (none) * status: closed => new * resolution: fixed => -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13366#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13366: addCStub doesn't allow control over compiler flags or source file file -------------------------------------+------------------------------------- Reporter: bgamari | Owner: (none) Type: feature request | Status: closed Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3280 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => closed * resolution: => fixed Comment: I think the currently situation is good enough for now. Phab:D3280 was merged in 0fac488cca04a07224926e35be9c45ee2d0e1631. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13366#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13366: addCStub doesn't allow control over compiler flags or source file file -------------------------------------+------------------------------------- Reporter: bgamari | Owner: (none) Type: feature request | Status: closed Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3280 Wiki Page: | -------------------------------------+------------------------------------- Comment (by alpmestan): The `T13366` test fails on master from yesterday, when executed with the `ghci` way: {{{ =====> T13366(ghci) 1 of 1 [0, 0, 0] cd "./th/T13366.run" && "/home/alp/ghc/inplace/test spaces/ghc-stage2" T13366.hs -dcore-lint -dcmm-lint -no-user-package-db -rtsopts -fno-warn- missed-specialisations -fshow-warning-groups -fdiagnostics-color=never -fno-diagnostics-show-caret -dno-debug-output -XTemplateHaskell -package template-haskell --interactive -v0 -ignore-dot-ghci -fno-ghci-history +RTS -I0.1 -RTS -lstdc++ -v0< T13366.genscript Actual stderr output differs from expected: diff -uw "/dev/null" "./th/T13366.run/T13366.run.stderr.normalised" --- /dev/null 2018-03-07 13:03:27.344000000 +0100 +++ ./th/T13366.run/T13366.run.stderr.normalised 2018-03-08 14:49:20.583965000 +0100 @@ -0,0 +1,13 @@ +ghc: ^^ Could not load 'fcxx', dependency unresolved. See top entry above. + + +ByteCodeLink: can't find label +During interactive linking, GHCi couldn't find the following symbol: + fcxx +This may be due to you not asking GHCi to load extra object files, +archives or DLLs needed by your current session. Restart GHCi, specifying +the missing library using the -L/path/to/object/dir and -lmissinglibname +flags, or simply by naming the relevant files on the GHCi command line. +Alternatively, this link failure might indicate a bug in GHCi. +If you suspect the latter, please send a bug report to: + glasgow-haskell-bugs@haskell.org *** unexpected failure for T13366(ghci) }}} where the aforementionned symbol is defined in a snippet of C++ code that TH adds to the build through `addForeignFile`: {{{#!hs foreign import ccall fcxx :: Int -> IO Int do addForeignFile LangCxx $ unlines [ "#include <iostream>" , "extern \"C\" {" , " int fcxx(int x) {" , " std::cout << \"calling fcxx(\" << x << \")\" << std::endl;" , " std::cout.flush();" , " return A_MACRO + x;" , " }" , "}" ] return [] }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13366#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13366: addCStub doesn't allow control over compiler flags or source file file -------------------------------------+------------------------------------- Reporter: bgamari | Owner: (none) Type: feature request | Status: closed Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3280 Wiki Page: | -------------------------------------+------------------------------------- Changes (by alpmestan): * cc: alpmestan (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13366#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC