1. 27 Jan, 2020 2 commits
    • Matthew Pickering's avatar
      97d0b0a3
    • Ryan Scott's avatar
      Use splitLHs{ForAll,Sigma}TyInvis throughout the codebase · 1132602f
      Ryan Scott authored
      Richard points out in #17688 that we use `splitLHsForAllTy` and
      `splitLHsSigmaTy` in places that we ought to be using the
      corresponding `-Invis` variants instead, identifying two bugs
      that are caused by this oversight:
      
      * Certain TH-quoted type signatures, such as those that appear in
        quoted `SPECIALISE` pragmas, silently turn visible `forall`s into
        invisible `forall`s.
      * When quoted, the type `forall a -> (a ~ a) => a` will turn into
        `forall a -> a` due to a bug in `DsMeta.repForall` that drops
        contexts that follow visible `forall`s.
      
      These are both ultimately caused by the fact that `splitLHsForAllTy`
      and `splitLHsSigmaTy` split apart visible `forall`s in addition to
      invisible ones. This patch cleans things up:
      
      * We now use `splitLHsForAllTyInvis` and `splitLHsSigmaTyInvis`
        throughout the codebase. Relatedly, the `splitLHsForAllTy` and
        `splitLHsSigmaTy` have been removed, as they are easy to misuse.
      * `DsMeta.repForall` now only handles invisible `forall`s to reduce
        the chance for confusion with visible `forall`s, which need to be
        handled differently. I also renamed it from `repForall` to
        `repForallT` to emphasize that its distinguishing characteristic
        is the fact that it desugars down to `L.H.TH.Syntax.ForallT`.
      
      Fixes #17688.
      1132602f
  2. 25 Jan, 2020 13 commits
    • Ryan Scott's avatar
      Do not bring visible foralls into scope in hsScopedTvs · 0940b59a
      Ryan Scott authored
      Previously, `hsScopedTvs` (and its cousin `hsWcScopedTvs`) pretended
      that visible dependent quantification could not possibly happen at
      the term level, and cemented that assumption with an `ASSERT`:
      
      ```hs
          hsScopedTvs (HsForAllTy { hst_fvf = vis_flag, ... }) =
            ASSERT( vis_flag == ForallInvis )
            ...
      ```
      
      It turns out that this assumption is wrong. You can end up tripping
      this `ASSERT` if you stick it to the man and write a type for a term
      that uses visible dependent quantification anyway, like in this
      example:
      
      ```hs
      {-# LANGUAGE ScopedTypeVariables #-}
      
      x :: forall a -> a -> a
      x = x
      ```
      
      That won't typecheck, but that's not the point. Before the
      typechecker has a chance to reject this, the renamer will try
      to use `hsScopedTvs` to bring `a` into scope over the body of `x`,
      since `a` is quantified by a `forall`. This, in turn, causes the
      `ASSERT` to fail. Bummer.
      
      Instead of walking on this dangerous ground, this patch makes GHC
      adopt a more hardline stance by pattern-matching directly on
      `ForallInvis` in `hsScopedTvs`:
      
      ```hs
          hsScopedTvs (HsForAllTy { hst_fvf = ForallInvis, ... }) = ...
      ```
      
      Now `a` will not be brought over the body of `x` at all (which is how
      it should be), there's no chance of the `ASSERT` failing anymore (as
      it's gone), and best of all, the behavior of `hsScopedTvs` does not
      change. Everyone wins!
      
      Fixes #17687.
      0940b59a
    • Ben Gamari's avatar
      hadrian: Throw error on duplicate-named flavours · b3e5c678
      Ben Gamari authored
      Throw an error if the user requests a flavour for which there is more
      than one match.
      
      Fixes #17156.
      b3e5c678
    • Sylvain Henry's avatar
      0a5e4f5f
    • xldenis's avatar
      Create ghci.cabal.sh · b1a32170
      xldenis authored
      b1a32170
    • xldenis's avatar
      Add ghc-in-ghci for stack based builds · 6eb566a0
      xldenis authored
      6eb566a0
    • PHO's avatar
      Fix rts allocateExec() on NetBSD · 8b726534
      PHO authored
      Similar to SELinux, NetBSD "PaX mprotect" prohibits marking a page
      mapping both writable and executable at the same time. Use libffi
      which knows how to work around it.
      8b726534
    • Sylvain Henry's avatar
      Module hierarchy: Cmm (cf #13009) · 6e2d9ee2
      Sylvain Henry authored
      6e2d9ee2
    • Ryan Scott's avatar
      Handle local fixity declarations in DsMeta properly · c3fde723
      Ryan Scott authored
      `DsMeta.rep_sig` used to skip over `FixSig` entirely, which had the
      effect of causing local fixity declarations to be dropped when quoted
      in Template Haskell. But there is no good reason for this state of
      affairs, as the code in `DsMeta.repFixD` (which handles top-level
      fixity declarations) handles local fixity declarations just fine.
      This patch factors out the necessary parts of `repFixD` so that they
      can be used in `rep_sig` as well.
      
      There was one minor complication: the fixity signatures for class
      methods in each `HsGroup` were stored both in `FixSig`s _and_ the
      list of `LFixitySig`s for top-level fixity signatures, so I needed
      to take action to prevent fixity signatures for class methods being
      converted to `Dec`s twice. I tweaked `RnSource.add` to avoid putting
      these fixity signatures in two places and added
      `Note [Top-level fixity signatures in an HsGroup]` in `GHC.Hs.Decls`
      to explain the new design.
      
      Fixes #17608. Bumps the Haddock submodule.
      c3fde723
    • Sebastian Graf's avatar
      PmCheck: Properly handle constructor-bound type variables · 86966d48
      Sebastian Graf authored
      In ghc/ghc!2192 (comment 246551)
      Simon convinced me that ignoring type variables existentially bound by
      data constructors have to be the same way as value binders.
      
      Sadly I couldn't think of a regression test, but I'm confident that this
      change strictly improves on the status quo.
      86966d48
    • Sebastian Graf's avatar
      PmCheck: Formulate as translation between Clause Trees · 8038cbd9
      Sebastian Graf authored
      We used to check `GrdVec`s arising from multiple clauses and guards in
      isolation. That resulted in a split between `pmCheck` and
      `pmCheckGuards`, the implementations of which were similar, but subtly
      different in detail. Also the throttling mechanism described in
      `Note [Countering exponential blowup]` ultimately got quite complicated
      because it had to cater for both checking functions.
      
      This patch realises that pattern match checking doesn't just consider
      single guarded RHSs, but that it's always a whole set of clauses, each
      of which can have multiple guarded RHSs in turn. We do so by
      translating a list of `Match`es to a `GrdTree`:
      
      ```haskell
      data GrdTree
        = Rhs !RhsInfo
        | Guard !PmGrd !GrdTree      -- captures lef-to-right  match semantics
        | Sequence !GrdTree !GrdTree -- captures top-to-bottom match semantics
        | Empty                      -- For -XEmptyCase, neutral element of Sequence
      ```
      
      Then we have a function `checkGrdTree` that matches a given `GrdTree`
      against an incoming set of values, represented by `Deltas`:
      
      ```haskell
      checkGrdTree :: GrdTree -> Deltas -> CheckResult
      ...
      ```
      
      Throttling is isolated to the `Sequence` case and becomes as easy as one
      would expect: When the union of uncovered values becomes too big, just
      return the original incoming `Deltas` instead (which is always a
      superset of the union, thus a sound approximation).
      
      The returned `CheckResult` contains two things:
      
      1. The set of values that were not covered by any of the clauses, for
         exhaustivity warnings.
      2. The `AnnotatedTree` that enriches the syntactic structure of the
         input program with divergence and inaccessibility information.
      
      This is `AnnotatedTree`:
      
      ```haskell
      data AnnotatedTree
        = AccessibleRhs !RhsInfo
        | InaccessibleRhs !RhsInfo
        | MayDiverge !AnnotatedTree
        | SequenceAnn !AnnotatedTree !AnnotatedTree
        | EmptyAnn
      ```
      
      Crucially, `MayDiverge` asserts that the tree may force diverging
      values, so not all of its wrapped clauses can be redundant.
      
      While the set of uncovered values can be used to generate the missing
      equations for warning messages, redundant and proper inaccessible
      equations can be extracted from `AnnotatedTree` by
      `redundantAndInaccessibleRhss`.
      
      For this to work properly, the interface to the Oracle had to change.
      There's only `addPmCts` now, which takes a bag of `PmCt`s. There's a
      whole bunch of `PmCt` variants to replace the different oracle functions
      from before.
      
      The new `AnnotatedTree` structure allows for more accurate warning
      reporting (as evidenced by a number of changes spread throughout GHC's
      code base), thus we fix #17465.
      
      Fixes #17646 on the go.
      
      Metric Decrease:
          T11822
          T9233
          PmSeriesS
          haddock.compiler
      8038cbd9
    • Ömer Sinan Ağacan's avatar
      Fix chaining tagged and untagged ptrs in compacting GC · 0e57d8a1
      Ömer Sinan Ağacan authored
      Currently compacting GC has the invariant that in a chain all fields are tagged
      the same. However this does not really hold: root pointers are not tagged, so
      when we thread a root we initialize a chain without a tag. When the pointed
      objects is evaluated and we have more pointers to it from the heap, we then add
      *tagged* fields to the chain (because pointers to it from the heap are tagged),
      ending up chaining fields with different tags (pointers from roots are NOT
      tagged, pointers from heap are). This breaks the invariant and as a result
      compacting GC turns tagged pointers into non-tagged.
      
      This later causes problem in the generated code where we do reads assuming that
      the pointer is aligned, e.g.
      
          0x7(%rax) -- assumes that pointer is tagged 1
      
      which causes misaligned reads. This caused #17088.
      
      We fix this using the "pointer tagging for large families" patch (#14373,
      !1742):
      
      - With the pointer tagging patch the GC can know what the tagged pointer to a
        CONSTR should be (previously we'd need to know the family size -- large
        families are always tagged 1, small families are tagged depending on the
        constructor).
      
      - Since we now know what the tags should be we no longer need to store the
        pointer tag in the info table pointers when forming chains in the compacting
        GC.
      
      As a result we no longer need to tag pointers in chains with 1/2 depending on
      whether the field points to an info table pointer, or to another field: an info
      table pointer is always tagged 0, everything else in the chain is tagged 1. The
      lost tags in pointers can be retrieved by looking at the info table.
      
      Finally, instead of using tag 1 for fields and tag 0 for info table pointers, we
      use two different tags for fields:
      
      - 1 for fields that have untagged pointers
      - 2 for fields that have tagged pointers
      
      When unchaining we then look at the pointer to a field, and depending on its tag
      we either leave a tagged pointer or an untagged pointer in the field.
      
      This allows chaining untagged and tagged fields together in compacting GC.
      
      Fixes #17088
      
      Nofib results
      -------------
      
      Binaries are smaller because of smaller `Compact.c` code.
      
      make mode=fast EXTRA_RUNTEST_OPTS="-cachegrind" EXTRA_HC_OPTS="-with-rtsopts=-c" NoFibRuns=1
      
          --------------------------------------------------------------------------------
                  Program           Size    Allocs    Instrs     Reads    Writes
          --------------------------------------------------------------------------------
                       CS          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                      CSD          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                       FS          -0.3%      0.0%     +0.0%     -0.0%     -0.0%
                        S          -0.3%      0.0%     +5.4%     +0.8%     +3.9%
                       VS          -0.3%      0.0%     +0.0%     -0.0%     -0.0%
                      VSD          -0.3%      0.0%     -0.0%     -0.0%     -0.2%
                      VSM          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                     anna          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
                     ansi          -0.3%      0.0%     +0.1%     +0.0%     +0.0%
                     atom          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
                   awards          -0.2%      0.0%     +0.0%      0.0%     -0.0%
                   banner          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
               bernouilli          -0.3%      0.0%     +0.1%     +0.0%     +0.0%
             binary-trees          -0.2%      0.0%     +0.0%      0.0%     +0.0%
                    boyer          -0.3%      0.0%     +0.2%     +0.0%     +0.0%
                   boyer2          -0.2%      0.0%     +0.2%     +0.1%     +0.0%
                     bspt          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
                cacheprof          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
                 calendar          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                 cichelli          -0.3%      0.0%     +1.1%     +0.2%     +0.5%
                  circsim          -0.2%      0.0%     +0.0%     -0.0%     -0.0%
                 clausify          -0.3%      0.0%     +0.0%     -0.0%     -0.0%
            comp_lab_zift          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
                 compress          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                compress2          -0.3%      0.0%     +0.0%     -0.0%     -0.0%
              constraints          -0.3%      0.0%     +0.2%     +0.1%     +0.1%
             cryptarithm1          -0.3%      0.0%     +0.0%     -0.0%      0.0%
             cryptarithm2          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                      cse          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
             digits-of-e1          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
             digits-of-e2          -0.3%      0.0%     +0.0%     +0.0%     -0.0%
                   dom-lt          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
                    eliza          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
                    event          -0.3%      0.0%     +0.1%     +0.0%     -0.0%
              exact-reals          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
                   exp3_8          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                   expert          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
           fannkuch-redux          -0.3%      0.0%     -0.0%     -0.0%     -0.0%
                    fasta          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                      fem          -0.2%      0.0%     +0.1%     +0.0%     +0.0%
                      fft          -0.2%      0.0%     +0.0%     -0.0%     -0.0%
                     fft2          -0.2%      0.0%     +0.0%     -0.0%     +0.0%
                 fibheaps          -0.3%      0.0%     +0.0%     -0.0%     -0.0%
                     fish          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                    fluid          -0.2%      0.0%     +0.4%     +0.1%     +0.1%
                   fulsom          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
                   gamteb          -0.2%      0.0%     +0.1%     +0.0%     +0.0%
                      gcd          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
              gen_regexps          -0.3%      0.0%     +0.0%     -0.0%     -0.0%
                   genfft          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                       gg          -0.2%      0.0%     +0.7%     +0.3%     +0.2%
                     grep          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
                   hidden          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
                      hpg          -0.2%      0.0%     +0.1%     +0.0%     +0.0%
                      ida          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                    infer          -0.2%      0.0%     +0.0%     -0.0%     -0.0%
                  integer          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                integrate          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
             k-nucleotide          -0.2%      0.0%     +0.0%     +0.0%     -0.0%
                    kahan          -0.3%      0.0%     -0.0%     -0.0%     -0.0%
                  knights          -0.3%      0.0%     +0.0%     -0.0%     -0.0%
                   lambda          -0.3%      0.0%     +0.0%     -0.0%     -0.0%
               last-piece          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                     lcss          -0.3%      0.0%     +0.0%     +0.0%      0.0%
                     life          -0.3%      0.0%     +0.0%     -0.0%     -0.0%
                     lift          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
                   linear          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
                listcompr          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                 listcopy          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                 maillist          -0.3%      0.0%     +0.0%     -0.0%     -0.0%
                   mandel          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
                  mandel2          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                     mate          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
                  minimax          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                  mkhprog          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
               multiplier          -0.3%      0.0%     +0.0%     -0.0%     -0.0%
                   n-body          -0.2%      0.0%     -0.0%     -0.0%     -0.0%
                 nucleic2          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
                     para          -0.2%      0.0%     +0.0%     -0.0%     -0.0%
                paraffins          -0.3%      0.0%     +0.0%     -0.0%     -0.0%
                   parser          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
                  parstof          -0.2%      0.0%     +0.8%     +0.2%     +0.2%
                      pic          -0.2%      0.0%     +0.1%     -0.1%     -0.1%
                 pidigits          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                    power          -0.2%      0.0%     +0.0%     -0.0%     -0.0%
                   pretty          -0.3%      0.0%     -0.0%     -0.0%     -0.1%
                   primes          -0.3%      0.0%     +0.0%     +0.0%     -0.0%
                primetest          -0.2%      0.0%     +0.0%     -0.0%     -0.0%
                   prolog          -0.3%      0.0%     +0.0%     -0.0%     -0.0%
                   puzzle          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                   queens          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                  reptile          -0.2%      0.0%     +0.2%     +0.1%     +0.0%
          reverse-complem          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                  rewrite          -0.3%      0.0%     +0.0%     -0.0%     -0.0%
                     rfib          -0.2%      0.0%     +0.0%     +0.0%     -0.0%
                      rsa          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
                      scc          -0.3%      0.0%     -0.0%     -0.0%     -0.1%
                    sched          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                      scs          -0.2%      0.0%     +0.1%     +0.0%     +0.0%
                   simple          -0.2%      0.0%     +3.4%     +1.0%     +1.8%
                    solid          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
                  sorting          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
            spectral-norm          -0.2%      0.0%     -0.0%     -0.0%     -0.0%
                   sphere          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
                   symalg          -0.2%      0.0%     +0.0%     +0.0%     +0.0%
                      tak          -0.3%      0.0%     +0.0%     +0.0%     -0.0%
                transform          -0.2%      0.0%     +0.2%     +0.1%     +0.1%
                 treejoin          -0.3%      0.0%     +0.2%     -0.0%     -0.1%
                typecheck          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
                  veritas          -0.1%      0.0%     +0.0%     +0.0%     +0.0%
                     wang          -0.2%      0.0%     +0.0%     -0.0%     -0.0%
                wave4main          -0.3%      0.0%     +0.0%     -0.0%     -0.0%
             wheel-sieve1          -0.3%      0.0%     +0.0%     -0.0%     -0.0%
             wheel-sieve2          -0.3%      0.0%     +0.0%     -0.0%     -0.0%
                     x2n1          -0.3%      0.0%     +0.0%     +0.0%     +0.0%
          --------------------------------------------------------------------------------
                      Min          -0.3%      0.0%     -0.0%     -0.1%     -0.2%
                      Max          -0.1%      0.0%     +5.4%     +1.0%     +3.9%
           Geometric Mean          -0.3%     -0.0%     +0.1%     +0.0%     +0.1%
      
          --------------------------------------------------------------------------------
                  Program           Size    Allocs    Instrs     Reads    Writes
          --------------------------------------------------------------------------------
                  circsim          -0.2%      0.0%     +1.6%     +0.4%     +0.7%
              constraints          -0.3%      0.0%     +4.3%     +1.5%     +2.3%
                 fibheaps          -0.3%      0.0%     +3.5%     +1.2%     +1.3%
                   fulsom          -0.2%      0.0%     +3.6%     +1.2%     +1.8%
                 gc_bench          -0.3%      0.0%     +4.1%     +1.3%     +2.3%
                     hash          -0.3%      0.0%     +6.6%     +2.2%     +3.6%
                     lcss          -0.3%      0.0%     +0.7%     +0.2%     +0.7%
                mutstore1          -0.3%      0.0%     +4.8%     +1.4%     +2.8%
                mutstore2          -0.3%      0.0%     +3.4%     +1.0%     +1.7%
                    power          -0.2%      0.0%     +2.7%     +0.6%     +1.9%
               spellcheck          -0.3%      0.0%     +1.1%     +0.4%     +0.4%
          --------------------------------------------------------------------------------
                      Min          -0.3%      0.0%     +0.7%     +0.2%     +0.4%
                      Max          -0.2%      0.0%     +6.6%     +2.2%     +3.6%
           Geometric Mean          -0.3%     +0.0%     +3.3%     +1.0%     +1.8%
      
      Metric changes
      --------------
      
      While it sounds ridiculous, this change causes increased allocations in
      the following tests. We concluded that this change can't cause a
      difference in allocations and decided to land this patch. Fluctuations
      in "bytes allocated" metric is tracked in #17686.
      
      Metric Increase:
          Naperian
          T10547
          T12150
          T12234
          T12425
          T13035
          T5837
          T6048
      0e57d8a1
    • Sebastian Graf's avatar
      be910728
    • Gabor Greif's avatar
      Document the fact, that openFileBlocking can consume an OS thread indefinitely. · ad4eb7a7
      Gabor Greif authored
      Also state that a deadlock can happen with the non-threaded runtime.
      [ci skip]
      ad4eb7a7
  3. 24 Jan, 2020 1 commit
  4. 20 Jan, 2020 14 commits
  5. 17 Jan, 2020 1 commit
  6. 16 Jan, 2020 6 commits
  7. 13 Jan, 2020 3 commits