RFR: addressing several issues in the implementation of universal tvars [v5]
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Tue May 24 10:42:08 UTC 2022
On Sat, 21 May 2022 01:23:28 GMT, Vicente Romero <vromero at openjdk.org> wrote:
>> Last review iteration found several issues in the current implementation, addressing them here
>
> Vicente Romero has updated the pull request incrementally with one additional commit since the last revision:
>
> missed a case in unchecked conversions
As discussed offline, rather than chasing individual bugs, a better approach might be *not* to use "loose" version of subtyping and type containment checks to issue warnings. Instead, the code for `isSubtypeUnchecked(S, T)` could work as follows:
1. first check if S <: T - if so, return `true`, otherwise
2. lift S to the same base type as T, using `Types.asSuper`, call the lifted type `S'`, then
3. if `S'` is raw, apply standard unchecked conversion, otherwise
4. perform a structural comparison between `S'` and `T` - if the two types are identical up to `.val`/`.ref` differences, issue an unchecked warning, and return `true`, otherwise return `false`.
I believe this has the potential to simplify the code quite a bit, since we would no longer need to duplicate subtyping and containment. Step (4) needs to be implemented in a new structural type visitor, but that's brand new code, and less likely to be problematic since it's only used for that specific purposes. Issues like reporting multiple diagnostic can easily be avoided under this scheme.
Since the type comparison doesn't really care about inference variables (`UndetVar`) I also do not think that there could be issues when it comes to (4) generating spurious inference constraints.
-------------
PR: https://git.openjdk.java.net/valhalla/pull/684
More information about the valhalla-dev
mailing list