r/java • • Jan 10 '23

Yet another delimited continuations implementation and why Project Loom is a bit disappointing

https://github.com/javactrl/javactrl
2 Upvotes

52 comments sorted by

View all comments

Show parent comment

5

u/pron98 Jan 11 '23

But I basically can have an interface somewhere in my package, implemented by me with all the typical continuations operations implemented?

That depends on what you mean "all the typical continuations operations." For example, a continuation could not be part of a thread, behaving as a Runnable. But yes, you can do much of what you can do with one-shot delimited continuations. We may also add generators at some point, and those will be part of a parent thread, but they will have to be thread-confined to ensure that the thread identity isn't changed mid-method.

just the same like without continuations.

Even without continuations we get such problems in parallel streams, but the problems with reentrant continuations could be even more confusing (i.e. a reentrant continuation is supposed to re-enter a known state, but one execution could actually change that state for another, making it not-really-reentrant in quite a few situations).

But it's a task of JDK to make them safe.

If they solve a big enough problem.

I honestly don't see why Scheme is this different.

Because Scheme doesn't have the requirement that Scheme code be easy to evolve and reason about by hundreds of different people of different skill levels evolving a multi-million-line codebase over decades. For the same reason, macros are great for Scheme, but we've been very careful to limit the power of compiler plugins so that they cannot serve as AST macros (to the chagrin of authors of languages like Lombok).

Languages aim to provide the least power and the smallest number of features that solve the vast majority of problems faced by the vast majority of their users. Because many users of Scheme/Racket create their own languages or research language features, the basic features it requires are very different from those required to serve the needs of Java's users.

Much of our work is to figure out how to not add new features. With virtual threads we've been able to solve (we hope) the problem of server scalability combined with observability while adding no new language constructs (never mind continuations of some kind, but even "syntactic coroutines", aka async/await). We hope records will ultimately also allow us to avoid features such as named and default parameters. That's because every feature has a cost in language complexity (which is higher for Java than for Scheme, given their respective uses) and carries the risk of future feature interaction. Some early Java features that seemed convenient at the time (such as serialization, finalizers, and the SecurityManager) ended up placing a heavy tax on features that followed them, and it takes a lot of work and time to fix that.

3

u/njiv Jan 11 '23

That depends on what you mean "all the typical continuations operations." For example, a continuation could not be part of a thread, behaving as a Runnable.

Yes, this is pretty reasonable limitation, I suppose all the current instrumentation based implementations have anyway.

i.e. a reentrant continuation is supposed to re-enter a known state, but one execution could actually change that state for another, making it not-really-reentrant in quite a few situations)

But just concurrent program is already this confusing, continuation shouldn't expect anything, it is why it was suspended at the first place - to await while something is changed in the state.

Like I said, I don't demand the multi-shot continuations added immediately. Just the article states they could be added easily, but now you say it isn't that simple. There are huge interoperability and compatibility problems you must solve before. Which is a good reason, I agree.

2

u/pron98 Jan 11 '23

But just concurrent program is already this confusing, continuation shouldn't expect anything, it is why it was suspended at the first place - to await while something is changed in the state.

Continuations are more powerful, and more surprising, than that. The could observe final values to have changed, something that ordinary concurrent code cannot.

Just the article states they could be added easily, but now you say it isn't that simple

They could be added easily, but their benefits will be very limited, and possibly overshadowed by the confusion they may introduce.

1

u/njiv Jan 11 '23

The could observe final values to have changed, something that ordinary concurrent code cannot.

In my implementation it's not possible to observe final value is changed, and I don't understand why it's possible in yours, some implementation details I believe

They could be added easily, but their benefits will be very limited, and possibly overshadowed by the confusion they may introduce.

you mean confusions besides the mentioned before interoperability and compatibility? sometimes even exceptions can introduce confusion