<feed xmlns='http://www.w3.org/2005/Atom'>
<title>delta/haskell.git, branch wip/T17841</title>
<subtitle>gitlab.haskell.org: ghc/ghc.git
</subtitle>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/haskell.git/'/>
<entry>
<title>Refactoring in TcSMonad</title>
<updated>2020-03-12T09:07:20+00:00</updated>
<author>
<name>Simon Peyton Jones</name>
<email>simonpj@microsoft.com</email>
</author>
<published>2020-03-11T15:29:07+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/haskell.git/commit/?id=9d87ced6832e75fce1e01b67bc6b7d9d1cf31efb'/>
<id>9d87ced6832e75fce1e01b67bc6b7d9d1cf31efb</id>
<content type='text'>
This patch is just refactoring: no change in
behaviour.

I removed the rather complicated
    checkConstraintsTcS
    checkTvConstraintsTcS

in favour of simpler functions
    emitImplicationTcS
    emitTvImplicationTcS
    pushLevelNoWorkList

The last of these is a little strange, but overall
it's much better I think.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This patch is just refactoring: no change in
behaviour.

I removed the rather complicated
    checkConstraintsTcS
    checkTvConstraintsTcS

in favour of simpler functions
    emitImplicationTcS
    emitTvImplicationTcS
    pushLevelNoWorkList

The last of these is a little strange, but overall
it's much better I think.
</pre>
</div>
</content>
</entry>
<entry>
<title>Wrap an implication around class-sig kind errors</title>
<updated>2020-03-12T09:07:20+00:00</updated>
<author>
<name>Simon Peyton Jones</name>
<email>simonpj@microsoft.com</email>
</author>
<published>2020-03-11T15:23:52+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/haskell.git/commit/?id=3f431587c2db712136a3b5a353758ca63e1a5fd8'/>
<id>3f431587c2db712136a3b5a353758ca63e1a5fd8</id>
<content type='text'>
Ticket #17841 showed that we can get a kind error
in a class signature, but lack an enclosing implication
that binds its skolems.

This patch

* Adds the wrapping implication: the new call to
  checkTvConstraints in tcClassDecl1

* Simplifies the API to checkTvConstraints, which
  was not otherwise called at all.

* Simplifies TcErrors.report_unsolved by *not*
  initialising the TidyEnv from the typechecker lexical
  envt.  It's enough to do so from the free vars of the
  unsolved constraints; and we get silly renamings if
  we add variables twice: once from the lexical scope
  and once from the implication constraint.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Ticket #17841 showed that we can get a kind error
in a class signature, but lack an enclosing implication
that binds its skolems.

This patch

* Adds the wrapping implication: the new call to
  checkTvConstraints in tcClassDecl1

* Simplifies the API to checkTvConstraints, which
  was not otherwise called at all.

* Simplifies TcErrors.report_unsolved by *not*
  initialising the TidyEnv from the typechecker lexical
  envt.  It's enough to do so from the free vars of the
  unsolved constraints; and we get silly renamings if
  we add variables twice: once from the lexical scope
  and once from the implication constraint.
</pre>
</div>
</content>
</entry>
<entry>
<title>Make DeriveFunctor-generated code require fewer beta reductions</title>
<updated>2020-03-12T00:34:14+00:00</updated>
<author>
<name>Ryan Scott</name>
<email>ryan.gl.scott@gmail.com</email>
</author>
<published>2020-03-06T16:47:56+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/haskell.git/commit/?id=cb93a1a4405b448e83cad973f93dab3f7f050736'/>
<id>cb93a1a4405b448e83cad973f93dab3f7f050736</id>
<content type='text'>
Issue #17880 demonstrates that `DeriveFunctor`-generated code is
surprisingly fragile when rank-_n_ types are involved. The culprit is
that `$fmap` (the algorithm used to generate `fmap` implementations)
was too keen on applying arguments with rank-_n_ types to lambdas,
which fail to typecheck more often than not.

