[Types-sig] updated proposal (fwd)

skaller skaller@maxtal.com.au
Thu, 06 Jan 2000 00:38:22 +1100


> Given the following code:
> 
>   decl a: Int
>   b = a ! String
> 
> The compiler will know that it will always fail. So it can flag it. In the
> following:
> 
>   decl a: Any
>   b = a ! String
> 
> It has no idea. So it lets it pass, to be evaluated at runtime. The
> operator *is* a runtime operator. The reason it is important to the
> compile-time checker, however, is that the checker now knows that "b" is a
> String. It cannot be anything else (or the exception would prevent the
> assignment).

More precisely: b is a string from the point at which b is 
bound to the checked expression, at least until:

	1) 'end of block'
	2) An exec statement is seen
	3) An assignment to b
	4) If b is global, then a function call
      	5) the module dictionary is fiddled with	

1) needs to be made more precise: at places like
the end of a conditional component in which
the assignment may be enclosed, it is possible
that a control path originating _before_ the
checked assignment branching to a point
afterwards, may leave 'b' bound to some non-string
object, or even unbound.

The above conditions should be 'reasonbly' easy to check;
except (5), must be taken as a precondition (short of
more sophisticated control flow analysis).

Note these conditions won't give the best results: there must be 
a way of determining when to 'forget' type information,
as well as deduce it. This 'way' must be conservative:
if there's any doubt, it is always safe to 'forget' type information.

Note that a function call can invalidate type assumptions
in two ways: by declaring b global and assigning to it,
or, by indirectly refering to b by a module.attr = value
assignment (or, worse, a dictionary fiddle).

IMHO: Because function calls are used a lot, global analysis
by _inlining_ functions will improve type safety enormously:
point (4) is a real killer: note it _only_ applies to 
global symbols (not function local ones).
{** probably also class instance attribute typing]

The function call problem would be alleviated by
banning module.attr = value and 'global' statements,
but the latter are reasonably easy to detect.
The former are really hard to detect (at compile time).

I'd love to see a better algorithm for 'forgetting'
type information.

-- 
John (Max) Skaller, mailto:skaller@maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia
homepage: http://www.maxtal.com.au/~skaller
voice: 61-2-9660-0850