Replies: 4 comments 8 replies
-
In most plausible scenarios, the control tags will be declared once per language runtime, not once per usage. This is likely to lead to the situation where control tags are imported rather than declared locally. |
Beta Was this translation helpful? Give feedback.
-
Sure. Good question. But let me give an example using just exceptions; the same issue arises for continuations and (other) effects. Suppose you have a Java interface for sequences
The idea is that these sequences knowsbetter how to iterate through their elements than the consumer does, and so Here are two simple examples of such sequences:
Note that the loop in
Now you can put these together to get some simple finite sequences. For example,
will print But when you try complex compositions, things go wrong. For example, you might expect
to print out Why did that happen? Well, because we used dynamically scoped exceptions, our complex composition experienced an accidental capture. In particular, when the "outer" AppendAfter saw 5 elements had been enumerated, the consumer it gave to its first sequence threw an exception to break out of its loop, but unfortunately the "inner" AppendAfter caught that exception (mistaking it for the one that could be thrown the the consumer it gave to its first sequence), and so the inner AppendAfter moved to its second sequence while the outer AppendAfter was left in an invalid state. Had we instead used lexically scoped exceptions—where the target destination is made explicit rather than dynamically searched for—such as in the following pseducode:
then our complex composition would have produced the expected output. All this is to illustrate what accidental capture is and why dynamic scoping is not compositional. And note that dynamic scoping failed to compose even though I used a private nominal "event tag" ( On the other hand, types for lexically scoped effects do guarantee effects are handled by the intended someone. This paper gives a language with effects and generics that can be given both dynamically scoped and lexically scoped semantics, and it proves that the lexically scoped semantics satisfies an extremely strong composability property (specifically relational parametricity) due to ensuring intended handling, and that the dynamically scoped semantics fails to satisfy this property due to accidental capture. There's more to say on why to use lexically-scoped (i.e. explicit) semantics rather than dynamically scoped (i.e. searching and using some policy when multiple matches are present) semantics, but you just asked about accidental capture, and I'm guessing I've already given you more to ponder over than you were hoping for. P.S; The above example was not contrived. For languages with generators, this is what happens behind the scenes when employing a valuable optimization to eliminate stack allocations in common usage patterns of generators, such as |
Beta Was this translation helpful? Give feedback.
-
I'd like to see efficiency claims evaluated on implementations because in other proposals we've dithered too long on efficiency considerations that turned out to be mirages. Concretely, if the typed continuations proposal gives rise to accidental capture or leads to a suboptimal encoding what is characterized here as lexically-scoped semantics, then that should manifest in concrete examples and concrete measurements. |
Beta Was this translation helpful? Give feedback.
-
There still seems to be some confusion and misleading information in First, it should be stressed that the question of how to select a Issues with "accidental capture" of effects (including exceptions) in (It is true that if we only have a second-class notion of exception, It is worth bearing in mind that though effect pollution can be a There are many solutions to the effect pollution problem. Here are a
It may be illuminating to look at the implementations of generators in OCaml 5: https://github.com/ocaml-multicore/effects-examples/blob/master/generator.ml Lines 56-58 are the crucial ones. They ensure that the C++ effects library [4]: Generators are described in Section 2.6. In neither case is any aspect of effects exposed to the user of the References[1] [2] [3] [4] [5] [6] [7] [8] [9] |
Beta Was this translation helpful? Give feedback.
-
I saw this topic come up several times in the CG in-person meeting but never saw it fleshed out.
With typed continuations, a suspending stack gives a control tag (which may be private to a module, or shared) that it should suspend to the nearest handler of on the stack. With fibers, a suspending stack must provide the ancestor fiberref to suspend to on the stack.
I heard concern that the typed continuations approach of suspending to nearest handler with a given control tag could lead to 'unwanted capture' (correct me if it was a different phrase, can't find any notes from the meeting).
Is it possible to get a concrete example of what this is and how it happens?
Beta Was this translation helpful? Give feedback.
All reactions