Compiler support

102 views
Skip to first unread message

Elliotte Harold

unread,
Aug 16, 2008, 8:30:35 PM8/16/08
to jsr...@googlegroups.com
1. Is anyone aware of efforts to build some of the JSR-305 checks
straight into the compiler, rather than waiting for static analysis? For
instance, it would not seem out of hand for a compiler to note that a
string annotated with @Syntax("Java") did not contain legal Java code.

2. Is anyone considering whether some of these checks might be performed
dynamically at runtime rather than statically? For instance the full
contents of a variable marked @Syntax("Java") might not be available
until runtime.

3. Is anyone considering the possibility of using some of these
annotations to actually generate code with a suitable compiler. For
example, a compiler might notice that an argument x is marked as
@NonNegative and essentially insert this at the beginning of the method:

if (x < 0) {
throw new IllegalArgumentException("Illegal negative value " + x);
}

I am not suggesting that any compiler or runtime be required to do this,
but would it be psosible to allow this, or their reasons why
interpetations of these annotations should be restricted to static
analysis alone?


--
Elliotte Rusty Harold elh...@metalab.unc.edu
Refactoring HTML Just Published!
http://www.amazon.com/exec/obidos/ISBN=0321503635/ref=nosim/cafeaulaitA

Bill Pugh

unread,
Aug 25, 2008, 1:05:02 AM8/25/08
to jsr...@googlegroups.com

On Aug 16, 2008, at 5:30 PM, Elliotte Harold wrote:

> 1. Is anyone aware of efforts to build some of the JSR-305 checks
> straight into the compiler, rather than waiting for static analysis?
> For
> instance, it would not seem out of hand for a compiler to note that a
> string annotated with @Syntax("Java") did not contain legal Java code.

Doing so is beyond the scope of JSR-305. JSR-305 just defines the
annotations.


> 2. Is anyone considering whether some of these checks might be
> performed
> dynamically at runtime rather than statically? For instance the full
> contents of a variable marked @Syntax("Java") might not be available
> until runtime.
>
> 3. Is anyone considering the possibility of using some of these
> annotations to actually generate code with a suitable compiler. For
> example, a compiler might notice that an argument x is marked as
> @NonNegative and essentially insert this at the beginning of the
> method:
>
> if (x < 0) {
> throw new IllegalArgumentException("Illegal negative value " + x);
> }

Yes, I have thought about these possibilities (2 and 3) a lot.

We received strong "political" advice from a number of quarters that
the idea of annotations changing the semantics of executing Java
programs raises red flags in some quarters. I don't quite understand
this, since J2EE annotations change runtime semantics, but the advice
was very strong and specific.

So I want to leave things open to this possibility, but JSR-305 will
not discuss such possibilities. Remember that all JSR-305 does is
define annotations, and doesn't say anything about what tools might
use them.


> I am not suggesting that any compiler or runtime be required to do
> this,
> but would it be psosible to allow this, or their reasons why
> interpetations of these annotations should be restricted to static
> analysis alone?

Hopefully, we haven't done anything to restrict them to static
analysis. If you think you see something, let me know.

Bill

Reply all
Reply to author
Forward
0 new messages