Commit Graph

33 Commits

Author SHA1 Message Date
Sophie Taylor
6a0125b9b7 Support GHC 9.2 2021-11-23 11:51:43 +01:00
Torsten Schmits
e9e791c4f3 add test case 2021-11-22 23:27:40 +01:00
Sandy Maguire
55150644c4
Remove custom type errors from Member (#429)
* Remove Member type errors

* Remove unused custom type errors

* Deprecate MemberWithError

* Remove readme notes about type errors

* Remove MemberWithError
2021-11-16 15:01:45 -08:00
Sandy Maguire
c0cf61ea1f
Plugin: Solve ambiguous types based on instances in scope (#424)
* Properly track skolems for plugin unification

* Cleanup imports

* Add test

* Stuff can now reference different packages

* Tools for looking up instances

* Add extra evidence

* Solve AmbiguousSpec :)

* Check givens for extra evidence

* Use StateT to cache instance lookups

* Remove numClass from Stuff

* Documentation

* Fix AmbiguousSpec

* Don't need deriving strategies anymore

* GHC9 imports

* Polymorphic and MTPC tests
2021-10-22 15:29:29 -07:00
Sandy Maguire
f30da0c178
Properly track skolems for plugin unification (#423)
* Properly track skolems for plugin unification

* Update haddock

* Cleanup imports

* Guard the import of unify
2021-10-20 16:16:48 -07:00
Torsten Schmits
6e2630fafd Add insertAt
A combinator that allows adding effects at a specified index into the
effect stack
2021-07-08 17:43:52 +02:00
Torsten Schmits
95c534bb10
start migration to ghc9 (#410)
* start migration to ghc9

* add ghc9 support for polysemy-plugin

* bump doctest version in package.yaml

* fix doctest message containing incorrect spaces

Co-authored-by: funketh <theodor.k.funke@gmail.com>
2021-05-03 16:45:18 +02:00
Samuel Evans-Powell
95b4b5508c Feature/cabal doctest and ghc 8.8.1 (#267)
* Use cabal-doctest

- Haskell build tools run in slightly different environments (meaning different
  package databases are available).
- The nixpkgs build for polysemy-plugin is failing due to a missing package
  database, which causes the doctest to fail (more information here:
  https://github.com/NixOS/nixpkgs/issues/71164).
- By using cabal-doctest we can expose the Haskell packages required to the
  doctests no matter the build tool we're using.

* Use cabal-doctest in polysemy, build on GHC 8.8.1

- Use @googleson78 's changes to build polysemy on GHC 8.8.1, with slight
  modifications. The source distribution is now found in "dist-newstyle/sdist",
  so we've updated the command to point at that folder. Additionally, cabal
  v2-install doesn't support installing .tar.gz files in the same way v1-install
  did, so updated the command to use "cabal v1-install".
- Modified polysemy to use "cabal-doctest" and so overcome issues with the
  doctest tests (see issue #258, PR #265).
2019-10-28 17:13:44 +01:00
Sandy Maguire
a86aec37fb
Revert "Let plugin solve stuck type rows + bug fixes in interpreter mode (#245)" (#249)
This reverts commit 7a009f70b6.
2019-10-09 14:35:07 +02:00
Sandy Maguire
7a009f70b6
Let plugin solve stuck type rows + bug fixes in interpreter mode (#245)
In interpreter mode, the plugin used to see rows like State (Identity a) ': State a ': r, with an action in State a, and then incorrectly unify that thing with the first thing in the list State (Identity a). As a result, we'd ask for Identity a ~ a, which is infinite, and things would go wrong.

Now we instead collect all of the unifications we'd like to do, and only emit the most specific one, as measured by number of type constructors in it. This will now only emit a State (Identity a) ~ State (Identity s), and then unify the state we're looking for, plus the a ~ s that solves the other state action.

But the next problem is that we can't determine IndexOf in the row above, because a is a type variable, and so IndexOf is stuck, even though we know IndexOf that_row (State a) ~ 'S 'Z. So the plugin now also solves "stuck" IndexOfs of that form.

All of this means we can now happily introduce local effects that have type variables, for effects that are already known to be present in the row. And somehow it just works! Amazing!
2019-10-09 14:07:46 +02:00
KingoftheHomeless
7bda143878
polysemy-plugin: Reject ununifiable effect candidates early (#221)
* polysemy-plugin: Reject ununifiable effect candidates early

* Bump version, update changelog, expand tests
2019-09-04 17:11:01 +02:00
KingoftheHomeless
4a5f2ce92a
Add Final Effect (#217)
* Add Final Effect

* Changes per review, Final at top-level, doc changes

* Update Changelog

* Final touches to Final

* Revert change to stack.yaml
2019-08-30 22:38:53 +02:00
Sandy Maguire
de1607ea1b
Rename everything and its grandmother (#175) 2019-07-15 12:40:42 -04:00
Georgi Lyubenov
48b6768ad4 Rename Lift to Embed (#161)
* Move Polysemy.Internal.Lift to Polysemy.Lift.Type

* Add Polysemy.Lift module and runLift interpreter

* Add a Sandy reminder

* Add explicit foralls and split type signature

* Fix import spacing, for there is no "qualified"

* Implement runIO in terms of runLift

* Rename Lift -> Embed

* Replace sendM with embed

* Add a Sandy todo for embed version

* Rename runEmbed and related runEmbedded (from IO)

* runEmbedded -> runEmbeddedInIO
* runEmbed -> runEmbedded

* Update cabal
2019-07-11 11:02:26 -04:00
TheMatten
ec03b04e8e Fix ambiguously looking variables in smart constructors, refactor Polysemy.Internal.TH.Common 2019-07-08 21:52:29 +02:00
Sandy Maguire
ef5ff1749a
Don't emit ambiguous effect errors for genuine type errors (#149)
This PR changes the plugin so it will notice an insoluble constraint of the form Sem r a ~ Foo, and mark that r takes part in a genuine type error. The plugin will then provide a bogus evidence term for IfStuck (IndexOf r _) _ _, which prevents the AmbiguousSend error message from firing.
2019-07-04 09:35:33 -04:00
TheMatten
8bbd9dc7d6 Use new, separate loopbreaker library for inlining (#145)
* Remove explicit loopbreakers, enable plugin

* Use uploaded version of `loopbreaker`

* Fix span of macro

* Disable plugin on GHC <8.6

* Add comment about use of plugin

* Separate unrelated conditions
2019-07-01 02:13:37 -04:00
Sandy Maguire
29216ceb69
Improve CI coverage -- now on GHC 8.4! (#39) 2019-06-19 17:25:37 -04:00
Sandy Maguire
6ffb4fd282
Remove Effect class (#118)
This thing was a vestige of the bad old days when you had to write
*instances* of classes things in Polysemy. It was a terrible experience,
and so we don't do that anymore. As a result, the only two instances of
`Effect` were for `Union` and `Yo` --- so I just inlined them.
2019-06-17 15:16:28 -04:00
Sandy Maguire
82f86add29
Custom type error testing (#113)
This PR adds doctests allowing us to write tests for the custom type errors. Having this stuff reified in the test suite means we can iterate on the implementations and give much better QA.
2019-06-15 20:04:11 -04:00
Sandy Maguire
e90c745d7a
Allow bidirectional typechecking in the plugin (#105)
* Allow bidirectional typechecking in the plugin

The plugin used to choke on this:

```haskell
flipShouldBe 11 . sum . fst . run . runFoldMapOutput id $ do
  output [1]
  output $ replicate 2 5
```

because it would fail to unify `Output (t Int)` (the polymorphic
`Traversable` variable in `sum`) with `Output [Int]`.

In this case, there are no given constraints, so the plugin is
attempting to solve a `Member (Output (t Int)) '[Output [Int]]`. We
reuse the codepath for unifying wanted/givens, pretending like the
`Output (t Int)` is a given.[^1]

[^1]: Pretending it's a wanted breaks something else that I don't
remember right now. This code is brittle :(

So now we have a "wanted" `Output [Int]`, and a "given" `Output (t
Int)`. In general, this thing isn't OK to solve. Consider a real
example:

```haskell
foo :: Member (Output (t Int)) r => Sem r ()
foo = output [5]
```

This is a type error, because the polymorphism goes the wrong way. We
have no guarantees that `t` is supposed to be `[]`.

But in our original example, this isn't a problem, because our `t` isn't
actually in given position. It's just an artifact of reusing the code!
`mkWanted` now takes a new parameter for whether or not it's OK to allow
the givens to be polymorphic.

Such a thing necessitates a change though. We never want to unify
a polymorphic *effect* in given position. Doing so will break Haskell's
regular type inference that determines what the effect row should be,
based on the order in which the interpreters are run.
2019-06-14 11:28:14 -04:00
Sandy Maguire
fc88a961ad
Ensure wanted constraints are emitted only once. (#102)
* Ensure wanted constraints are emitted only once.

This is a fix for the "solveSimpleWanteds: too many iterations" problem
that people are running into. In these cases, the plugin is being asked
to solve the same `Member` constraint several times, and generating
a new wanted each time. In doing so, GHC thinks that work was done, so
it will ask the plugin to run again next time. This process diverges,
and produces the error.

Fixes #79
2019-06-13 14:39:49 -04:00
Sandy Maguire
b7f2922c3a
Better Resource bracketing (#87) 2019-06-12 09:36:08 -04:00
Sandy Maguire
66be47036d
Perform recursive unification attempts in the plugin (#96) 2019-06-09 00:20:23 -04:00
Sandy Maguire
f5dcbe3c98
Fixes #54 (#85) 2019-06-05 09:44:34 -04:00
Sandy Maguire
0f41b3fddf Test for #47 2019-06-05 03:44:31 -04:00
Sandy Maguire
63b1f4257f
GetInspectorT (#71)
* Evacuation wip

* Two other uses of weave

* Evacuator -> Inspector

* Inspector test
2019-05-31 00:06:46 -04:00
Sandy Maguire
7cc2f8c567 Fix #68 2019-05-28 15:48:03 -04:00
Sandy Maguire
feacd2a001
Fix the plugin (#62) 2019-05-23 17:05:32 -04:00
Sandy Maguire
ff222d826a
Automatically inline recursive calls in the plugin (#52)
* Inline recursive calls + bonus passes for inlining

* Broken inspection test

* Bug in inspection testing

* Deprecate inlineRecursiveCalls

* Move inlineRecursiveCalls into the deprecated section
2019-05-20 02:15:18 -04:00
Sandy Maguire
c3e13cadc7 Let plugin deal with incorrect polymorphism 2019-05-01 15:13:51 -04:00
Sandy Maguire
ec58986443 Plugin works + tests 2019-04-27 22:39:18 -04:00
Sandy Maguire
30169352e4 plugin 2019-04-20 18:31:17 -04:00