Exploit capture monotonicity in the apply rule? #14387
Replies: 3 comments
-
This new rule for application seems to make a lot of sense. It mirrors
Other than that, the example makes sense to me. It's also further evidence that we want paths in capture sets. |
Beta Was this translation helpful? Give feedback.
-
One problem with the new rule is that the capture prediction lemma breaks down. In fact One way to salvage the capture prediction lemma would be to treat every reference as a proxy for the set of primitive capabilities it could be instantiated with. Under that viewpoint it would be true that |
Beta Was this translation helpful? Give feedback.
-
Yet another way to treat the example would be to extend paths to applications. i.e. |
Beta Was this translation helpful? Give feedback.
-
Captures have a monotonicity property. The references captured by the result of an evaluation are a subset of the references that captured by the evaluation itself. Specifically in a function call
f x
, the captures of the result must be subsumed by the union of the captures off
and the captures ofx
. This motivates a new, more permissive rule for apply:An example where the new rule is helpful is typing lazy lists. Here we have in slightly simplified form:
With the old rule,
xs()
has capture set{*}
so the typing oftail
fails. But with the new rule, it would havecapture set
{this.xs} /\ {*}
={this.xs}
, andthis.xs <: this
by the path subsumption rule. So it checks out.The idea is to replace the previous rule #13657 with the new rule, since it has a much clearer semantic motivation.
As a first step, the current implementation specializes the rule for the case where
f
is a tracked function and the capture set of the argumenta
is empty. That covers theLazyList
example. We should consider generalizing to the case where the function arguments have non-empty capture sets, but that would make capture set computations more complex, so we should also evaluate the performance impact.Beta Was this translation helpful? Give feedback.
All reactions