RFR: 8194743: Compiler implementation for Statements before super() [v16]

Archie Cobbs acobbs at openjdk.org
Mon Sep 25 17:56:23 UTC 2023


On Mon, 25 Sep 2023 16:59:43 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Archie Cobbs has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Have RefBeforeCtorCalledError extend StaticError and customize debug strings.
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java line 3971:
> 
>> 3969: 
>> 3970:         // Match this scan stack: 1=JCMethodDecl, 2=JCExpressionStatement, 3=JCMethodInvocation
>> 3971:         private static final int MATCH_SCAN_DEPTH = 3;
> 
> This logic seems a bit fragile in that it relies on the shape of the AST. Also, in principle you can create something that will overflow the int, and will cause the check to spuriously pass for a very very very large number of nested expressions :-)
> 
> That said, I understand that, in order to make this code "tighter", you would need to override al visitors that can "nest" code inside other code, which is also not great.

Agree about this appearing fragile. The thinking was that, well, the JLS rule for this is simply:

> _ConstructorBody:_
>     { [_BlockStatements_] } 
>     { [_BlockStatements_] _ExplicitConstructorInvocation_ [_BlockStatements_] }

So this tries to mirror exactly that in the most direct way. The fragility comes from the possibility of some unexpected change to the AST class model... but at least if that ever did happen, you would probably get a clear warning when a bunch of JDK code stopped compiling :)

> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java line 1511:
> 
>> 1509:                     if (staticOnly)
>> 1510:                         return new StaticError(sym);
>> 1511:                     if (env1.info.ctorPrologue && (sym.flags_field & SYNTHETIC) == 0)
> 
> where does the SYNTHETIC check comes from?

This is related to the previous question... some generated classes contain constructors with extra blocks, and these fail the `JCMethodDecl, JCExpressionStatement, JCMethodInvocation` stack check test.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/13656#discussion_r1336205773
PR Review Comment: https://git.openjdk.org/jdk/pull/13656#discussion_r1336205806


More information about the compiler-dev mailing list