Integrated: 8303820: Simplify type metadata
Maurizio Cimadamore
mcimadamore at openjdk.org
Fri Mar 10 13:16:19 UTC 2023
On Wed, 8 Mar 2023 13:57:51 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).
This pull request has now been integrated.
Changeset: b9951dd6
Author: Maurizio Cimadamore <mcimadamore at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/b9951dd63997b6330001311c925e171f4645a28b
Stats: 376 lines in 8 files changed: 59 ins; 235 del; 82 mod
8303820: Simplify type metadata
Reviewed-by: vromero
-------------
PR: https://git.openjdk.org/jdk/pull/12924
More information about the compiler-dev
mailing list