RFR: 8303820: Simplify type metadata [v2]
Vicente Romero
vromero at openjdk.org
Wed Mar 8 16:17:05 UTC 2023
On Wed, 8 Mar 2023 14:32:37 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:
>
> Further simplify code
nice patch, nice simplification, just added a question
-------------
PR: https://git.openjdk.org/jdk/pull/12924
More information about the compiler-dev
mailing list