In this patch, I change `$fmap` (both the specification and the
implementation) to produce code that avoids creating as many lambdas,
avoiding problems when rank-_n_ field types arise.
See the comments titled "Functor instances" in `TcGenFunctor` for a
more detailed description. Not only does this fix #17880, but it also
ensures that the code that `DeriveFunctor` generates will continue
to work after simplified subsumption is implemented (see #17775).

What is truly amazing is that #17880 is actually a regression
(introduced in GHC 7.6.3) caused by commit
49ca2a37bef18aa57235ff1dbbf1cc0434979b1e, the fix #7436. Prior to
that commit, the version of `$fmap` that was used was almost
identical to the one used in this patch! Why did that commit change
`$fmap` then? It was to avoid severe performance issues that would
arise for recursive `fmap` implementations, such as in the example
below:

```hs
data List a = Nil | Cons a (List a) deriving Functor

-- ===&gt;

instance Functor List where
  fmap f Nil = Nil
  fmap f (Cons x xs) = Cons (f x) (fmap (\y -&gt; f y) xs)
```

The fact that `\y -&gt; f y` was eta expanded caused significant
performance overheads. Commit
49ca2a37bef18aa57235ff1dbbf1cc0434979b1e fixed this performance
issue, but it went too far. As a result, this patch partially
reverts 49ca2a37bef18aa57235ff1dbbf1cc0434979b1e.

To ensure that the performance issues pre-#7436 do not resurface,
I have taken some precautionary measures:

* I have added a special case to `$fmap` for situations where the
  last type variable in an application of some type occurs directly.
  If this special case fires, we avoid creating a lambda expression.
  This ensures that we generate
  `fmap f (Cons x xs) = Cons (f x) (fmap f xs)` in the derived
  `Functor List` instance above. For more details, see
  `Note [Avoid unnecessary eta expansion in derived fmap implementations]`
  in `TcGenFunctor`.
* I have added a `T7436b` test case to ensure that the performance
  of this derived `Functor List`-style code does not regress.

When implementing this, I discovered that `$replace`, the algorithm
which generates implementations of `(&lt;$)`, has a special case that is
very similar to the `$fmap` special case described above. `$replace`
marked this special case with a custom `Replacer` data type, which
was a bit overkill. In order to use the same machinery for both
`Functor` methods, I ripped out `Replacer` and instead implemented
a simple way to detect the special case. See the updated commentary
in `Note [Deriving &lt;$]` for more details.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Issue #17880 demonstrates that `DeriveFunctor`-generated code is
surprisingly fragile when rank-_n_ types are involved. The culprit is
that `$fmap` (the algorithm used to generate `fmap` implementations)
was too keen on applying arguments with rank-_n_ types to lambdas,
which fail to typecheck more often than not.

In this patch, I change `$fmap` (both the specification and the
implementation) to produce code that avoids creating as many lambdas,
avoiding problems when rank-_n_ field types arise.
See the comments titled "Functor instances" in `TcGenFunctor` for a
more detailed description. Not only does this fix #17880, but it also
ensures that the code that `DeriveFunctor` generates will continue
to work after simplified subsumption is implemented (see #17775).

What is truly amazing is that #17880 is actually a regression
(introduced in GHC 7.6.3) caused by commit
49ca2a37bef18aa57235ff1dbbf1cc0434979b1e, the fix #7436. Prior to
that commit, the version of `$fmap` that was used was almost
identical to the one used in this patch! Why did that commit change
`$fmap` then? It was to avoid severe performance issues that would
arise for recursive `fmap` implementations, such as in the example
below:

```hs
data List a = Nil | Cons a (List a) deriving Functor

-- ===&gt;

instance Functor List where
  fmap f Nil = Nil
  fmap f (Cons x xs) = Cons (f x) (fmap (\y -&gt; f y) xs)
```

The fact that `\y -&gt; f y` was eta expanded caused significant
performance overheads. Commit
49ca2a37bef18aa57235ff1dbbf1cc0434979b1e fixed this performance
issue, but it went too far. As a result, this patch partially
reverts 49ca2a37bef18aa57235ff1dbbf1cc0434979b1e.

To ensure that the performance issues pre-#7436 do not resurface,
I have taken some precautionary measures:

* I have added a special case to `$fmap` for situations where the
  last type variable in an application of some type occurs directly.
  If this special case fires, we avoid creating a lambda expression.
  This ensures that we generate
  `fmap f (Cons x xs) = Cons (f x) (fmap f xs)` in the derived
  `Functor List` instance above. For more details, see
  `Note [Avoid unnecessary eta expansion in derived fmap implementations]`
  in `TcGenFunctor`.
* I have added a `T7436b` test case to ensure that the performance
  of this derived `Functor List`-style code does not regress.

When implementing this, I discovered that `$replace`, the algorithm
which generates implementations of `(&lt;$)`, has a special case that is
very similar to the `$fmap` special case described above. `$replace`
marked this special case with a custom `Replacer` data type, which
was a bit overkill. In order to use the same machinery for both
`Functor` methods, I ripped out `Replacer` and instead implemented
a simple way to detect the special case. See the updated commentary
in `Note [Deriving &lt;$]` for more details.
</pre>
</div>
</content>
</entry>
<entry>
<title>Use a Set to represent Ways</title>
<updated>2020-03-12T00:33:37+00:00</updated>
<author>
<name>Sylvain Henry</name>
<email>sylvain@haskus.fr</email>
</author>
<published>2020-03-05T19:44:57+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/haskell.git/commit/?id=a6989971379c26d8c288551d536149675e009e34'/>
<id>a6989971379c26d8c288551d536149675e009e34</id>
<content type='text'>
Should make `member` queries faster and avoid messing up with missing
`nubSort`.

Metric Increase:
    hie002
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Should make `member` queries faster and avoid messing up with missing
`nubSort`.

Metric Increase:
    hie002
</pre>
</div>
</content>
</entry>
<entry>
<title>Refactor interpreterDynamic and interpreterProfiled</title>
<updated>2020-03-12T00:33:37+00:00</updated>
<author>
<name>Sylvain Henry</name>
<email>sylvain@haskus.fr</email>
</author>
<published>2020-03-05T17:25:55+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/haskell.git/commit/?id=bc41e47123b205a45385a3aa69de97ce22686423'/>
<id>bc41e47123b205a45385a3aa69de97ce22686423</id>
<content type='text'>
* `interpreterDynamic` and `interpreterProfiled` now take `Interp`
  parameters instead of DynFlags

* slight refactoring of `ExternalInterp` so that we can read the iserv
  configuration (which is pure) without reading an MVar.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* `interpreterDynamic` and `interpreterProfiled` now take `Interp`
  parameters instead of DynFlags

* slight refactoring of `ExternalInterp` so that we can read the iserv
  configuration (which is pure) without reading an MVar.
</pre>
</div>
</content>
</entry>
<entry>
<title>Refactor GHC.Driver.Session (Ways and Flags)</title>
<updated>2020-03-12T00:33:37+00:00</updated>
<author>
<name>Sylvain Henry</name>
<email>sylvain@haskus.fr</email>
</author>
<published>2020-03-05T10:17:46+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/haskell.git/commit/?id=8e6febcee4b91a88a5027baac4bee5a8847fe79b'/>
<id>8e6febcee4b91a88a5027baac4bee5a8847fe79b</id>
<content type='text'>
* extract flags and ways into their own modules (with some renaming)

* remove one SOURCE import of GHC.Driver.Session from GHC.Driver.Phases

* when GHC uses dynamic linking (WayDyn), `interpWays` was only
  reporting WayDyn even if the host was profiled (WayProf).  Now it
  returns both as expected (might fix #16803).

* `mkBuildTag :: [Way] -&gt; String` wasn't reporting a canonical tag for
  differently ordered lists. Now we sort and nub the list to fix this.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* extract flags and ways into their own modules (with some renaming)

* remove one SOURCE import of GHC.Driver.Session from GHC.Driver.Phases

* when GHC uses dynamic linking (WayDyn), `interpWays` was only
  reporting WayDyn even if the host was profiled (WayProf).  Now it
  returns both as expected (might fix #16803).

* `mkBuildTag :: [Way] -&gt; String` wasn't reporting a canonical tag for
  differently ordered lists. Now we sort and nub the list to fix this.
</pre>
</div>
</content>
</entry>
<entry>
<title>Zero any slop after compaction in compacting GC</title>
<updated>2020-03-11T12:20:27+00:00</updated>
<author>
<name>Ömer Sinan Ağacan</name>
<email>omeragacan@gmail.com</email>
</author>
<published>2020-03-10T13:44:03+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/haskell.git/commit/?id=3aa9b35fcc417ab39d8da633482fe64dc9f898b1'/>
<id>3aa9b35fcc417ab39d8da633482fe64dc9f898b1</id>
<content type='text'>
In copying GC, with the relevant debug flags enabled, we release the old
blocks after a GC, and the block allocator zeroes the space before
releasing a block. This effectively zeros the old heap.

In compacting GC we reuse the blocks and previously we didn't zero the
unused space in a compacting generation after compaction. With this
patch we zero the slop between the free pointer and the end of the block
when we're done with compaction and when switching to a new block
(because the current block doesn't have enough space for the next object
we're shifting).
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
In copying GC, with the relevant debug flags enabled, we release the old
blocks after a GC, and the block allocator zeroes the space before
releasing a block. This effectively zeros the old heap.

In compacting GC we reuse the blocks and previously we didn't zero the
unused space in a compacting generation after compaction. With this
patch we zero the slop between the free pointer and the end of the block
when we're done with compaction and when switching to a new block
(because the current block doesn't have enough space for the next object
we're shifting).
</pre>
</div>
</content>
</entry>
<entry>
<title>Deepen call stack for isIn</title>
<updated>2020-03-11T12:19:44+00:00</updated>
<author>
<name>Simon Peyton Jones</name>
<email>simonpj@microsoft.com</email>
</author>
<published>2020-03-10T10:24:28+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/haskell.git/commit/?id=c61b9b02925acf248cde1ec0f67730c1a6f6c6e5'/>
<id>c61b9b02925acf248cde1ec0f67730c1a6f6c6e5</id>
<content type='text'>
I see quite a few warnings like:

  WARNING: file compiler/utils/Util.hs, line 593
    Over-long elem in unionLists

But the call stack is uninformative.   Better to add HasDebugCallStack
to isIn.  Ditto isn'tIn.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
I see quite a few warnings like:

  WARNING: file compiler/utils/Util.hs, line 593
    Over-long elem in unionLists

But the call stack is uninformative.   Better to add HasDebugCallStack
to isIn.  Ditto isn'tIn.
</pre>
</div>
</content>
</entry>
<entry>
<title>testsuite: Mark ghci056 and ghcilink004 as fragile in unreg</title>
<updated>2020-03-11T12:19:08+00:00</updated>
<author>
<name>Ben Gamari</name>
<email>ben@smart-cactus.org</email>
</author>
<published>2020-03-09T23:12:46+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/haskell.git/commit/?id=336eac7ef049ba9feab5a948120f0f732e26f773'/>
<id>336eac7ef049ba9feab5a948120f0f732e26f773</id>
<content type='text'>
As noted in #17018.

Also fix fragile declaration of T13786, which only runs in the normal
way.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
As noted in #17018.

Also fix fragile declaration of T13786, which only runs in the normal
way.
</pre>
</div>
</content>
</entry>
<entry>
<title>Re-quantify when generalising over rewrite rule types</title>
<updated>2020-03-11T12:18:32+00:00</updated>
<author>
<name>Ryan Scott</name>
<email>ryan.gl.scott@gmail.com</email>
</author>
<published>2020-03-09T13:57:39+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/haskell.git/commit/?id=0bc23338b02ffd624247ace409ab690b2b4a6186'/>
<id>0bc23338b02ffd624247ace409ab690b2b4a6186</id>
<content type='text'>
Previously, `tcRules` would check for naughty quantification
candidates (see `Note [Naughty quantification candidates]` in
`TcMType`) when generalising over the type of a rewrite rule. This
caused sensible-looking rewrite rules (like those in #17710) to be
rejected. A more permissing (and easier-to-implement) approach is to
do what is described in `Note [Generalising in tcTyFamInstEqnGuts]`
in `TcTyClsDecls`: just re-quantify all the type variable binders,
regardless of the order in which the user specified them. After all,
the notion of type variable specificity has no real meaning in
rewrite rules, since one cannot "visibly apply" a rewrite rule.
I have written up this wisdom in
`Note [Re-quantify type variables in rules]` in `TcRules`.

As a result of this patch, compiling the `ExplicitForAllRules1` test
case now generates one fewer warning than it used to. As far as I can
tell, this is benign, since the thing that the disappearing warning
talked about was also mentioned in an entirely separate warning.

Fixes #17710.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Previously, `tcRules` would check for naughty quantification
candidates (see `Note [Naughty quantification candidates]` in
`TcMType`) when generalising over the type of a rewrite rule. This
caused sensible-looking rewrite rules (like those in #17710) to be
rejected. A more permissing (and easier-to-implement) approach is to
do what is described in `Note [Generalising in tcTyFamInstEqnGuts]`
in `TcTyClsDecls`: just re-quantify all the type variable binders,
regardless of the order in which the user specified them. After all,
the notion of type variable specificity has no real meaning in
rewrite rules, since one cannot "visibly apply" a rewrite rule.
I have written up this wisdom in
`Note [Re-quantify type variables in rules]` in `TcRules`.

As a result of this patch, compiling the `ExplicitForAllRules1` test
case now generates one fewer warning than it used to. As far as I can
tell, this is benign, since the thing that the disappearing warning
talked about was also mentioned in an entirely separate warning.

Fixes #17710.
</pre>
</div>
</content>
</entry>
</feed>
