RFR: 8303820: Simplify type metadata [v3]
Vicente Romero
vromero at openjdk.org
Thu Mar 9 15:40:06 UTC 2023
On Thu, 9 Mar 2023 12:32:01 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> This patch simplifies the TypeMetadata API. TypeMetadata can be used as a side-channel, to attach extra information to a javac type (type annotations, constant values).
>>
>> While TypeMetadata provides the right knobs to compare types (see `Type::equalsIgnoreMetadata`), which is used uniformly across the type-system related routines (e.g. subtyping, type equality and type containment), the TypeMetadata API is also rather cumbersome to use.
>>
>> The only way to add a new metadata to a type is to "combine" the metadata into an existing one, which feels odd, and probably too biased by the type annotations requirements.
>>
>> This patch simplifies this: now TypeMetadata is a simple marker interface. There can be many implementations - one is `Annotations` (used to store type annotations), another is `ConstantValue` (used to store a type's constant value).
>>
>> A type is then associated with a `List<TypeMetadata>`, and there are methods to add/drop/get metadata. These methods are used to provide support for annotated and constant types.
>>
>> The resulting code feels simpler: to add a new metadata, one only has to define a new class/record inside TypeMetadata, and that's pretty much it. Javac will truck the metadata around in the correct way (as it did before).
>
> Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:
>
> Revert `constType` to only be implemented for primitive/class types
looks good thanks
-------------
Marked as reviewed by vromero (Reviewer).
PR: https://git.openjdk.org/jdk/pull/12924
More information about the compiler-dev
mailing list