1) Representation of function values:

For functions that have to be closure converted, we need to represent the function value as something like (fn, env) pair.

ex:
(define p (let ((x 3)) (lambda y x)))

The lambda is represented using a pointer to the pair

(fn = <code pointer>, env = {x = 3})

If we closure convert only the functions that escape with a captured value, I think we must represent the other functions also as the pair:

(fn = <code pointer>, env = {}).

Note that this does not imply dynamic allocation. Since the environment is empty, it can be a statically allocated record. This will canonicalize the way expressions like

(lambda (x) (x)) are handled.

2) If the condition initiating the closure conversion of a function are:

i) the function should capture a value
ii) the function should escape

I can see only two cases that does not qualify for the second rule.

i) When a function is defined and immediately applied, as in
    ((lambda (x) x) 10)
ii) When a lambda is lost in a sequence as in
    (let ((x 3)) (lambda (y) x) x)
    [in which case the lambda can as well be dropped]

Is there any other case?

I think that things like
(let ((x 3) (y 5)) (== (lambda z x) (lambda z y))) may still need to be closure converted, (at least logically) even though they do not escape. This depends on the way equality is defined over functions.

I do think that it is a good idea to define some form of equality over functions (if it is feasible). Otherwise we will

- need to introduce equality types and all associated complications into the type-system -- as in SML
- or throw a run-time exception like Ocaml.

Swaroop.
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to