summaryrefslogtreecommitdiff
path: root/compiler/main/SysTools
Commit message (Collapse)AuthorAgeFilesLines
* Modules (#13009)Sylvain Henry2020-04-187-1760/+0
| | | | | | | | | | | | | | * SysTools * Parser * GHC.Builtin * GHC.Iface.Recomp * Settings Update Haddock submodule Metric Decrease: Naperian parsing001
* Session: Memoize stderrSupportsAnsiColorsBen Gamari2020-04-021-2/+10
| | | | | Not only is this a reasonable efficiency measure but it avoids making reentrant calls into ncurses, which is not thread-safe. See #17922.
* Simplify stderrSupportsAnsiColorsÖmer Sinan Ağacan2020-03-311-13/+6
| | | | | The combinator andM is used only once, and the code is shorter and simpler if you inline it.
* Require GHC 8.8 as the minimum compiler for bootstrappingRyan Scott2020-03-311-4/+0
| | | | | | | | This allows us to remove several bits of CPP that are either always true or no longer reachable. As an added bonus, we no longer need to worry about importing `Control.Monad.Fail.fail` qualified to avoid clashing with `Control.Monad.fail`, since the latter is now the same as the former.
* Modules: Types (#13009)Sylvain Henry2020-03-292-3/+3
| | | | | | | Update Haddock submodule Metric Increase: haddock.compiler
* Refactor CmmToAsm (disentangle DynFlags)Sylvain Henry2020-03-151-4/+5
| | | | | | | | | | | | | | | | | | | | | This patch disentangles a bit more DynFlags from the native code generator (CmmToAsm). In more details: - add a new NCGConfig datatype in GHC.CmmToAsm.Config which contains the configuration of a native code generation session - explicitly pass NCGConfig/Platform arguments when necessary - as a consequence `sdocWithPlatform` is gone and there are only a few `sdocWithDynFlags` left - remove the use of `unsafeGlobalDynFlags` from GHC.CmmToAsm.CFG - remove `sdocDebugLevel` (now we pass the debug level via NCGConfig) There are still some places where DynFlags is used, especially because of pretty-printing (CLabel), because of Cmm helpers (such as `cmmExprType`) and because of `Outputable` instance for the instructions. These are left for future refactoring as this patch is already big.
* SysTools: Ensure that error parser can handle absolute paths on WindowsBen Gamari2020-03-101-3/+14
| | | | | | | This fixes #17786, where the error parser fails to correctly handle the drive name in absolute Windows paths. Unfortunately I couldn't find a satisfactory way to test this.
* SysTools: Don't use process jobs if they are brokenBen Gamari2020-02-261-8/+22
|
* Modules: Driver (#13009)Sylvain Henry2020-02-214-6/+6
| | | | submodule updates: nofib, haddock
* Modules: Llvm (#13009)Sylvain Henry2020-02-181-1/+1
|
* SysTools: Use "process job" when spawning processes on WindowsTamar Christina2020-02-141-3/+16
| | | | | | | | | | | | | | GHC should make calls using process jobs when calling out to GCC and LD. The reason is these use the exec () family of posix functions. Window's process model doesn't allow replacement of processes so this is emulated by creating a new process and immediately exiting the old one. Because of this when using normal Windows wait functions you would return even without the child process having finished. In this case if you are depending on data from the child you will enter a race condition. The usual fix for this is to use process jobs and wait for the termination of all children that have ever been spawn by the process you called. But also waiting for the freeing of all resources.
* Refactor package related codeSylvain Henry2020-01-311-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The package terminology is a bit of a mess. Cabal packages contain components. Instances of these components when built with some flags/options/dependencies are called units. Units are registered into package databases and their metadata are called PackageConfig. GHC only knows about package databases containing units. It is a sad mismatch not fixed by this patch (we would have to rename parameters such as `package-id <unit-id>` which would affect users). This patch however fixes the following internal names: - Renames PackageConfig into UnitInfo. - Rename systemPackageConfig into globalPackageDatabase[Path] - Rename PkgConfXX into PkgDbXX - Rename pkgIdMap into unitIdMap - Rename ModuleToPkgDbAll into ModuleNameProvidersMap - Rename lookupPackage into lookupUnit - Add comments on DynFlags package related fields It also introduces a new `PackageDatabase` datatype instead of explicitly passing the following tuple: `(FilePath,[PackageConfig])`. The `pkgDatabase` field in `DynFlags` now contains the unit info for each unit of each package database exactly as they have been read from disk. Previously the command-line flag `-distrust-all-packages` would modify these unit info. Now this flag only affects the "dynamic" consolidated package state found in `pkgState` field. It makes sense because `initPackages` could be called first with this `distrust-all-packages` flag set and then again (using ghc-api) without and it should work (package databases are not read again from disk when `initPackages` is called the second time). Bump haddock submodule
* while at it rename XCode to the official XcodeGabor Greif2019-12-271-3/+3
|
* Fix typosBrian Wignall2019-11-231-1/+1
|
* Prevent -optc arguments from being duplicated in reverse order (#17471)Ryan Scott2019-11-231-3/+2
| | | | | | | | | | | | | | | | | This reverts a part of commit 7bc5d6c6578ab9d60a83b81c7cc14819afef32ba that causes all arguments to `-optc` (and `-optcxx`) to be passed twice to the C/C++ compiler, once in reverse order and then again in the correct order. While passing duplicate arguments is usually harmless it can cause breakage in this pattern, which is employed by Hackage libraries in the wild: ``` ghc Foo.hs foo.c -optc-D -optcFOO ``` As `FOO -D -D FOO` will cause compilers to error. Fixes #17471.
* SysTools: Only apply Windows-specific workaround on WindowsBen Gamari2019-11-041-1/+7
| | | | | | | | | Issue #1110 was apparently due to a bug in Vista which prevented GCC from finding its binaries unless we explicitly added it to PATH. However, this workaround was incorrectly applied on non-Windows platforms as well, resulting in ill-formed PATHs (#17266). Fixes #17266.
* Make dynflag argument for withTiming pure.Andreas Klebinger2019-10-231-1/+1
| | | | | | | | | | | | 19 times out of 20 we already have dynflags in scope. We could just always use `return dflags`. But this is in fact not free. When looking at some STG code I noticed that we always allocate a closure for this expression in the heap. Clearly a waste in these cases. For the other cases we can either just modify the callsite to get dynflags or use the _D variants of withTiming I added which will use getDynFlags under the hood.
* Clean up `#include`s in the compilerJohn Ericson2019-10-051-2/+2
| | | | | | | | - Remove unneeded ones - Use <..> for inter-package. Besides general clean up, helps distinguish between the RTS we link against vs the RTS we compile for.
* Add tryFindTopDir to look for the top dir without blowing up if it isJohn Ericson2019-10-041-11/+17
| | | | not found.
* Pull out the settings file parsing code into it's own module.John Ericson2019-10-041-0/+253
| | | | | | | | | | | This has two benefits: 1. One less hunk of code dependent on DynFlags 2. Add a little bit of error granularity to distrinugish between missing data and bad data. This could someday be shared with ghc-pkg which aims to work even with a missing file. I also am about to to make --supported-extensions use this too.
* linker: Move -optl flags to end of linker invocation.Niklas Hambüchen2019-09-111-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Until now, giving `-optl` linker flags to `ghc` on the command line placed them in the wrong place in the `ld` command line: They were given before all the Haskell libararies, when they should appear after. Background: Most linkers like `ld.bfd` and `ld.gold`, but not the newer LLVM `lld`, work in a way where the order of `-l` flags given matters; earlier `-lmylib1` flags are supposed to create "holes" for linker symbols that are to be filled with later `lmylib2` flags that "fill the holes" for these symbols. As discovered in https://github.com/haskell/cabal/pull/5451#issuecomment-518001240, the `-optl` flags appeared before e.g. the -lHStext-1.2.3.1 -lHSbinary-0.8.6.0 -lHScontainers-0.6.0.1 flags that GHC added at the very end. Haskell libraries typically depend on C libraries, so `-lHS*` flags will create holes for the C libraries to fill in, but that only works when those libraries' `-l` flags are given **after** the `-lHS*` flags; until now they were given before, which was wrong. This meant that Cabal's `--ld-options` flag and `ld-options` `.cabal` file field were pretty ineffective, unless you used the `--ld-option=--start-group` hack as (https://github.com/haskell/cabal/pull/5451#issuecomment-406761676) that convinces the classical linkers to not be dependent on the order of linker flags given. This commit fixes the problem by simply flipping the order, putting `-optl` flags at the end, after Haskell libraries. The code change is effectively only `args1 ++ args` -> `args ++ args1` but the commit also renames the variables for improved clarity. Simple way to test it: ghc --make Main.hs -fforce-recomp -v -optl-s on a `Main.hs` like: import qualified Data.Set as Set main = print $ Set.fromList "hello"
* Replace queryCygwinTerminal with Win32's isMinTTYHandleRyan Scott2019-09-091-61/+11
| | | | | | | | | | | | `SysTools.Terminal.queryCygwinTerminal` now exists in the `Win32` library under the name `isMinTTYHandle` since `Win32-2.5.0.0`. (GHC 8.4.4 ships with `Win32-2.6.1.0`, so this is well within GHC's support window.) We can therefore get replace `queryCygwinTerminal` with `isMinTTYHandle` and delete quite a bit of code from `SysTools.Terminal` in the process. Along the way I needed to replace some uses of `#if defined x` with `#if defined(x)` to please the CI linters.
* Fix LLVM version check yet againÖmer Sinan Ağacan2019-08-291-13/+5
| | | | | | | | | | | | | | | There were two problems with LLVM version checking: - The parser would only parse x and x.y formatted versions. E.g. 1.2.3 would be rejected. - The version check was too strict and would reject x.y formatted versions. E.g. when we support version 7 it'd reject 7.0 ("LLVM version 7.0") and only accept 7 ("LLVM version 7"). We now parse versions with arbitrarily deep minor numbering (x.y.z.t...) and accept versions as long as the major version matches the supported version (e.g. 7.1, 7.1.2, 7.1.2.3 ...).
* compiler: trace SysTools commands to emit start/stop eventlog markersAlp Mestanogullari2019-07-131-18/+31
| | | | | | | | | | | | | | | | | | | This patch was motivated by some performance characterization work done for #16822, where we suspected that GHC was spending a lot of time waiting on the linker to be done. (That turned out to be true.) The tracing is taken care of by ErrUtils.withTiming, so this patch just defines and uses a little wrapper around that function in all the helpers for calling the various systools (C compiler, linker, unlit, ...). With this patch, assuming a GHC executable linked against an eventlog-capable RTS (RTS ways that contain the debug, profiling or eventlog way units), we can measure how much time is spent in each of the SysTools when building hello.hs by simply doing: ghc hello.hs -ddump-timings +RTS -l The event names are "systool:{cc, linker, as, unlit, ...}".
* Fixes for LLVM 7Erik de Castro Lopo2019-06-241-4/+6
| | | | | | | LLVM version numberinf changed recently. Previously, releases were numbered 4.0, 5.0 and 6.0 but with version 7, they dropped the redundant ".0". Fix requires for Llvm detection and some code.
* ghc-pkg needs settings file to un-hardcode target platformJohn Ericson2019-06-191-16/+0
| | | | This matches GHC itself getting the target platform from there.
* Move 'Platform' to ghc-bootJohn Ericson2019-06-193-3/+3
| | | | | | | ghc-pkg needs to be aware of platforms so it can figure out which subdire within the user package db to use. This is admittedly roundabout, but maybe Cabal could use the same notion of a platform as GHC to good affect too.
* Maintain separate flags for C++ compiler invocationsBen Gamari2019-06-132-13/+17
| | | | | | | Previously we would pass flags intended for the C compiler to the C++ compiler (see #16738). This would cause, for instance, `-std=gnu99` to be passed to the C++ compiler, causing spurious test failures. Fix this by maintaining a separate set of flags for C++ compilation invocations.
* Factor out 'getLibDir' / 'getBaseDir' into a new GHC.BaseDir ghc-boot moduleJohn Ericson2019-06-071-40/+3
| | | | | | | | | | | | | | ghc-pkg and ghc already both needed this. I figure it is better to deduplicate, especially seeing that changes to one (FreeBSD CPP) didn't make it to the other. Additionally in !1090 I make ghc-pkg look up the settings file, which makes it use the top dir a bit more widely. If that lands, any difference in the way they find the top dir would be more noticable. That change also means sharing more code between ghc and ghc-package (namely the settings file parsing code), so I'd think it better to get off the slipperly slope of duplicating code now.
* Add `-optcxx` option (#16477)Yuriy Syrovetskiy2019-04-082-5/+22
|
* Update Trac ticket URLs to point to GitLabRyan Scott2019-03-152-5/+5
| | | | | This moves all URL references to Trac tickets to their corresponding GitLab counterparts.
* Rip out object splittingBen Gamari2019-03-052-6/+1
| | | | | | | | | | | | | | | The splitter is an evil Perl script that processes assembler code. Its job can be done better by the linker's --gc-sections flag. GHC passes this flag to the linker whenever -split-sections is passed on the command line. This is based on @DemiMarie's D2768. Fixes Trac #11315 Fixes Trac #9832 Fixes Trac #8964 Fixes Trac #8685 Fixes Trac #8629
* Use --no-as-needed with LLD tooSimon Marlow2018-12-071-1/+3
| | | | | | | | | | | | Test Plan: validate using LLD as the linker (TODO) Reviewers: bgamari, angerman, kavon, erikd Reviewed By: bgamari Subscribers: watashi, rwbarton, carter Differential Revision: https://phabricator.haskell.org/D5336
* Calling gcc: Pass optc flags as last options (#14452)Roland Senn2018-11-221-1/+3
| | | | | | | | | | | | | | Test Plan: make test TEST=T14452 Reviewers: hvr, bgamari, monoidal, thomie, osa1 Reviewed By: osa1 Subscribers: rwbarton, carter GHC Trac Issues: #14452 Differential Revision: https://phabricator.haskell.org/D5318
* Building GHC with hadrian on FreeBSDKrzysztof Gogolewski2018-11-171-2/+2
| | | | | | | | | | | | | | | Summary: I'm currently trying to make `hadrian` work as a build system on FreeBSD (https://ghc.haskell.org/trac/ghc/ticket/15860). I'm still having some issues with `libgmp` but one can get a working `ghc` using `--integer-simple` and this patch. Reviewers: bgamari, erikd, alpmestan Reviewed By: alpmestan Subscribers: rwbarton, carter Differential Revision: https://phabricator.haskell.org/D5335
* Drop GHC 8.2 compatibilityRyan Scott2018-10-031-97/+0
| | | | | | | | | | | | | | | | | Summary: GHC 8.6.1 is out, so now GHC's support window only extends back to GHC 8.4. This means we can delete gobs of code that were only used for GHC 8.2 support. Hooray! Test Plan: ./validate Reviewers: bgamari, Phyx, erikd Reviewed By: bgamari, Phyx Subscribers: rwbarton, erikd, carter Differential Revision: https://phabricator.haskell.org/D5192
* Add -fkeep-cafsSimon Marlow2018-09-281-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | Summary: I noticed while playing around with https://github.com/fbsamples/ghc-hotswap/ that the main binary needs to have a custom main function to set `config.keep_cafs = true` when initialising the runtime. This is pretty annoying, it means an extra C file with some cryptic incantations in it, and a `-no-hs-main` flag. So I've replaced this with a link-time flag to GHC, `-fkeep-cafs` that does the same thing. Test Plan: New unit test that tests for the RTS's GC'd CAFs assertion, and also the -keep-cafs flag. Reviewers: bgamari, osa1, erikd, noamz Reviewed By: osa1 Subscribers: rwbarton, carter Differential Revision: https://phabricator.haskell.org/D5183
* ghc, ghc-pkg: use getExecutablePath on Windows when base >= 4.11.0Tamar Christina2018-08-251-1/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This completes the work started in D4227 by using just 'getExecutablePath' in ghc and ghc-pkg when building with base >= 4.11.0. On the long term, we will be able to simply kill the existing code that follows (or not) symlinks and just get this behaviour for free from getExecutable. For now we however have to require base >= 4.11.0 to be able to just use getExecutablePath under Windows, and use the current code when building with an older base. Original code by @alpmestan commandeering since patch has been stale and bug remains open. Test Plan: Validate Reviewers: angerman, bgamari, erikd, alpmestan Reviewed By: bgamari Subscribers: carter, rwbarton, thomie GHC Trac Issues: #14483 Differential Revision: https://phabricator.haskell.org/D4229
* Modifications to support loading GHC into GHCiMichael Sloan2018-07-271-6/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change was previously part of [D4904](https://phabricator.haskell.org/D4904), but is being split off to aid in getting this reviewed and merged. * The compiler code is built with `NoImplicitPrelude`, but GHCi's modules are incompatible with it. So, this adds the pragma to all GHCi modules that didn't have it, and adds imports of Prelude. * In order to run GHC within itself, a `call of 'initGCStatistics` needed to be skipped. This uses CPP to skip it when `-DGHC_LOADED_INTO_GHCI` is set. * There is an environment variable workaround suggested by Ben Gamari [1], where `_GHC_TOP_DIR` can be used to specify GHC's top dir if `-B` isn't provided. This can be used to solve a problem where the GHC being run within GHCi attempts to look in `inplace/lib/lib/` instead of `inplace/lib/`. [1]: https://phabricator.haskell.org/D4904#135438 Reviewers: goldfire, bgamari, erikd, alpmestan Reviewed By: alpmestan Subscribers: alpmestan, lelf, rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4986
* A few more typofixes in docs/comments [ci skip]Gabor Greif2018-06-201-1/+1
|
* Introduce a $tooldir variable for nicer toolchain detection on WindowsAlp Mestanogullari2018-04-171-6/+58
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch affects several files that affect how we detect mingw and perl on Windows. The initial motivation is: https://github.com/snowleopard/hadrian/issues/564 where, with Hadrian building relocatable (non-inplace) GHCs, the current detection mechanism falls short by e.g only trying $topdir/../mingw. But in Hadrian, for reasons given in that issue, we would need to store e.g mingw under $topdir/../../mingw except for binary distributions, where we want to follow the existing structure, in which case $topdir/../mingw is correct. So we need to support both, which is what this patch hopefully implements. Test Plan: ./validate Reviewers: Phyx, hvr, bgamari, erikd Reviewed By: Phyx Subscribers: snowleopard, thomie, carter Differential Revision: https://phabricator.haskell.org/D4598
* llvmGen: Pass -optlo flags last to optOleg Grenrus2018-03-251-1/+3
| | | | | | | | | | | | | | | LLVM, like GHC, processes flags in the order that they appear. Consequently, we need to ensure the user-provided flags appear last so they can override flags produced by GHC. See #14821. Test Plan: `ghc -O2 -optlo-O2 -v3 $FILE` and ensure that `opt` and `llc` are invoked with `-O2`. Subscribers: rwbarton, thomie, carter GHC Trac Issues: #14821 Differential Revision: https://phabricator.haskell.org/D4421
* Drop GHC 8.0 compatibilityRyan Scott2018-03-131-4/+0
| | | | | | | | | | | | | | | | GHC 8.4.1 is out, so now GHC's support window only extends back to GHC 8.2. This means we can delete gobs of code that were only used for GHC 8.0 support. Hooray! Test Plan: ./validate Reviewers: bgamari, erikd, dfeuer Reviewed By: bgamari, dfeuer Subscribers: alexbiehl, dfeuer, rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4492
* SysTools: Add detection support for LLD linkerBen Gamari2018-01-211-0/+4
| | | | | | I noticed while trying to test against LLVM 5.0 that GHC would throw "Couldn't figure out linker information" warnings due to LLD being chosen by configure. Adding detection support to silence these is simple enough, let's just do it.
* Remove executable filename check on windowsklebinger.andreas@gmx.at2018-01-151-13/+4
| | | | | | | | | | | | | | | | | | | | On Windows GHC enforces currently that the real executable is named ghc.exe/ghc-stage[123].exe. I don't see a good reason why this is neccessary. This patch removes this restriction and fixes #14652 Test Plan: ci Reviewers: bgamari, Phyx Reviewed By: Phyx Subscribers: Phyx, rwbarton, thomie, carter GHC Trac Issues: #14652 Differential Revision: https://phabricator.haskell.org/D4296
* SysTools: Split up TopDir logic into new moduleBen Gamari2017-11-231-0/+208
| | | | | | | | | | Test Plan: Validate on Linux and Windows Reviewers: erikd Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D4225
* Split SysTools up someTamar Christina2017-10-104-0/+1185
| | | | | | | | | | | | | | | | | Summary: SysTools and DriverTools have an annoying mutual dependency. They also each contain pieces of the linker. In order for changes to be shared between the library and the exe linking code this dependency needs to be broken in order to avoid using hs-boot files. Reviewers: austin, bgamari, erikd Reviewed By: bgamari Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D4071
* Fix Windows build regression due to GhcPrelude changeBen Gamari2017-09-191-1/+2
|
* compiler: introduce custom "GhcPrelude" PreludeHerbert Valerio Riedel2017-09-191-0/+2
| | | | | | | | | | | | | | | | | | This switches the compiler/ component to get compiled with -XNoImplicitPrelude and a `import GhcPrelude` is inserted in all modules. This is motivated by the upcoming "Prelude" re-export of `Semigroup((<>))` which would cause lots of name clashes in every modulewhich imports also `Outputable` Reviewers: austin, goldfire, bgamari, alanz, simonmar Reviewed By: bgamari Subscribers: goldfire, rwbarton, thomie, mpickering, bgamari Differential Revision: https://phabricator.haskell.org/D3989
* Windows: Improve terminal detection mechanismPhil Ruffwind2016-12-171-0/+150
The previous detection mechanism allowed environment variables (ANSICON, ConEmuANSI, TERM) to supersede the fact that the stderr is not a terminal, which is probably what led to color codes appearing in the stderr of the tests (see: 847d229346431483b99adcff12e46c7bf6af15da). This commit changes the detection mechanism to detect Cygwin/MSYS2 terminals in a more reliable manner, avoiding the use of environment variables entirely. Test Plan: validate Reviewers: Phyx, austin, erikd, bgamari Reviewed By: Phyx, bgamari Subscribers: RyanGlScott, thomie Differential Revision: https://phabricator.haskell.org/D2809