Integrated: 8320220: Compilation of cyclic hierarchy causes infinite recursion
Archie Cobbs
acobbs at openjdk.org
Tue Feb 25 19:42:08 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.
This pull request has now been integrated.
Changeset: b78043fd
Author: Archie Cobbs <acobbs at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/b78043fdc64dba62293631ad0cc263029e8dfb1e
Stats: 24 lines in 3 files changed: 19 ins; 0 del; 5 mod
8320220: Compilation of cyclic hierarchy causes infinite recursion
Reviewed-by: vromero, jlahoda
-------------
PR: https://git.openjdk.org/jdk/pull/23704
More information about the compiler-dev
mailing list