summaryrefslogtreecommitdiff
path: root/compiler/GHC
Commit message (Collapse)AuthorAgeFilesLines
...
* Minor fix to pretty-printing of linear typesKrzysztof Gogolewski2021-08-053-8/+12
| | | | | | The function ppr_arrow_chain was not printing multiplicities. Also remove the Outputable instance: no longer used, and could cover bugs like those.
* Use Reductions to keep track of rewritingssheaf2021-08-0418-917/+1405
| | | | | | | | | | | | | | | | | | | | | | | | | | | | We define Reduction = Reduction Coercion !Type. A reduction of the form 'Reduction co new_ty' witnesses an equality ty ~co~> new_ty. That is, the rewriting happens left-to-right: the right-hand-side type of the coercion is the rewritten type, and the left-hand-side type the original type. Sticking to this convention makes the codebase more consistent, helping to avoid certain applications of SymCo. This replaces the parts of the codebase which represented reductions as pairs, (Coercion,Type) or (Type,Coercion). Reduction being strict in the Type argument improves performance in some programs that rewrite many type families (such as T9872). Fixes #20161 ------------------------- Metric Decrease: T5321Fun T9872a T9872b T9872c T9872d -------------------------
* Make HsWrapper a MonoidJohn Ericson2021-08-041-0/+21
| | | | See instance documentation for caviat.
* Linear types: fix linting of multiplicities (#19165)Krzysztof Gogolewski2021-08-041-14/+20
| | | | The previous version did not substitute the type used in the scrutinee.
* Disable -fdefer-type-errors for linear types (#20083)Krzysztof Gogolewski2021-08-043-3/+32
|
* Don't store tmpDir in SettingsSylvain Henry2021-08-033-18/+9
| | | | There was no point in doing this as indicated by the TODO.
* move bytecode preparation into the STG pipelineLuite Stegeman2021-08-034-199/+244
| | | | | this makes it possible to combine passes to compute free variables more efficiently in a future change
* Correctly unload libs on GHCi with external iservTito Sacchi2021-08-031-1/+1
| | | | | | | | | Fix #17669 `hostIsDynamic` is basically a compile-time constant embedded in the RTS. Therefore, GHCi didn't unload object files properly when used with an external interpreter built in a different way.
* Handle OverloadedRecordDot in TH (#20185)Zubin Duggal2021-08-033-5/+31
|
* Improve documentation for HscTypes.usg_mod_hashAndreas Klebinger2021-08-031-2/+5
|
* Remove eager forcing of RuleInfo in substRuleInfoMatthew Pickering2021-08-032-9/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | substRuleInfo updates the IdInfo for an Id, therefore it is important to not force said IdInfo whilst updating it, otherwise we end up in an infinite loop. This is what happened in #20112 where `mkTick` forced the IdInfo being updated by checking the arity in isSaturatedConApp. The fix is to stop the expression being forced so early by removing the call to seqRuleInfo. The call sequence looked something like: * `substRecBndrs` * `substIdBndr` * `substIdInfo` * `substRuleInfo` * `substRule` * `substExpr` * `mkTick` * `isSaturatedConApp` * Look at `IdInfo` for thing we are currently substituting because the rule is attached to `transpose` and mentions it in the `RHS` of the rule. Which arose because the `transpose` Id had a rule attached where the RHS of the rule also mentioned `transpose`. This call to seqRuleInfo was introduced in 4e7d56fde0f44d38bbb9a6fc72cf9c603264899d where it was explained > I think there are now *too many* seqs, and they waste work, but I don't have > time to find which ones. We also observe that there is the ominous note on `substRule` about making sure substExpr is called lazily. > {- Note [Substitute lazily] > ~~~~~~~~~~~~~~~~~~~~~~~~~~~ > The functions that substitute over IdInfo must be pretty lazy, because > they are knot-tied by substRecBndrs. > > One case in point was #10627 in which a rule for a function 'f' > referred to 'f' (at a different type) on the RHS. But instead of just > substituting in the rhs of the rule, we were calling simpleOptExpr, which > looked at the idInfo for 'f'; result <<loop>>. > > In any case we don't need to optimise the RHS of rules, or unfoldings, > because the simplifier will do that. Before `seqRuleInfo` was removed, this note was pretty much ignored in the `substSpec` case because the expression was immediately forced after `substRule` was called. Unfortunately it's a bit tricky to add a test for this as the failure only manifested (for an unknown reason) with a dwarf enabled compiler *AND* compiling with -g3. Fortunatley there is currently a CI configuration which builds a dwarf compiler to test this. Also, for good measure, finish off the work started in 840df33685e8c746ade4b9d4d0eb7c764a773e48 which renamed SpecInfo to RuleInfo but then didn't rename 'substSpec' to 'substRuleInfo'. Fixes #20112
* Catch type-checker exceptions when splicingSimon Peyton Jones2021-08-021-4/+10
| | | | | | | | In GHC.Tc.Gen.Splice.tcTopSpliceExpr we were forgetting to catch exceptions. As a result we missed the kind error in the unsolved constraints. This patch has an easy fix, which cures #20179
* Supply missing case for '.' inShayne Fletcher2021-08-021-0/+1
|
* Disallow nonlinear fields in Template Haskell (#18378)Krzysztof Gogolewski2021-08-023-1/+21
|
* Remove Semigroup instance for UniqDFM (#19654)Krzysztof Gogolewski2021-08-022-11/+1
| | | | | | | The (<>) operator was not associative. Fortunately, the instance is not used anywhere, except to derive another unused instance for UniqDSet.
* Lookup string literals in top-level thunks (fix #16373)Sylvain Henry2021-08-021-6/+8
|
* Constant-fold unpackAppendCString (fix #20174)Sylvain Henry2021-08-022-48/+103
| | | | | | | Minor renaming: since 1ed0409010afeaa318676e351b833aea659bf93a rules get an InScopeEnv arg (containing an IdUnfoldingFun) instead of an IdUnfoldingFun directly, hence I've renamed the parameter from "id_unf" to "env" for clarity.
* Only create callstack in DEBUG buildsSylvain Henry2021-08-021-16/+16
|
* [AArch64/Darwin] fix packed calling conv alignmentMoritz Angermann2021-08-021-6/+38
| | | | | | Apparently we need some padding as well. Fixes #20137
* PrimOps: Add CAS op for all int sizesPeter Trommler2021-08-024-4/+150
| | | | | | | | | | | PPC NCG: Implement CAS inline for 32 and 64 bit testsuite: Add tests for smaller atomic CAS X86 NCG: Catch calls to CAS C fallback Primops: Add atomicCasWord[8|16|32|64]Addr# Add tests for atomicCasWord[8|16|32|64]Addr# Add changelog entry for new primops X86 NCG: Fix MO-Cmpxchg W64 on 32-bit arch ghc-prim: 64-bit CAS C fallback on all archs
* Reject pattern synonyms with linear types (#18806)Krzysztof Gogolewski2021-07-293-3/+23
|
* UNREG: implement 64-bit mach ops for 32-bit targetsSergei Trofimovich2021-07-291-29/+29
| | | | | | | | | | | | | | | Noticed build failures like ``` ghc-stage1: panic! (the 'impossible' happened) GHC version 9.3.20210721: pprCallishMachOp_for_C: MO_x64_Ne not supported! ``` on `--tagget=hppa2.0-unknown-linux-gnu`. The change does not fix all 32-bit unreg target problems, but at least allows linking final ghc binaries. Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
* compiler: Name generated locals more descriptivelyBen Gamari2021-07-291-9/+14
| | | | | | Previously `GHC.Types.Id.Make.newLocal` would name all locals `dt`, making it unnecessarily difficult to determine their origin. Noticed while looking at #19557.
* Delete ToDo about incorrect optimisation [skip ci]Peter Trommler2021-07-291-4/+0
| | | | | On big-endian systems a narrow after a load cannot be replaced with a narrow load.
* Port more DriverUnknownMessage into richer DriverMessage constructorsAlfredo Di Napoli2021-07-286-59/+274
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In order: * Introduce the `PsErrUnknownOptionsPragma` diagnostic message This commit changes the diagnostic emitted inside `GHC.Parser.Header.checkProcessArgsResult` from an (erroneous) and unstructured `DriverUnknownMessage` to a `PsErrUnknownOPtionsPragma`, i.e. a new data constructor of a `PsHeaderMessage`. * Add the `DriverUserDefinedRuleIgnored` diagnostic message * Add `DriverUserDefinedRuleIgnored` data constructor This commit adds (and use) a new data constructor to the `DriverMessage` type, replacing a `DriverUnknownMessage` with it. * Add and use `DriverCannotLoadInterfaceFile` constructor This commit introduces the DriverCannotLoadInterfaceFile constructor for the `DriverMessage` type and it uses it to replace and occurrence of `DriverUnknownMessage`. * Add and use the `DriverInferredSafeImport` constructor This commit adds a new `DriverInferredSafeImport` constructor to the `DriverMessage` type, and uses it in `GHC.Driver.Main` to replace one occurrence of `DriverUnknownMessage`. * Add and use `DriverCannotImportUnsafeModule` constructor This commit adds the `DriverCannotImportUnsafeModule` constructor to the `DriverMessage` type, and later using it to replace one usage of `DriverUnknownMessage` in the `GHC.Driver.Main` module. * Add and use `DriverMissingSafeHaskellMode` constructor * Add and use `DriverPackageNotTrusted` constructor * Introduce and use `DriverInferredSafeModule` constructor * Add and use `DriverMarkedTrustworthyButInferredSafe` constructor * Add and use `DriverCannotImportFromUntrustedPackage`
* Fix type check error message grammar (fixes #20122)CarrieMY2021-07-282-3/+22
| | | | Remove trailing spaces
* Fix a subtle scoping error in simplLazyBindSimon Peyton Jones2021-07-281-10/+15
| | | | | | | | | | | | | | | | | | In the call to prepareBinding (in simplLazyBind), I had failed to extend the in-scope set with the binders from body_floats1. As as result, when eta-expanding deep inside prepareBinding we made up an eta-binder that shadowed a variable free in body1. Yikes. It's hard to trigger this bug. It showed up when I was working on !5658, and I started using the in-scope set for eta-expansion, rather than taking free variables afresh. But even then it only showed up when compiling a module in Haddock utils/haddock/haddock-api/src/Haddock/Interface/Rename.hs Sadly Haddock is compiled without Core Lint, so we ultimately got a seg-fault. Lint nailed it fast once I realised that it was off. There is some other tiny refactoring in this patch.
* Improve performance of eta expansionSimon Peyton Jones2021-07-284-73/+152
| | | | | | | | | | | | | | | | | | | | | | | | | | | Eta expansion was taking ages on T18223. This patch * Aggressively squash reflexive casts in etaInfoApp. See Note [Check for reflexive casts in eta expansion] These changes decreased compile-time allocation by 80%! * Passes the Simplifier's in-scope set to etaExpandAT, so we don't need to recompute it. (This alone saved 10% of compile time.) Annoyingly several functions in the Simplifier (namely makeTrivialBinding and friends) need to get SimplEnv, rather than SimplMode, but that is no big deal. Lots of small changes in compile-time allocation, less than 1% and in both directions. A couple of bigger changes, including the rather delicate T18223 T12425(optasm) ghc/alloc 98448216.0 97121224.0 -1.3% GOOD T18223(normal) ghc/alloc 5454689676.0 1138238008.0 -79.1% GOOD Metric Decrease: T12425 T18223
* Simplify and improve the eta expansion mechanismSimon Peyton Jones2021-07-284-154/+150
| | | | | | | | | | | Previously the eta-expansion would return lambdas interspersed with casts; now the cast is just pushed to the outside: #20153. This actually simplifies the code. I also improved mkNthCo to account for SymCo, so that mkNthCo n (SymCo (TyConAppCo tc cos)) would work well.
* Inline less logging codeSimon Peyton Jones2021-07-282-26/+47
| | | | | | | | | | | | When eyeballing calls of GHC.Core.Opt.Simplify.Monad.traceSmpl, I saw that lots of cold-path logging code was getting inlined into the main Simplifier module. So in GHC.Utils.Logger I added a NOINLINE on logDumpFile'. For logging, the "hot" path, up to and including the conditional, should be inlined, but after that we should inline as little as possible, to reduce code size in the caller.
* Make the occurrence analyser a bit stricterSimon Peyton Jones2021-07-281-29/+31
| | | | | | | | | | | | occAnalArgs and occAnalApp are very heavily used functions, so it pays to make them rather strict: fewer thunks constructed. All these thunks are ultimately evaluated anyway. This patch gives a welcome reduction compile time allocation of around 0.5% across the board. For T9961 it's a 2.2% reduction. Metric Decrease: T9961
* White space, spelling, and a tiny refactorSimon Peyton Jones2021-07-282-6/+9
| | | | No change in behaviour
* Extend the in-scope set to silence substExpr warningsSimon Peyton Jones2021-07-281-2/+12
| | | | | | substExpr warns if it finds a LocalId that isn't in the in-scope set. This patch extends the in-scope set to silence the warnings. (It has no effect on behaviour.)
* Improve postInlineUnconditionallySimon Peyton Jones2021-07-281-14/+29
| | | | | | | | | | | See Note [Use occ-anald RHS in postInlineUnconditionally]. This explains how to eliminate an extra round of simplification, which can happen if postInlineUnconditionally uses a RHS that is no occurrence-analysed. This opportunity has been there for ages; I discovered it when looking at a compile-time perf regression that happened because the opportunity wasn't exploited.
* Print out module name in "bailing out" messageSimon Peyton Jones2021-07-281-2/+2
|
* Fix smallEnoughToInlineSimon Peyton Jones2021-07-281-2/+5
| | | | | I noticed that smallEnoughToInline said "no" to UnfWhen guidance, which seems quite wrong -- those functions are particularly small.
* PIC: test for cross-module referencesSylvain Henry2021-07-271-7/+4
|
* Don't abort on representation polymorphism checkKrzysztof Gogolewski2021-07-271-1/+1
| | | | | | | | | This is reverting a change introduced in linear types commit 40fa237e1da. Previously, we had to abort early, but thanks to later changes, this is no longer needed. There's no test, but the behavior should be better. The plan is to remove levity polymorphism checking in the desugarer anyway.
* Remove some unused namesKrzysztof Gogolewski2021-07-272-23/+8
| | | | The comment about 'parError' was obsolete.
* Simplify FFI codeKrzysztof Gogolewski2021-07-271-15/+7
| | | | Remains of the dotnet FFI, see a7d8f43718 and 1fede4bc95
* Parser: suggest TemplateHaskell on $$(...) (#20157)Krzysztof Gogolewski2021-07-271-0/+1
|
* Eliminate unnecessary unsafeEqualityProofSimon Peyton Jones2021-07-272-50/+102
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch addresses #20143, which wants to discard unused calls to unsafeEqualityProof. There are two parts: * In exprOkForSideEffects, we want to know that unsafeEqualityProof indeed terminates, without any exceptions etc * But we can only discard the case if we know that the coercion variable is not used, which means we have to gather accurate occurrence info for CoVars. Previously OccurAnal only did a half hearted job of doing so; this patch finishes the job. See Note [Gather occurrences of coercion variables] in OccurAnal. Because the occurrence analyser does more work, there is a small compile-time cost but it's pretty small. The compiler perf tests are usually 0.0% but occasionally up to 0.3% increase. I'm just going to accept this -- gathering accurate occurrence information really seems like the Right Thing to do. There is an increase in `compile_time/peak_megabytes_allocated`, for T11545, or around 14%; but I can't reproduce it on my machine (it's the same before and after), and the peak-usage stats are vulnerable to when exactly the GC takes place, so I'm just going to accept it. Metric Increase: T11545
* Eta expand through CallStacksSimon Peyton Jones2021-07-273-24/+55
| | | | | | | This patch fixes #20103, by treating HasCallStack constraints as cheap when eta-expanding. See Note [Eta expanding through CallStacks] in GHC.Core.Opt.Arity
* Make CallStacks work better with RebindableSyntaxSimon Peyton Jones2021-07-277-43/+111
| | | | | | | | | | | | | | | | | | | | As #19918 pointed out, the CallStack mechanism didn't work well with RebindableSyntax. This patch improves matters. See GHC.Tc.Types.Evidence Note [Overview of implicit CallStacks] * New predicate isPushCallStackOrigin distinguishes when a CallStack constraint should be solved "directly" or by pushing an item on the stack. * The constructor EvCsPushCall now has a FastString, which can describe not only a function call site, but also things like "the literal 42" or "an if-then-else expression". * I also fixed #20126 thus: exprCtOrigin (HsIf {}) = IfThenElseOrigin (Previously it was "can't happen".)
* rts: Introduce and use ExecPage abstractionBen Gamari2021-07-271-1/+1
| | | | | Here we introduce a very thin abstraction for allocating, filling, and freezing executable pages to replace allocateExec.
* rename: Avoid unnecessary map lookupBen Gamari2021-07-271-2/+2
| | | | | | | | Previously the -Wcompat-unqualified-imports warning would first check whether an import is of a covered module, incurring an map lookup, before checking the simple boolean predicate of whether it is qualified. This is more expensive than strictly necessary (although at the moment the warning is unused, so this will make little difference).
* Remove unused module GHC.Rename.DocFendor2021-07-271-23/+0
|
* Cmm.Opt: Fix type of shift amount in constant foldingBen Gamari2021-07-231-2/+2
| | | | | | | | Previously the `MO_S_Quot` constant folding rule would incorrectly pass the shift amount of the same width as the shifted value. However, the machop's type expects the shift amount to be a Word. Fixes #20142.
* Stop ug_boring_info retaining a chain of old CoreExprMatthew Pickering2021-07-231-8/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | It was noticed in #20134 that each simplifier iteration used an increasing amount of memory and that a certain portion of memory was not released until the simplfier had completely finished. I profiled the program using `-hi` profiling and observed that there was a thunk arising in the computation of `ug_boring_ok`. On each iteration `ug_boring_ok` would be updated, but not forced, which would leave a thunk in the shape of ug_boring_ok = inlineBoringOk expr0 || inlineBoringOk expr2 || inlineBoringOk expr3 || ... which would retain all previous `expr` until `ug_boring_ok` was forced or discarded. Forcing this accumulator eagerly results in a flat profile over multiple simplifier runs. This reduces the maximum residency when compiling the test in #20134 from 2GB to 1.3G. ------------------------- Metric Decrease: T11545 -------------------------
* Fix a few retainer leaks of TcGblEnvMatthew Pickering2021-07-233-4/+18
| | | | | | | | | | | | Methodology: Create a -hi profile and then search for TcGblEnv then use ghc-debug to work out why they are being retained and remove the reason. Retaining TcGblEnv is dangerous because it contains pointers to things such as a TypeEnv which is updated throughout compilation. I found two places which were retaining a TcGblEnv unecessarily. Also fix a few places where an OccName was retaining an Id.