Quite some time ago we went back and forth about STACK-REF. I want to
revisit that in much-reduced form. Basically, I am looking for a way to
introduce by-reference parameters so that we can have procedures that
are analogous to constructors.
The key points are:
by-reference parameters cannot be captured by an escaping closure
[if necessary: cannot be captured by a closure at all]
(BY-REFERENCE 'a) can only appear as a parameter type. This is a
syntactic restriction.
BY-REFERENCE is not inferred.
So the notion here is that any function parameter type may be annotated
with BY-REFERENCE:
(define (f x: (BY-REFERENCE (mutable Mumble))) ..)
With the following (initial) behavior:
1. Internally, x is a pointer. It is implicitly dereferenced at all
use-occurrences.
2. Since no field may be of type (BY-REFERENCE 'a), it is illegal for
any closure to contain a member of type (BY-REFERENCE 'a)
3. BY-REFERENCE is never inferred.
4. If 'a <- 'b is copy compatible, then
(BY-REFERENCE 'a) <- 'b is copy compatible.
5. In principle, it would be possible to admit the following as
legal code:
(let ((y:(by-reference 'a) x:'a)) ...)
with the effect that Y becomes an alias for X within the LET body.
While this is type-safe and semantically sensible, it has no
pragmatically compelling use-case. The introduction of a new case
to consider for alias analysis is a significant burden on the
compiler and any analysis tools, and we therefore should not
permit this. BY-REFERENCE should be restricted to parameters.
There are two possible relaxations to consider:
1. Captured by-reference arguments might be considered legal if
the closure is non-escaping.
Swaroop: What is the status of our closure escape analysis?
At this point I don't even know if we are *doing* closure
escape analysis.
2. Captured by-reference arguments are legal in *escaping* closures,
but a *copy* of the by-reference value is made at the time of
closure construction.
This yields sensible behavior and preserves type safety, but it
introduces behavioral subtlety that will confuse programmers. My
intuition is that is is better to prohibit escaping capture of
BY-REFERENCE parameters, even if this means that we must prohibit
their capture in *all* closures.
Have I missed something major here?
shap
--
Jonathan S. Shapiro, Ph.D.
Managing Director
The EROS Group, LLC
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev