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
Junction short-circuiting clarification #2120
Comments
I updated in 2c92134 See if it makes it clearer and if yes, then close the issue. Thanks. |
Hi zoffixznet, Thanks so much for taking a look at this. So it is now clear that short-circuiting can happen in a boolean context. Testing seems to show it is not currently the case with Rakudo, but I understand the possibility remains and needs to be considered. But to be clear, is short-circuiting guaranteed to not be a problem here: Is it correct to say that most Junctions do not have a problem with short-circuiting. Junctions "none", "all", and "one", must evaluate every element in the junction to determine their boolean value so could never be short-circuited by any compiler. Can this be stated explicitly in the docs if it is true? Edit: Ooops, the "none" junction could short circuit as soon as it sees any true value. And as mentioned below, the others can as well. Thanks pmichaud. |
Not so: Pm |
Now that I think more of it, we should remove the Unless there's some extra design planned I'm not aware of? my $x = a() | b() | c() The above just creates an
The above will always call
The above will always call So really, I'm unsure whether that should even be mentioned in the docs... |
Thanks for that great explanation zoffixznet. This is what I was fighting to understand. Worried that a term wouldn't be evaluated because of short-circuiting as in the || or && cases. All of my side effects are parallel safe, but I do need them all executed, not removed by an optimization. I'd vote for removing that short-circuit mention from the documentation unless someone can see a way that short-circuiting can bite you. |
Historical note: For as long as I can remember, S09 has always contemplated the possibility that junctions would be multi-threaded somehow to evaluate things in parallel, and that it would be possible for some threads to be terminated early once an answer had been determined within the appropriate context. So, in the case of a boolean context, I think it's possible that So either language designers decide on a specific interpretation now (and we document it), or the documentation gets listed as "short circuiting behavior is currently undefined; programs should not rely on short-circuiting or non-short-circuiting behavior in Junctions". (If this sounds onerous, I think it's not too far off the mark of what is already said about other lazy constructs.) Anyway, that's my remembrance/contribution here. Pm |
👍 on this. Let's leave the possibility of this type of short-circuiting open. Once we have an implementation of actual auto-threaded Junctions it might be easier to evaluate whether this sort of short-circuiting is feasible and desirable. |
The problem
https://docs.perl6.org/type/Junction says:
"The type of a Junction does not affect the number of items in the resultant Junction after autothreading."
but in the next sentence it says "the compiler is allowed to short-circuit autothreading".
If a Junction result is always the same size until put into boolean context, where would it ever get short-circuited? Every element must always be evaluated and not short-circuited in order to produce the full junction -- correct? There doesn't seem to be an opportunity for a compiler to short circuit.
Suggestions
Either remove the mention of short circuiting if it is indeed impossible, or give an example of where short-circuiting can happen with junctions.
The text was updated successfully, but these errors were encountered: