X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=docs%2Fusers_guide%2Fusing.xml;h=024a4e786963db7c0e2e3fef87fa9653dc679ffa;hp=aa133ee35aa10eadb74ff0cb84e2317860a46dd9;hb=9d0c8f842e35dde3d570580cf62a32779f66a6de;hpb=ba5729e5b8d80b3fcc8a477cb36d6a03800ac0dd diff --git a/docs/users_guide/using.xml b/docs/users_guide/using.xml index aa133ee..024a4e7 100644 --- a/docs/users_guide/using.xml +++ b/docs/users_guide/using.xml @@ -14,7 +14,7 @@ Options can be specified in three ways: - command-line arguments + Command-line arguments structure, command-line command-linearguments @@ -26,9 +26,9 @@ ghc [argument...] - command-line arguments are either options or file names. + Command-line arguments are either options or file names. - command-line options begin with -. + Command-line options begin with -. They may not be grouped: is different from . Options need not precede filenames: e.g., ghc *.o -o @@ -40,32 +40,31 @@ ghc [argument...] - command line options in source files + Command line options in source files source-file options Sometimes it is useful to make the connection between a source file and the command-line options it requires quite - tight. For instance, if a Haskell source file uses GHC - extensions, it will always need to be compiled with the - option. Rather than maintaining + tight. For instance, if a Haskell source file deliberately + uses name shadowing, it should be compiled with the + option. Rather than maintaining the list of per-file options in a Makefile, it is possible to do this directly in the source file using the OPTIONS_GHC pragma OPTIONS_GHC pragma: -{-# OPTIONS_GHC -fglasgow-exts #-} +{-# OPTIONS_GHC -fno-warn-name-shadowing #-} module X where ... - OPTIONS_GHC pragmas are only looked for at - the top of your source files, upto the first - (non-literate,non-empty) line not containing - OPTIONS_GHC. Multiple OPTIONS_GHC - pragmas are recognised. Do not put comments before, or on the same line - as, the OPTIONS_GHC pragma. + OPTIONS_GHC is a file-header pragma + (see ). + + Only dynamic flags can be used in an OPTIONS_GHC pragma + (see ). Note that your command shell does not get to the source file options, they are just included literally @@ -73,15 +72,14 @@ module X where maintains internally, so you'll be desperately disappointed if you try to glob etc. inside OPTIONS_GHC. - NOTE: the contents of OPTIONS_GHC are prepended to the - command-line options, so you do have the - ability to override OPTIONS_GHC settings via the command - line. + NOTE: the contents of OPTIONS_GHC are appended to the + command-line options, so options given in the source file + override those given on the command-line. It is not recommended to move all the contents of your Makefiles into your source files, but in some circumstances, the OPTIONS_GHC pragma is the Right Thing. (If you - use and have OPTION flags in + use and have OPTION flags in your module, the OPTIONS_GHC will get put into the generated .hc file). @@ -104,8 +102,8 @@ module X where modeoptions - Each of GHC's command line options is classified as either - static or dynamic or + Each of GHC's command line options is classified as + static, dynamic or mode: @@ -113,7 +111,7 @@ module X where Mode flags For example, or . - There may be only a single mode flag on the command line. The + There may only be a single mode flag on the command line. The available modes are listed in . @@ -122,7 +120,7 @@ module X where Most non-mode flags fall into this category. A dynamic flag may be used on the command line, in a - GHC_OPTIONS pragma in a source file, or set + OPTIONS_GHC pragma in a source file, or set using :set in GHCi. @@ -138,6 +136,11 @@ module X where The flag reference tables () lists the status of each flag. + + There are a few flags that are static except that they can + also be used with GHCi's :set command; these + are listed as “static/:set” in the + table. @@ -225,8 +228,7 @@ module X where - ghc - ––interactive + ghc --interactive interactive mode ghci @@ -240,8 +242,7 @@ module X where - ghc - ––make + ghc --make make mode @@ -258,8 +259,8 @@ module X where - ghc - –e expr + ghc -e + expr eval mode @@ -275,13 +276,10 @@ module X where - ghc - - -E - -C - -S - -c - + ghc -E + ghc -c + ghc -S + ghc -c @@ -302,8 +300,7 @@ module X where - ghc - –M + ghc -M dependency-generation mode @@ -311,23 +308,119 @@ module X where Dependency-generation mode. In this mode, GHC can be used to generate dependency information suitable for use in a Makefile. See . + linkend="makefile-dependencies"/>. - ghc - ––mk-dll + ghc --mk-dll - dependency-generation mode + DLL-creation mode DLL-creation mode (Windows only). See . + + + + + ghc --help ghc -? + + + + + Cause GHC to spew a long usage message to standard + output and then exit. + + + + + + + ghc --show-iface file + + + + + Read the interface in + file and dump it as text to + stdout. For example ghc --show-iface M.hi. + + + + + + + ghc --supported-languages + + + + + Print the supported language extensions. + + + + + + + ghc --info + + + + + Print information about the compiler. + + + + + + + ghc --version + ghc -V + + + + + + Print a one-line string including GHC's version number. + + + + + + + ghc --numeric-version + + + + + Print GHC's numeric version number only. + + + + + + + ghc --print-libdir + + + + + Print the path to GHC's library directory. This is + the top of the directory tree containing GHC's libraries, + interfaces, and include files (usually something like + /usr/local/lib/ghc-5.04 on Unix). This + is the value of + $libdirlibdir + in the package configuration file + (see ). + + + @@ -337,7 +430,7 @@ module X where When given the option, GHC will build a multi-module Haskell program by following - dependencies from a single root module (usually + dependencies from one or more root modules (usually just Main). For example, if your Main module is in a file called Main.hs, you could compile and link the @@ -351,7 +444,7 @@ ghc ––make Main.hs names or module names; GHC will figure out all the modules in the program by following the imports from these initial modules. It will then attempt to compile each module which is out of - date, and finally if there is a Main module, + date, and finally, if there is a Main module, the program will also be linked into an executable. The main advantages to using ghc @@ -446,7 +539,7 @@ olleh The first phase to run is determined by each input-file suffix, and the last phase is determined by a flag. If no - relevant flag is present, then go all the way through linking. + relevant flag is present, then go all the way through to linking. This table summarises: @@ -538,15 +631,13 @@ ghc -c Foo.hs Note: The option -E option runs just the pre-processing passes - of the compiler, dumping the result in a file. Note that this - differs from the previous behaviour of dumping the file to - standard output. + of the compiler, dumping the result in a file. Overriding the default behaviour for a file As described above, the way in which a file is processed by GHC - depends on its suffix. This behaviour can be overriden using the + depends on its suffix. This behaviour can be overridden using the option: @@ -574,24 +665,11 @@ ghc -c Foo.hs help options verbosity options + See also the , , , + and modes in . - - - - - - - - - Cause GHC to spew a long usage message to standard - output and then exit. - - - - - @@ -685,47 +763,6 @@ ghc -c Foo.hs - - - - - - - - - - Print a one-line string including GHC's version number. - - - - - - - - - - Print GHC's numeric version number only. - - - - - - - - - - Print the path to GHC's library directory. This is - the top of the directory tree containing GHC's libraries, - interfaces, and include files (usually something like - /usr/local/lib/ghc-5.04 on Unix). This - is the value of - $libdirlibdir - in the package configuration file (see ). - - - - @@ -803,10 +840,15 @@ ghc -c Foo.hs of warnings which are generally likely to indicate bugs in your program. These are: , - , + , + , , - , and - . The following flags are + , + , + , + , and + . The following + flags are simple ways to select standard “packages” of warnings: @@ -818,6 +860,7 @@ ghc -c Foo.hs -W option Provides the standard warnings plus , + , , , and . @@ -825,18 +868,28 @@ ghc -c Foo.hs - : + : - - Turns off all warnings, including the standard ones. + + Turns on all warning options that indicate potentially + suspicious code. The warnings that are + not enabled by + are + , + , + , + , + , and + . - : + : - - Turns on all warning options. + + Turns off all warnings, including the standard ones and + those that -Wall doesn't enable. @@ -849,6 +902,16 @@ ghc -c Foo.hs + + : + + + Warnings are treated only as warnings, not as errors. This is + the default, but can be useful to negate a + flag. + + + The full set of warning options is described below. To turn @@ -858,15 +921,98 @@ ghc -c Foo.hs - : + : - + + warnings + pragmas + Causes a warning to be emitted when a + pragma that GHC doesn't recognise is used. As well as pragmas + that GHC itself uses, GHC also recognises pragmas known to be used + by other tools, e.g. OPTIONS_HUGS and + DERIVE. + + This option is on by default. + + + + + : + + + + warnings deprecations + Causes a warning to be emitted when a + module, function or type with a WARNING or DEPRECATED pragma + is used. See for more + details on the pragmas. + + This option is on by default. + + + + + : + + + + deprecated-flags Causes a warning to be emitted when a deprecated - function or type is used. Entities can be marked as - deprecated using a pragma, see . + commandline flag is used. + + This option is on by default. + + + + + : + + + + Causes a warning to be emitted for foreign imports of + the following form: + +foreign import "f" f :: FunPtr t + + on the grounds that it probably should be + +foreign import "&f" f :: FunPtr t + + The first form declares that `f` is a (pure) C + function that takes no arguments and returns a pointer to a + C function with type `t`, whereas the second form declares + that `f` itself is a C function with type `t`. The first + declaration is usually a mistake, and one that is hard to + debug because it results in a crash, hence this + warning. + + + + + : + + + + Causes a warning to be emitted when a datatype + T is imported + with all constructors, i.e. T(..), but has been + exported abstractly, i.e. T. + + + + + : + + + + Causes a warning to be emitted when an unlifted type + is bound in a way that looks lazy, e.g. + where (I# x) = .... Use + where !(I# x) = ... instead. This will be an + error, rather than a warning, in GHC 6.14. + @@ -902,6 +1048,31 @@ ghc -c Foo.hs + : + + + implicit prelude, warning + Have the compiler warn if the Prelude is implicitly + imported. This happens unless either the Prelude module is + explicitly imported with an import ... Prelude ... + line, or this implicit import is disabled (either by + or a + LANGUAGE NoImplicitPrelude pragma). + + Note that no warning is given for syntax that implicitly + refers to the Prelude, even if + would change whether it refers to the Prelude. + For example, no warning is given when + 368 means + Prelude.fromInteger (368::Prelude.Integer) + (where Prelude refers to the actual Prelude module, + regardless of the imports of the module being compiled). + + This warning is off by default. + + + + : @@ -918,7 +1089,7 @@ ghc -c Foo.hs g [] = 2 - This option isn't enabled be default because it can be + This option isn't enabled by default because it can be a bit noisy, and it doesn't always indicate a bug in the program. However, it's generally considered good practice to cover all the cases in your functions. @@ -946,7 +1117,7 @@ f :: Foo -> Foo f foo = foo { x = 6 } - This option isn't enabled be default because it can be + This option isn't enabled by default because it can be very noisy, and it often doesn't indicate a bug in the program. @@ -1003,7 +1174,8 @@ f foo = foo { x = 6 } If you would like GHC to check that every top-level function/value has a type signature, use the - option. This + option. As part of + the warning GHC also reports the inferred type. The option is off by default. @@ -1018,12 +1190,13 @@ f foo = foo { x = 6 } inner-scope value has the same name as an outer-scope value, i.e. the inner value shadows the outer one. This can catch typographical errors that turn into hard-to-find bugs, e.g., - in the inadvertent cyclic definition let x = ... x - ... in. - - Consequently, this option does - will complain about cyclic recursive - definitions. + in the inadvertent capture of what would be a recursive call in + f = ... let f = id in ... f .... + The warning is suppressed for names beginning with an underscore. For example + + f x = do { _ignore <- this; _ignore <- that; return (the other) } + + @@ -1036,7 +1209,7 @@ f foo = foo { x = 6 } This option causes a warning to be emitted whenever the module contains an "orphan" instance declaration or rewrite rule. - An instance declartion is an orphan if it appears in a module in + An instance declaration is an orphan if it appears in a module in which neither the class nor the type being instanced are declared in the same module. A rule is an orphan if it is a rule for a function declared in another module. A module containing any @@ -1044,7 +1217,8 @@ f foo = foo { x = 6 } The trouble with orphans is that GHC must pro-actively read the interface files for all orphan modules, just in case their instances or rules play a role, whether or not the module's interface would otherwise - be of any use. Other things being equal, avoid orphan modules. + be of any use. See for details. + @@ -1057,7 +1231,7 @@ f foo = foo { x = 6 } By default, the compiler will warn you if a set of - patterns are overlapping, i.e., + patterns are overlapping, e.g., f :: String -> Int @@ -1082,7 +1256,7 @@ f "2" = 2 patterns that can fail, eg. \(x:xs)->.... Normally, these aren't treated as incomplete patterns by . - ``Lambda-bound patterns'' includes all places where there is a single pattern, + “Lambda-bound patterns” includes all places where there is a single pattern, including list comprehensions and do-notation. In these cases, a pattern-match failure is quite legitimate, and triggers filtering (list comprehensions) or the monad fail operation (monads). For example: @@ -1092,10 +1266,18 @@ f "2" = 2 Switching on will elicit warnings about these probably-innocent cases, which is why the flag is off by default. - The deriving( Read ) mechanism produces monadic code with - pattern matches, so you will also get misleading warnings about the compiler-generated - code. (This is arguably a Bad Thing, but it's awkward to fix.) + + + + + : + + + tabs, warning + Have the compiler warn if there are tabs in your source + file. + This warning is off by default. @@ -1108,7 +1290,7 @@ f "2" = 2 the Haskell defaulting mechanism for numeric types kicks in. This is useful information when converting code from a context that assumed one default into one with another, - e.g., the `default default' for Haskell 1.4 caused the + e.g., the ‘default default’ for Haskell 1.4 caused the otherwise unconstrained value 1 to be given the type Int, whereas Haskell 98 defaults it to Integer. This may lead to @@ -1120,6 +1302,20 @@ f "2" = 2 + : + + + monomorphism restriction, warning + Have the compiler warn/inform you where in your source + the Haskell Monomorphism Restriction is applied. If applied silently + the MR can give rise to unexpected behaviour, so it can be helpful + to have an explicit warning that it is being applied. + + This warning is off by default. + + + + : @@ -1171,6 +1367,56 @@ f "2" = 2 + + : + + + unused do binding, warning + do binding, unused + + Report expressions occuring in do and mdo blocks + that appear to silently throw information away. + For instance do { mapM popInt xs ; return 10 } would report + the first statement in the do block as suspicious, + as it has the type StackM [Int] and not StackM (), but that + [Int] value is not bound to anything. The warning is suppressed by + explicitly mentioning in the source code that your program is throwing something away: + + do { _ <- mapM popInt xs ; return 10 } + + Of course, in this particular situation you can do even better: + + do { mapM_ popInt xs ; return 10 } + + + + + + + : + + + apparently erroneous do binding, warning + do binding, apparently erroneous + + Report expressions occuring in do and mdo blocks + that appear to lack a binding. + For instance do { return (popInt 10) ; return 10 } would report + the first statement in the do block as suspicious, + as it has the type StackM (StackM Int) (which consists of two nested applications + of the same monad constructor), but which is not then "unpacked" by binding the result. + The warning is suppressed by explicitly mentioning in the source code that your program is throwing something away: + + do { _ <- return (popInt 10) ; return 10 } + + For almost all sensible programs this will indicate a bug, and you probably intended to write: + + do { popInt 10 ; return 10 } + + + + + If you're feeling really paranoid, the @@ -1211,7 +1457,7 @@ f "2" = 2 Note that higher optimisation levels cause more cross-module optimisation to be performed, which can have an impact on how much of your program needs to be recompiled when - you change something. This is one reaosn to stick to + you change something. This is one reason to stick to no-optimisation when developing code. @@ -1255,10 +1501,6 @@ f "2" = 2 Means: “Generate good-quality code without taking too long about it.” Thus, for example: ghc -c -O Main.lhs - - currently also implies - . This may change in the - future. @@ -1357,7 +1599,7 @@ f "2" = 2 Exception.assert in source code (in other words, rewriting Exception.assert p e to e (see ). This flag is turned on by + linkend="assertions"/>). This flag is turned on by . @@ -1410,6 +1652,36 @@ f "2" = 2 + + + + + Turn on call-pattern specialisation. + + + + + + + + + + Turn on the liberate-case transformation. + + + + + + + + + + Turn on the static argument transformation. + + + + + @@ -1424,6 +1696,36 @@ f "2" = 2 + + + + + Tells GHC to omit all inessential information from the interface file + generated for the module being compiled (say M). This means that a module + importing M will see only the types of the functions that M exports, but not + their unfoldings, strictness info, etc. Hence, for example, + no function exported by M will be inlined + into an importing module. The benefit is that modules that import M will + need to be recompiled less often (only when M's exports change their type, + not when they change their implementation). + + + + + + + + + + + Tells GHC to ignore all inessential information when reading interface files. + That is, even if M.hi contains unfolding or strictness information + for a function, GHC will ignore that information. + + + + + : strict constructor fields @@ -1446,25 +1748,7 @@ f "2" = 2 - - - - - Switches on an experimental "optimisation". - Switching it on makes the compiler a little keener to - inline a function that returns a constructor, if the - context is that of a thunk. - - x = plusInt a b - - If we inlined plusInt we might get an opportunity to use - update-in-place for the thunk 'x'. - - - - - - : + : inlining, controlling unfolding, controlling @@ -1490,7 +1774,7 @@ f "2" = 2 - : + inlining, controlling @@ -1512,7 +1796,7 @@ f "2" = 2 &phases; - + Using Concurrent Haskell Concurrent Haskellusing @@ -1542,7 +1826,7 @@ f "2" = 2 - + Using SMP parallelism parallelism @@ -1566,43 +1850,137 @@ f "2" = 2 is also possible to obtain performance improvements with parallelism on programs that do not use concurrency. This section describes how to use GHC to compile and run parallel programs, in we desribe the language features that affect + linkend="lang-parallel" /> we describe the language features that affect parallelism. - - Options to enable SMP parallelism + + Compile-time options for SMP parallelism In order to make use of multiple CPUs, your program must be linked with the option (see ). Then, to run a program on multiple - CPUs, use the RTS option: + linkend="options-linker" />). Additionally, the following + compiler options affect parallelism: + + + + + + Blackholing is the act of marking a thunk (lazy + computuation) as being under evaluation. It is useful for + three reasons: firstly it lets us detect certain kinds of + infinite loop (the NonTermination + exception), secondly it avoids certain kinds of space + leak, and thirdly it avoids repeating a computation in a + parallel program, because we can tell when a computation + is already in progress. + + + The option causes + each thunk to be blackholed as soon as evaluation begins. + The default is "lazy blackholing", whereby thunks are only + marked as being under evaluation when a thread is paused + for some reason. Lazy blackholing is typically more + efficient (by 1-2% or so), because most thunks don't + need to be blackholed. However, eager blackholing can + avoid more repeated computation in a parallel program, and + this often turns out to be important for parallelism. + + + + We recommend compiling any code that is intended to be run + in parallel with the + flag. + + + + + + + + RTS options for SMP parallelism + + To run a program on multiple CPUs, use the + RTS option: + + - + RTS option Use x simultaneous threads when running the program. Normally x - should be chosen to match the number of CPU cores on the machine. - There is no means (currently) by which this value may vary after - the program has started. - - For example, on a dual-core machine we would probably use + should be chosen to match the number of CPU cores on the + machineWhether hyperthreading cores should be counted or not is an + open question; please feel free to experiment and let us know what + results you find.. For example, + on a dual-core machine we would probably use +RTS -N2 -RTS. - Whether hyperthreading cores should be counted or not is an - open question; please feel free to experiment and let us know what - results you find. + Omitting x, + i.e. +RTS -N -RTS, lets the runtime + choose the value of x itself + based on how many processors are in your machine. + + Be careful when using all the processors in your + machine: if some of your processors are in use by other + programs, this can actually harm performance rather than + improve it. + + Setting also has the effect of + enabling the parallel garbage collector (see + ). + + There is no means (currently) by which this value + may vary after the program has started. + + The following options affect the way the runtime schedules + threads on CPUs: + + + + + RTS + option + + Disable automatic migration for load balancing. + Normally the runtime will automatically try to schedule + threads across the available CPUs to make use of idle + CPUs; this option disables that behaviour. It is probably + only of use if you are explicitly scheduling threads onto + CPUs with GHC.Conc.forkOnIO. + + + + + RTS + option + + Migrate a thread to the current CPU when it is woken + up. Normally when a thread is woken up after being + blocked it will be scheduled on the CPU it was running on + last; this option allows the thread to immediately migrate + to the CPU that unblocked it. + + The rationale for allowing this eager migration is + that it tends to move threads that are communicating with + each other onto the same CPU; however there are + pathalogical situations where it turns out to be a poor + strategy. Depending on the communication pattern in your + program, it may or may not be a good idea. + + + Hints for using SMP parallelism - Add the -sstderr RTS option when + Add the -s RTS option when running the program to see timing stats, which will help to tell you whether your program got faster by using more CPUs or not. If the user time is greater than @@ -1668,16 +2046,15 @@ statements or clauses. intermediate code generation GHC can dump its optimized intermediate code (said to be in “Core” format) - to a file as a side-effect of compilation. Core files, which are given the suffix - .hcr, can be read and processed by non-GHC back-end - tools. The Core format is formally described in + to a file as a side-effect of compilation. Non-GHC back-end tools can read and process Core files; these files have the suffix + .hcr. The Core format is described in An External Representation for the GHC Core Language, - and sample tools (in Haskell) - for manipulating Core files are available in the GHC source distribution - directory /fptools/ghc/utils/ext-core. + and sample tools + for manipulating Core files (in Haskell) are in the GHC source distribution + directory under utils/ext-core. Note that the format of .hcr - files is different (though similar) to the Core output format generated - for debugging purposes (). + files is different from the Core output format that GHC generates + for debugging purposes (), though the two formats appear somewhat similar. The Core format natively supports notes which you can add to your source code using the CORE pragma (see -GHC can also read in External Core files as source; just give the .hcr file on -the command line, instead of the .hs or .lhs Haskell source. -A current infelicity is that you need to give the -fglasgow-exts flag too, because -ordinary Haskell 98, when translated to External Core, uses things like rank-2 types. +Currently (as of version 6.8.2), GHC does not have the ability to read in External Core files as source. If you would like GHC to have this ability, please make your wishes known to the GHC Team. + &debug;