RFR: 8232933: Javac inferred type does not conform to equality constraint

Maurizio Cimadamore mcimadamore at openjdk.org
Tue Nov 1 10:31:19 UTC 2022


On Fri, 28 Oct 2022 02:56:17 GMT, Vicente Romero <vromero at openjdk.org> wrote:

> When dealing with nested invocations it could be that the inference context of a nested invocation is propagated to the inference context of the outer invocation. There are occasions when the propagated inference context can be minimized if some of its inference variables are deemed redundant. This is an optimization that is done in order to speed up the type inference algo which can take a while if the number of variables to be reduced is large. Of course by removing some variables from an inference context we have an inherent risk of cutting too much and not being able to produce the same results compared to not minimizing it. My understanding is that this bug shows one of those cases in which an inference context has been reduced too much.
> 
> The proposed solution is not to minimize an inference context if at least one of its inference variables is a capture type. The reason is because when capture types are present, some bounds are wildcards which could be captured again generating new capture types etc., this could make impossible to prove that some constraints hold for an inference context, thus making the compiler wrongly reject correct code.
> 
> TIA

The fix seems ok, if perhaps a bit too aggressive. Probably the problem comes from the fact that we should never treat captured inference variables as "regular" inference variables - so the minimization algorithm should treat them as black boxes and try not to do much with them. Of course bailing out if any capture is spotted is also an ok approach. It would be interesting to understand if this patch significantly alter the performance of the compiler in more common use cases.

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

Marked as reviewed by mcimadamore (Reviewer).

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


More information about the compiler-dev mailing list