[lworld] RFR: 8359370: [lworld] allow instance fields of identity classes to be readable in the prologue phase [v19]

Vicente Romero vromero at openjdk.org
Mon Sep 1 21:42:54 UTC 2025


On Mon, 1 Sep 2025 12:17:45 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> > Do we still need the changes in `Attr.checkAssignable` -- e.g. flexible constructor bodies used to check some extra properties in there. Now that we have an LHS variable in the prologue scanner, I wonder if we can unify the checks?
> 
> I did an experiment, and adding this:
> 
> ```
>             if (isInLHS && !insideLambdaOrClassDef) {
>                 // Check instance field assignments that appear in constructor prologues
>                 if (isEarlyReference(localEnv, tree.hasTag(SELECT) ? ((JCFieldAccess)tree).selected : null, sym)) {
>                     // Field may not be inherited from a superclass
>                     if (sym.owner != localEnv.enclClass.sym) {
>                         log.error(tree, Errors.CantRefBeforeCtorCalled(sym));
>                         return;
>                     }
> 
>                     // Field may not have an initializer
>                     if ((sym.flags() & HASINIT) != 0) {
>                         log.error(tree, Errors.CantAssignInitializedBeforeCtorCalled(sym));
>                         return;
>                     }
>                 }
>                 return;
>             };
> ```
> 
> At the start of `analyzeSymbol` seems to work fine. Maybe we want to break `analyzeSymbol` in different parts, one for reads and one for writes.
> 
> But one nice consequence of this is that now `isEarlyReference` is only called inside this visitor -- this means we can probably avoid having to pass `isPrologue = true` and, we can also avoid this dance:
> 
> ```
> tree.hasTag(SELECT) ? ((JCFieldAccess)tree).selected : null
> ```
> 
> Which is required at every callsite.

addressed in last commit, thanks!

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

PR Comment: https://git.openjdk.org/valhalla/pull/1523#issuecomment-3243287853


More information about the valhalla-dev mailing list