RFR: 8320220: Compilation of cyclic hierarchy causes infinite recursion

Jan Lahoda jlahoda at openjdk.org
Mon Feb 24 17:35:57 UTC 2025


On Wed, 19 Feb 2025 18:15:51 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:

> This input currently causes an infinite loop:
> 
> interface A extends B, C {}
> interface B extends A {}
> interface C extends A {}
> 
> However, less complicated cycles are handled properly.
> 
> When a cycle is found, we currently:
> (a) Emit a warning; and
> (b) Set the symbol's type to the error type.
> 
> These two steps are done in `Check.noteCyclic()`.
> 
> Step (b) is what normally prevents the infinite loop from happening later in the compilation. But we only do this for the first class in the loop, presumably because it would be too verbose to do (a) for every class in the loop. But that means we're also only doing (b) for the first class in the loop.
> 
> In more complicated scenarios like the bug example, that means some classes in the cycle can escape without (b) being applied. But this is incorrect (or, at least, weirdly indeterminate) because a loop is a loop no matter which class you start with.
> 
> So the solution is to continue to do (a) only to the first class in the cycle but do (b) for every class in the cycle.

FWIW, looks OK to me. It is difficult to estimate if there will be an impact from making the errors for the whole cycle erroneous, but we'll see.

FWIW, I tried to find out an example that wouldn't be fixed by this patch, but I couldn't.

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

Marked as reviewed by jlahoda (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/23704#pullrequestreview-2637925931


More information about the compiler-dev mailing list