interactions between type annotations and language model APIs.

Eric McCorkle eric.mccorkle at oracle.com
Thu May 8 23:42:51 UTC 2014


On 05/08/14 18:55, Alex Buckley wrote:
> On 5/5/2014 1:48 PM, Alex Buckley wrote:
>> To be specific, the "generator" methods in jx.l.m.u.Types are these ten:
>>
>> asMemberOf
>> boxedClass
>> capture
>> directSupertypes
>> erasure
>> getArrayType
>> getDeclaredType x2
>> getWildcardType
>> unboxedType
> 
> boxedClass(PrimitiveType) returns a TypeElement, i.e., a declaration, so
> any type annotations on the PrimitiveType mirror are irrelevant. So
> we're down to nine methods.
> 
> Eric, you indicated that you're already preserving type annotations
> "everywhere they ought to be". For each of the nine Types methods that
> generate a TypeMirror, can you sketch (one line) what the preservation
> involves? If the answer is often "it's obvious", then I'll write the
> obvious thing for the API spec.

I will make an opportunistic plug here for adding a unit test suite to
the core parts of the pipeline, which would allow us to examine these
sorts of questions in much greater detail...

In the patch currently under review, (which eliminates AnnotatedType),
the primary goal is to preserve the visible functioning of javac.  This
goal is assisted by the fact that javac makes most of its important
decisions using type annotations attached to either Symbol's or
JCTree's, not Type's (in the cases where it didn't I wound up having to
make modifications anyway, due to the elimination of AnnotatedType).

I have added code that preserves type annotations everywhere that a type
(which can carry them) is copied, through Mappings.  The only exception
to this is a mapping on Wildcards, because the only use does not look at
annotations.

Annotations are currently disallowed on ForAll, MethodType, and the
various types (not an exhaustive list) that exist to assist type
inference.  I make no attempt to preserve them through inference,
because doing so is highly nontrivial.

Annotations are preserved through erasure.  This was the behavior of
javac before the patch, and changing it may have nontrivial effects.  So
if it is to be changed, that needs to be filed as a separate issue.

Annotations are not preserved when creating supertypes, lower or
upper-bounds.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: eric_mccorkle.vcf
Type: text/x-vcard
Size: 303 bytes
Desc: not available
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20140508/c1829a53/eric_mccorkle.vcf>


More information about the compiler-dev mailing list