Commit Graph

307 Commits

Author SHA1 Message Date
Edwin Brady
1cf9849a55 Add the bits of Chapter 12 that work
Still need enumeration syntax for the rest
2019-07-10 20:22:00 +02:00
Edwin Brady
fd4f90e331 Add some Control.Monad things
This required a small change to auto implicit search (and I'm still not
sure about this). Now search arguments right to left, because solving
later arguments may resolve earlier arguments by unification and this
can happen in particular when chasing parent interfaces (which may have
fewer parameters).
2019-07-10 20:18:40 +02:00
Edwin Brady
9f6a3fd2b8 Fix in scheme backend and test script
At least on Linux, \r needs to be in singles quotes as an argument to tr
or it removes all the 'r' instead! Hopefully it also works this way on
Windows...
2019-07-10 17:23:45 +02:00
Edwin Brady
a422294f36 Pass auto implicits through interfaces
This allows 'traverse' to work now (it was treating them as normal
implicits, so building the wrong form of application)
2019-07-10 17:23:33 +02:00
Niklas Larsson
28438650d0 windows support 2019-07-10 01:51:41 +02:00
Edwin Brady
2487c30232 Adding missing test files 2019-07-09 09:22:50 +02:00
Edwin Brady
2bb496f74b Chapter 11 examples now working 2019-07-08 23:46:20 +02:00
Edwin Brady
164a0a60cf Add Chapter 10 TypeDD tests
A lot to change here! To be honest, this chapter probably needs a
complete revision...
2019-07-08 13:04:39 +02:00
Edwin Brady
11199acab6 Improve 'with' implementation
Now supports with applications on the RHS when auto implicits are
involved. Auto implicit bound names in patterns now become searches on
the rhs in a with-application (I should write this construct up properly
in a paper some time!)
2019-07-08 12:55:55 +02:00
Edwin Brady
51c406ff7d Deal with non-existent files more gracefully
So now you can start idris2 with a non-existent file and use :e to start
editing it
2019-07-07 13:10:14 +01:00
Edwin Brady
fc224b1450 Fix Total004 test
Names in Data.List clashed
2019-07-06 15:55:47 +01:00
Edwin Brady
4ab543b83d A bit more library support, for Chapter 9
Also a tweak to errors when compiling to scheme, so that it properly
reports an error then quits if it's supposed to crash.
2019-07-05 17:24:15 +01:00
Edwin Brady
5fc0aa8248 Add Chapter 8 tests 2019-07-05 11:28:37 +01:00
Edwin Brady
7c34fa1db4 Change equality elaboration
Elaborate via either === (homogeneous equality) or ~=~ (heterogeneous
equality) both of which are synonyms for Equal. This is to get the Idris
1 behaviour that equality is homogeneous by default to reduce the need
for type annotations, but heterogeneous if that doesn't work.
2019-07-05 11:26:45 +01:00
Edwin Brady
40d9235b3f Allow ambiguity when chasing parent interfaces
There's a bit of a trade off here. It would be better to report the
ambiguity but this would lead to a need for (I think) excessive
precision in types which would impact usability. It will always take the
leftmost interface.

Chapter 7 tests added.
2019-07-05 10:29:41 +01:00
Edwin Brady
aa58114671 Add 'last chance' unification and tweak guesses
Idris 1 will fill in the last metavariables by matching rather than
unification, as a convenience. I still think this is okay, even if it's
a bit hacky, because it's a huge convenience and doesn't affect other
unification problems.

Also abstract over lets in guesses, like in delayed elaborators, to
avoid any difficulties when linearity checking and to make sure that let
bound things don't get reevaluated.

This is enough to get the Chapter 6 TypeDD tests working
2019-07-05 00:09:00 +01:00
Edwin Brady
c260f6c90e Improve dot patterns
Allow matching rather than unification, as long as it doesn't solve any
metavariables on the way. I noticed a potential unification bug on the
way, forgetting to update whether holes are solved when unifying
argument lists.
2019-07-04 23:16:08 +01:00
Edwin Brady
6f5d3f5fef Unelaborate hole applications properly
This was left over from Blodwen (where it was also wrong :)) but the way
we apply metavariables now means we don't need to do anything fancy when
unelaborating them for pretty printing.
2019-07-03 15:31:46 +01:00
Edwin Brady
89c8314a0f Desugar pattern matching lambdas 2019-07-03 15:11:57 +01:00
Edwin Brady
0f56c239c2 Parse pattern matching lambda
This is now enough for Chapter 5 tests to work
2019-07-03 13:04:25 +01:00
Edwin Brady
e526badfe2 Delay case elaboration
This helps a few things because it delays elaboration of the block until
as much as possible is known about its type.

