Opened 5 years ago

Closed 5 years ago

#4063 closed feature request (fixed)

target "is not a module name or a source file"

Reported by: beroal Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.12.2
Keywords: target, module name, source file, flag Cc: rabeslik@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

Create a standalone Haskell program "/tmp/delme.hs". Then do

$ cd /tmp
{- 0 -}$ ghc --make -o delme.exe /tmp/delme.hs
[1 of 1] Compiling Main ( /tmp/delme.hs, /tmp/delme.o )
Linking delme.exe ...
$ rm delme.o
{- 1 -}$ ghc --make -o delme.exe /tmp/delme
[1 of 1] Compiling Main ( /tmp/delme.hs, /tmp/delme.o )
Linking delme.exe ...
$ rm delme.o
$ mv delme.hs delme
{- 2 -}$ ghc --make -o delme.exe /tmp/delme
target `/tmp/delme' is not a module name or a source file

We see that:

  • in "1" GHC compiles "/tmp/delme.hs" though I say "/tmp/delme";
  • in "2" GHC can not see file "/tmp/delme".

The problem is that a target (the last argument) may be a module name or a source file. GHC uses heuristics to determine this. Though heuristics may seem neat and clever, they draw GHC more intricate and unpredictable (see also KISS).

I encountered this intricacy when ran "ghc" on a shell script. Shell scripts in Unix commonly do not have extensions, because interpreter name is included in a shell script. And "runghc" runs them fine. "ghc" in theory also does not require a file to have an extension because it clearly contains Haskell source code — what else?

I propose to introduce a GHC flag which says explicitly which type a target is of.

Change History (5)

comment:1 Changed 5 years ago by beroal

  • Cc rabeslik@… added

comment:2 Changed 5 years ago by simonmar

GHC already has such a flag, -x. See section 4.4.3.1: http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/modes.html#options-order,

Maybe you'd like us to simplify the heuristics, perhaps removing the option to omit the .hs or .lhs suffix for a source file (your example 1 above). I wouldn't strongly object to that, if there was general support for it, though I suspect it might offend some people who are used to the shortcut ghc --make hello. I certainly use that myself quite a lot, and in 6.14 it will get even simpler, as --make is now the default.

comment:3 follow-up: Changed 5 years ago by beroal

Thanks Simon for the answer. I do not object to GHC appending file extension and recognizing target type by default. But I fail to see how "-x" may be a solution: it substitute an extension so makes matters even more complex. Suppose that Haskell file is named "del.me" — with "-x hs" would compile "del.hs" — failed again. ;)

I mean like "--target-find file" and "--target-find module", "--target-find" turns heuristics off, default behavior is not changed.

comment:4 in reply to: ↑ 3 Changed 5 years ago by simonmar

Replying to beroal:

Thanks Simon for the answer. I do not object to GHC appending file extension and recognizing target type by default. But I fail to see how "-x" may be a solution: it substitute an extension so makes matters even more complex. Suppose that Haskell file is named "del.me" — with "-x hs" would compile "del.hs" — failed again. ;)

Hmm, I think you may have misunderstood what -x does:

$ cat >del.me
module Main where
main = putStrLn "hello"
$ ghc -x hs del.me --make
[1 of 1] Compiling Main             ( del.me, del.o )
Linking del ...

Isn't that what you wanted?

comment:5 Changed 5 years ago by beroal

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.