Skip to content
Snippets Groups Projects
  1. Nov 09, 2023
  2. Aug 29, 2023
  3. Aug 09, 2023
  4. Jul 18, 2023
    • sheaf's avatar
      Do primop rep-poly checks when instantiating · 889c2bbb
      sheaf authored and Marge Bot's avatar Marge Bot committed
      This patch changes how we perform representation-polymorphism checking
      for primops (and other wired-in Ids such as coerce).
      When instantiating the primop, we check whether each type variable
      is required to instantiated to a concrete type, and if so we create a
      new concrete metavariable (a ConcreteTv) instead of a simple MetaTv.
      (A little subtlety is the need to apply the substitution obtained from
      instantiating to the ConcreteTvOrigins, see
      Note [substConcreteTvOrigin] in GHC.Tc.Utils.TcMType.)
      
      This allows us to prevent representation-polymorphism in non-argument
      position, as that is required for some of these primops.
      
      We can also remove the logic in tcRemainingValArgs, except for
      the part concerning representation-polymorphic unlifted newtypes.
      The function has been renamed rejectRepPolyNewtypes; all it does now
      is reject unsaturated occurrences of representation-polymorphic newtype
      constructors when the representation of its argument isn't a concrete
      RuntimeRep (i.e. still a PHASE 1 FixedRuntimeRep check).
      The Note [Eta-expanding rep-poly unlifted newtypes] in GHC.Tc.Gen.Head
      gives more explanation about a possible path to PHASE 2, which would be
      in line with the treatment for primops taken in this patch.
      
      We also update the Core Lint check to handle this new framework. This
      means Core Lint now checks representation-polymorphism in continuation
      position like needed for catch#.
      
      Fixes #21906
      
      -------------------------
      Metric Increase:
          LargeRecord
      -------------------------
      889c2bbb
  5. Jun 26, 2023
    • Sylvain Henry's avatar
      JS: support levity-polymorphic datatypes (#22360,#22291) · 8d6574bc
      Sylvain Henry authored and Marge Bot's avatar Marge Bot committed
      - thread knowledge about levity into PrimRep instead of panicking
      - JS: remove assumption that unlifted heap objects are rts objects (TVar#, etc.)
      
      Doing this also fixes #22291 (test added).
      
      There is a small performance hit (~1% more allocations).
      
      Metric Increase:
          T18698a
          T18698b
      8d6574bc
  6. Jun 14, 2023
  7. May 15, 2023
    • sheaf's avatar
      Migrate errors to diagnostics in GHC.Tc.Module · 4d29ecdf
      sheaf authored and Marge Bot's avatar Marge Bot committed
      This commit migrates the errors in GHC.Tc.Module to use the new
      diagnostic infrastructure.
      
      It required a significant overhaul of the compatibility checks between
      an hs-boot or signature module and its implementation; we now use
      a Writer monad to accumulate errors; see the BootMismatch datatype
      in GHC.Tc.Errors.Types, with its panoply of subtypes.
      For the sake of readability, several local functions inside the
      'checkBootTyCon' function were split off into top-level functions.
      
      We split off GHC.Types.HscSource into a "boot or sig" vs "normal hs file"
      datatype, as this mirrors the logic in several other places where we
      want to treat hs-boot and hsig files in a similar fashion.
      
      This commit also refactors the Backpack checks for type synonyms
      implementing abstract data, to correctly reject implementations that
      contain qualified or quantified types (this fixes #23342 and #23344).
      4d29ecdf
  8. May 13, 2023
    • Simon Peyton Jones's avatar
      Use the eager unifier in the constraint solver · 8b9b7dbc
      Simon Peyton Jones authored and Marge Bot's avatar Marge Bot committed
      This patch continues the refactoring of the constraint solver
      described in #23070.
      
      The Big Deal in this patch is to call the regular, eager unifier from the
      constraint solver, when we want to create new equalities. This
      replaces the existing, unifyWanted which amounted to
      yet-another-unifier, so it reduces duplication of a rather subtle
      piece of technology. See
      
        * Note [The eager unifier] in GHC.Tc.Utils.Unify
        * GHC.Tc.Solver.Monad.wrapUnifierTcS
      
      I did lots of other refactoring along the way
      
      * I simplified the treatment of right hand sides that contain CoercionHoles.
        Now, a constraint that contains a hetero-kind CoercionHole is non-canonical,
        and cannot be used for rewriting or unification alike.  This required me
        to add the ch_hertero_kind flag to CoercionHole, with consequent knock-on
        effects. See wrinkle (2) of `Note [Equalities with incompatible kinds]` in
        GHC.Tc.Solver.Equality.
      
      * I refactored the StopOrContinue type to add StartAgain, so that after a
        fundep improvement (for example) we can simply start the pipeline again.
      
      * I got rid of the unpleasant (and inefficient) rewriterSetFromType/Co functions.
        With Richard I concluded that they are never needed.
      
      * I discovered Wrinkle (W1) in Note [Wanteds rewrite Wanteds] in
        GHC.Tc.Types.Constraint, and therefore now prioritise non-rewritten equalities.
      
      Quite a few error messages change, I think always for the better.
      
      Compiler runtime stays about the same, with one outlier: a 17% improvement in T17836
      
      Metric Decrease:
          T17836
          T18223
      8b9b7dbc
  9. Apr 26, 2023
  10. Apr 25, 2023
  11. Apr 15, 2023
  12. Apr 14, 2023
    • Simon Peyton Jones's avatar
      Major refactor in the handling of equality constraints · 2371d6b2
      Simon Peyton Jones authored and Krzysztof Gogolewski's avatar Krzysztof Gogolewski committed
      This MR substantially refactors the way in which the constraint
      solver deals with equality constraints.  The big thing is:
      
      * Intead of a pipeline in which we /first/ canonicalise and /then/
        interact (the latter including performing unification) the two steps
        are more closely integreated into one.  That avoids the current
        rather indirect communication between the two steps.
      
      The proximate cause for this refactoring is fixing #22194, which involve
      solving   [W] alpha[2] ~ Maybe (F beta[4])
      by doing this:
                alpha[2] := Maybe delta[2]
                [W] delta[2] ~ F beta[4]
      That is, we don't promote beta[4]!  This is very like introducing a cycle
      breaker, and was very awkward to do before, but now it is all nice.
      See GHC.Tc.Utils.Unify Note [Promotion and level-checking] and
      Note [Family applications in canonical constraints].
      
      The big change is this:
      
      * Several canonicalisation checks (occurs-check, cycle-breaking,
        checking for concreteness) are combined into one new function:
           GHC.Tc.Utils.Unify.checkTyEqRhs
      
        This function is controlled by `TyEqFlags`, which says what to do
        for foralls, type families etc.
      
      * `canEqCanLHSFinish` now sees if unification is possible, and if so,
        actually does it: see `canEqCanLHSFinish_try_unification`.
      
      There are loads of smaller changes:
      
      * The on-the-fly unifier `GHC.Tc.Utils.Unify.unifyType` has a
        cheap-and-cheerful version of `checkTyEqRhs`, called
        `simpleUnifyCheck`.  If `simpleUnifyCheck` succeeds, it can unify,
        otherwise it defers by emitting a constraint. This is simpler than
        before.
      
      * I simplified the swapping code in `GHC.Tc.Solver.Equality.canEqCanLHS`.
        Especially the nasty stuff involving `swap_for_occurs` and
        `canEqTyVarFunEq`.  Much nicer now.  See
            Note [Orienting TyVarLHS/TyFamLHS]
            Note [Orienting TyFamLHS/TyFamLHS]
      
      * Added `cteSkolemOccurs`, `cteConcrete`, and `cteCoercionHole` to the
        problems that can be discovered by `checkTyEqRhs`.
      
      * I fixed #23199 `pickQuantifiablePreds`, which actually allows GHC to
        to accept both cases in #22194 rather than rejecting both.
      
      Yet smaller:
      
      * Added a `synIsConcrete` flag to `SynonymTyCon` (alongside `synIsFamFree`)
        to reduce the need for synonym expansion when checking concreteness.
        Use it in `isConcreteType`.
      
      * Renamed `isConcrete` to `isConcreteType`
      
      * Defined `GHC.Core.TyCo.FVs.isInjectiveInType` as a more efficient
        way to find if a particular type variable is used injectively than
        finding all the injective variables.  It is called in
        `GHC.Tc.Utils.Unify.definitely_poly`, which in turn is used quite a
        lot.
      
      * Moved `rewriterView` to `GHC.Core.Type`, so we can use it from the
        constraint solver.
      
      Fixes #22194, #23199
      
      Compile times decrease by an average of 0.1%; but there is a 7.4%
      drop in compiler allocation on T15703.
      
      Metric Decrease:
          T15703
      2371d6b2
  13. Mar 29, 2023
    • sheaf's avatar
      Handle records in the renamer · 3f374399
      sheaf authored
      This patch moves the field-based logic for disambiguating record updates
      to the renamer. The type-directed logic, scheduled for removal, remains
      in the typechecker.
      
      To do this properly (and fix the myriad of bugs surrounding the treatment
      of duplicate record fields), we took the following main steps:
      
        1. Create GREInfo, a renamer-level equivalent to TyThing which stores
           information pertinent to the renamer.
           This allows us to uniformly treat imported and local Names in the
           renamer, as described in Note [GREInfo].
      
        2. Remove GreName. Instead of a GlobalRdrElt storing GreNames, which
           distinguished between normal names and field names, we now store
           simple Names in GlobalRdrElt, along with the new GREInfo information
           which allows us to recover the FieldLabel for record fields.
      
        3. Add namespacing for record fields, within the OccNames themselves.
           This allows us to remove the mangling of duplicate field selectors.
      
           This change ensures we don't print mangled names to the user in
           error messages, and allows us to handle duplicate record fields
           in Template Haskell.
      
        4. Move record disambiguation to the renamer, and operate on the
           level of data constructors instead, to handle #21443.
      
           The error message text for ambiguous record updates has also been
           changed to reflect that type-directed disambiguation is on the way
           out.
      
      (3) means that OccEnv is now a bit more complex: we first key on the
      textual name, which gives an inner map keyed on NameSpace:
      
        OccEnv a ~ FastStringEnv (UniqFM NameSpace a)
      
      Note that this change, along with (2), both increase the memory residency
      of GlobalRdrEnv = OccEnv [GlobalRdrElt], which causes a few tests to
      regress somewhat in compile-time allocation.
      
      Even though (3) simplified a lot of code (in particular the treatment of
      field selectors within Template Haskell and in error messages), it came
      with one important wrinkle: in the situation of
      
        -- M.hs-boot
        module M where { data A; foo :: A -> Int }
        -- M.hs
        module M where { data A = MkA { foo :: Int } }
      
      we have that M.hs-boot exports a variable foo, which is supposed to match
      with the record field foo that M exports. To solve this issue, we add a
      new impedance-matching binding to M
      
        foo{var} = foo{fld}
      
      This mimics the logic that existed already for impedance-binding DFunIds,
      but getting it right was a bit tricky.
      See Note [Record field impedance matching] in GHC.Tc.Module.
      
      We also needed to be careful to avoid introducing space leaks in GHCi.
      So we dehydrate the GlobalRdrEnv before storing it anywhere, e.g. in
      ModIface. This means stubbing out all the GREInfo fields, with the
      function forceGlobalRdrEnv.
      When we read it back in, we rehydrate with rehydrateGlobalRdrEnv.
      This robustly avoids any space leaks caused by retaining old type
      environments.
      
      Fixes #13352 #14848 #17381 #17551 #19664 #21443 #21444 #21720 #21898 #21946 #21959 #22125 #22160 #23010 #23062 #23063
      
      Updates haddock submodule
      
      -------------------------
      Metric Increase:
          MultiComponentModules
          MultiLayerModules
          MultiLayerModulesDefsGhci
          MultiLayerModulesNoCode
          T13701
          T14697
          hard_hole_fits
      -------------------------
      3f374399
  14. Mar 22, 2023
    • Simon Peyton Jones's avatar
      Be more careful about quantification · 926ad6de
      Simon Peyton Jones authored and Marge Bot's avatar Marge Bot committed
      This MR is driven by #23051. It does several things:
      
      * It is guided by the generalisation plan described in #20686.
        But it is still far from a complete implementation of that plan.
      
      * Add Note [Inferred type with escaping kind] to GHC.Tc.Gen.Bind.
        This explains that we don't (yet, pending #20686) directly
        prevent generalising over escaping kinds.
      
      * In `GHC.Tc.Utils.TcMType.defaultTyVar` we default RuntimeRep
        and Multiplicity variables, beause we don't want to quantify over
        them.  We want to do the same for a Concrete tyvar, but there is
        nothing sensible to default it to (unless it has kind RuntimeRep,
        in which case it'll be caught by an earlier case). So we promote
        instead.
      
      * Pure refactoring in GHC.Tc.Solver:
        * Rename decideMonoTyVars to decidePromotedTyVars, since that's
          what it does.
      
        * Move the actual promotion of the tyvars-to-promote from
          `defaultTyVarsAndSimplify` to `decidePromotedTyVars`.  This is a
          no-op; just tidies up the code.  E.g then we don't need to
          return the promoted tyvars from `decidePromotedTyVars`.
      
        * A little refactoring in `defaultTyVarsAndSimplify`, but no
          change in behaviour.
      
      * When making a TauTv unification variable into a ConcreteTv
        (in GHC.Tc.Utils.Concrete.makeTypeConcrete), preserve the occ-name
        of the type variable.  This just improves error messages.
      
      * Kill off dead code: GHC.Tc.Utils.TcMType.newConcreteHole
      926ad6de
  15. Feb 02, 2023
    • jeffrey young's avatar
      CI: JavaScript backend runs testsuite · 394b91ce
      jeffrey young authored and Marge Bot's avatar Marge Bot committed
      This MR runs the testsuite for the JS backend. Note that this is a
      temporary solution until !9515 is merged.
      
      Key point: The CI runs hadrian on the built cross compiler _but not_ on
      the bindist.
      
      Other Highlights:
      
       - stm submodule gets a bump to mark tests as broken
       - several tests are marked as broken or are fixed by adding more
       - conditions to their test runner instance.
      
      List of working commit messages:
      
      CI: test cross target _and_ emulator
      
      CI: JS: Try run testsuite with hadrian
      
      JS.CI: cleanup and simplify hadrian invocation
      
      use single bracket, print info
      
      JS CI: remove call to test_compiler from hadrian
      
      don't build haddock
      
      JS: mark more tests as broken
      
      Tracked in ghc/ghc#22576
      
      JS testsuite: don't skip sum_mod test
      
      Its expected to fail, yet we skipped it which automatically makes it
      succeed leading to an unexpected success,
      
      JS testsuite: don't mark T12035j as skip
      
      leads to an unexpected pass
      
      JS testsuite: remove broken on T14075
      
      leads to unexpected pass
      
      JS testsuite: mark more tests as broken
      
      JS testsuite: mark T11760 in base as broken
      
      JS testsuite: mark ManyUnbSums broken
      
      submodules: bump process and hpc for JS tests
      
      Both submodules has needed tests skipped or marked broken for th JS
      backend. This commit now adds these changes to GHC.
      
      See:
      
      HPC: hpc/hpc!21
      
      Process: https://github.com/haskell/process/pull/268
      
      remove js_broken on now passing tests
      
      separate wasm and js backend ci
      
      test: T11760: add threaded, non-moving only_ways
      
      test: T10296a add req_c
      
      T13894: skip for JS backend
      
      tests: jspace, T22333: mark as js_broken(22573)
      
      test: T22513i mark as req_th
      
      stm submodule: mark stm055, T16707 broken for JS
      
      tests: js_broken(22374) on unpack_sums_6, T12010
      
      dont run diff on JS CI, cleanup
      
      fixup: More CI cleanup
      
      fix: align text to master
      
      fix: align exceptions submodule to master
      
      CI: Bump DOCKER_REV
      
      Bump to ci-images commit that has a deb11 build with node. Required for
      !9552
      
      testsuite: mark T22669 as js_skip
      
      See #22669
      
      This test tests that .o-boot files aren't created when run in using the
      interpreter backend. Thus this is not relevant for the JS backend.
      
      testsuite: mark T22671 as broken on JS
      
      See #22835
      
      base.testsuite: mark Chan002 fragile for JS
      
      see #22836
      
      revert: submodule process bump
      
      bump stm submodule
      
      New hash includes skips for the JS backend.
      
      testsuite: mark RnPatternSynonymFail broken on JS
      
      Requires TH:
       - see !9779
       - and #22261
      
      compiler: GHC.hs ifdef import Utils.Panic.Plain
      394b91ce
  16. Nov 29, 2022
    • Sylvain Henry's avatar
      Add Javascript backend · cc25d52e
      Sylvain Henry authored
      
      Add JS backend adapted from the GHCJS project by Luite Stegeman.
      
      Some features haven't been ported or implemented yet. Tests for these
      features have been disabled with an associated gitlab ticket.
      
      Bump array submodule
      
      Work funded by IOG.
      
      Co-authored-by: default avatarJeffrey Young <jeffrey.young@iohk.io>
      Co-authored-by: default avatarLuite Stegeman <stegeman@gmail.com>
      Co-authored-by: default avatarJosh Meredith <joshmeredith2008@gmail.com>
      cc25d52e
    • Apoorv Ingle's avatar
      Killing cc_fundeps, streamlining kind equality orientation, and type equality processing order · 8d15eadc
      Apoorv Ingle authored and Marge Bot's avatar Marge Bot committed
      Fixes: #217093
      Associated to #19415
      
      This change
      * Flips the orientation of the the generated kind equality coercion in canEqLHSHetero;
      * Removes `cc_fundeps` in CDictCan as the check was incomplete;
      * Changes `canDecomposableTyConAppOk` to ensure we process kind equalities before type equalities and avoiding a call to `canEqLHSHetero` while processing wanted TyConApp equalities
      * Adds 2 new tests for validating the change
         - testsuites/typecheck/should_compile/T21703.hs and
         - testsuites/typecheck/should_fail/T19415b.hs (a simpler version of T19415.hs)
      * Misc: Due to the change in the equality direction some error messages now have flipped type mismatch errors
      * Changes in Notes:
        - Note [Fundeps with instances, and equality orientation] supercedes Note [Fundeps with instances]
        - Added Note [Kind Equality Orientation] to visualize the kind flipping
        - Added Note [Decomposing Dependent TyCons and Processing Wanted Equalties]
      8d15eadc
  17. Nov 25, 2022
    • Vladislav Zavialov's avatar
      Print unticked promoted data constructors (#20531) · 13d627bb
      Vladislav Zavialov authored and Marge Bot's avatar Marge Bot committed
      
      Before this patch, GHC unconditionally printed ticks before promoted
      data constructors:
      
      	ghci> type T = True  -- unticked (user-written)
      	ghci> :kind! T
      	T :: Bool
      	= 'True              -- ticked (compiler output)
      
      After this patch, GHC prints ticks only when necessary:
      
      	ghci> type F = False    -- unticked (user-written)
      	ghci> :kind! F
      	F :: Bool
      	= False                 -- unticked (compiler output)
      
      	ghci> data False        -- introduce ambiguity
      	ghci> :kind! F
      	F :: Bool
      	= 'False                -- ticked by necessity (compiler output)
      
      The old behavior can be enabled by -fprint-redundant-promotion-ticks.
      
      Summary of changes:
      * Rename PrintUnqualified to NamePprCtx
      * Add QueryPromotionTick to it
      * Consult the GlobalRdrEnv to decide whether to print a tick (see mkPromTick)
      * Introduce -fprint-redundant-promotion-ticks
      
      Co-authored-by: default avatarArtyom Kuznetsov <hi@wzrd.ht>
      13d627bb
  18. Nov 11, 2022
    • Simon Peyton Jones's avatar
      Type vs Constraint: finally nailed · 778c6adc
      Simon Peyton Jones authored and Simon Peyton Jones's avatar Simon Peyton Jones committed
      This big patch addresses the rats-nest of issues that have plagued
      us for years, about the relationship between Type and Constraint.
      See #11715/#21623.
      
      The main payload of the patch is:
      * To introduce CONSTRAINT :: RuntimeRep -> Type
      * To make TYPE and CONSTRAINT distinct throughout the compiler
      
      Two overview Notes in GHC.Builtin.Types.Prim
      
      * Note [TYPE and CONSTRAINT]
      
      * Note [Type and Constraint are not apart]
        This is the main complication.
      
      The specifics
      
      * New primitive types (GHC.Builtin.Types.Prim)
        - CONSTRAINT
        - ctArrowTyCon (=>)
        - tcArrowTyCon (-=>)
        - ccArrowTyCon (==>)
        - funTyCon     FUN     -- Not new
        See Note [Function type constructors and FunTy]
        and Note [TYPE and CONSTRAINT]
      
      * GHC.Builtin.Types:
        - New type Constraint = CONSTRAINT LiftedRep
        - I also stopped nonEmptyTyCon being built-in; it only needs to be wired-in
      
      * Exploit the fact that Type and Constraint are distinct throughout GHC
        - Get rid of tcView in favour of coreView.
        - Many tcXX functions become XX functions.
          e.g. tcGetCastedTyVar --> getCastedTyVar
      
      * Kill off Note [ForAllTy and typechecker equality], in (old)
        GHC.Tc.Solver.Canonical.  It said that typechecker-equality should ignore
        the specified/inferred distinction when comparein two ForAllTys.  But
        that wsa only weakly supported and (worse) implies that we need a separate
        typechecker equality, different from core equality. No no no.
      
      * GHC.Core.TyCon: kill off FunTyCon in data TyCon.  There was no need for it,
        and anyway now we have four of them!
      
      * GHC.Core.TyCo.Rep: add two FunTyFlags to FunCo
        See Note [FunCo] in that module.
      
      * GHC.Core.Type.  Lots and lots of changes driven by adding CONSTRAINT.
        The key new function is sORTKind_maybe; most other changes are built
        on top of that.
      
        See also `funTyConAppTy_maybe` and `tyConAppFun_maybe`.
      
      * Fix a longstanding bug in GHC.Core.Type.typeKind, and Core Lint, in
        kinding ForAllTys.  See new tules (FORALL1) and (FORALL2) in GHC.Core.Type.
        (The bug was that before (forall (cv::t1 ~# t2). blah), where
        blah::TYPE IntRep, would get kind (TYPE IntRep), but it should be
        (TYPE LiftedRep).  See Note [Kinding rules for types] in GHC.Core.Type.
      
      * GHC.Core.TyCo.Compare is a new module in which we do eqType and cmpType.
        Of course, no tcEqType any more.
      
      * GHC.Core.TyCo.FVs. I moved some free-var-like function into this module:
        tyConsOfType, visVarsOfType, and occCheckExpand.  Refactoring only.
      
      * GHC.Builtin.Types.  Compiletely re-engineer boxingDataCon_maybe to
        have one for each /RuntimeRep/, rather than one for each /Type/.
        This dramatically widens the range of types we can auto-box.
        See Note [Boxing constructors] in GHC.Builtin.Types
        The boxing types themselves are declared in library ghc-prim:GHC.Types.
      
        GHC.Core.Make.  Re-engineer the treatment of "big" tuples (mkBigCoreVarTup
        etc) GHC.Core.Make, so that it auto-boxes unboxed values and (crucially)
        types of kind Constraint. That allows the desugaring for arrows to work;
        it gathers up free variables (including dictionaries) into tuples.
        See  Note [Big tuples] in GHC.Core.Make.
      
        There is still work to do here: #22336. But things are better than
        before.
      
      * GHC.Core.Make.  We need two absent-error Ids, aBSENT_ERROR_ID for types of
        kind Type, and aBSENT_CONSTRAINT_ERROR_ID for vaues of kind Constraint.
        Ditto noInlineId vs noInlieConstraintId in GHC.Types.Id.Make;
        see Note [inlineId magic].
      
      * GHC.Core.TyCo.Rep. Completely refactor the NthCo coercion.  It is now called
        SelCo, and its fields are much more descriptive than the single Int we used to
        have.  A great improvement.  See Note [SelCo] in GHC.Core.TyCo.Rep.
      
      * GHC.Core.RoughMap.roughMatchTyConName.  Collapse TYPE and CONSTRAINT to
        a single TyCon, so that the rough-map does not distinguish them.
      
      * GHC.Core.DataCon
        - Mainly just improve documentation
      
      * Some significant renamings:
        GHC.Core.Multiplicity: Many -->  ManyTy (easier to grep for)
                               One  -->  OneTy
        GHC.Core.TyCo.Rep TyCoBinder      -->   GHC.Core.Var.PiTyBinder
        GHC.Core.Var      TyCoVarBinder   -->   ForAllTyBinder
                          AnonArgFlag     -->   FunTyFlag
                          ArgFlag         -->   ForAllTyFlag
        GHC.Core.TyCon    TyConTyCoBinder --> TyConPiTyBinder
        Many functions are renamed in consequence
        e.g. isinvisibleArgFlag becomes isInvisibleForAllTyFlag, etc
      
      * I refactored FunTyFlag (was AnonArgFlag) into a simple, flat data type
          data FunTyFlag
            = FTF_T_T           -- (->)  Type -> Type
            | FTF_T_C           -- (-=>) Type -> Constraint
            | FTF_C_T           -- (=>)  Constraint -> Type
            | FTF_C_C           -- (==>) Constraint -> Constraint
      
      * GHC.Tc.Errors.Ppr.  Some significant refactoring in the TypeEqMisMatch case
        of pprMismatchMsg.
      
      * I made the tyConUnique field of TyCon strict, because I
        saw code with lots of silly eval's.  That revealed that
        GHC.Settings.Constants.mAX_SUM_SIZE can only be 63, because
        we pack the sum tag into a 6-bit field.  (Lurking bug squashed.)
      
      Fixes
      * #21530
      
      Updates haddock submodule slightly.
      
      Performance changes
      ~~~~~~~~~~~~~~~~~~~
      I was worried that compile times would get worse, but after
      some careful profiling we are down to a geometric mean 0.1%
      increase in allocation (in perf/compiler).  That seems fine.
      
      There is a big runtime improvement in T10359
      
      Metric Decrease:
          LargeRecord
          MultiLayerModulesTH_OneShot
          T13386
          T13719
      Metric Increase:
          T8095
      778c6adc
  19. Oct 26, 2022
  20. Sep 13, 2022
    • sheaf's avatar
      Diagnostic codes: acccept test changes · 362cca13
      sheaf authored and Marge Bot's avatar Marge Bot committed
      The testsuite output now contains diagnostic codes, so many tests need
      to be updated at once.
      We decided it was best to keep the diagnostic codes in the testsuite
      output, so that contributors don't inadvertently make changes to the
      diagnostic codes.
      362cca13
  21. Aug 19, 2022
  22. Jun 09, 2022
    • sheaf's avatar
      Typecheck remaining ValArgs in rebuildHsApps · 28880828
      sheaf authored and Marge Bot's avatar Marge Bot committed
      This patch refactors hasFixedRuntimeRep_remainingValArgs, renaming it
      to tcRemainingValArgs. The logic is moved to rebuildHsApps, which
      ensures consistent behaviour across tcApp and quickLookArg1/tcEValArg.
      
      This patch also refactors the treatment of stupid theta for data
      constructors, changing the place we drop stupid theta arguments
      from dsConLike to mkDataConRep (now the datacon wrapper drops these
      arguments).
      
      We decided not to implement PHASE 2 of the FixedRuntimeRep plan for
      these remaining ValArgs. Future directions are outlined on the wiki:
        https://gitlab.haskell.org/ghc/ghc/-/wikis/Remaining-ValArgs
      
      Fixes #21544 and #21650
      28880828
  23. Jun 06, 2022
  24. May 26, 2022
  25. May 25, 2022
    • CarrieMY's avatar
      Desugar RecordUpd in `tcExpr` · e74fc066
      CarrieMY authored and sheaf's avatar sheaf committed
      This patch typechecks record updates by desugaring them inside
      the typechecker using the HsExpansion mechanism, and then typechecking
      this desugared result.
      
      Example:
      
          data T p q = T1 { x :: Int, y :: Bool, z :: Char }
                     | T2 { v :: Char }
                     | T3 { x :: Int }
                     | T4 { p :: Float, y :: Bool, x :: Int }
                     | T5
      
      The record update `e { x=e1, y=e2 }` desugars as follows
      
        e { x=e1, y=e2 }
          ===>
        let { x' = e1; y' = e2 } in
        case e of
           T1 _ _ z -> T1 x' y' z
           T4 p _ _ -> T4 p y' x'
      
      The desugared expression is put into an HsExpansion, and we typecheck
      that.
      
      The full details are given in Note [Record Updates] in GHC.Tc.Gen.Expr.
      
      Fixes #2595 #3632 #10808 #10856 #16501 #18311 #18802 #21158 #21289
      
      Updates haddock submodule
      e74fc066
  26. Apr 28, 2022
    • sheaf's avatar
      Fix unification of ConcreteTvs, removing IsRefl# · a8c99391
      sheaf authored and Marge Bot's avatar Marge Bot committed
      This patch fixes the unification of concrete type variables.
      The subtlety was that unifying concrete metavariables is more subtle
      than other metavariables, as decomposition is possible. See the Note
      [Unifying concrete metavariables], which explains how we unify a
      concrete type variable with a type 'ty' by concretising 'ty', using
      the function 'GHC.Tc.Utils.Concrete.concretise'.
      
      This can be used to perform an eager syntactic check for concreteness,
      allowing us to remove the IsRefl# special predicate. Instead of emitting
      two constraints `rr ~# concrete_tv` and `IsRefl# rr concrete_tv`, we
      instead concretise 'rr'. If this succeeds we can fill 'concrete_tv',
      and otherwise we directly emit an error message to the typechecker
      environment instead of deferring. We still need the error message
      to be passed on (instead of directly thrown), as we might benefit from
      further unification in which case we will need to zonk the stored types.
      To achieve this, we change the 'wc_holes' field of 'WantedConstraints'
      to 'wc_errors', which stores general delayed errors. For the moement,
      a delayed error is either a hole, or a syntactic equality error.
      
      hasFixedRuntimeRep_MustBeRefl is now hasFixedRuntimeRep_syntactic, and
      hasFixedRuntimeRep has been refactored to directly return the most
      useful coercion for PHASE 2 of FixedRuntimeRep.
      
      This patch also adds a field ir_frr to the InferResult datatype,
      holding a value of type Maybe FRROrigin. When this value is not
      Nothing, this means that we must fill the ir_ref field with a type
      which has a fixed RuntimeRep.
      When it comes time to fill such an ExpType, we ensure that the type
      has a fixed RuntimeRep by performing a representation-polymorphism
      check with the given FRROrigin
      This is similar to what we already do to ensure we fill an Infer
      ExpType with a type of the correct TcLevel.
      This allows us to properly perform representation-polymorphism checks
      on 'Infer' 'ExpTypes'.
      
      The fillInferResult function had to be moved to GHC.Tc.Utils.Unify
      to avoid a cyclic import now that it calls hasFixedRuntimeRep.
      
      This patch also changes the code in matchExpectedFunTys to make use
      of the coercions, which is now possible thanks to the previous change.
      This implements PHASE 2 of FixedRuntimeRep in some situations.
      For example, the test cases T13105 and T17536b are now both accepted.
      
      Fixes #21239 and #21325
      
      -------------------------
      Metric Decrease:
          T18223
          T5631
      -------------------------
      a8c99391
  27. Apr 08, 2022
    • sheaf's avatar
      Docs: datacon eta-expansion, rep-poly checks · 23f95735
      sheaf authored and Marge Bot's avatar Marge Bot committed
      The existing notes weren't very clear on how the eta-expansion of
      data constructors that occurs in tcInferDataCon/dsConLike interacts
      with the representation polymorphism invariants. So we explain with
      a few more details how we ensure that the representation-polymorphic
      lambdas introduced by tcInferDataCon/dsConLike don't end up causing
      problems, by checking they are properly instantiated and then relying
      on the simple optimiser to perform beta reduction.
      
      A few additional changes:
      
        - ConLikeTc just take type variables instead of binders, as we
          never actually used the binders.
        - Removed the FRRApp constructor of FRROrigin; it was no longer used
          now that we use ExpectedFunTyOrigin.
        - Adds a bit of documentation to the constructors
          of ExpectedFunTyOrigin.
      23f95735
  28. Apr 01, 2022
  29. Mar 14, 2022
    • sheaf's avatar
      Fix isLiftedType_maybe and handle fallout · 8eadea67
      sheaf authored and Marge Bot's avatar Marge Bot committed
      As #20837 pointed out, `isLiftedType_maybe` returned `Just False` in
      many situations where it should return `Nothing`, because it didn't
      take into account type families or type variables.
      
      In this patch, we fix this issue. We rename `isLiftedType_maybe` to
      `typeLevity_maybe`, which now returns a `Levity` instead of a boolean.
      We now return `Nothing` for types with kinds of the form
      `TYPE (F a1 ... an)` for a type family `F`, as well as
      `TYPE (BoxedRep l)` where `l` is a type variable.
      
      This fix caused several other problems, as other parts of the compiler
      were relying on `isLiftedType_maybe` returning a `Just` value, and were
      now panicking after the above fix. There were two main situations in
      which panics occurred:
      
        1. Issues involving the let/app invariant. To uphold that invariant,
           we need to know whether something is lifted or not. If we get an
           answer of `Nothing` from `isLiftedType_maybe`, then we don't know
           what to do. As this invariant isn't particularly invariant, we
           can change the affected functions to not panic, e.g. by behaving
           the same in the `Just False` case and in the `Nothing` case
           (meaning: no observable change in behaviour compared to before).
      
        2. Typechecking of data (/newtype) constructor patterns. Some programs
           involving patterns with unknown representations were accepted, such
           as T20363. Now that we are stricter, this caused further issues,
           culminating in Core Lint errors. However, the behaviour was
           incorrect the whole time; the incorrectness only being revealed by
           this change, not triggered by it.
      
           This patch fixes this by overhauling where the representation
           polymorphism involving pattern matching are done. Instead of doing
           it in `tcMatches`, we instead ensure that the `matchExpected`
           functions such as `matchExpectedFunTys`, `matchActualFunTySigma`,
           `matchActualFunTysRho` allow return argument pattern types which
           have a fixed RuntimeRep (as defined in Note [Fixed RuntimeRep]).
           This ensures that the pattern matching code only ever handles types
           with a known runtime representation. One exception was that
           patterns with an unknown representation type could sneak in via
           `tcConPat`, which points to a missing representation-polymorphism
           check, which this patch now adds.
      
           This means that we now reject the program in #20363, at least until
           we implement PHASE 2 of FixedRuntimeRep (allowing type families in
           RuntimeRep positions). The aforementioned refactoring, in which
           checks have been moved to `matchExpected` functions, is a first
           step in implementing PHASE 2 for patterns.
      
      Fixes #20837
      8eadea67
  30. Mar 02, 2022
    • sheaf's avatar
      Introduce ConcreteTv metavariables · b27b2af3
      sheaf authored and Marge Bot's avatar Marge Bot committed
        This patch introduces a new kind of metavariable, by adding the
        constructor `ConcreteTv` to `MetaInfo`. A metavariable with
        `ConcreteTv` `MetaInfo`, henceforth a concrete metavariable, can only
        be unified with a type that is concrete (that is, a type that answers
        `True` to `GHC.Core.Type.isConcrete`).
      
        This solves the problem of dangling metavariables in `Concrete#`
        constraints: instead of emitting `Concrete# ty`, which contains a
        secret existential metavariable, we simply emit a primitive equality
        constraint `ty ~# concrete_tv` where `concrete_tv` is a fresh concrete
        metavariable.
      
        This means we can avoid all the complexity of canonicalising
        `Concrete#` constraints, as we can just re-use the existing machinery
        for `~#`.
      
        To finish things up, this patch then removes the `Concrete#` special
        predicate, and instead introduces the special predicate `IsRefl#`
        which enforces that a coercion is reflexive.
        Such a constraint is needed because the canonicaliser is quite happy
        to rewrite an equality constraint such as `ty ~# concrete_tv`, but
        such a rewriting is not handled by the rest of the compiler currently,
        as we need to make use of the resulting coercion, as outlined in the
        FixedRuntimeRep plan.
      
        The big upside of this approach (on top of simplifying the code)
        is that we can now selectively implement PHASE 2 of FixedRuntimeRep,
        by changing individual calls of `hasFixedRuntimeRep_MustBeRefl` to
        `hasFixedRuntimeRep` and making use of the obtained coercion.
      b27b2af3
  31. Oct 26, 2021
    • sheaf's avatar
      Don't default type variables in type families · 9cc6c193
      sheaf authored and Marge Bot's avatar Marge Bot committed
        This patch removes the following defaulting of type variables
        in type and data families:
      
          - type variables of kind RuntimeRep defaulting to LiftedRep
          - type variables of kind Levity defaulting to Lifted
          - type variables of kind Multiplicity defaulting to Many
      
        It does this by passing "defaulting options" to the `defaultTyVars`
        function; when calling from `tcTyFamInstEqnGuts` or
        `tcDataFamInstHeader` we pass options that avoid defaulting.
      
        This avoids wildcards being defaulted, which caused type families
        to unexpectedly fail to reduce.
      
        Note that kind defaulting, applicable only with -XNoPolyKinds,
        is not changed by this patch.
      
        Fixes #17536
      
      -------------------------
      Metric Increase:
          T12227
      -------------------------
      9cc6c193
  32. Oct 17, 2021
    • sheaf's avatar
      Introduce Concrete# for representation polymorphism checks · 81740ce8
      sheaf authored and Marge Bot's avatar Marge Bot committed
      PHASE 1: we never rewrite Concrete# evidence.
      
      This patch migrates all the representation polymorphism checks to
      the typechecker, using a new constraint form
      
        Concrete# :: forall k. k -> TupleRep '[]
      
      Whenever a type `ty` must be representation-polymorphic
      (e.g. it is the type of an argument to a function), we emit a new
      `Concrete# ty` Wanted constraint. If this constraint goes
      unsolved, we report a representation-polymorphism error to the user.
      The 'FRROrigin' datatype keeps track of the context of the
      representation-polymorphism check, for more informative error messages.
      
      This paves the way for further improvements, such as
      allowing type families in RuntimeReps and improving the soundness
      of typed Template Haskell. This is left as future work (PHASE 2).
      
      fixes #17907 #20277 #20330 #20423 #20426
      
      updates haddock submodule
      
      -------------------------
      Metric Decrease:
          T5642
      -------------------------
      81740ce8
Loading