Forgive me if this is a naive question, but as regards the caller/current-method question, since you have the complete AST in front of you, why not just synthesize extra arguments to any method that happens to use the caller or __method__ magic?
If it's at most the immediate caller that the callee is interested in, well, that is a service the compiler can provide, no stack trace skullduggery required.
And, of course, for errno, there is a middle ground between exceptions and magical in-band return values--in Scala-land we call it Either. When you're a whole-program compiler (or are allowed to pretend you are one until a monkey comes along) you can feel free to rewrite everyone's returns for your own optimization. Whether that turns out to be a win in the long run is, of course, a different question. :)
Alas, for want of an effect system... :)
-0xe1a (sorry for top-posting, on my phone)
--
You received this message because you are subscribed to the Google Groups "JVM Languages" group.
To post to this group, send email to jvm-la...@googlegroups.com.
To unsubscribe from this group, send email to jvm-language...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jvm-languages?hl=en.
You can use Throwable.getStackTraceElement()
which is package visible and OpenJDK specific but at least
it will be faster for all VMs that uses OpenJDK.
Please never optimize warnings, they are here to bug usersuntil they fix the thing. So they should be slow :)
Forgive me if this is a naive question, but as regards the caller/current-method question, since you have the complete AST in front of you, why not just synthesize extra arguments to any method that happens to use the caller or __method__ magic?
If it's at most the immediate caller that the callee is interested in, well, that is a service the compiler can provide, no stack trace skullduggery required.
And, of course, for errno, there is a middle ground between exceptions and magical in-band return values--in Scala-land we call it Either. When you're a whole-program compiler (or are allowed to pretend you are one until a monkey comes along) you can feel free to rewrite everyone's returns for your own optimization. Whether that turns out to be a win in the long run is, of course, a different question. :)
Alas, for want of an effect system... :)
* Exceptions as non-exceptional or moderately-exceptional method results
In this case I'm specifically thinking about Ruby's tendency to
propagate errno values as exceptions; EAGAIN/EWOULDBLOCK for example
are thrown from nonblocking IO methods when there's no data available.
You will probably say "that's a horrible use for exceptions" and I
agree. But there are a couple reasons why it's nicer too:
- using return value sigils requires you to propagate them back out
through many levels of calls
- exception-handling is cleaner in code than having all your errno
handling logic spliced into regular program flow
In any case, the cost of generating a stack trace for potentially
every non-blocking IO call is obviously too high. In JRuby, we default
to having EAGAIN/EWOULDBLOCK exceptions not generate a stack trace,
and you must pass a flag for them to do so. The justification is that
these exceptions are almost always used to branch back to the top of a
nonblocking IO loop, so the backtrace is useless.