Commit Graph

92 Commits

Author SHA1 Message Date
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
9f4ca9e67f Add pruneByType
This shortcuts ambiguity checking by only keeping the things which have
the target type. Given a set of ambiguous applications, the rules are:

- keep any which return the expected target type (a concrete match), or
  a polymorphic type (a possible match)
- if there are any concrete matches, drop any possible match which has
  the '%allow_overloads' flag set (in practice this will be interface
  methods, but other things can be flagged).
- if there ar eno matches, keep everything so that the error messages
  show everything that went wrong.
2019-05-21 12:11:55 +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
11a72dc953 Some small tweaks
These are attempts to allocate slightly less memory. They don't achieve
much, but also don't do any harm...
2019-05-20 13:36:32 +01:00
Edwin Brady
0ac539fdc2 Substitute a whole environment at once 2019-05-19 23:41:02 +01:00
Edwin Brady
871ca6603c Move options out of Core and into Defs
This is quite a performance win, because there's less thunking (and I
imagine more scope for inlining?)
2019-05-19 23:25:35 +01:00
Edwin Brady
f95205b8b9 Some small performances improvements
The biggest one being that logging wasn't taking the String as a lazy
argument!
2019-05-19 23:05:21 +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
c01fb4a555 Look out for cycles in implicits when normalising
This is not quite an occurs check (there's no guarantee anyone will ask
for normalisation after all) but it catches the error which will result
if there's a cyclic metavariable solution.

My plan is to implement the occurs check by going through all the
metavariables at the end of elaboration of an expression, so that we
don't do too much work checking half-finished solutions.
2019-05-15 17:50:40 +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
8d6d0c6847 Add NestedNames argument throughout elaborator
This is for tracking locally defined names, so that we can expand their
applications to the full globally lifted name. At the moment, they don't
do anything, but since it's a change throughout the elaborator it
probably deserves its own commit.
2019-05-12 19:43:01 +01:00
Edwin Brady
83dc0b0e6d Add simple let bindings 2019-05-12 19:04:31 +01:00
Edwin Brady
9baf180127 Clear delayed holes on failure 2019-05-12 16:32:56 +01:00
Edwin Brady
14f717aa33 Add test for failed delayed elaborator 2019-05-12 16:03:04 +01:00
Edwin Brady
2536b03e84 Don't allow nested delays
This makes the rules for ambiguous names a lot more restrictive (but I
think that's probably good...)
2019-05-12 15:29:08 +01:00
Edwin Brady
f3c31f3089 Give correct multiplicity count to arguments 2019-05-12 14:24:24 +01:00
Edwin Brady
6c00349274 And again... 2019-05-11 22:26:08 +01:00
Edwin Brady
905820efed Add missing file 2019-05-11 22:25:35 +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
42f2d1c729 Expand ambiguous names
This has exposed an issue with resolved name indexes when reading from
ttc, which will be addressed shortly...
2019-05-11 12:19:39 +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
Edwin Brady
ef36ea1752 Add TTImp.Unelab
This unelaborates things we don't even elaborate yet :). But we'll get
there...
2019-05-06 17:33:08 +01:00
Edwin Brady
3e03e397c5 Add the rest of RawImp type
Just has placeholders for the elaboration at the moment, but it's useful
to see what is needed!
2019-05-06 13:19:36 +01:00
Edwin Brady
55c8b9d6fb Check locals are usable (with determining args) 2019-05-06 01:06:24 +01:00
Edwin Brady
f504ffa777 Add missing conversion check in application
This is for the case where the function type is unknown, so we have to
invent one and make sure it unifies
2019-05-05 21:25:30 +01:00
Edwin Brady
759524b838 More work on implicit search
Search on syntax rather than values, since this makes it easier to deal
with local variables accurately, and since we need to go back to syntax
anyway. We ensure that target types are normalised before search.
2019-05-05 19:25:40 +01:00
Edwin Brady
78fbfc84a8 searchLocal looks inside pairs
We'll need this for interface resolution - build up applications of fst
and snd as we go deeper. This also adds options for controlling names of
pairs, proofs, primitives, etc.
2019-05-04 23:32:41 +01:00
Edwin Brady
257d381524 Added logging and directives to ImpDecl 2019-05-04 22:04:54 +01:00
Edwin Brady
ad54711050 Check determining arguments before search 2019-05-04 20:41:43 +01:00
Edwin Brady
87eeb200ce Add searchNames
Can now search for expressions by trying constructors
2019-05-04 19:19:22 +01:00
Edwin Brady
bfe78baf07 Add a 'staging area' to contexts
This is for updates we make while branching in an elaborator - we don't
want to update the context immediately, because if the branch fails,
we'll need to revert, so for safety we'll note the updates we're going
to make and only complete the update when we're back at the top level.
2019-05-03 02:43:47 +01:00
Edwin Brady
29a41ed975 Initial implementation of auto implicit search
This only searches for lambdas and locals so far, and doesn't take into
account that it shouldn't search for holes, but it does set up the basic
mechanism.
2019-04-27 20:18:53 +01:00