Andreas Zwinkau <zwin...@kit.edu> wrote on 09/21/2012 12:17:32 PM:
>
> The language report is not clear about the case, where a return
> statement is within a finish block. Consider the following program:
>
> class Async2 {
>    public static def foo() {
>       finish {
>          async Console.OUT.println("Async");
>          if (always()) { return; }
>       }
>       async Console.OUT.println("After Finish");
>    }
>    public static def main(Array[String]) {
>       Console.OUT.println("Start");
>       foo();
>       Console.OUT.println("After Async");
>    }
> }
>
> Intuitively, I'd say that
> (a) "After Async" must always be printed after "Async" and
> (b) "After Finish" is never printed.
>
>

Your intuition is correct.  This is allowed, and does what one would
expect.

[dgrove@linchen myTests]$ x10c++ Async2.x10
[dgrove@linchen myTests]$ ./a.out
Start
Async
After Async


> The x10c++ compiler seems to insert
> x10::compiler::Finalization::throwReturn for the return statement. Does
> this mean it is forbidden to use return within finish?
>

No,

        This is an artifact of how finally blocks are (were) implemented in
the C++ backend.  The throwReturn method throws a special exception, which
is caught in the enclosing try/catch structure to avoid replicating the
code in the finally block (sort of like how javac used to implement finally
blocks using the jsr bytecode).   In the current svn head of X10 (and the
upcoming 2.3.0 release) the codegen has been changed to replicate the code
of the finally block before any return statement.  So it looks a bit more
normal.

        (the finally block is introduced as part of the expansion of finish).


--dave
------------------------------------------------------------------------------
Got visibility?
Most devs has no idea what their production app looks like.
Find out how fast your code is with AppDynamics Lite.
http://ad.doubleclick.net/clk;262219671;13503038;y?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to