summaryrefslogtreecommitdiff
path: root/compiler
Commit message (Collapse)AuthorAgeFilesLines
...
* Zonk the returned kind in tcFamTyPatsSimon Peyton Jones2021-01-301-0/+31
| | | | | | The motivation is given in Note [tcFamTyPats: zonking the result kind]. Fixes #19250 -- the fix is easy.
* Fix parsing of -fstg-lift-lams-non-recKrzysztof Gogolewski2021-01-291-2/+2
| | | | | | | | -fstg-lift-lams-rec-* and -fstg-lift-lams-non-rec-* were setting the same field. Fix manual: -fstg-lift-lams-non-rec-args is disabled by -fstg-lift-lams-non-rec-args-any, there's no -fno-stg-lift-*.
* Make PatSyn immutableSimon Peyton Jones2021-01-2928-204/+203
| | | | | | | | | | Provoked by #19074, this patch makes GHC.Core.PatSyn.PatSyn immutable, by recording only the *Name* of the matcher and builder rather than (as currently) the *Id*. See Note [Keep Ids out of PatSyn] in GHC.Core.PatSyn. Updates haddock submodule.
* Ppr: compute length of string literals at compile time (#19266)Sylvain Henry2021-01-291-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | SDoc string literals created for example with `text "xyz"` are converted into `PtrString` (`Addr#` + size in bytes) with a rewrite rule to avoid allocating a String. Before this patch, the size in bytes was still computed at runtime. For every literal, we obtained the following pseudo STG: x :: Addr# x = "xzy"# s :: PtrString s = \u [] case ffi:strlen [x realWorld#] of (# _, sz #) -> PtrString [x sz] But since GHC 9.0, we can use `cstringLength#` instead to get: x :: Addr# x = "xzy"# s :: PtrString s = PtrString! [x 3#] Literals become statically known constructor applications. Allocations seem to decrease a little in perf tests (between -0.1% and -0.7% on CI).
* Add missing .hi-boot dependencies with ghc -M (#14482)Sylvain Henry2021-01-292-1/+19
|
* Add explicit import lists to Data.List importsOleg Grenrus2021-01-2954-61/+62
| | | | | | | | | | | | | Related to a future change in Data.List, https://downloads.haskell.org/ghc/8.10.3/docs/html/users_guide/using-warnings.html?highlight=wcompat#ghc-flag--Wcompat-unqualified-imports Companion pull&merge requests: - https://github.com/judah/haskeline/pull/153 - https://github.com/haskell/containers/pull/762 - https://gitlab.haskell.org/ghc/packages/hpc/-/merge_requests/9 After these the actual change in Data.List should be easy to do.
* Remove StgLamLeif Metcalf2021-01-2911-67/+65
| | | | | | | | | | | | | | | | StgLam is used exclusively in the work of CoreToStg, but there's nothing in the type of StgExpr that indicates this, so we're forced throughout the Stg.* codebase to handle cases like: case expr of ... StgLam lam -> panic "Unexpected StgLam" ... This patch removes the StgLam constructor from the base StgExpr so these cases no longer need to be handled. Instead, we use a new intermediate type in CoreToStg, PreStgRhs, to represent the RHS expression of a binding.
* typecheck: Account for -XStrict in irrefutability checkBen Gamari2021-01-294-27/+71
| | | | | | | | | | | | | | | | | | | | | | When -XStrict is enabled the rules for irrefutability are slightly modified. Specifically, the pattern in a program like do ~(Just hi) <- expr cannot be considered irrefutable. The ~ here merely disables the bang that -XStrict would usually apply, rendering the program equivalent to the following without -XStrict do Just hi <- expr To achieve make this pattern irrefutable with -XStrict the user would rather need to write do ~(~(Just hi)) <- expr Failing to account for this resulted in #19027. To fix this isIrrefutableHsPat takes care to check for two the irrefutability of the inner pattern when it encounters a LazyPat and -XStrict is enabled.
* Fix strictness in TyCo.Tidy (#14738)Sylvain Henry2021-01-281-18/+38
| | | | | | | | | Metric Decrease: T12545 T14683 T16577 T5321Fun T5642
* SimplM: Create uniques via IO instead of threadingAndreas Klebinger2021-01-285-70/+147
|
* Remove some redundant validity checks.Richard Eisenberg2021-01-271-41/+10
| | | | | | | | | | | | This commit also consolidates documentation in the user manual around UndecidableSuperClasses, UndecidableInstances, and FlexibleContexts. Close #19186. Close #19187. Test case: typecheck/should_compile/T19186, typecheck/should_fail/T19187{,a}
* Remove -XMonadFailDesugaring referencesHécate2021-01-272-6/+3
|
* CoreToStg.Prep: Speculative evaluationSebastian Graf2021-01-231-7/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | From `Note [Speculative evaluation]`: Since call-by-value is much cheaper than call-by-need, we case-bind arguments that are either 1. Strictly evaluated anyway, according to the StrictSig of the callee, or 2. ok-for-spec, according to 'exprOkForSpeculation' While (1) is a no-brainer and always beneficial, (2) is a bit more subtle, as the careful haddock for 'exprOkForSpeculation' points out. Still, by case-binding the argument we don't need to allocate a thunk for it, whose closure must be retained as long as the callee might evaluate it. And if it is evaluated on most code paths anyway, we get to turn the unknown eval in the callee into a known call at the call site. NoFib Results: ``` -------------------------------------------------------------------------------- Program Allocs Instrs -------------------------------------------------------------------------------- ansi -9.4% -10.4% maillist -0.1% -0.1% paraffins -0.7% -0.5% scc -0.0% +0.1% treejoin -0.0% -0.1% -------------------------------------------------------------------------------- Min -9.4% -10.4% Max 0.0% +0.1% Geometric Mean -0.1% -0.1% ``` Fixes #19224.
* Track the dependencies of `GHC.Hs.Expr.Types`John Ericson2021-01-233-7/+11
| | | | | | Thery is still, in my view, far too numerous, but I believe this won't be too hard to improve upon. At the very lease, we can always add more extension points!
* Separate AST from GhcPass (#18936)John Ericson2021-01-2330-6195/+7272
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ---------------- What: There are two splits. The first spit is: - `Language.Haskell.Syntax.Extension` - `GHC.Hs.Extension` where the former now just contains helpers like `NoExtCon` and all the families, and the latter is everything having to do with `GhcPass`. The second split is: - `Language.Haskell.Syntax.<mod>` - `GHC.Hs.<mod>` Where the former contains all the data definitions, and the few helpers that don't use `GhcPass`, and the latter contains everything else. The second modules also reexport the former. ---------------- Why: See the issue for more details, but in short answer is we're trying to grasp at the modularity TTG is supposed to offer, after a long time of mainly just getting the safety benefits of more complete pattern matching on the AST. Now, we have an AST datatype which, without `GhcPass` is decently stripped of GHC-specific concerns. Whereas before, not was it GHC-specific, it was aware of all the GHC phases despite the parameterization, with the instances and parametric data structure side-by-side. For what it's worth there are also some smaller, imminent benefits: - The latter change also splits a strongly connected component in two, since none of the `Language.Haskell.Syntax.*` modules import the older ones. - A few TTG violations (Using GhcPass directly in the AST) in `Expr` are now more explicitly accounted for with new type families to provide the necessary indirection. ----------------- Future work: - I don't see why all the type families should live in `Language.Haskell.Syntax.Extension`. That seems anti-modular for little benefit. All the ones used just once can be moved next to the AST type they serve as an extension point for. - Decide what to do with the `Outputable` instances. Some of these are no orphans because they referred to `GhcPass`, and had to be moved. I think the types could be generalized so they don't refer to `GhcPass` and therefore can be moved back, but having gotten flak for increasing the size and complexity types when generalizing before, I did *not* want to do this. - We should triage the remaining contents of `GHC.Hs.<mod>`. The renaming helpers are somewhat odd for needing `GhcPass`. We might consider if they are a) in fact only needed by one phase b) can be generalized to be non-GhcPass-specific (e.g. take a callback rather than GADT-match with `IsPass`) and then they can live in `Language.Haskell.Syntax.<mod>`. For more details, see https://gitlab.haskell.org/ghc/ghc/-/wikis/implementing-trees-that-grow Bumps Haddock submodule
* Bignum: add Natural constant folding rules (#15821)Sylvain Henry2021-01-235-390/+610
| | | | | | | | | | | | | | | | | | | * Implement constant folding rules for Natural (similar to Integer ones) * Add mkCoreUbxSum helper in GHC.Core.Make * Remove naturalTo/FromInt We now only provide `naturalTo/FromWord` as the semantics is clear (truncate/zero-extend). For Int we have to deal with negative numbers (throw an exception? convert to Word beforehand?) so we leave the decision about what to do to the caller. Moreover, now that we have sized types (Int8#, Int16#, ..., Word8#, etc.) there is no reason to bless `Int#` more than `Int8#` or `Word8#` (for example). * Replaced a few `()` with `(# #)`
* Make matchableGivens more reliably correct.Richard Eisenberg2021-01-2314-177/+258
| | | | | | | | | | | | | | | | | | | | | | | This has two fixes: 1. Take TyVarTvs into account in matchableGivens. This fixes #19106. 2. Don't allow unifying alpha ~ Maybe alpha. This fixes #19107. This patch also removes a redundant Note and redirects references to a better replacement. Also some refactoring/improvements around the BindFun in the pure unifier, which now can take the RHS type into account. Close #19106. Close #19107. Test case: partial-sigs/should_compile/T19106, typecheck/should_compile/T19107
* Make DmdAnalOpts a newtypeAndreas Klebinger2021-01-222-3/+3
|
* Enhance nested TransCo pretty-printingSylvain Henry2021-01-221-2/+5
| | | | | | | | | | | | | | | | Nested TransCo were printed with a lot of indentation, e.g.: `cast` (Sub (Sym (Foo.D:R:Index[0] <Bool>_N <'[]>_N)) ; ((Index (Sym (SubDef (<1>_N, <1>_N))) <'[Bool]>_N)_R ; ... With this patch we print them as follows: `cast` (Sub (Sym (Foo.D:R:Index[0] <Bool>_N <'[]>_N)) ; (Index (Sym (SubDef (<1>_N, <1>_N))) <'[Bool]>_N)_R ; Sub (Sym (Foo.D:R:Index[1] <1>_N <Int>_N <'[Bool]>_N)) ; (Index (Sym (SubDef (<2>_N, <1>_N))) <'[Int, Bool]>_N)_R
* CmmToC: Fix translation of Cmm literals to word sized literalsStefan Schulze Frielinghaus2021-01-221-5/+7
| | | | | For big-endian machines remove the byte swap in the non-recursive call of goSubWord since the integer is already in proper format.
* LLVM: fix sized shift primops (#19215)Sylvain Henry2021-01-221-10/+20
| | | | | Ensure that shift amount parameter has the same type as the parameter to shift.
* Core: introduce Alt/AnnAlt/IfaceAlt datatypesSylvain Henry2021-01-2251-261/+276
| | | | | | Alt, AnnAlt and IfaceAlt were using triples. This patch makes them use dedicated types so that we can try to make some fields strict (for example) in the future.
* Enhance Data instance generationSylvain Henry2021-01-221-6/+6
| | | | | | | | | | | | | | | | Use `mkConstrTag` to explicitly pass the constructor tag instead of using `mkConstr` which queries the tag at runtime by querying the index of the constructor name (a string) in the list of constructor names. Perf improvement: T16577(normal) ghc/alloc 11325573876.0 9249786992.0 -18.3% GOOD Thanks to @sgraf812 for suggesting an additional list fusion fix during reviews. Metric Decrease: T16577
* Add missing fixed-sized primops and constant foldingJohn Ericson2021-01-224-38/+488
| | | | | | | | | | | | | | - `inversePrimOp` is renamed to `semiInversePrimOp` to indicate the given primop is only a right inverse, not left inverse (and contra-wise for the primop which we are giving rules for). This explains why are new usage is not incorrect. - The removed `subsumedByPrimOp` calls were actually dead as the match on ill-typed code. @hsyl20 pointed this out in https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4390#note_311912, Metric Decrease: T13701
* Cleanup primop constant folding rules in a few waysJohn Ericson2021-01-222-28/+29
| | | | | | | | - `leftZero`, `rightZero` and `zeroElem` could all be written using `isZeroLit` - "modulo 1" rules could be written with `nonOneLit 1 $> Lit zero<type>` All are due to @hsyl20; thanks!
* C-- shift amount is always native size, not shiftee sizeJohn Ericson2021-01-221-2/+2
| | | | | This isn't a bug yet, because we only shift native-sized types, but I hope to change that.
* Parameterise Messages over eAlfredo Di Napoli2021-01-2221-170/+272
| | | | | | | | | This commit paves the way to a richer and more structured representation of GHC error messages, as per GHC proposal #306. More specifically 'Messages' from 'GHC.Types.Error' now gains an extra type parameter, that we instantiate to 'ErrDoc' for now. Later, this will allow us to replace ErrDoc with something more structure (for example messages coming from the parser, the typechecker etc).
* Fix error recovery in solveEqualitiesSimon Peyton Jones2021-01-223-28/+83
| | | | | | | | | | | | | | | | | | | As #19142 showed, with -fdefer-type-errors we were allowing compilation to proceed despite a fatal kind error. This patch fixes it, as described in the new note in GHC.Tc.Solver, Note [Wrapping failing kind equalities] Also fixes #19158 Also when checking default( ty1, ty2, ... ) only consider a possible default (C ty2) if ty2 is kind-compatible with C. Previously we could form kind-incompatible constraints, with who knows what kind of chaos resulting. (Actually, no chaos results, but that's only by accident. It's plain wrong to form the constraint (Num Either) for example.) I just happened to notice this during fixing #19142.
* Factorize and document binder collect functionsSylvain Henry2021-01-2218-266/+284
| | | | | | | | | Parameterize collect*Binders functions with a flag indicating if evidence binders should be collected. The related note in GHC.Hs.Utils has been updated. Bump haddock submodule
* Arrows: collect evidence bindersSylvain Henry2021-01-221-3/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Evidence binders were not collected by GHC.HsToCore.Arrows.collectStmtBinders, hence bindings for dictionaries were not taken into account while computing local variables in statements. As a consequence we had a transformation similar to this: data Point a where Point :: RealFloat a => a -> Point a do p -< ... returnA -< ... (Point 0) ===> { Type-checking } do let $dRealFloat_xyz = GHC.Float.$fRealFloatFloat p -< ... returnA -< ... (Point $dRealFloat_xyz 0) ===> { Arrows HsToCore } first ... >>> arr (\(p, ()) -> case p of ... -> let $dRealFloat_xyz = GHC.Float.$fRealFloatFloat in case .. of () -> ()) >>> \((),()) -> ... (Point $dRealFloat_xyz 0) -- dictionary not in scope Now evidences are passed in the environment if necessary and we get: ===> { Arrows HsToCore } first ... >>> arr (\(p, ()) -> case p of ... -> let $dRealFloat_xyz = GHC.Float.$fRealFloatFloat in case .. of () -> $dRealFloat_xyz) >>> \(ds,()) -> let $dRealFloat_xyz = ds in ... (Point $dRealFloat_xyz 0) -- dictionary in scope Note that collectStmtBinders has been copy-pasted from GHC.Hs.Utils. This ought to be factorized but Note [Dictionary binders in ConPatOut] claims that: Do *not* gather (a) dictionary and (b) dictionary bindings as binders of a ConPatOut pattern. For most calls it doesn't matter, because it's pre-typechecker and there are no ConPatOuts. But it does matter more in the desugarer; for example, GHC.HsToCore.Utils.mkSelectorBinds uses collectPatBinders. In a lazy pattern, for example f ~(C x y) = ..., we want to generate bindings for x,y but not for dictionaries bound by C. (The type checker ensures they would not be used.) Desugaring of arrow case expressions needs these bindings (see GHC.HsToCore.Arrows and arrowcase1), but SPJ (Jan 2007) says it's safer for it to use its own pat-binder-collector: Accordingly to the last sentence, this patch doesn't make any attempt at factorizing both codes. Fix #18950
* dataToTag#: Avoid unnecessary entryBen Gamari2021-01-221-18/+21
| | | | When the pointer is already tagged we can avoid entering the closure.
* Use pointer tag in dataToTag#Ben Gamari2021-01-221-7/+35
| | | | | | | | | While looking at !2873 I noticed that dataToTag# previously didn't look at a pointer's tag to determine its constructor. To be fair, there is a bit of a trade-off here: using the pointer tag requires a bit more code and another branch. On the other hand, it allows us to eliminate looking at the info table in many cases (especially now since we tag large constructor families; see #14373).
* When deriving Eq always use tag based comparisons for nullary constructorsAndreas Klebinger2021-01-223-217/+173
| | | | | | | Instead of producing auxiliary con2tag bindings we now rely on dataToTag#, eliminating a fair bit of generated code. Co-Authored-By: Ben Gamari <ben@well-typed.com>
* Fix wrong comment about UnitStateSylvain Henry2021-01-221-5/+1
| | | | [CI skip]
* Use captureTopConstraints at top levelSimon Peyton Jones2021-01-171-4/+6
| | | | Missing this caused #19197. Easily fixed.
* Bignum: fix for Integer/Natural Ord instancesSylvain Henry2021-01-172-39/+56
| | | | | | | | | * allow `integerCompare` to inline into `integerLe#`, etc. * use `naturalSubThrow` to implement Natural's `(-)` * use `naturalNegate` to implement Natural's `negate` * implement and use `integerToNaturalThrow` to implement Natural's `fromInteger` Thanks to @christiaanb for reporting these
* Fix unsoundness for linear guards (#19120)Krzysztof Gogolewski2021-01-171-1/+2
|
* Revert "Remove SpecConstrAnnotation (#13681)" (#19168)Sylvain Henry2021-01-172-27/+80
| | | | | | This reverts commit 7bc3a65b467c4286377b9bded277d5a2f69160b3. NoSpecConstr is used in the wild (see #19168)
* Remove unused extension pragmas from the compiler code baseHécate2021-01-1718-26/+17
|
* CmmToLlvm: Sign/Zero extend parameters for foreign callsStefan Schulze Frielinghaus2021-01-173-24/+47
| | | | | | | | For some architectures the C calling convention is that any integer shorter than 64 bits is replaced by its 64 bits representation using sign or zero extension. Fixes #19023.
* PmCheck: Positive info doesn't imply there is an inhabitant (#18960)Sebastian Graf2021-01-171-28/+152
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Consider `T18960`: ```hs pattern P :: a -> a pattern P x = x {-# COMPLETE P :: () #-} foo :: () foo = case () of P _ -> () ``` We know about the match variable of the case match that it is equal to `()`. After the match on `P`, we still know it's equal to `()` (positive info), but also that it can't be `P` (negative info). By the `COMPLETE` pragma, we know that implies that the refinement type of the match variable is empty after the `P` case. But in the PmCheck solver, we assumed that "has positive info" means "is not empty", thus assuming we could omit a costly inhabitation test. Which is wrong, as we saw above. A bit of a complication arises because the "has positive info" spared us from doing a lot of inhabitation tests in `T17836b`. So we keep that check, but give it a lower priority than the check for dirty variables that requires us doing an inhabitation test. Needless to say: This doesn't impact soundness of the checker at all, it just implements a better trade-off between efficiency and precision. Fixes #18960. Metric Decrease: T17836
* Missing fields: enhance error messages (#18869)Sylvain Henry2021-01-172-21/+41
| | | | | | This patch delays the detection of missing fields in record creation after type-checking. This gives us better error messages (see updated test outputs).
* Show missing field types (#18869)Sylvain Henry2021-01-171-6/+10
|
* WorkWrap: Use SysLocal Name for Thunk Splitting (#19180)Sebastian Graf2021-01-101-13/+45
| | | | | | | | | | | | | | | | | | Since !4493 we annotate top-level bindings with demands, which leads to novel opportunities for thunk splitting absent top-level thunks. It turns out that thunk splitting wasn't quite equipped for that, because it re-used top-level, `External` Names for local helper Ids. That triggered a CoreLint error (#19180), reproducible with `T19180`. Fixed by adjusting the thunk splitting code to produce `SysLocal` names for the local bindings. Fixes #19180. Metric Decrease: T12227 T18282
* Fix `not32Word#` -> `notWord32#`John Ericson2021-01-101-1/+1
| | | | | | This is is correcting a mistake I unfortunately missed in !4698. But that is a recent PR so this fix is not a compatibility hazard with released versions of GHC.
* Never Anyify during kind inferenceRichard Eisenberg2021-01-099-84/+296
| | | | | | | | | See Note [Error on unconstrained meta-variables] in TcMType. Close #17301 Close #17567 Close #17562 Close #15474
* Remove errShortString, cleanup error-related functionsAlfredo Di Napoli2021-01-0918-210/+231
| | | | | | | | | | | This commit removes the errShortString field from the ErrMsg type, allowing us to cleanup a lot of dynflag-dependent error functions, and move them in a more specialised 'GHC.Driver.Errors' closer to the driver, where they are actually used. Metric Increase: T4801 T9961
* compiler: Initialize ForeignExportsList.n_entriesBen Gamari2021-01-071-1/+4
| | | | | | | | | | The refactoring in ed57c3a9eb9286faa222f98e484a9ef3432b2025 failed to initialize this field, resulting in no exports being registered. A very silly bug and yet somehow none of our tests caught it. See #18548. Fixes #19149.
* GHCi: Fill field `DynFlags.dumpPrefix`. (Fixes #17500)Roland Senn2021-01-072-4/+5
| | | | | | | | | | | For interactive evaluations set the field `DynFlags.dumpPrefix` to the GHCi internal module name. The GHCi module name for an interactive evaluation is something like `Ghci9`. To avoid user confusion, don't dump any data for GHCi internal evaluations. Extend the comment for `DynFlags.dumpPrefix` and fix a little typo in a comment about the GHCi internal module names.
* Make primops for `{Int,Word}32#`John Ericson2021-01-075-18/+180
| | | | | | | | | | | | | Progress towards #19026. The type was added before, but not its primops. We follow the conventions in 36fcf9edee31513db2ddbf716ee0aa79766cbe69 and 2c959a1894311e59cd2fd469c1967491c1e488f3 for names and testing. Along with the previous 8- and 16-bit primops, this will allow us to avoid many conversions for 8-, 16-, and 32-bit sized numeric types. Co-authored-by: Sylvain Henry <hsyl20@gmail.com>