Integrated: 8324809: compiler can crash with SOE while proving if two recursive types are disjoint

Vicente Romero vromero at openjdk.org
Fri May 17 14:19:09 UTC 2024


On Sat, 11 May 2024 22:18:12 GMT, Vicente Romero <vromero at openjdk.org> wrote:

> javac is crashing with SOE while compiling code like:
> 
> 
> class Criteria<B extends Builder<? extends Criteria>> {
>     public <D extends Builder<E>, E extends Criteria<D>> D builder() {
>         return (D) new Builder<>();
>     }
> 
> }
> 
> class Builder<C extends Criteria<? extends Builder<C>>> {}
> 
> 
> here while attributing: `return (D)new Builder<>();` the compiler is trying to prove that: `Builder<C>` is castable to `D`, then as the upper bound of `D` is `Builder<E>`, we need to check if `Builder<C>` is castable to `Builder<E>`. Then the next step is to try to check if type variables C and E are disjoint. During this process is when the compiler gets out of resources given that
> 
> E <: Criteria<D>
> D <: Builder<E> here we have E again and we start over in an infinite loop,
> 
> Here the proposal is to detect cycles in the type arguments graph and accept these type of casts if we find a cycle and thus can't prove if two types are disjoint,
> 
> TIA

This pull request has now been integrated.

Changeset: 39a55e97
Author:    Vicente Romero <vromero at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/39a55e97799b5328da85aaa66c8d23175b305691
Stats:     57 lines in 2 files changed: 50 ins; 0 del; 7 mod

8324809: compiler can crash with SOE while proving if two recursive types are disjoint

Reviewed-by: mcimadamore

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

PR: https://git.openjdk.org/jdk/pull/19194


More information about the compiler-dev mailing list