Skip to content
Snippets Groups Projects
  1. Oct 06, 2021
    • David Feuer's avatar
      Add utilities to use unsafe equality proofs · 2a0c18b5
      David Feuer authored
      It's generally best practice to limit unsafe equalities as much as
      possible, to avoid mistakes. A good way to do that is to use
      `unsafeEqualityProof` to produce fake evidence of the smallest equality
      needed. For example, if you know that `A` and `P` are sufficiently
      similar and you need to coerce `[A] -> B -> C` to `[P] -> B -> C`, it's
      much nicer to explicitly introduce fake evidence that `A ~ P` than to
      use `unsafeCoerce` and hope you aren't accidentally coercing some
      unrelated things elsewhere in the type.
      
      Unfortunately, actually using the limited fake evidence can be tricky.
      You might think you could write something like
      
      ```haskell
      cabc :: ([A] -> B -> C) -> [P] -> B -> C
      cabc f = case unsafeEqualityProof @A @P of
        UnsafeRefl -> f
      ```
      
      But this won't work! When type checking the case branch, GHC rejects
      `A ~ P` without even noticing that there's evidence for it available. This
      means that more explicit utilities are needed to manipulate unsafe
      equalities. One simple option would be to offer just a single function
      
      ```haskell
      unsafeEqualityProofToEquality :: UnsafeEquality a b -> a :~: b
      unsafeEqualityProofToEquality UnsafeRefl = Refl
      ```
      
      Then people could use the utilities in `Data.Type.Equality` to manipulate
      the resulting equality. But it seems to me that it's much nicer to
      help users keep equality proofs *obviously* unsafe right up to the
      point of use, to avoid a sort of "equality blindness". This commit
      adds versions of the various equality proof functions in
      `Data.Type.Equality` for `UnsafeEquality`, along with a few more
      for convenience inspired by the Agda standard library.
      2a0c18b5
  2. Oct 05, 2021
    • Zubin's avatar
      docs: Clarify documentation of `getFileSystemEncoding` (#20344) · 29ee04f3
      Zubin authored and Marge Bot's avatar Marge Bot committed
      It may not always be a Unicode encoding
      29ee04f3
    • Sylvain Henry's avatar
      Constant folding for (.&.) maxBound (#20448) · 11240b74
      Sylvain Henry authored and Marge Bot's avatar Marge Bot committed
      11240b74
    • Simon Peyton Jones's avatar
      Ensure top-level binders in scope in SetLevels · 52400ebb
      Simon Peyton Jones authored and Marge Bot's avatar Marge Bot committed
      Ticket #20200 (the Agda failure) showed another case in which
      lookupIdSubst would fail to find a local Id in the InScopeSet.
      This time it was because SetLevels was given a program in which
      the top-level bindings were not in dependency order.
      
      The Simplifier (see Note [Glomming] in GHC.Core.Opt.Occuranal) and
      the specialiser (see Note [Top level scope] in GHC.Core.Opt.Specialise)
      may both produce top-level bindings where an early binding refers
      to a later one.
      
      One solution would be to run the occurrence analyser again to
      put them all in the right order. But a simpler one is to make
      SetLevels OK with this input by bringing all top-level binders into
      scope at the start. That's what this patch does.
      52400ebb
    • Alfredo Di Napoli's avatar
      Eradicate TcRnUnknownMessage from GHC.Tc.Deriv · ac275f42
      Alfredo Di Napoli authored and Marge Bot's avatar Marge Bot committed
      This (big) commit finishes porting the GHC.Tc.Deriv module to support
      the new diagnostic infrastructure (#18516) by getting rid of the legacy
      calls to `TcRnUnknownMessage`. This work ended up being quite pervasive
      and touched not only the Tc.Deriv module but also the Tc.Deriv.Utils and
      Tc.Deriv.Generics module, which needed to be adapted to use the new
      infrastructure. This also required generalising `Validity`.
      
      More specifically, this is a breakdown of the work done:
      
      * Add and use the TcRnUselessTypeable data constructor
      * Add and use TcRnDerivingDefaults data constructor
      * Add and use the TcRnNonUnaryTypeclassConstraint data constructor
      * Add and use TcRnPartialTypeSignatures
      * Add T13324_compile2 test to test another part of the
        TcRnPartialTypeSignatures diagnostic
      * Add and use TcRnCannotDeriveInstance data constructor, which introduces a
        new data constructor to TcRnMessage called TcRnCannotDeriveInstance, which
        is further sub-divided to carry a `DeriveInstanceErrReason` which explains
        the reason why we couldn't derive a typeclass instance.
      * Add DerivErrSafeHaskellGenericInst data constructor to DeriveInstanceErrReason
      * Add DerivErrDerivingViaWrongKind and DerivErrNoEtaReduce
      * Introduce the SuggestExtensionInOrderTo Hint, which adds (and use) a new
        constructor to the hint type `LanguageExtensionHint` called `SuggestExtensionInOrderTo`,
        which can be used to give a bit more "firm" recommendations when it's
        obvious what the required extension is, like in the case for the
        `DerivingStrategies`, which automatically follows from having enabled
        both `DeriveAnyClass` and `GeneralizedNewtypeDeriving`.
      * Wildcard-free pattern matching in mk_eqn_stock, which removes `_` in
        favour of pattern matching explicitly on `CanDeriveAnyClass` and
        `NonDerivableClass`, because that determine whether or not we can
        suggest to the user `DeriveAnyClass` or not.
      ac275f42
    • Alfredo Di Napoli's avatar
      Make GHC.Utils.Error.Validity type polymorphic · f52df067
      Alfredo Di Napoli authored and Marge Bot's avatar Marge Bot committed
      This commit makes the `Validity` type polymorphic:
      
      ```
      data Validity' a
        = IsValid      -- ^ Everything is fine
        | NotValid a   -- ^ A problem, and some indication of why
      
      -- | Monomorphic version of @Validity'@ specialised for 'SDoc's.
      type Validity = Validity' SDoc
      ```
      
      The type has been (provisionally) renamed to Validity' to not break
      existing code, as the monomorphic `Validity` type is quite pervasive
      in a lot of signatures in GHC.
      
      Why having a polymorphic Validity? Because it carries the evidence of
      "what went wrong", but the old type carried an `SDoc`, which clashed
      with the new GHC diagnostic infrastructure (#18516). Having it
      polymorphic it means we can carry an arbitrary, richer diagnostic type,
      and this is very important for things like the
      `checkOriginativeSideConditions` function, which needs to report the
      actual diagnostic error back to `GHC.Tc.Deriv`.
      
      It also generalises Validity-related functions to be polymorphic in @a@.
      f52df067
    • vdukhovni's avatar
      Explain Endo, Dual, ... in laws · 5282eaa1
      vdukhovni authored and Marge Bot's avatar Marge Bot committed
      5282eaa1
    • vdukhovni's avatar
      Adopt David Feuer's explantion of foldl' via foldr · f49c7012
      vdukhovni authored and Marge Bot's avatar Marge Bot committed
      f49c7012
    • vdukhovni's avatar
      Minor wording tweaks/fixes · fb6b772f
      vdukhovni authored and Marge Bot's avatar Marge Bot committed
      fb6b772f
    • vdukhovni's avatar
      Note elem ticket 20421 · 56899c8d
      vdukhovni authored and Marge Bot's avatar Marge Bot committed
      56899c8d
    • vdukhovni's avatar
      Note linear `elem` cost · 43358ab9
      vdukhovni authored and Marge Bot's avatar Marge Bot committed
      This is a writeup of the state of play for better than linear `elem` via
      a helper type class.
      43358ab9
    • vdukhovni's avatar
      Add laws link and tweak Traversable class text · 7059a729
      vdukhovni authored and Marge Bot's avatar Marge Bot committed
      7059a729
    • vdukhovni's avatar
      Address some Foldable documentation nits · 000f2a30
      vdukhovni authored and Marge Bot's avatar Marge Bot committed
      - Add link to laws from the class head
      - Simplify wording of left/right associativity intro paragraph
      - Avoid needless mention of "endomorphisms"
      000f2a30
    • Sebastian Graf's avatar
      CprAnal: Activate Sum CPR for local bindings · cd1b016f
      Sebastian Graf authored and Marge Bot's avatar Marge Bot committed
      We've had Sum CPR (#5075) for top-level bindings for a couple of years now.
      That begs the question why we didn't also activate it for local bindings, and
      the reasons for that are described in `Note [CPR for sum types]`. Only that it
      didn't make sense! The Note said that Sum CPR would destroy let-no-escapes, but
      that should be a non-issue since we have syntactic join points in Core now and
      we don't WW for them (`Note [Don't w/w join points for CPR]`).
      
      So I simply activated CPR for all bindings of sum type, thus fixing #5075 and
      \#16570. NoFib approves:
      
      ```
      --------------------------------------------------------------------------------
              Program         Allocs    Instrs
      --------------------------------------------------------------------------------
        comp_lab_zift          -0.0%     +0.7%
                fluid          +1.7%     +0.7%
              reptile          +0.1%     +0.1%
      --------------------------------------------------------------------------------
                  Min          -0.0%     -0.2%
                  Max          +1.7%     +0.7%
       Geometric Mean          +0.0%     +0.0%
      ```
      
      There were quite a few metric decreases on the order of 1-4%, but T6048 seems to
      regress significantly, by 26.1%. WW'ing for a `Just` constructor and the nested
      data type meant additional Simplifier iterations and a 30% increase in term
      sizes as well as a 200-300% in type sizes due to unboxed 9-tuples. There's not
      much we can do about it, I'm afraid: We're just doing much more work there.
      
      Metric Decrease:
          T12425
          T18698a
          T18698b
          T20049
          T9020
          WWRec
      Metric Increase:
          T6048
      cd1b016f
    • Sebastian Graf's avatar
      Simplifier: Get rid of demand zapping based on Note [Arity decrease] · b4c0cc36
      Sebastian Graf authored and Marge Bot's avatar Marge Bot committed
      The examples in the Note were inaccurate (`$s$dm` has arity 1 and that seems OK)
      and the code didn't actually nuke the demand *signature* anyway. Specialise has
      to nuke it, but it starts from a clean IdInfo anyway (in `newSpecIdM`).
      
      So I just deleted the code. Fixes #20450.
      b4c0cc36
    • Sebastian Graf's avatar
      WorkWrap: Nuke CPR signatures of join points (#18824) · 643b6f01
      Sebastian Graf authored and Marge Bot's avatar Marge Bot committed
      In #18824 we saw that the Simplifier didn't nuke a CPR signature of a join point
      when it pushed a continuation into it when it better should have.
      
      But join points are local, mostly non-exported bindings. We don't use their
      CPR signature anyway and would discard it at the end of the Core pipeline.
      Their main purpose is to propagate CPR info during CPR analysis and by the time
      worker/wrapper runs the signature will have served its purpose. So we zap it!
      
      Fixes #18824.
      643b6f01
    • Krzysztof Gogolewski's avatar
      Reject type family equation with wrong name (#20260) · 298df16d
      Krzysztof Gogolewski authored and Marge Bot's avatar Marge Bot committed
      We should reject "type family Foo where Bar = ()".
      This check was done in kcTyFamInstEqn but not in tcTyFamInstEqn.
      I factored out arity checking, which was duplicated.
      298df16d
    • Matthías Páll Gissurarson's avatar
      Speed up valid hole-fits by adding early abort and checks. · 5601b9e2
      Matthías Páll Gissurarson authored and Marge Bot's avatar Marge Bot committed
      By adding an early abort flag in `TcSEnv`, we can fail fast in the presence of
      insoluble constraints. This helps us avoid a lot of work in valid hole-fits, and
      we geta massive speed-up by avoiding a lot of useless work solving constraints that
      never come into play.
      
      Additionally, we add a simple check for degenerate hole types, such as
      when the type of the hole is an immutable type variable (as is the case
      when the hole is completely unconstrained). Then the only valid fits are
      the locals, so we can ignore the global candidates.
      
      This fixes #16875
      5601b9e2
    • sheaf's avatar
      Add a regression test for #17723 · 48b0f17a
      sheaf authored and Marge Bot's avatar Marge Bot committed
        The underlying bug was fixed by b8d98827, see MR !2477
      48b0f17a
    • sheaf's avatar
      Bump TcLevel of failing kind equality implication · a14d0e63
      sheaf authored and Marge Bot's avatar Marge Bot committed
        Not bumping the TcLevel meant that we could end up
        trying to add evidence terms for the implication constraint
        created to wrap failing kind equalities (to avoid their deferral).
      
      fixes #20043
      a14d0e63
    • Vladislav Zavialov's avatar
      Bespoke TokenLocation data type · a7629334
      Vladislav Zavialov authored and Marge Bot's avatar Marge Bot committed
      The EpaAnnCO we were using contained an Anchor instead of EpaLocation,
      making it harder to work with.
      
      At the same time, using EpaLocation by itself isn't possible either,
      as we may have tokens without location information.
      
      Hence the new data type:
      	data TokenLocation = NoTokenLoc
      	                   | TokenLoc !EpaLocation
      a7629334
    • Ben Gamari's avatar
      compiler: Fix racy ticker counter registration · a0f44ceb
      Ben Gamari authored and Marge Bot's avatar Marge Bot committed
      Previously registration of ticky entry counters was racy, performing a
      read-modify-write to add the new counter to the ticky_entry_ctrs list.
      This could result in the list becoming cyclic if multiple threads
      entered the same closure simultaneously.
      
      Fixes #20451.
      a0f44ceb
    • Ben Gamari's avatar
      compiler: Improve Haddocks of atomic MachOps · 347537a5
      Ben Gamari authored and Marge Bot's avatar Marge Bot committed
      347537a5
    • Matthew Pickering's avatar
      ci: Run hadrian builds verbosely, but not tests · 40c81dd2
      Matthew Pickering authored and Marge Bot's avatar Marge Bot committed
      This reduces the output from the testsuite to a more manageable level.
      
      Fixes #20432
      40c81dd2
  3. Oct 04, 2021
  4. Oct 03, 2021
  5. Oct 02, 2021
  6. Oct 01, 2021
    • Matthew Pickering's avatar
      ci: Unset CI_* variables before run_hadrian and test_make · e3701815
      Matthew Pickering authored and Marge Bot's avatar Marge Bot committed
      The goal here is to somewhat sanitize the environment so that
      performance tests don't fluctuate as much as they have been doing. In
      particular the length of the commit message was causing benchmarks to
      increase because gitlab stored the whole commit message twice in
      environment variables. Therefore when we used `getEnvironment` it would
      cause more allocation because more string would be created.
      
      See #20431
      
      -------------------------
      Metric Decrease:
          T10421
          T13035
          T18140
          T18923
          T9198
          T12234
          T12425
      -------------------------
      e3701815
    • Matthew Pickering's avatar
      code gen: Improve efficiency of findPrefRealReg · 9600a5fb
      Matthew Pickering authored and Marge Bot's avatar Marge Bot committed
      Old strategy: For each variable linearly scan through all the blocks and
      check to see if the variable is any of the block register mappings. This
      is very slow when you have a lot of blocks.
      
      New strategy: Maintain a map from virtual registers to the first real
      register the virtual register was assigned to. Consult this map in
      findPrefRealReg.
      
      The map is updated when the register mapping is updated and is hidden
      behind the BlockAssigment abstraction.
      
      On the mmark package this reduces compilation time from about 44s to
      32s.
      
      Ticket: #19471
      9600a5fb
Loading