-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mailbox typing and pattern matching #148
Comments
I was considering how to deal specifically with
patterns. We noticed that it's hard to determine the type of the mailbox when Os effects come into play, and our spitball solution was to just combine them all into a per-module Do we need a way to notice that we have outstanding |
I also thought a bit about how to unify the machinery for the cases where you want to receive just the result for the submission we created and potentially lexically bound the
Perhaps we could get the result in one of two ways. First, getting the result directly from the future.
or
This idea obviously uses a compile-time function to create a type |
I don't think we should try to protect the application from blocking on message receipt which cannot possibly happen. The more general case of this problem is an application bug due to blocking forever on a message receipt from another actor which will never actually send the desired message. Re: the future-related ideas, I'm confused because it looks like |
Let's see if I can do that and go a little deeper.
Basically blocking synchronous use-case.
Matching on a specific read
|
Semantically this looks good to me. Once we have a few more I/O types to consider as examples I think we should play around with APIs to see if the multi-level |
As an offshoot of #147 we delved into the problem of how to support mailbox pattern matching. There are several interrelated problems to solve, e.g.
match
.receive
syntax?Mailbox pattern matching iterates over the mailbox messages and extracts the first message which matches a pattern. Absent special syntax this could look something like:
With special syntax, this could look something like:
However there remains the question of how to support blocking/non-blocking/timed-wait
receive
. As for the question of whether to providereceive
syntax, it may in fact be critical to do so in order to get typing correct (see below).There are some interesting composability problems with regard to message typing. Our intention has long been to have each actor spawn via a module which defines its supported message types. For example (leaving out as-yet-unspecified details):
However, our current plan is to deliver asynchronous I/O completions (
Os
messages as seen above) via the mailbox. Imagine a third-party library which performs asynchronous I/O. If that library's I/O completions were to have the same types as the application's I/O completions, havoc could ensue due to under-specified pattern matches "handling" the library's I/O completions. Furthermore, there is the problem of how to pattern match on just I/O completions (not inter-actor messages) in a type-safe way. This at first seems like a problem that could be mitigated by segregatingOs
messages from inter-actor messages, but the same problem applies there! That is to say that a third-party library could utilize inter-actor communication (IAC), and that should really be opaque from the application's perspective.We tentatively settled on a solution based on link-time module dependencies. The idea is to require an actor handle to be converted to a typed value only capable of sending messages of a statically specified type. This conversion can of course fail at run time, in which case messages of the specified type cannot be sent to the actor. Under the covers this conversion is implemented by introspecting the module dependencies for the actor's module type —
A
in the snippet above — and only converting to types in the transitive closure ofA
's module dependencies. This does not assure that messages will actually be handled, but it does assure that it's at least plausible for messages to be handled.Back to the question of
receive
syntax, it is probably critical to have special syntax so that the association between lexical context and the type being matched on can be enforced at compile time. During discussions we imagined that each module scope would provide a unique message type space. However, lexically nested modules present a challenge to this approach; probably better is to provide a unique message type space only for the outermost lexical module context.The question of whether to support some sort of multiplexed dispatch to various modules came up. After a bit of cleanup from brain splatter we tentatively concluded that this is equivalent to trying to solve the multiple event loop unification problem. Hemlock's answer to that problem is, "Don't do that; use multiple actors."
The text was updated successfully, but these errors were encountered: