summaryrefslogtreecommitdiff
path: root/compiler/utils/Util.lhs
Commit message (Collapse)AuthorAgeFilesLines
* compiler: de-lhs utils/Austin Seipp2014-12-031-1135/+0
| | | | Signed-off-by: Austin Seipp <austin@well-typed.com>
* Refactor: use System.FilePath.splitSearchPathThomas Miedema2014-11-191-21/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: To address #2521 ("Trailing colon on GHC_PACKAGE_PATH doesn't work with ghc-pkg"), we were using a custom version of splitSearchPath (e4f46f5de). This solution however caused issue #9698 ("GHC_PACKAGE_PATH should be more lenient for empty paths"). This patch reverts back to System.FilePath.splitSearchPath (fixes #9698) and adresses (#2521) by testing for a trailing search path separators explicitly (instead of implicitly using empty search path elements). Empty paths are now allowed (ignored on Windows, interpreted as current directory on Posix systems), and trailing path separator still tack on the user and system package databases. Also update submodule filepath, which has a version of splitSearchPath which handles quotes in the same way as our custom version did. Test Plan: $ GHC_PACKAGE_PATH=/::/home: ./ghc-pkg list ... db stack: ["/",".","/home","<userdb>","<systemdb>"] ... Reviewers: austin Reviewed By: austin Subscribers: thomie, carter, simonmar Differential Revision: https://phabricator.haskell.org/D414 GHC Trac Issues: #2521, #9698
* Use dropWhileEndLE p instead of reverse . dropWhile p . reverseDavid Feuer2014-10-021-1/+15
| | | | | | | | | | | | | | | | | | | | | | | | Summary: Using `dropWhileEndLE` tends to be faster and easier to read than the `reverse . dropWhile p . reverse` idiom. This also cleans up some other, nearby, messes. Fix #9616 (incorrect number formatting potentially leading to incorrect numbers in output). Test Plan: Run validate Reviewers: thomie, rwbarton, nomeata, austin Reviewed By: nomeata, austin Subscribers: simonmar, ezyang, carter, thomie Projects: #ghc Differential Revision: https://phabricator.haskell.org/D259 GHC Trac Issues: #9623, #9616 Conflicts: compiler/basicTypes/OccName.lhs
* Revert "Use dropWhileEndLE p instead of reverse . dropWhile p . reverse"Austin Seipp2014-10-021-15/+1
| | | | This reverts commit 2a8856884de7d476e26b4ffa829ccb3a14d6f63e.
* Use dropWhileEndLE p instead of reverse . dropWhile p . reverseDavid Feuer2014-10-011-1/+15
| | | | | | | | | | | | | | | | | | | | | | | | Summary: Using `dropWhileEndLE` tends to be faster and easier to read than the `reverse . dropWhile p . reverse` idiom. This also cleans up some other, nearby, messes. Fix #9616 (incorrect number formatting potentially leading to incorrect numbers in output). Test Plan: Run validate Reviewers: thomie, rwbarton, nomeata, austin Reviewed By: nomeata, austin Subscribers: simonmar, ezyang, carter, thomie Projects: #ghc Differential Revision: https://phabricator.haskell.org/D259 GHC Trac Issues: #9623, #9616 Conflicts: compiler/basicTypes/OccName.lhs
* Delete all /* ! __GLASGOW_HASKELL__ */ codeThomas Miedema2014-09-231-2/+0
| | | | | | | | | | | | | | | | | Summary: ``` git grep -l '\(#ifdef \|#if defined\)(\?__GLASGOW_HASKELL__)\?' ``` Test Plan: validate Reviewers: rwbarton, hvr, austin Reviewed By: rwbarton, hvr, austin Subscribers: rwbarton, simonmar, ezyang, carter Differential Revision: https://phabricator.haskell.org/D218
* Delete hack when takeDirectory returns ""Thomas Miedema2014-09-231-5/+3
| | | | | | | | | | | | | | | | | | | | | | | Summary: Since commits 8fe1f8 and bb6731 in the filepath packages (ticket #2034, closed in 2010), takeDirectory "foo" returns ".", and not "", so this check is no longer needed. Other commits: * Remove trailing whitespace * Update comments for #2278 Test Plan: harbormaster Reviewers: austin Reviewed By: austin Subscribers: simonmar, ezyang, carter Differential Revision: https://phabricator.haskell.org/D213 GHC Trac Issues: #2034
* Define Util.leLength :: [a] -> [b] -> BoolSimon Peyton Jones2014-09-191-1/+9
|
* build: require GHC 7.6 for bootstrappingAustin Seipp2014-08-191-10/+0
| | | | | | | | | | | | | | | | | | | | | | Summary: Per the usual standards, a build of GHC is only compileable by the last two releases (e.g. 7.8 only by 7.4 and 7.6). To make sure we don't get suckered into supporting older compilers, let's remove this support now. Signed-off-by: Austin Seipp <austin@well-typed.com> Test Plan: Try to bootstrap with GHC 7.4, watch it fail. Bootstrap with 7.6 or better, and everything works. Reviewers: hvr Reviewed By: hvr Subscribers: simonmar, ezyang, carter Differential Revision: https://phabricator.haskell.org/D167
* Fix ghci tab completion of duplicate identifiers.Shachaf Ben-Kiki2014-07-131-1/+5
| | | | | | | | | | | | | | | | | | | Summary: Currently, if the same identifier is imported via multiple modules, ghci shows multiple completions for it. Use the nub of the completions instead so that it only shows up once. Signed-off-by: Shachaf Ben-Kiki <shachaf@gmail.com> Test Plan: by hand Reviewers: simonmar, austin, hvr Reviewed By: austin, hvr Subscribers: hvr, simonmar, relrod, carter Differential Revision: https://phabricator.haskell.org/D58
* Add LANGUAGE pragmas to compiler/ source filesHerbert Valerio Riedel2014-05-151-0/+1
| | | | | | | | | | | | | | | | | | In some cases, the layout of the LANGUAGE/OPTIONS_GHC lines has been reorganized, while following the convention, to - place `{-# LANGUAGE #-}` pragmas at the top of the source file, before any `{-# OPTIONS_GHC #-}`-lines. - Moreover, if the list of language extensions fit into a single `{-# LANGUAGE ... -#}`-line (shorter than 80 characters), keep it on one line. Otherwise split into `{-# LANGUAGE ... -#}`-lines for each individual language extension. In both cases, try to keep the enumeration alphabetically ordered. (The latter layout is preferable as it's more diff-friendly) While at it, this also replaces obsolete `{-# OPTIONS ... #-}` pragma occurences by `{-# OPTIONS_GHC ... #-}` pragmas.
* Add a better implementation of dropTail, and use itSimon Peyton Jones2013-08-191-1/+9
|
* Implement "roles" into GHC.Richard Eisenberg2013-08-021-1/+9
| | | | | | | | | | | | | | | | Roles are a solution to the GeneralizedNewtypeDeriving type-safety problem. Roles were first described in the "Generative type abstraction" paper, by Stephanie Weirich, Dimitrios Vytiniotis, Simon PJ, and Steve Zdancewic. The implementation is a little different than that paper. For a quick primer, check out Note [Roles] in Coercion. Also see http://ghc.haskell.org/trac/ghc/wiki/Roles and http://ghc.haskell.org/trac/ghc/wiki/RolesImplementation For a more formal treatment, check out docs/core-spec/core-spec.pdf. This fixes Trac #1496, #4846, #7148.
* Add NegativeLiterals extensionIan Lynagh2013-07-311-1/+1
| | | | | | | | | | | I'd been meaning to do this for some time, but finally got around to it due to the overflowing literals warning. With that enabled, we were getting a warning for -128 :: Int8 as that is parsed as negate (fromInteger 128) which just happens to do the right thing, as negate (fromInteger 128) = negate (-128) = -128
* Define chkAppend, and use itSimon Peyton Jones2013-05-301-1/+8
| | | | | | Somtimes we need (xs ++ ys) in situations where ys is almost always empty. Utils.chkAppend checks for that case first.
* By default, use the dynamic way for programs in the GHC treeIan Lynagh2013-03-151-8/+1
| | | | | In particular, this means that GHCi will use DLLs, rather than loading object files itself.
* Add a flag to tell ghc to use $ORIGIN when linking program dynamicallyIan Lynagh2012-10-021-0/+12
|
* Remove Util.{isDarwinTarget,isWindowsTarget}Ian Lynagh2012-08-281-12/+5
|
* Copy Data.HashTable's hashString into our Util moduleIan Lynagh2012-06-301-1/+72
| | | | | Data.HashTable is now deprecated and will soon be removed, but deSugar/Coverage.lhs uses hashString.
* Remove sortLeIan Lynagh2012-06-221-93/+2
| | | | We now use Data.List's sort(By)
* Remove some uses of sortLeIan Lynagh2012-06-221-3/+1
| | | | | | Technically the behaviour of sortWith has changed, as it used x `le` y = get_key x < get_key y (note "<" rather than "<="), but I assume that that was just a mistake.
* Remove a GHC 6.4 workaroundIan Lynagh2012-06-221-6/+1
|
* Remove 'on' from UtilIan Lynagh2012-06-221-5/+1
| | | | We can now rely on it being available from Data.Function
* Support code generation for unboxed-tuple function argumentsunboxed-tuple-arguments2Max Bolingbroke2012-05-151-1/+11
| | | | | | | | | | | This is done by a 'unarisation' pre-pass at the STG level which translates away all (live) binders binding something of unboxed tuple type. This has the following knock-on effects: * The subkind hierarchy is vastly simplified (no UbxTupleKind or ArgKind) * Various relaxed type checks in typechecker, 'foreign import prim' etc * All case binders may be live at the Core level
* Replace createDirectoryHierarchy with createDirectoryIfMissing TrueTakano Akio2012-02-271-14/+2
| | | | | | createDirectoryHierarchy consisted of an existence test followed by createDirectory, which failed if that directory was creted just after the test. createDirectoryifMissing does not have this problem.
* Switch to using the time package, rather than old-timeIan Lynagh2012-01-141-3/+21
|
* Add extra Num constraints since the Num superclass of Bits is removedBas van Dijk2012-01-141-3/+3
|
* Tabs -> SpacesDavid Terei2011-12-191-33/+28
|
* Fix bitrotted NCG_DEBUG code, and switch to using a Haskell conditionalIan Lynagh2011-11-051-1/+9
|
* Use -fwarn-tabs when validatingIan Lynagh2011-11-041-0/+7
| | | | | We only use it for "compiler" sources, i.e. not for libraries. Many modules have a -fno-warn-tabs kludge for now.
* Put the target platform in the settings fileIan Lynagh2011-10-191-1/+6
|
* Comments and functions renaming onlySimon Peyton Jones2011-09-231-9/+9
|
* Merge branch 'no-pred-ty'Max Bolingbroke2011-09-091-1/+10
|\ | | | | | | | | | | | | | | | | | | Conflicts: compiler/iface/BuildTyCl.lhs compiler/iface/MkIface.lhs compiler/iface/TcIface.lhs compiler/typecheck/TcTyClsDecls.lhs compiler/types/Class.lhs compiler/utils/Util.lhs
| * Implement -XConstraintKindMax Bolingbroke2011-09-061-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Basically as documented in http://hackage.haskell.org/trac/ghc/wiki/KindFact, this patch adds a new kind Constraint such that: Show :: * -> Constraint (?x::Int) :: Constraint (Int ~ a) :: Constraint And you can write *any* type with kind Constraint to the left of (=>): even if that type is a type synonym, type variable, indexed type or so on. The following (somewhat related) changes are also made: 1. We now box equality evidence. This is required because we want to give (Int ~ a) the *lifted* kind Constraint 2. For similar reasons, implicit parameters can now only be of a lifted kind. (?x::Int#) => ty is now ruled out 3. Implicit parameter constraints are now allowed in superclasses and instance contexts (this just falls out as OK with the new constraint solver) Internally the following major changes were made: 1. There is now no PredTy in the Type data type. Instead GHC checks the kind of a type to figure out if it is a predicate 2. There is now no AClass TyThing: we represent classes as TyThings just as a ATyCon (classes had TyCons anyway) 3. What used to be (~) is now pretty-printed as (~#). The box constructor EqBox :: (a ~# b) -> (a ~ b) 4. The type LCoercion is used internally in the constraint solver and type checker to represent coercions with free variables of type (a ~ b) rather than (a ~# b)
* | Implement associated type defaultsMax Bolingbroke2011-09-091-1/+10
|/ | | | | | | | | | | | | | | | | | | Basically, now you can write: class Cls a where type Typ a type Typ a = Just a And now if an instance does not specify an explicit associated type instance, one will be generated afresh based on that default. So for example this instance: instance Cls Int where Will be equivalent to this one: instance Cls Int where type Typ Int = Just Int
* Add CoreMonad.reinitializeGlobals so plugins can work around linker issuesMax Bolingbroke2011-07-291-7/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When a plugin is loaded, it currently gets linked against a *newly loaded* copy of the GHC package. This would not be a problem, except that the new copy has its own mutable state that is not shared with that state that has already been initialized by the original GHC package. This leads to loaded plugins calling GHC code which pokes the static flags, and then dying with a panic because the static flags *it* sees are uninitialized. There are two possible solutions: 1. Export the symbols from the GHC executable from the GHC library and link against this existing copy rather than a new copy of the GHC library 2. Carefully ensure that the global state in the two copies of the GHC library matches I tried 1. and it *almost* works (and speeds up plugin load times!) except on Windows. On Windows the GHC library tends to export more than 65536 symbols (see #5292) which overflows the limit of what we can export from the EXE and causes breakage. (Note that if the GHC exeecutable was dynamically linked this wouldn't be a problem, because we could share the GHC library it links to.) We are going to try 2. instead. Unfortunately, this means that every plugin will have to say `reinitializeGlobals` before it does anything, but never mind. I've threaded the cr_globals through CoreM rather than giving them as an argument to the plugin function so that we can turn this function into (return ()) without breaking any plugins when we eventually get 1. working.
* Implement a findCycle function in Digraph,Simon Peyton Jones2011-07-221-1/+5
| | | | | | | | | | | | | | and use it to report module loops nicely This fixes Trac #5307. Now we get Module imports form a cycle: module `M8' (.\M8.hs) imports `M1' (M1.hs) which imports `M9' (.\M9.hs-boot) which imports `M8' (.\M8.hs) And the algorithm is linear time.
* Rename "extra-gcc-opts" to "settings", and start generalising itIan Lynagh2011-04-211-0/+14
|
* Force re-linking if the options have changed (#4451)Simon Marlow2011-04-081-2/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A common sequence of commands (at least for me) is this: $ ghc hello 1 of 1] Compiling Main ( hello.hs, hello.o ) Linking hello ... $ ./hello +RTS -s hello: Most RTS options are disabled. Link with -rtsopts to enable them. $ ghc hello -rtsopts $ grr, nothing happened. I could use -fforce-recomp, but if this was a large program I probably don't want to recompile it all again, so: $ rm hello removed `hello' $ ghc hello -rtsopts Linking hello ... $ ./hello +RTS -s ./hello +RTS -s Hello World! 51,264 bytes allocated in the heap 2,904 bytes copied during GC 43,808 bytes maximum residency (1 sample(s)) 17,632 bytes maximum slop etc. With this patch, GHC notices when the options have changed and forces a relink, so you don't need to rm the binary or use -fforce-recomp. This is done by adding the pertinent stuff to the binary in a special section called ".debug-ghc-link-info": $ readelf -p .debug-ghc-link-info ./hello String dump of section 'ghc-linker-opts': [ 0] (["-lHSbase-4.3.1.0","-lHSinteger-gmp-0.2.0.2","-lgmp","-lHSghc-prim-0.2.0.0","-lHSrts","-lm","-lrt","-ldl","-u","ghczmprim_GHCziTypes_Izh_static_info","-u","ghczmprim_GHCziTypes_Czh_static_info","-u","ghczmprim_GHCziTypes_Fzh_static_info","-u","ghczmprim_GHCziTypes_Dzh_static_info","-u","base_GHCziPtr_Ptr_static_info","-u","base_GHCziWord_Wzh_static_info","-u","base_GHCziInt_I8zh_static_info","-u","base_GHCziInt_I16zh_static_info","-u","base_GHCziInt_I32zh_static_info","-u","base_GHCziInt_I64zh_static_info","-u","base_GHCziWord_W8zh_static_info","-u","base_GHCziWord_W16zh_static_info","-u","base_GHCziWord_W32zh_static_info","-u","base_GHCziWord_W64zh_static_info","-u","base_GHCziStable_StablePtr_static_info","-u","ghczmprim_GHCziTypes_Izh_con_info","-u","ghczmprim_GHCziTypes_Czh_con_info","-u","ghczmprim_GHCziTypes_Fzh_con_info","-u","ghczmprim_GHCziTypes_Dzh_con_info","-u","base_GHCziPtr_Ptr_con_info","-u","base_GHCziPtr_FunPtr_con_info","-u","base_GHCziStable_StablePtr_con_info","-u","ghczmprim_GHCziTypes_False_closure","-u","ghczmprim_GHCziTypes_True_closure","-u","base_GHCziPack_unpackCString_closure","-u","base_GHCziIOziException_stackOverflow_closure","-u","base_GHCziIOziException_heapOverflow_closure","-u","base_ControlziExceptionziBase_nonTermination_closure","-u","base_GHCziIOziException_blockedIndefinitelyOnMVar_closure","-u","base_GHCziIOziException_blockedIndefinitelyOnSTM_closure","-u","base_ControlziExceptionziBase_nestedAtomically_closure","-u","base_GHCziWeak_runFinalizzerBatch_closure","-u","base_GHCziTopHandler_runIO_closure","-u","base_GHCziTopHandler_runNonIO_closure","-u","base_GHCziConcziIO_ensureIOManagerIsRunning_closure","-u","base_GHCziConcziSync_runSparks_closure","-u","base_GHCziConcziSignal_runHandlers_closure","-lHSffi"],Nothing,RtsOptsAll,False,[],[]) And GHC itself uses the readelf command to extract it when deciding whether to relink. The reason for the name ".debug-ghc-link-info" is that sections beginning with ".debug" are removed automatically by strip. This currently only works on Linux; Windows and OS X still have the old behaviour.
* Make fuzzy matching a little less eager for short identifierssimonpj@microsoft.com2011-01-071-3/+12
| | | | | For single-character identifiers we now don't make any suggestions See comments in Util.fuzzyLookup
* Add fuzzyLookup, a variant of fuzzyMatchsimonpj@microsoft.com2010-12-221-36/+73
| | | | Plus, I changed quite a bit of layout to make the lines shorter.
* Replace uses of the old catch function with the new oneIan Lynagh2010-12-181-4/+5
|
* Remove code that is dead now that we need >= 6.12 to buildIan Lynagh2010-12-151-8/+0
|
* looksLikeModuleName: allow apostrophe in module names (#4051)Simon Marlow2010-05-101-1/+1
|
* Spelling correction for LANGUAGE pragmasMax Bolingbroke2010-04-131-1/+96
|
* Add Data and Typeable instances to HsSynDavid Waern2010-03-301-0/+30
| | | | | The instances (and deriving declarations) have been taken from the ghc-syb package.
* Remove redundant importsimonpj@microsoft.com2010-02-081-1/+0
|
* locateOneObj: don't look for dynamic libs in static modeSimon Marlow2010-01-031-5/+5
| | | | | also replace picIsOn with isDynamicGhcLib, as __PIC__ is not the correct test for whether the GHC library is dynamically linked.
* Substantial improvements to coercion optimisationsimonpj@microsoft.com2010-01-041-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | The main purpose of this patch is to add a bunch of new rules to the coercion optimiser. They are documented in the (revised) Appendix of the System FC paper. Some code has moved about: - OptCoercion is now a separate module, mainly because it now uses tcMatchTy, which is defined in Unify, so OptCoercion must live higehr up in the hierarchy - Functions that manipulate Kinds has moved from Type.lhs to Coercion.lhs. Reason: the function typeKind now needs to call coercionKind. And in any case, a Kind is a flavour of Type, so it builds on top of Type; indeed Coercions and Kinds are both flavours of Type. This change required fiddling with a number of imports, hence the one-line changes to otherwise-unrelated modules - The representation of CoTyCons in TyCon has changed. Instead of an extensional representation (a kind checker) there is now an intensional representation (namely TyCon.CoTyConDesc). This was needed for one of the new coercion optimisations.
* Use the standard library versions of elem and notElemIan Lynagh2009-10-051-21/+12
| | | | rather than our own copies