Generation of synthesized parameters
Peter Jensen
peter.jensen at oracle.com
Fri Feb 1 14:50:51 PST 2013
On 02/01/13 13:11, Alex Buckley wrote:
> Yes. The Java language and the core reflection API jointly and
> explicitly agree on the concept of an "implicitly declared" construct.
> (It's not even tacit agreement - the terms used are obviously the same.)
>
> Meanwhile, the ClassFile structure offers ACC_MANDATED as a way for
> some other spec (namely, the joint JLS and Java SE API spec) to flag
> that they own the construct. (The JVMS acknowledges that their
> ownership is currently something to do with "implicitly declared in
> source code", but that reason could broaden in future.)
I have a hard time seeing this as an offer to "the joint JLS and Java SE
API spec". Unless, by "joint" you mean "joint by a hypothetical compiler
spec (or concrete implementation)".
I think these flags are offered to a compiler spec (or implementer),
which may use it to map a concept of "implicit" in an implemented
language specification, to ACC_MANDATED in the VM specification.
As far as I can tell, ACC_SYNTHETIC/ACC_MANDATED has
- no semantics in the VM
- no semantics in the JLS
- no semantics in core reflection (They are just values. They have no
impact on reflected parameter names, and generally no meaning without
assumptions about the class file origin).
basically, anyone relying on the synthetic/mandated flags to mean
anything must trust the provenance of the class file.
So, the important question for me is, what is the the intended use of
these flags by javac (i.e. what does the javac compiler specification say).
Writing test for this, I assumed something along the lines of:
- Non-synthetic methods with declared arguments must have the
MethodParameters attribute. (all assuming -parameters of, course)
- Synthetics may have one (allowances for lambdas, which happens to have
perfectly good explicitly declared parameter names)
- Expect 2 leading mandated arguments for an enum constructor.
- Expect one leading mandated or synthetic argument for non-static
member classes, local classes and anon inner classes. (couldn't figure
out precisely
when to expect mandated and when it's merely synthetic. I thin Alex
clarified that).
- For synthetic or mandated parameters, the compiler generates names on
the form "argI", except when the specification names the
implied parameter for an enum valueOf(). The JLS give the parameter
name as "name" (maybe by accident, but nevertheless, it's there).
Are these reasonable?
Further questions:
The enum valueOf method is "mandated". Is the parameter also "mandated".
I think it must be! and I think the name must be "name"!
Lambdas are explicit language constructs. They are implemented by
synthetic methods. This seems reasonable, but raises the question: when
is a language construct a class, method or parameter, and when is it
merely implemented using these constructs? I guess each compiler spec
will just have to decide what's considered synthetic and what's not.
Is it fair to assume that the parameters of a lambda (synthetic) are
neither "synthetic" nor "mandated", since they are explicitly named in
source?
If so, I would expect the source names to be reflected in the
MethodParameters attribute, and consequently through the reflection API.
Before you changed "synthesized" to "mandated", you could, based on the
word alone, make a case for lambda arguments being marked "synthesized"
and recorded in "argI" format (i.e. the recorded name is synthesized,
and not reflecting source). Since that's not the intended use,
"mandated" probably is a better word.
>
> Alex
>
> On 2/1/2013 12:55 PM, Eric McCorkle wrote:
>> Is it intentional that the isSynthesized() has been renamed to
>> isImplicit() instead of isMandated()?
>>
>> On 02/01/13 14:43, Alex Buckley wrote:
>>> The enhanced metadata spec PDF showing 2013-01-31 is up to date.
>>>
>>> Alex
>>>
>>> On 2/1/2013 11:07 AM, Joe Darcy wrote:
>>>>
>>>> On 2/1/2013 10:59 AM, John Rose wrote:
>>>>> On Feb 1, 2013, at 10:15 AM, Eric McCorkle <eric.mccorkle at oracle.com
>>>>> <mailto:eric.mccorkle at oracle.com>> wrote:
>>>>>
>>>>>> Has there been a convergence on what to name this, then? I'd
>>>>>> like to
>>>>>> get changsets into the review process ASAP.
>>>>>
>>>>> This message is relevant:
>>>>>
>>>>> http://mail.openjdk.java.net/pipermail/enhanced-metadata-spec-discuss/2013-January/000141.html
>>>>>
>>>>>
>>>>>
>>>>> The bottom line appears to be s/synthesized/mandated/g.
>>>>>
>>>>
>>>> I believe Alex has some alternate wording in the works...
>>>>
>>>> -Joe
>>>>
More information about the compiler-dev
mailing list