1#compdef ghc ghci ghc-pkg
2# ------------------------------------------------------------------------------
3# Copyright (c) 2014 Github zsh-users - http://github.com/zsh-users
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are met:
8# * Redistributions of source code must retain the above copyright
9# notice, this list of conditions and the following disclaimer.
10# * Redistributions in binary form must reproduce the above copyright
11# notice, this list of conditions and the following disclaimer in the
12# documentation and/or other materials provided with the distribution.
13# * Neither the name of the zsh-users nor the
14# names of its contributors may be used to endorse or promote products
15# derived from this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20# DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY
21# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27# ------------------------------------------------------------------------------
28# Description
29# -----------
30#
31# Completion script for ghc (http://www.haskell.org/ghc/)
32#
33# ------------------------------------------------------------------------------
34# Authors
35# -------
36#
37# * Gérard Milmeister
38# * Philip Dexter <philip.dexter@gmail.com>
39#
40# ------------------------------------------------------------------------------
41
42local state
43local WORDS
44
45#
46# ghci
47#
48
49_ghc_ghci () { _ghc_compiler }
50
51#
52# ghc
53#
54
55_ghc_compiler ()
56{
57    _arguments \
58        "-no-hs-main[Don't assume this program contains main]" \
59        "-no-user-package-conf[Don't load the user's package config file]" \
60        '(- *)'{--help,-\?}'[Show help information]' \
61        '*-I-[Add directory to path for #include files]:directory:_files -/' \
62        '*-X-[Language flags]:flag:_ghc_language_flags' \
63        '*-d-[Debugging options]:flag:_ghc_debugging_options' \
64        '*-f-[Compiler options]:flag:_ghc_compiler_flags' \
65        '*-hide-package[Hide package]:Package:_ghc_pkg_list_packages' \
66        '*-trust[Expose package and set it to be trusted]:Package:_ghc_pkg_list_packages' \
67        '*-distrust[Expose package and set it to be distrusted]:Package:_ghc_pkg_list_packages' \
68        '*-distrust-all[Distrust all packages by default]' \
69        '*-i-[Add directory to import path]:directory:->ghc_include_directory' \
70        '*-package[Expose package]:Package:_ghc_pkg_list_packages' \
71        '*:file:_files -g \*.\{lhs,hs,hc,c,s\}' \
72        '--info[Display information about the compiler]' \
73        '--show-options[Display the supported command line options]' \
74        '--interactive[Interactive mode]' \
75        '--make[Compile and link a complete Haskell program]:file:_files -g "*.{lhs,hs,hc,c,s}"' \
76        '--numeric-version[Display GHC version (numeric only)]' \
77        '--print-libdir[Display GHC library directory]' \
78        '--show-iface[Show interface]:file:_files -g "*.hi"' \
79        {--supported-languages,--supported-extensions}'[Display the supported language extensions]' \
80        '-C[Stop after generating C]' \
81        '-E[Stop after generating preprocessed, de-litted Haskell]' \
82        '-H[Minimum heap size]:size:' \
83        '-M[Output Makefile rules]' \
84        '-O-[Enable optimization]:level:(0 1 2)' \
85        '-Rghc-timing[Summarise timing stats for GHC]' \
86        '-S[Stop after generating assembler]' \
87        '-V[Display GHC version]' \
88        '-W[Enable normal warnings]' \
89        '-Wall[Enable almost all warnings]' \
90        '-Werror[Make warnings fatal]' \
91        '-Wwarn[Make warnings non-fatal]' \
92        '-c[Stop after generating object files]' \
93        '-eventlog[Enable runtime event tracing]' \
94        '-debug[Use the debugging runtime]' \
95        "-dylib-install-name[On Darwin/macOS only, set the install name]" \
96        '-dynamic[Use dynamic Haskell libraries]' \
97        '-dynamic-too[Build dynamic object files as well as static object files during compilation]' \
98        '-dynosuf[Set the output suffix for dynamic object files]' \
99        '-dynload[Select one of a number of modes for finding shared libraries at runtime]' \
100        '--mk-dll[DLL-creation mode (Windows only)]' \
101        '-framework-path[On Darwin/macOS/iOS only, add dir to the list of directories searched for frameworks]' \
102        '-shared[Generate a shared library (as opposed to an executable)]' \
103        '-staticlib[On Darwin/macOS/iOS only, generate a standalone static library (as opposed to an executable)]' \
104        '-e[Evaluate expression]' \
105        '-hide-all-packages[Hide all packages by default]' \
106        '-hpcdir[Directory to deposit .mix files during compilation (default is .hpc)]' \
107        '-n[Do a dry run]' \
108        '-o[Set output filename]:file:_files' \
109        '-outputdir[Set output directory]:directory:_files -/' \
110        '-package-name[Compile to be part of package]' \
111        '-hide-all-packages[Hide all packages by default]' \
112        '-package-db[Add file to the package db stack]:file:_files' \
113        '-clear-package-db[Clear the package db stack]' \
114        '-msse2[(x86 only) Use SSE2 for floating point]' \
115        '-monly-\[432\]-regs[(x86 only) give some registers back to the C compiler]' \
116        '-no-global-package-db[Remove the global package db from the stack]' \
117        '-global-package-db[Add the global package db to the stack]' \
118        "-no-user-package-db[Remove the user's package db from the stack]" \
119        "-user-package-db[Add the user's package db to the stack]" \
120        "-no-auto-link-packages[Don't automatically link in the base and rts packages]" \
121        '-optL[pass option to the literate pre-processor]' \
122        '-optP[pass option to cpp (with -cpp only)]' \
123        '-optF[pass option to the custom pre-processor]' \
124        '-optc[pass option to the C compiler]' \
125        '-optlo[pass option to the LLVM optimiser]' \
126        '-optlc[pass option to the LLVM compiler]' \
127        '-optm[pass option to the mangler]' \
128        '-opta[pass option to the assembler]' \
129        '-optl[pass option to the linker]' \
130        '-optdll[pass option to the DLL generator]' \
131        '-optwindres[pass option to windres.]' \
132        '-prof[Turn on profiling]' \
133        '-pgmL[Use cmd as the literate pre-processor]' \
134        '-pgmP[Use cmd as the C pre-processor (with -cpp only)]' \
135        '-pgmc[Use cmd as the C compiler]' \
136        '-pgms[Use cmd as the splitter]' \
137        '-pgml[Use cmd as the linker]' \
138        '-pgmdll[Use cmd as the DLL generator]' \
139        '-pgmF[Use cmd as the pre-processor (with -F only)]' \
140        '-pgmwindres[Use cmd as the program for embedding manifests on Windows]' \
141        '-pgmlibtool[Use cmd as the command for libtool (with -staticlib only)]' \
142        '-rtsopts[Only a minimum of safe options can be given to RTS]' \
143        '-rtsopts=[Control whether the RTS behavior can be tweaked via command-line flags and the GHCRTS environment variable (none, some, or all)]' \
144        '-with-rtsopts=[Set the default RTS options]' \
145        '-threaded[Use the threaded runtime]' \
146        '-ticky[Turn on ticky-ticky profiling]' \
147        '-tmpdir[Set the directory for temporary files]:directory:_files -/' \
148        '-v-[Control verbosity]:level:(0 1 2 3 4 5)' \
149        '-w[Disable all warnings]' \
150        '-x[Override default behaviour for source files]:suffix:(hs lhs hc c s o hspp)' \
151        '-hcsuf[Set the suffix to use for intermediate]:suffix:' \
152        '-hidir[Set directory for interface files]:directory:_files -/' \
153        '-hisuf[Set the suffix to use for interface files]:suffix:' \
154        '-odir[Set directory for object files]:directory:_files -/' \
155        '-ohi[Set the filename in which to put the interface]:filename:_files -/' \
156        '-osuf[Set the output file suffix]:suffix:' \
157        '-stubdir[Redirect FFi stub files]:directory:_files -/' \
158        '-dumpdir[Redirect dump files]:directory:_files -/' \
159        '-outputdir[Set output directory]:directory:_files -/' \
160        '-keep-hc-files[Retain intermediate .hc files]' \
161        '-keep-llvm-files[Retain intermediate LLVM .ll files]' \
162        '-keep-s-files[Retain intermediate .s files]' \
163        '-keep-raw-s-files[Retain intermediate .raw_s files]' \
164        '-keep-tmp-files[Retain all intermediate temporary files]' \
165        '-static[Use static Haskell libraries]' \
166        '-split-objs[Split objects (for libraries)]' \
167        '-no-link[Omit linking]' \
168        '-main-is[Set main module and function]:function:' \
169        '*-L-[Add dir to the list of directories searched for libraries]:directory:_files -/' \
170        '*-l-[Link in library]:library:->library'
171
172    [[ -n "$state" ]] &&
173    case "$state" in
174        ghc_include_directory) _ghc_include_directory ;;
175        library)
176            _wanted libraries expl library \
177                compadd - \
178                ${^=LD_LIBRARY_PATH:-/usr/lib /usr/local/lib}/lib*.(a|so*)(:t:fr:s/lib//) \
179                && ret=0
180    esac
181}
182
183
184_ghc_include_directory ()
185{
186    compset -P '*:'
187    compset -S ':*'
188    _path_files -r': ' -/
189}
190
191_ghc_compiler_flags ()
192{
193    local _ghc_compiler_flags_list
194    _ghc_compiler_flags_list=(
195        'ghci-hist-size:Set the number of entries GHCi keeps for \:history'
196        'print-explicit-foralls:Print explicit forall quantification in types'
197        'print-explicit-kinds:Print explicit kind foralls and kind arguments in types'
198        {no-,}'break-on-error:Break on uncaught exceptions and errors'
199        {no-,}'break-on-exception:Break on any exception thrown'
200        {no-,}'case-merge:Enable case-merging'
201        {no-,}'defer-type-errors:Defer as many type errors as possible until runtime'
202        {no-,}'dicts-strict:Make dictionaries strict'
203        {no-,}'do-eta-reduction:Enable eta-reduction'
204        {no-,}'do-lambda-eta-expansion:Enable lambda eta-reduction'
205        'eager-blackholing:Turn on eager blackholing'
206        {no-,}'enable-rewrite-rules:Switch on all rewrite rules (including rules generated by automatic specialisation of overloaded functions)'
207        'error-spans:Output full span in error messages'
208        'ext-core:Generate .hcr external Core file'
209        'force-recomp:Turn off recompilation checking'
210        {no-,}'float-in:Turn on the float-in transformation'
211        {no-,}'full-laziness:Turn on full laziness (floating bindings outwards)'
212        {no-,}'fun-to-thunk:Allow worker-wrapper to convert a function closure into a thunk if the function does not use any of its arguments. Off by default.'
213        {no-,}'glasgow-exts:Enable most language extensions'
214        {no-,}'helpful-errors:Make suggestions for mis-spelled names'
215        'history-size:Set simplification history size'
216        {no-,}'ignore-asserts:Ignore assertions in the source'
217        {no-,}'ignore-interface-pragmas:Ignore pragmas in interface files'
218        {no-,}'loopification:Turn saturated self-recursive tail-calls into local jumps in the generated assembly'
219        {no-,}'late-dmd-anal:Run demand analysis again, at the end of the simplification pipeline'
220        {no-,}'liberate-case:Turn on the liberate-case transformation'
221        'liberate-case-threshold=:Set the size threshold for the liberate-case transformation (default 200)'
222        'no-liberate-case-threshold:Set the size threshold for the liberate-case transformation (default 200)'
223        {no-,}'max-relevant-bindings=N:Set the maximum number of bindings to display in type error messages (default 6).'
224        'max-worker-args=:If a worker has that many arguments, none will be unpacked anymore (default 10)'
225        'max-simplifier-iterations=:Set the max iterations for the simplifier'
226        'no-asm-mangling:Turn off assembly mangling'
227        'no-black-holing:Turn off black holing'
228        "no-hi-version-check:Don't complain about .hi file mismatches"
229        'no-implicit-import-qualified:Turn off implicit qualified import of everything in GHCi'
230        'no-print-bind-contents:Turn off printing of binding contents in GHCi'
231        'no-opt-coercion:Turn off the coercion optimiser'
232        'no-ghci-history:Do not use the load/store the GHCi command history from/to ghci_history'
233        'no-ghci-sandbox:Turn off the GHCi sandbox. Means computations are run in the main thread, rather than a forked thread'
234        'no-gen-manifest:Do not generate a manifest file (Windows only)'
235        'no-embed-manifest:Do not embed the manifest in the executable (Windows only)'
236        "no-shared-implib:Don't generate an import library for a DLL (Windows only)"
237        'no-pre-inlining:Turn off pre-inlining'
238        'no-state-hack:Turn off the "state hack" whereby any lambda with a real-world state token as argument is considered to be single-entry'
239        {no-,}'print-bind-result:Turn on printing of binding results in GHCi'
240        {no-,}'print-evld-with-show:Enable usage of Show instances in \:print'
241        'unregisterised:Unregisterised compilation'
242        'asm:Use the native code generator'
243        'via-C:Compile via C'
244        'no-code:Omit code generation'
245        'byte-code:Generate byte-code'
246        'object-code:Generate object code'
247        'hpc:Turn on Haskell program coverage instrumentation'
248        'PIC:Generate position-independent code'
249        'plugin=:Load a plugin exported by a given module'
250        'plugin-opt=:Give arguments to a plugin module'
251        'context-stack=:Set the limit for context reduction (default is 20)'
252        'type-function-depth=:Set the limit for type function reductions (default is 200)'
253        'force-recomp:Turn off recompilation checking'
254        {no-,}"omit-interface-pragmas:Don't generate interface pragmas"
255        'package-trust:Enable Safe Haskell trusted package requirement for trustworthy modules'
256        {no-,}'pedantic-bottoms:Make GHC be more precise about its treatment of bottom'
257        {no-,}'disambiguate-record-fields:Enable record field disambiguation'
258        {no-,}'irrefutable-tuples:Make tuple pattern matching irrefutable'
259        {no-,}'vectorise:Enable vectorisation of nested data parallelism'
260        {no-,}'avoid-vect:Enable vectorisation avoidance'
261        {no-,}'excess-precision:Enable excess intermediate precision'
262        {no-,}'prof-auto:Auto-add SCCs to all bindings not marked INLINE'
263        {no-,}'prof-auto-top:Auto-add SCCs to all top-level bindings not marked INLINE'
264        {no-,}'prof-auto-exported:Auto-add SCCs to all exported bindings not marked INLINE'
265        {no-,}'prof-cafs:Auto-add SCCs to all CAFs'
266        {no-,}'prof-count-entries:Collect entry counts'
267        'simplifier-phases:Set the number of phases for the simplifier (default 2)'
268        'simpl-tick-factor=:Set the percentage factor for simplifier ticks (default 100)'
269        {no-,}'spec-constr:Turn on the SpecConstr transformation'
270        {no-,}'spec-constr-threshold=:Set the size threshold for the SpecConstr transformation (default 200)'
271        {no-,}'spec-constr-count=:Set the maximum number of specialisations that will be created for any one function by the SpecConstr transformation (default 3)'
272        'strictness=before=:Run an additional strictness analysis before a simplifier phase'
273        {no-,}'static-argument-transformation:Turn on the static argument transformation'
274        {no-,}'unbox-strict-fields:Flatten strict constructor fields'
275        {no-,}'unbox-small-strict-fields:Flatten strict constructor fields with a pointer-sized representation'
276        {no-,}'unfolding-creation-threshold:Tweak unfolding settings'
277        {no-,}'unfolding-fun-discount:Tweak unfolding settings'
278        {no-,}'unfolding-keeness-factor:Tweak unfolding settings'
279        {no-,}'unfolding-use-threshold:Tweak unfolding settings'
280        {no-,}'warn-warnings-deprecations:Warn about uses of functions & types that have warnings or deprecated pragmas'
281        {no-,}'warn-deprecated-flags:Warn about uses of commandline flags that are deprecated'
282        {no-,}'warn-duplicate-exports:Warn when an entity is exported multiple times'
283        {no-,}'warn-hi-shadowing:Warn when a .hi file in the current directory shadows a library'
284        {no-,}'warn-implicit-prelude:Warn when the Prelude is implicitly imported'
285        {no-,}'warn-incomplete-patterns:Warn when a pattern match could fail'
286        {no-,}'warn-incomplete-record-updates:Warn when a record update could fail'
287        {no-,}'warn-missing-fields:Warn when fields of a record are uninitialised'
288        {no-,}'warn-missing-methods:Warn when class methods are undefined'
289        {no-,}'warn-missing-signatures:Warn about top-level functions without signatures'
290        {no-,}'warn-duplicate-constraints:Warn when a constraint appears duplicated in a type signature'
291        {no-,}'warn-identities:Warn about uses of Prelude numeric conversions that are probably the identity (and hence could be omitted)'
292        {no-,}'warn-incomplete-uni-patterns:Warn when a pattern match in a lambda expression or pattern binding could fail'
293        {no-,}'warn-lazy-unlifted-bindings:(Deprecated) warn when a pattern binding looks lazy but must be strict'
294        {no-,}'warn-missing-import-lists:Warn when an import declaration does not explicitly list all the names brought into scope'
295        {no-,}'warn-missing-local-sigs:Warn about polymorphic local bindings without signatures'
296        {no-,}'warn-monomorphism-restriction:Warn when the Monomorphism Restriction is applied'
297        {no-,}'warn-name-shadowing:Warn when names are shadowed'
298        {warn-orphans,warn-auto-orphans}':Warn when the module contains orphan instance declarations or rewrite rules'
299        {no-,}'warn-overlapping-patterns:Warn about overlapping patterns'
300        {no-,}'warn-tabs:Warn if there are tabs in the source file'
301        {no-,}'warn-type-defaults:Warn when defaulting happens'
302        {no-,}"warn-unrecognised-pragmas:Warn about uses of pragmas that GHC doesn't recognise"
303        {no-,}'warn-unused-binds:Warn about bindings that are unused'
304        {no-,}'warn-unused-imports:Warn about unnecessary imports'
305        {no-,}"warn-unused-matches:Warn about variables in patterns that aren't used"
306        {no-,}'warn-unused-do-bind:Warn about do bindings that appear to throw away values of types other than ()'
307        {no-,}'warn-wrong-do-bind:Warn about do bindings that appear to throw away monadic values that you should have bound instead'
308        {no-,}'warn-unsafe:Warn if the module being compiled is regarded to be unsafe'
309        {no-,}'warn-safe:Warn if the module being compiled is regarded to be safe'
310        {no-,}'warn-amp:Warn on definitions conflicting with the Applicative-Monad Proposal (AMP)'
311        {no-,}'warn-typed-holes:Enable holes in expressions'
312        )
313    _describe -t flags 'ghc' _ghc_compiler_flags_list || compadd "$@"
314}
315
316_ghc_debugging_options ()
317{
318    local _ghc_debugging_options_list
319    _ghc_debugging_options_list=(
320        "dump-hi:Dump the new interface to stdout"
321        "dump-hi-diffs:Show the differences vs. the old interface"
322        "dump-minimal-imports:Dump a minimal set of imports"
323        "core-lint:Turn on internal sanity checking"
324        "dump-asm:Dump assembly"
325        "dump-bcos:Dump interpreter byte code"
326        "dump-cmm:Dump C-- output"
327        "dump-cpranal:Dump output from CPR analysis"
328        "dump-cse:Dump CSE output"
329        "dump-deriv:Dump deriving output"
330        "dump-ds:Dump desugarer output"
331        'dump-flatC:Dump "flat" C'
332        "dump-foreign:Dump foreign export stubs"
333        "dump-hpc:Dump after instrumentation for program coverage"
334        "dump-inlinings:Dump inlining info"
335        "dump-occur-anal:Dump occurrence analysis output"
336        "dump-opt-cmm:Dump the results of C-- to C-- optimising passes"
337        "dump-parsed:Dump parse tree"
338        "dump-prep:Dump prepared core"
339        "dump-rn:Dump renamer output"
340        "dump-rules:Dump rules"
341        "dump-simpl:Dump final simplifier output"
342        "dump-simpl-phases:Dump output from each simplifier phase"
343        "dump-simpl-iterations:Dump output from each simplifier iteration"
344        "dump-spec:Dump specialiser output"
345        "dump-splices:Dump TH spliced expressions"
346        "dump-stg:Dump final STG"
347        "dump-stranal:Dump strictness analyser output"
348        "dump-tc:Dump typechecker output"
349        "dump-types:Dump type signatures"
350        "dump-worker-wrapper:Dump worker-wrapper output"
351        "dump-if-trace:Trace interface files"
352        "dump-tc-trace:Trace typechecker"
353        "dump-to-file:Dump to files instead of stdout"
354        "dump-core-stats:Print a one-line summary of the size of the Core program at the end of the optimisation pipeline"
355        "dump-llvm:Dump LLVM intermediate code"
356        "dump-rule-firings:Dump rule firing info"
357        "dump-rule-rewrites:Dump detailed rule firing info"
358        "dump-vect:Dump vectoriser input and output"
359        "dump-strsigs:Dump strictness signatures"
360        "dump-vt-trace:Trace vectoriser"
361        "dump-rn-trace:Trace renamer"
362        "dump-rn-stats:Renamer stats"
363        "dump-simpl-stats:Dump simplifier stats"
364        "suppress-all:In core dumps, suppress everything (except for uniques) that is suppressible"
365        "suppress-uniques:Suppress the printing of uniques in debug output (easier to use diff)"
366        "suppress-idinfo:Suppress extended information about identifiers where they are bound"
367        "suppress-module-prefixes:Suppress the printing of module qualification prefixes"
368        "suppress-type-signatures:Suppress type signatures"
369        "suppress-type-applications:Suppress type applications"
370        "suppress-coercions:Suppress the printing of coercions in Core dumps to make them shorter"
371        "no-debug-output:Suppress unsolicited debugging output"
372        "ppr-debug:Turn on debug printing (more verbose)"
373        "ppr-noprags:Don't output pragma info in dumps"
374        "ppr-user-length:Set the depth for printing expressions in error msgs"
375        "ppr-colsNNN:Set the width of debugging output. For example -dppr-cols200"
376        "ppr-case-as-let:Print single alternative case expressions as strict lets"
377        "source-stats:Dump haskell source stats"
378        "cmm-lint:C-- pass sanity checking"
379        "stg-lint:STG pass sanity checking"
380        "stg-stats:Dump STG stats"
381        "verbose-core2core:Show output from each core-to-core pass"
382        "verbose-stg2stg:Show output from each STG-to-STG pass"
383        "show-passes:Print out each pass name as it happens"
384        "faststring-stats:Show statistics for fast string usage when finished"
385    )
386    _describe -t flags 'ghc' _ghc_debugging_options_list || compadd "$@"
387}
388
389
390_ghc_language_flags ()
391{
392    local _ghc_language_flags_list
393    _ghc_language_flags_list=(
394        "AllowAmbiguousTypes:Allow the user to write ambiguous types, and the type inference engine to infer them"
395        "Arrows:Enable arrow notation extension"
396        "AutoDeriveTypeable:Automatically derive Typeable instances for every datatype and type class declaration"
397        "BangPatterns:Enable bang patterns"
398        "ConstraintKinds:Enable a kind of constraints"
399        "CPP:Enable the C preprocessor"
400        "ConstrainedClassMethods:Enable constrained class methods"
401        "DataKinds:Enable datatype promotion"
402        "DefaultSignatures:Enable default signatures"
403        "DeriveDataTypeable:Enable deriving for the Data and Typeable classes"
404        "DeriveGeneric:Enable deriving for the Generic class"
405        "DisambiguateRecordFields:Enable record field disambiguation"
406        "EmptyCase:Allow empty case alternatives"
407        "EmptyDataDecls:Enable empty data declarations"
408        "ExistentialQuantification:Enable existential quantification"
409        "ExplicitForAll:Enable explicit universal quantification"
410        "ExplicitNamespaces:Enable using the keyword type to specify the namespace of entries in imports and exports"
411        "ExtendedDefaultRules:Use GHCi's extended default rules in a normal module"
412        "FlexibleContexts:Enable flexible contexts"
413        "FlexibleInstances:Enable flexible instances"
414        "ForeignFunctionInterface:Enable foreign function interface"
415        "FunctionalDependencies:Enable functional dependencies"
416        "GADTs:Enable generalised algebraic data types"
417        "GADTSyntax:Enable generalised algebraic data type syntax"
418        "GeneralizedNewtypeDeriving:Enable newtype deriving"
419        "Generics:Enable generic classes"
420        "ImplicitParams:Enable Implicit Parameters"
421        "ImpredicativeTypes:Enable impredicative types"
422        "IncoherentInstances:Enable incoherent instances"
423        "InterruptibleFFI:Enable interruptible FFI"
424        "KindSignatures:Enable kind signatures"
425        "LambdaCase:Enable lambda-case expressions"
426        "LiberalTypeSynonyms:Enable liberalised type synonyms"
427        "MonadComprehensions:Enable monad comprehensions"
428        "MonoLocalBinds:Enable do not generalise local bindings"
429        "MultiParamTypeClasses:Enable multi parameter type classes"
430        "MultiWayIf:Enable multi-way if-expressions"
431        "NamedFieldPuns:Enable record puns"
432        "NegativeLiterals:Enable support for negative literals"
433        "NewQualifiedOperators:Enable new qualified operator syntax"
434        "NoImplicitPrelude:Don't implicitly import Prelude"
435        "NoMonoPatBinds:Make pattern bindings polymorphic"
436        "NoMonomorphismRestriction:Disable the monomorphism"
437        "NoNPlusKPatterns:Disable support for n+k patterns"
438        "NoTraditionalRecordSyntax:Disable support for traditional record syntax (as supported by Haskell 98) C {f = x}"
439        "NullaryTypeClasses:Enable nullary (no parameter) type classes"
440        "NumDecimals:Enable support for 'fractional' integer literals"
441        "OverlappingInstances:Enable overlapping instances"
442        "OverloadedLists:Enable overloaded lists"
443        "OverloadedStrings:Enable overloaded string literals"
444        "PArr:Enable parallel arrays"
445        "PackageImports:Enable package-qualified imports"
446        "ParallelArrays:Enable parallel arrays"
447        "ParallelListComp:Enable parallel list comprehensions"
448        "PatternGuards:Enable pattern guards"
449        "PolyKinds:Enable kind polymorphism"
450        "PolymorphicComponents:Enable polymorphic components for data constructors"
451        "QuasiQuotes:Enable quasiquotation"
452        "Rank2Types:Enable rank-2 types"
453        "RankNTypes:Enable rank-N types"
454        "RebindableSyntax:Employ rebindable syntax"
455        "RecordWildCards:Enable record wildcards"
456        "RecursiveDo:Enable recursive do (mdo) notation"
457        "RelaxedPolyRec:Relaxed checking for mutually-recursive polymorphic functions"
458        "Safe:Enable the Safe Haskell Safe mode"
459        "ScopedTypeVariables:Enable lexically-scoped type variables"
460        "StandaloneDeriving:Enable standalone deriving"
461        "TemplateHaskell:Enable Template Haskell"
462        "TransformListComp:Enable transform list comprehensions"
463        "TypeFamilies:Enable type families"
464        "TypeOperators:Enable type operators"
465        "TypeSynonymInstances:Enable type synonyms"
466        "Trustworthy:Enable the Safe Haskell Trustworthy mode"
467        "UnboxedTuples:Enable unboxed tuples"
468        "UndecidableInstances:Enable undecidable instances"
469        "UnicodeSyntax:Enable unicode syntax"
470        "UnliftedFFITypes:Enable unlifted FFI types"
471        "Unsafe:Enable Safe Haskell Unsafe mode"
472        "ViewPatterns:Enable view patterns"
473        'MagicHash:Allow "#" as a postfix modifier on identifiers'
474    )
475    _describe -t flags 'ghc' _ghc_language_flags_list || compadd "$@"
476}
477
478#
479# ghc-pkg
480#
481
482_ghc_pkg ()
483{
484    WORDS=()
485    for w in $words[1,(($CURRENT - 1))]; do
486        if [[ $w != --* ]]; then WORDS+=$w; fi
487    done
488    _arguments '*:command:_ghc_pkg_command'
489}
490
491_ghc_pkg_command()
492{
493    local -a _ghc_pkg_cmds
494    _ghc_pkg_cmds=(
495        "register:Register the package using package description"
496        "update:Register the package (overwriting existing package)"
497        "unregister:Unregister the specified package"
498        "expose:Expose the specified package"
499        "hide:Hide the specified package"
500        "list:List registered packages"
501        "find-module:List registered packages exposing module"
502        "latest:Prints the highest registered version of a package"
503        "check:Check the consistency of package dependencies and list broken packages"
504        "describe:Give the registered description for the specified package"
505        "field:Extract the specified field of the package description"
506        "dump:Dump the registered description for every package"
507    )
508
509    if (( $#WORDS == 1 )); then
510	_describe -t commands 'command' _ghc_pkg_cmds || compadd "$@"
511    else
512    	local curcontext="$curcontext"
513        cmd="${${_ghc_pkg_cmds[(r)$WORDS[2]:*]%%:*}}"
514        if (( $#cmd )); then
515            _arguments \
516                "--user[Use current user's package database]" \
517                '--global[User the global package database]' \
518                {-f,--package-conf=}'[Use the specified package config file]:Package config file:_files' \
519                '--no-user-package-conf[Never reader the user package config]' \
520                {-V,--version}'[Output version information and exit]' \
521                '--force[Ignore missing directories and libraries only]' \
522                {-g,--auto-ghci-libs}'[Automatically build libs for GHCi]' \
523                {-?,--help}'[Display this help and exit]' \
524                '--simple-output[Print output in easy-to-parse format for some commands]' \
525                '--names-only[Only print package names, not versions]' \
526                '--ignore-case[Ignore case for substring matching]' \
527                '*:argument:_ghc_pkg_'$cmd
528        else
529            _message "unknown ghc-pkg command: $WORDS[2]"
530        fi
531    fi
532}
533
534_ghc_pkg_unregister () { _ghc_pkg_list_packages }
535
536_ghc_pkg_expose () { _ghc_pkg_list_packages }
537
538_ghc_pkg_hide () { _ghc_pkg_list_packages }
539
540_ghc_pkg_latest () { _ghc_pkg_list_packages }
541
542_ghc_pkg_describe () { _ghc_pkg_list_packages }
543
544_ghc_pkg_field ()
545{
546    _ghc_pkg_available_packages
547    if (( $#WORDS == 2 )); then
548        compadd "$@" -a -- _ghc_pkg_packages
549    elif (( $#WORDS == 3 )); then
550        compset -P '*,'
551        compset -S ',*'
552        compadd "$@" -S ',' -q -- \
553            name version license copyright maintainer \
554            stability homepage package-url description \
555            category author exposed exposed-modules \
556            hidden-modules import-dirs hs-libraries \
557            extra-libraries extra-ghci-libraries include-dirs \
558            includes depends hugs-options cc-options ld-options \
559            framework-dirs frameworks haddock-interfaces \
560            haddock-html
561    fi
562}
563
564_ghc_pkg_register () { _files }
565
566_ghc_pkg_update () { _files }
567
568_ghc_pkg_list () { _ghc_pkg_list_packages }
569
570_ghc_pkg_find-module ()
571{
572    if (( $#WORDS == 2)); then
573        if ( [[ ${+_ghc_modules} -eq 0 ]] || _cache_invalid GHC_MODULES ) &&
574	    ! _retrieve_cache GHC_MODULES;
575        then
576            _ghc_modules=( $(ghc-pkg dump | sed -n '/^exposed-modules:/{s/^exposed-modules:[ ]\+\(.*\)$/\1/;s/ /\n/;p;be};b;:e;n;/^ /{s/^[ ]\+\(.*\)$/\1/;s/ /\n/;p;be}') )
577            _store_cache GHC_MODULES _ghc_modules
578        fi
579        compadd "$@" -a -- _ghc_modules
580    fi
581}
582
583_ghc_pkg_dump () {}
584
585_ghc_pkg_check () {}
586
587_ghc_pkg_available_packages ()
588{
589    if ( [[ ${+_ghc_pkg_packages_pkgs} -eq 0 ]] || _cache_invalid GHC_PACKAGES ) &&
590	! _retrieve_cache GHC_PACKAGES;
591    then
592        _ghc_pkg_packages=( $(ghc-pkg list --simple-output --names-only) )
593        _store_cache GHC_PACKAGES _ghc_pkg_packages
594    fi
595}
596
597_ghc_pkg_list_packages ()
598{
599    _ghc_pkg_available_packages
600    compadd "$@" -a -- _ghc_pkg_packages
601}
602
603
604#
605# dispatcher
606#
607
608case $service in
609    ghc)
610        _ghc_compiler
611        ;;
612    ghci)
613        _ghc_ghci
614        ;;
615    ghc-pkg)
616        _ghc_pkg
617        ;;
618esac
619