RFR: 8303820: Simplify type metadata [v3]
Maurizio Cimadamore
mcimadamore at openjdk.org
Thu Mar 9 12:32:01 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).
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
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/12924/files
- new: https://git.openjdk.org/jdk/pull/12924/files/1083a70b..7293495b
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=12924&range=02
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=12924&range=01-02
Stats: 13 lines in 1 file changed: 12 ins; 0 del; 1 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