Also added a few libraries.
2019-07-02 16:53:41 +01:00
Edwin Brady
5eec46f6ce TypeDD chapter 4 tests 2019-07-01 21:35:19 +01:00
Edwin Brady
00514887c4 More base libraries
This has shown up a problem with 'case' which is hard to fix - since it
works by generating a function with the appropriate type, it's hard to
ensure that let bindings computational behaviour is propagated while
maintaining appropriate dependencies between arguments and keeping the
let so that it only evaluates once. So, I've disabled the computational
behaviour of 'let' inside case blocks. I hope this isn't a big
inconvenience (there are workarounds if it's ever needed, anyway).
2019-06-30 23:54:50 +01:00
Edwin Brady
577b68dd5a Make a start on Data.Vect 2019-06-30 17:38:40 +01:00
Edwin Brady
f2dff5cae4 Normalise holes in error messages
The solved holes may not outlive the error, so normalise before throwing
so that they can be displayed properly.
2019-06-30 17:23:19 +01:00
Edwin Brady
f37da6c5b7 Start adding tests for TypeDD book
Also detailing any changes needed to the code. Added primitives for
Doubles, and repl/replWith to get Chapter 2 code to work.
2019-06-30 15:50:58 +01:00
Edwin Brady
eddb23d108 Need to save postponed names in ttc too
Flag these when searching names for references
2019-06-30 12:49:11 +01:00
Edwin Brady
ae777b8dcb Add parameters blocks 2019-06-29 23:55:17 +01:00
Edwin Brady
2f4cdf857d Make typecase on -> work 2019-06-29 22:43:06 +01:00
Edwin Brady
17c862fe00 Add parse error tests from Blodwen 2019-06-29 21:37:30 +01:00
Edwin Brady
f9ea1ff329 Updating typecase, add tests 2019-06-29 21:32:19 +01:00
Edwin Brady
7aa8a71f8f Fix loading of hints, and add test
Need to add by full name, due to ordering of loading (the name it's
attached to may not be resolved yet!). This doesn't seem to cause any
performance problems but we can revisit if it does.
2019-06-29 20:51:48 +01:00
Edwin Brady
e463a2864a Add a couple more tests 2019-06-29 20:03:00 +01:00
Edwin Brady
a65d1efa38 Throw error if case type is not inferred
This is probably quite rare to want, but we could consider putting this
under a delayOnFailure
2019-06-29 19:39:11 +01:00
Edwin Brady
99dac56e1e Make sure matches are not too specific
i.e. if an argument has a polymorphic type, we shouldn't allow a
concrete type in its place
2019-06-29 19:28:04 +01:00
Edwin Brady
cda87a9c16 Fix coverage checker issue
Don't use the type of a scrutinee to restrict possible patterns, because
it might have been refined by a Rig0 argument that has a missing case.
Instead, generate all the possible cases and check that the generated
ones are impossible (there's no obvious change in performance)
2019-06-29 16:41:26 +01:00
Edwin Brady
9b44839c57 Add test for eta 2019-06-28 12:43:55 +01:00
Edwin Brady
e9a3167e2f Even more tests
Small change needed to fix one - assume given implicits which are of the
form x@_ arise from types. It's a bit of a hack but I don't think
there's any need for anything more complicated.
2019-06-27 20:19:00 +01:00
Edwin Brady
110a7461fc More tests from Blodwen 2019-06-27 19:33:02 +01:00
Edwin Brady
82ceedb84e Add linearity tests 2019-06-27 19:28:14 +01:00
Edwin Brady
b0cad15c65 Refine dot pattern rules
Only valid if unifying the pattern at the end doesn't solve any
metavariables. Also when elaborating applications of fromInteger etc to
constants on the LHS we need to be in expression mode, then reduce the
result later.
2019-06-27 19:16:33 +01:00
Edwin Brady
211de419bb Fix environments for nested names
This was a slight difference from Blodwen that wasn't accounted for -
there might be lets in the nested environment, so when building the
expanded application type, make sure we go under them
2019-06-27 15:26:18 +01:00
Edwin Brady
d053a18977 Set fresh name counter on loading Main ttc
Make sure this is the counter from the right namespace, or we might get
name clashes at the REPL
2019-06-27 14:47:47 +01:00
Edwin Brady
ce78abaaef Build and save references for metavars too
This wasn't necessary before, since we always inlined, but since we can
now postpone things longer and don't always inline until much later, we
need to know what names everything refers to earlier.
2019-06-27 09:01:59 +01:00
Edwin Brady
2cd81a9eb0 More tests moved over... 2019-06-25 21:50:48 +01:00
Edwin Brady
3eda2494bf Add error message tests 2019-06-25 21:46:28 +01:00
Edwin Brady
7b504e7a9e More Chez tests 2019-06-25 21:27:46 +01:00
Edwin Brady
69199639cf Fix Nat hack
And add chez scheme section to tests, with one initial test
2019-06-25 14:05:54 +01:00
Edwin Brady
bf64f843aa A bit more totality checking polish
Need to check for 'assert_total' in getRefs, and get Inf and Lazy the
right way around!
2019-06-25 12:57:49 +01:00
Edwin Brady
0b4f4ec46d Fix naming issue in totality checker
Also added a new test
2019-06-25 10:26:14 +01:00
Edwin Brady
5caa277cbe Fix some totality issues, add tests
These are related to the change in naming and metavariables, mostly
2019-06-25 00:42:52 +01:00
Edwin Brady
fb7190b337 Add first batch of totality checking tests 2019-06-24 18:14:07 +01:00
Edwin Brady
b1acceb870 Add a simple lazy Inf test 2019-06-24 18:08:32 +01:00
Edwin Brady
32583d608d More interface tests
and a small fix for the generation of method types which was okay for
Blodwen, but not here
2019-06-24 18:04:43 +01:00
Edwin Brady
e9514f3c22 Add first interface tests 2019-06-24 17:36:55 +01:00
Edwin Brady
e6292acdf0 Finish adding interactive tests from Blodwen
This involved implementing the 'TryWithImplicits' hack for allowing
unbound implicits in types with case blocks
2019-06-24 16:23:32 +01:00
Edwin Brady
1e2fcb8ccd Fix small error is as patterns
Also added new interactive test
2019-06-24 15:30:36 +01:00
Edwin Brady
7a47c9ae0c Add a couple of interactive tests 2019-06-24 15:16:49 +01:00
Edwin Brady
af9dc69c61 Add record tests from Blodwen 2019-06-24 12:44:34 +01:00
Edwin Brady
0a15c2cda1 Pay attention to visibility of names
Name lookup and search should ignore names which aren't visible (that
is, private names in another namespace)
2019-06-24 00:57:22 +01:00
Edwin Brady
67a43e0000 Check names are visible/public 2019-06-24 00:12:58 +01:00
Edwin Brady
9c902de5d1 Fix case tree compiler for coverage checking
We can't refine by a name in Rig0 because we can't assume it covers all
possibilities, so only refine by them at the end, at which point we
check that there's only one case left (otherwise we have to match on it,
which is not allowed for an erased thing)
2019-06-23 20:36:06 +01:00
Edwin Brady
6a72508e80 Eliminate cycles in auto search
This is important for, e.g. interfaces with parent constraints, so we
don't keep looping making the constraint bigger
2019-06-17 09:50:05 +01:00
Edwin Brady
f5a5d01274 Turn lets to lambdas in hole environments
This works better when lifting lemmas, and ensures that the type of
everything will be shown and not normalised away
2019-06-16 23:10:32 +01:00
Edwin Brady
1be12c7f72 Block reduction of private/export names 2019-06-15 16:10:01 +01:00
Edwin Brady
772b098de0 The Prelude type checks! 2019-06-13 13:23:21 +01:00
Edwin Brady
2374f23320 Add default alternatives 2019-06-11 13:52:49 +01:00
Edwin Brady
07229bdb5e Add first Idris2 tests 2019-06-11 11:54:47 +01:00
Edwin Brady
5a3aa3b13c Some fixes for as patterns, add them implicitly
Much of the effort in renaming is to make types of holes display more
nicely!
2019-06-09 23:12:11 +01:00
Edwin Brady
146c301f6c Change main program to be Idris2
With the --yaffle flag, you get the old behaviour which is to invoke the
checker for the core theory (and all the tests are updated appropriately
for this).
2019-06-09 11:58:29 +01:00
Edwin Brady
bf67f5c87c Record mutual type definitions
Also add some tests for totality checker
2019-06-05 17:28:55 +01:00
Edwin Brady
2c6202879e Calculate missing cases via coverage checker 2019-06-02 23:43:21 +01:00
Edwin Brady
1f52530313 Implement 'impossible' 2019-06-02 21:21:07 +01:00
Edwin Brady
d6e637b2c5 Fix structural difference check in search
Now it successfully finds zipWith too
2019-06-02 15:16:54 +01:00
Edwin Brady
109dcf08f9 Add definition generation 2019-06-02 14:28:26 +01:00
Edwin Brady
af79e57ae2 Store number of locals in holes
This gives useful information for expression search, because we can add
lambdas while we're still building the environment, and start looking at
locals after that.
2019-06-02 01:23:01 +01:00
Edwin Brady
6c88bfec7a Elaborate 'with' blocks 2019-05-29 11:57:07 +01:00
Edwin Brady
a59a104230 Implement 'rewrite' expressions
Mostly direct from Blodwen (some minor modifications to deal with new
way of going into a new scope in the elaborator as well as the usual
bits dealing with name lookup and Glued terms)
2019-05-27 12:15:37 +01:00
Edwin Brady
7cc37d28b3 Add (dependent) record update
This is pretty much straight from Blodwen
2019-05-27 10:56:13 +01:00
Edwin Brady
22a5286ed9 Added record declarations
Also, since it could need it when building types, added auto implicit
binding (so no need for $ everywhere in the tests from now on...)
2019-05-26 23:51:20 +01:00
Edwin Brady
c4d7e18742 Extend unification so that Functors work
Need to identify invertible (or cancellable) holes so that we can unify
e.g. ?f Nat with List Nat and get f = List.
2019-05-26 18:41:48 +01:00
Edwin Brady
628a7bde0f Improve auto search to support interfaces
Parser now allows options on data types and functions, and elaborator
processes options so we can set up interfaces
2019-05-26 14:28:38 +01:00
Edwin Brady
3e3c224bcb Move some tests around
Add a 'search' category
2019-05-26 11:34:02 +01:00
Edwin Brady
18e0cabc26 Save hints to TTC files
And process them on loading. We record that hints need saving out when
adding them, and clear that list unless we happen to be reexporting the
thing we've just read (import public).
2019-05-25 23:31:47 +01:00
Edwin Brady
54d4d5a8ed Implement auto implicits 2019-05-25 22:13:38 +01:00
Edwin Brady
c65285a1f6 Check pattern variables don't unify with things
This is bad because it means a pattern variable isn't actually a
variable, but rather has a specific value!
2019-05-25 20:18:43 +01:00
Edwin Brady
6c7f13d128 Implement dot patterns
Like Idris 1, these are implicitly added on encountering a repeated name
or a non-constructor application. Unlike Idris 1 (and Blodwen) they are
checking by unification rather than matching (which means in particular
that function argument names can't be bound in dot patterns) which is
slightly less expressive, but better overall because matching is
potentially more error prone.
2019-05-25 18:39:21 +01:00
Edwin Brady
c75569c255 Implement laziness
Slight change of plan: instead of having special names, add Lazy, Inf,
Delay and Force and keywords and elaborate them specially.
Correspondingly, add DelayCase for case trees. Given that implicit
laziness is important, it seems better to do it this way than constantly
check whether the name we're working with is important.

This turns out to make implicit laziness much easier, because the
unifier can flag whether it had to go under a 'Delayed' to succeed, and
report that back to the elaborator which can then insert the necessary
coercion.
2019-05-22 19:42:43 +01:00
Edwin Brady
c2e1b85143 Let's not use exceptions for control flow... 2019-05-20 19:05:28 +01:00
Edwin Brady
6385cb6e0f A bit more on performance
Most notably, when elaborating deferring argument, if the hole
standing for the argument is still a hole, fill it in directly rather
than going via unification. This prevents some needless evaluation.
2019-05-20 18:41:08 +01:00
Edwin Brady
d256dbf5ec Add a test for non linear LHS 2019-05-19 20:30:27 +01:00
Edwin Brady
8081b0374a First attempt at linearity checking pass
This slows things down a bit because to find the holes and give them the
right multiplicities, we need to normalise all the arguments which might
have been metavariables. Maybe we should skip this if we're not using
anything linear, for efficiency?

As patterns are handled by deciding which side of the as is considered
'used'. In case blocks, that should be the variable name, but in general
it should be the pattern, so IAs now has a flag to say which one.
2019-05-19 20:24:14 +01:00
Edwin Brady
9bd063bbd5 Check holes are solved after elaboration
Need to record which holes are still to be solved (not counting
elaborations where there are user defined holes) and check at the end
that they are now solved.
2019-05-18 19:08:43 +01:00
Edwin Brady
1a84fde2a4 Added named holes
Unlike in blodwen, it is okay for a named hole to be solved by
unification. (Is this the right choice?)
2019-05-18 11:47:57 +01:00
Edwin Brady
5383bd89be Fix interaction between as patterns and case
There was a check on evaluating lets which was in Blodwen but I hadn't
added to the normaliser yet! Also, normalisation needs to reduce as
patterns for unification, but not when reducing finished LHS and
argument terms. This is a bit of a hack (but then, so is the
implementation of as patterns in general...).

So, when we're checking a nested expression, we have the as pattern as a
let bound variable (so that it has the necessary computational force)
but when we compile we just pass it as an ordinary argument, then it
gets the desired behaviour in case trees.
2019-05-17 18:47:20 +01:00
Edwin Brady
ea0de3d499 Initial implementation of 'case' blocks
It's not quite there yet, though, because the treatment of 'as' patterns
isn't quite right and the slightly hacky approach we're taking might not
be the best. Rethinking now...
2019-05-17 13:52:09 +01:00
Edwin Brady
984c3ff70d Implement local function definitions
Changed nested names (and case blocks) to store the resolved name as the
outer name, rather than the unresolved name, otherwise we'll have issues
when loading from TTC
2019-05-13 00:44:28 +01:00
Edwin Brady
83dc0b0e6d Add simple let bindings 2019-05-12 19:04:31 +01:00
Edwin Brady
14f717aa33 Add test for failed delayed elaborator 2019-05-12 16:03:04 +01:00
Edwin Brady
f3c31f3089 Give correct multiplicity count to arguments 2019-05-12 14:24:24 +01:00
Edwin Brady
eaff52a6e1 Use updated NF for delayed elaborators
Since the NF might refer to hole names, and those hole names might be
possible to evaluate now, we'll need to recalculate the expected type's
normal form before rerunning the delayed elaborator
2019-05-11 22:23:50 +01:00
Edwin Brady
43d323f685 First go at ambiguous name resolution
Works by running all possible elaborators and checking that exactly one
succeeds. Still to do: pruning the list of elaborators by target type,
dealing with 'UniqueDefault', checking that delaying on failure works as
it should.
2019-05-11 20:50:51 +01:00
Edwin Brady
46213a903c Store resolved ids in pattern names
It's only for keeping them unique, so this is both more efficient, and
means we can safely write them out using their resolved ids in the name
map
2019-05-11 13:00:12 +01:00
Edwin Brady
a2ce8d0b7d Add as patterns
When we encounter them, not that they're a binding as normal, but also
record the thing they expand to. Then bind as a PLet, and convert that
to a Let on the RHS so it has computational force. The case tree
compiler knows about as patterns, so they get compiled to use the
appropriate name on the rhs (rather than a let).
2019-05-09 16:48:09 +01:00
Edwin Brady
664008d046 Add operations on primitives 2019-05-08 10:21:00 +01:00
Edwin Brady
411b8ccc07 Support eta in unification
Also added (necessarily) a rule for lambdas
2019-05-07 15:06:00 +01:00
Edwin Brady
77bf4c7c44 Added test framework (copied from Blodwen) 2019-05-07 10:43:02 +01:00