Commit Graph

295 Commits

Author SHA1 Message Date
Neil Brown
4586cdd43a Added an export list to RainTypes, and removed some tests for old passes 2008-05-18 09:49:11 +00:00
Neil Brown
f79cba0616 Changed the parameter type checking to use type unification 2008-05-18 09:43:12 +00:00
Neil Brown
e53fda754e Fixed the Rain passes so the the alphabet test case now works (at least) 2008-05-17 20:51:42 +00:00
Neil Brown
1e5268dea5 Fixed the types that are definitely known (declarations, etc) so that they are available during type unification 2008-05-17 19:48:48 +00:00
Neil Brown
bf07c441ae Changed the communication type checking to be part of the type unification framework 2008-05-17 19:47:47 +00:00
Neil Brown
1115364d47 Changed TypeExp to stop using Data.Generics (which was getting awkward)
Instead of storing the Constr, which was messy, we now store a String (to allow comparison of constructor types during unification) and a function to reform the type at the end of the type checking.
2008-05-17 19:44:45 +00:00
Neil Brown
ddb9ba2fd3 Corrected a bug in unifyArgs where errors that occur while processing arguments were being ignored 2008-05-17 19:42:49 +00:00
Neil Brown
ab0301a342 Made the Rain parser actually record an unknown (to-be-inferred) type for numeric literals 2008-05-17 14:24:45 +00:00
Neil Brown
cd0c8d2901 Added assignments to the new type unification system for Rain 2008-05-17 14:23:31 +00:00
Neil Brown
1e6ae6bff9 Improved the error messages when the type unification fails 2008-05-17 14:23:00 +00:00
Neil Brown
f10cb7d525 Moved the TypeExp type out to its own module, UnifyType 2008-05-17 14:21:57 +00:00
Neil Brown
3249381995 Added a Rain test file for the type checker 2008-05-17 13:17:12 +00:00
Neil Brown
7d65db43c0 Changed TestHarness to support Rain test files as well as occam 2008-05-17 13:13:52 +00:00
Neil Brown
63a28d0044 Changed the conditionals type-checking to use type unification rather than the old system 2008-05-17 12:53:05 +00:00
Neil Brown
f8b7e8f8cb Added unifying-related items to CompState, and changed all the uses of ST to IO in the TypeUnification module
As part of this patch I also had to provide a Data instance for TypeExp (to allow CompState to still be an instance of Data).  Using IORefs is easier than STRef RealWorld, and puts everything in terms of IO (which is already in PassM) rather than ST (which would require more lifting).
2008-05-17 12:50:52 +00:00
Neil Brown
875cf4b40a Provided slightly better error messages from the type unification module 2008-05-14 12:18:58 +00:00
Neil Brown
e3bf321f33 Made the key type in the type unification generic (as long as it provides Ord and Show) 2008-05-14 12:06:11 +00:00
Neil Brown
e09fb2b9ec Added support for numeric literals in the type inference algorithm 2008-05-14 12:01:32 +00:00
Neil Brown
ed9c92878a Added a helper function to RainTypesTest to make the unification tests shorter 2008-05-14 10:09:42 +00:00
Neil Brown
9f1d65f4a0 Added more tests for type unification, fixed some bugs and added cleaner error handling 2008-05-14 09:52:16 +00:00
Neil Brown
e3fa3df623 Added a module for doing type unification, and some very basic tests for it 2008-05-13 23:25:42 +00:00
Neil Brown
89c25e3f6c Added a type-class for retrieving the (AST) type of things
This patch hides all the old typeOfExpression, typeOfName, typeOfVariable, etc, and unifies them into a single type-class with an "astTypeOf" function.  The type-class is currently named Typed, but that can easily be changed (it's only explicitly referred to in the Types module).  The patch is essentially the type-class with a giant find-and-replace on the other modules.
2008-05-17 11:41:52 +00:00
Neil Brown
3daf82d318 Merged Alternative and AlternativeCond into a single Alternative item that always has a pre-condition 2008-04-03 14:52:37 +00:00
Adam Sampson
3da2ad1385 Provide combinators for generic traversals.
The types get hairier, but the code is much simpler!

I've left {check,apply}DepthM{,2} there for now, but reimplemented them in
terms of the new combinators.

Fixes #58.
2008-04-08 14:41:25 +00:00
Adam Sampson
eb8a855f32 Change most uses of underlyingType to resolveUserType in OccamTypes.
underlyingType recurses, and in at least one case it was going too far.
2008-04-07 23:52:44 +00:00
Adam Sampson
a5bd28bab4 Use a sensible NameType for names converted to unscoped.
This is because the code that finds free names looks at the NameType -- which
it certainly shouldn't.
2008-04-07 23:36:53 +00:00
Adam Sampson
feb0496d71 Handle DATA TYPE FOO IS (some record). 2008-04-07 23:36:30 +00:00
Adam Sampson
201788b478 Fix explicitly-typed array literals -- don't throw away the type. 2008-04-07 22:43:51 +00:00
Adam Sampson
c627214727 Resolve the v[s] ambiguity outside the parser.
This removes the last use of typeOf* from the parser.
2008-04-07 21:36:21 +00:00
Adam Sampson
cc907a1339 Pick the best type available for operators and array literals.
This is rather more expensive than the approach it was using, but it
does the right thing for things like "3 + 4(MYINT)" and "[3, 4(MYINT)]",
and the code's actually simpler.
2008-04-07 20:14:00 +00:00
Adam Sampson
3326c56a54 Always infer left-to-right for dyadic operators (except shifts).
This isn't the right behaviour, although it's closer: what it really needs to
do is to try to infer both sides in the current (or no) context, pick the more
specific type of the two inferred, then use that to redo the other one. Yuck!
2008-04-07 12:04:34 +00:00
Adam Sampson
caa59c6788 Reinstate support for intrinsic Procs and Functions.
This works the same way that it used to. I did experiment with actually
defining them as Procs and Functions in the normal way, but that'd require an
awful lot of special-casing later on, and would preclude support for multiple
types in the future, so I'll keep it this way for now.
2008-04-07 11:55:20 +00:00
Adam Sampson
ea69ebd0ec Assume that string literals have type []BYTE unless otherwise specified.
This means that "" has the correct type, which cgtest07 checks for.
2008-04-07 00:20:42 +00:00
Adam Sampson
d0072fc2ee Infer types in record literals.
This also changes the behaviour for array literals so that the inferred type of
the first item is used as the default for the rest. This satisfies all the
cgtests except for a test in cgtest59 which does "a IS [3, 4 (type)]:", which
I've never seen in a real program, and would require a bit more complication to
handle.
2008-04-07 00:05:15 +00:00
Adam Sampson
6d31c79234 Only apply inferTypes to the AST.
It updates the state itself anyway, and applying it to the AST results in it
doing an awful lot of traversal this early on.
2008-04-06 22:28:58 +00:00
Adam Sampson
3d1d2c4d9c Fix type inference for BytesInExpr. 2008-04-06 19:04:16 +00:00
Adam Sampson
988c5c6fef Add special handling for CHAN ANY.
Fixes #57.
2008-04-06 18:54:32 +00:00
Adam Sampson
71d8c7024b Unsubscript the context (when walking a subscripted expression. 2008-04-06 18:43:34 +00:00
Adam Sampson
2d15eb800c Make pushTypeContext handle Infer as no context. 2008-04-06 18:43:01 +00:00
Adam Sampson
39f78e56ee Relax the type checking on array assignment: [3]INT := []INT is OK.
I'd forgotten to move this rule over from the old checker in the parser.
2008-04-06 18:28:02 +00:00
Adam Sampson
ab6e3d1b3e Infer the types of channel arrays. 2008-04-06 17:59:29 +00:00
Adam Sampson
95e3693efd Die with a sensible error message if the type of an empty array can't be inferred. 2008-04-06 17:59:03 +00:00
Adam Sampson
feefcfd017 Resolve the c ! x ambiguity outside the parser.
Unfortunately there appears to be exactly one place you can do this, and it
turns out to be inside inferTypes (because you need to know the type of c
completely, and you can't type-infer x until you know if it's a tag or a
variable). It's definitely nicer than doing it in the parser, though.

I've also started adding "-- AMBIGUITY" comments in the parser.
2008-04-06 17:47:41 +00:00
Adam Sampson
4b841e1dc1 Show expected tags when none are specified. 2008-04-06 17:47:07 +00:00
Adam Sampson
8cedbed5fc Move makeUniqueName and findUnscopedName into CompState. 2008-04-06 17:42:12 +00:00
Adam Sampson
1640b9ce63 Move applyDimension into Types. 2008-04-06 15:32:35 +00:00
Adam Sampson
1977e7880b Move evalIntExpression into EvalConstants, now that Types doesn't need it.
It now uses the full expression evaluator rather than the literal-only version.
2008-04-06 13:31:37 +00:00
Adam Sampson
8f7c8b9fcb Define variables necessary for some of the constant-folding tests. 2008-04-06 13:12:04 +00:00
Adam Sampson
118a1f3527 Add a resolveAmbiguities pass.
Currently this only handles the FunctionCallList ambiguity.
2008-04-06 11:33:10 +00:00
Adam Sampson
ecab9c1881 foldConstants *after* inferTypes.
On second thoughts, we can't reasonably fold constants until we know what types
they are.
2008-04-06 11:20:34 +00:00
Adam Sampson
8a914cd19a Strip out most of the type awareness from the parser.
Type inference and checking is now handled entirely by the later passes.

There are a few remaining places in the parser that look at the types of things
that have been defined; this is in order to resolve syntax ambiguities (e.g.
c[x], c ! x). This is a temporary measure to minimise cgtest breakage; it can't
work for things that need to be inferred (e.g. "CHAN INT c:" "d IS c:" "d !
x"), so it'll need moving out to a pass in the near future.

There's still quite a bit of work to do on this, but results so far are
encouraging: the code is an awful lot cleaner, and about four hundred lines
shorter.
2008-04-06 02:59:49 +00:00
Adam Sampson
c39503c175 Move occam type inference out to a pass.
This infers the types of literals and abbreviations.

This is not yet complete, but it's mostly there. I was surprised at how complex
it turned out to be, but it's significantly less awkward than having it
threaded through the parser (plus it works correctly, unlike the old code).
There are a few FIXMEs for things I've yet to implement.
2008-04-06 02:56:59 +00:00
Adam Sampson
e6980ba382 Update all specifications when constant folding.
It used to only update IsExprs, but that meant that all the constants inside
types in other things didn't get folded properly, which caused problems.
2008-04-06 02:01:47 +00:00
Adam Sampson
475a77404c Handle the RHS type of A.Counted consistently.
Previously the parser set it to the element type, but everything that used it
set it to the type of the whole array. Now it's documented in AST.hs, and the
parser makes it the type of the whole array, since that's almost always what
you really want later on.
2008-04-06 00:09:23 +00:00
Neil Brown
4ef1ff7196 Changed to a state monad for warnings, and added a runPassM function to remove duplicate code for running passes 2008-04-03 12:21:59 +00:00
Neil Brown
20843f70a4 Corrected all the tests to use the new PassM monad 2008-03-10 17:07:48 +00:00
Neil Brown
d66fb79796 Fixed some unused module import warnings, now that PassM is not build of monad transformers 2008-03-10 17:19:45 +00:00
Adam Sampson
7525138c96 Defined types for tree traversals, and moved them to their own file.
We now have three kinds of canned tree traversals, all of which are smart about
which types they're applied to: explicit-descent transformations,
implicit-descent transformations, and implicit-descent checks. I've only
provided depth-first application of the latter two, but we could do
breadth-first in the future if necessary.
2008-04-01 12:01:09 +00:00
Adam Sampson
3283b7db41 Remove the Type/AbbrevMode information from Actual*.
It's redundant, since you can always compute them from the variable, and it
makes the code that deals with actuals rather cleaner.

On the other hand, it slightly complicates some of the tests, because any names
you use in an Actual need to be defined...
2008-03-26 18:16:09 +00:00
Adam Sampson
b296706bea Update Rain typechecker to match isIntegerType change.
isIntegerType now recognises Time as an integral type, so the rules for Time
operations in the Rain typechecker needed updating.
2008-03-26 14:55:15 +00:00
Adam Sampson
b36068b815 Move retypes check into the SpecType checker, and update the pass list.
This completes the occam typechecker.
2008-03-26 14:39:12 +00:00
Adam Sampson
ef329e3ed0 Check SpecTypes. 2008-03-26 14:20:35 +00:00
Adam Sampson
c9cb7d2bf9 Check Proc calls. 2008-03-26 12:26:04 +00:00
Neil Brown
c37e183879 Added support for a not-equals operator in Rain 2008-03-24 23:44:40 +00:00
Adam Sampson
b672900f46 Check Case, Alt, and all the trivial processes. 2008-03-25 17:27:33 +00:00
Adam Sampson
6861b22da6 Check timer operations. 2008-03-25 16:45:25 +00:00
Adam Sampson
d7e829b4c6 Check assignments. 2008-03-25 16:26:09 +00:00
Adam Sampson
b3e3308b3e Implement channel IO checks, and refactor OccamTypes (again). 2008-03-25 15:56:03 +00:00
Neil Brown
8fe152bf98 Merged the type-checking on time-related statements in Rain into the pass that checks types in communications 2008-03-24 15:15:28 +00:00
Neil Brown
eb50c010b2 Fixed the tests for parsing time-related stuff in Rain to match the recent changes 2008-03-24 14:27:46 +00:00
Neil Brown
cbbafffbd2 Changed Rain to use the new timer type rather than things like the GetTime statement 2008-03-24 13:50:14 +00:00
Neil Brown
c68aa42277 Added a sub-type to Timers, to support multiple types 2008-03-23 22:20:16 +00:00
Neil Brown
74a5cf52a7 Stopped constants being assigned to in the type-checker for Rain 2008-03-23 12:15:00 +00:00
Neil Brown
b316a7d3f4 Added some tests for checking that constants can't be assigned to in Rain 2008-03-23 12:14:34 +00:00
Neil Brown
c1479bc1a8 Fixed the list of excluded Rain things by removing IntrinsicFunctionCall from the list 2008-03-23 11:48:33 +00:00
Neil Brown
1650d55d4e Added the functionTypesChecked property to the dummy occam pass 2008-03-23 11:47:59 +00:00
Neil Brown
78c2160eb4 Fixed the type of a function name to avoid confusing the pass to remove free names later on 2008-03-23 00:11:11 +00:00
Neil Brown
dd7b0268b2 Added a new property (functionTypesChecked) to help fix the pass ordering 2008-03-23 00:09:01 +00:00
Neil Brown
7a7b60449c Enhanced an error message in RainTypes 2008-03-22 19:04:34 +00:00
Neil Brown
e767e33190 Added support for some intrinsic (time-related) functions in Rain 2008-03-22 18:58:10 +00:00
Neil Brown
230db2de08 Added support for specifications at the start of functions without ruining the check for a return statement 2008-03-22 18:57:23 +00:00
Neil Brown
ae142a94e1 Added support for uniquifying function arguments to the Rain passes 2008-03-22 18:34:07 +00:00
Neil Brown
813d6affd1 Fixed an error message in RainTypes 2008-03-22 18:02:43 +00:00
Neil Brown
710abd7019 Added support for function calls to the Rain parser 2008-03-22 17:49:21 +00:00
Adam Sampson
b8b7e04b7c Refactor literal and subscript checks.
For both of these, we already examine all the places they occur for other
reasons, so there's no good reason to do a separate traversal for them.
2008-03-22 23:58:18 +00:00
Adam Sampson
60ca26128c More occam typechecks: input/output items, replicators, choices.
Various infrastructure too to support these.

Doing A.ForEach raised an interesting question: what does it work over?  In
plain occam it'd just be arrays, but it should obviously work for lists too.
This suggests that Size and Subscript should work on lists as well, since
ForEach will be implemented in terms of them. I've therefore introduced the
idea of a "sequence" class of types.
2008-03-22 23:47:29 +00:00
Adam Sampson
6ab4a9923f Implement expression typechecking for occam.
There's obviously some overlap with the Rain typechecker here. I've tried to
cover everything in the AST that could potentially be bound into occam at some
point in the future, even if the occam parser doesn't support it yet (so
this'll do checks for Concat and mobile allocation, for example).
2008-03-22 01:00:42 +00:00
Neil Brown
025eebf61d Added support for giving ranges an explicit type in Rain 2008-03-21 21:10:47 +00:00
Neil Brown
0511c852da Added a couple of reminders to RainPassesTest 2008-03-21 20:16:48 +00:00
Neil Brown
2189a6c28a Added support for list literals to the Rain parser 2008-03-21 20:03:47 +00:00
Neil Brown
fe24c5cfb4 Corrected some test numbering in ParseRainTest 2008-03-21 19:25:19 +00:00
Neil Brown
7bd5bdf1fa Changed a Rain pass to transform the Plus operator on lists into the proper Concat operator 2008-03-21 19:23:16 +00:00
Neil Brown
ebef4aaedf Fixed array constructors by adding an occam pass to figure out their type early on, and also corrected the ordering of the later passes 2008-03-21 18:23:42 +00:00
Neil Brown
8db5975671 Refactored checkExpressionTypes a little 2008-03-21 16:35:57 +00:00
Neil Brown
33b04e7646 Tidied up a few unused functions and module imports 2008-03-21 15:16:36 +00:00
Neil Brown
0dc458ff03 Fixed transformEachRange to change the abbreviation mode of the loop counter 2008-03-21 15:09:00 +00:00
Neil Brown
dfea2c11a5 Added a dummy Rain pass to supply the new retypesChecked property 2008-03-21 15:07:56 +00:00
Neil Brown
edf1060c9b Fixed conflicts in the Rain passes 2008-03-21 12:45:24 +00:00
Neil Brown
50ce3410b8 Added the pass for giving lists a type to the pass list 2008-03-20 16:54:40 +00:00
Neil Brown
af4a66e2e4 Corrected the spelling of the name of one of the Rain passes 2008-03-20 16:46:45 +00:00