This makes sure that we catch all leftover instances of using SYB to do generic operations that we should be using Polyplate for instead. Most modules should only import Data, and possibly Typeable.
This may seem like an odd change, but it simplifies the logic a lot. I kept having problems with passes not operating on externals (e.g. functions-to-procs, adding array sizes, constant folding in array dimensions) and adding a special case every time to also process the externals was getting silly.
Putting the externals in the AST therefore made sense, but I didn't want to just add dummy bodies as this would cause them to throw up errors (e.g. in the type-checking for functions). So I turned the bodies into a Maybe type, and that has worked out well.
I also stopped storing the formals in csExternals (since they are now in csNames, and the tree), which streamlined that nicely, and stopped me having to keep them up to date.
This expansion was causing a big blow-up in the code, as things like:
VAL [2][1]INT as IS [[0,1]]
were getting transformed into:
VAL [2]INT n0 IS [0,1]:
VAL [2]INT n1 IS [0,1]:
VAL [2]INT n2 IS [n0[0], n1[1]]:
VAL [2][1]INT as IS [n2]:
Or something similar -- the inner arrays were pulled up into multiple definitions that were then subscripted, because the first pull-up did this:
VAL [2]INT n2 IS [[0,1][0], [0,1][1]]:
and then the inner arrays got pulled up again, separately. The change hasn't immediately broken anything, but I haven't fully tested it yet
At the moment, the information is only needed in the parser, which must define recursive names before parsing the body of the function. But in future, we should keep the information when the function becomes a proc, and then the C/C++ backends may need to use it (for example, when calculating stack space usage)
For example, a call like foo(6, cs!) will have cs! pulled up, iff cs was of type CHAN X. If cs was of type CHAN! X, nothing is done (and the needless direction will be removed later on).
This was causing a problem in the C/C++ backends, where the slice function call was having _sizes appended to it. So now we pull up anything that results in an array, or is a slice.
All the passes now have their information (name, pre-requisites and post- properties) stored at the point where the pass is declared, which means the pass lists are just a simple list of pass functions.
The main consequence of this change was that the tests had to be changed. Now, instead of taking a "pass applied to data" item (type: PassM b), they take both the pass (type: Pass) and source data (type: b), and apply them later. This was the decision that involved the simplest changes to the existing tests (simply unbracketing the application of the pass to the source). I also had to include a few old-style versions though (testPass', testPassShouldFail') for where the functions were being used to test things that weren't actually passes (mainly StructureOccam).
Fixes#48
NameType is only really needed in the parser, so this takes it out of
NameDef, meaning that later passes defining names no longer need to
set an arbitrary NameType for them. The parser gets slightly more
complicated (because some productions now have to return a SpecType
and a NameType too), but lots of other code gets simpler.
The code that removed free names was the only thing outside the parser
using NameType, and it now makes a more sensible decision based on the
SpecType. Since unscoped names previously didn't have a SpecType at
all, I've added an Unscoped constructor to it and arranged matters
such that unscoped names now get a proper entry in csNames.
Fixes#61.
This changes the Traversal API to the one that I've been working on in
the Polyplate branch, but implemented in terms of Data. The
performance isn't as good as the Polyplate version, but the code is a
lot simpler because it doesn't need all the type constraints (and it
doesn't make GHC struggle).
This also reworks all the passes in Tock to use the new API, including
those that previously used makeGeneric (which I've now removed) or
everywhereM. Most of the passes are simpler because of this, and I
suspect it's fixed a few subtle bugs resulting from missing recursion
in makeGeneric code.
I haven't yet profiled this, but subjectively it seems about the same
as the old Traversal (and thus faster for all the passes that didn't
yet use it).