RFR: 8303820: Simplify type metadata

Maurizio Cimadamore mcimadamore at openjdk.org
Wed Mar 8 14:08:15 UTC 2023


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).

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

Commit messages:
 - Add duplicate check on addMetadata
 - Add more javadoc
 - Initial push

Changes: https://git.openjdk.org/jdk/pull/12924/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=12924&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8303820
  Stats: 398 lines in 8 files changed: 75 ins; 252 del; 71 mod
  Patch: https://git.openjdk.org/jdk/pull/12924.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/12924/head:pull/12924

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


More information about the compiler-dev mailing list