[code-reflection] RFR: Extensible types in the code model
Paul Sandoz
psandoz at openjdk.org
Mon Feb 12 20:46:40 UTC 2024
Prior to this PR types in the code model were modeled as general "type descriptors" and therefore did not differentiate between kinds of type. This lack of differentiation is confusing and limiting. The code model defines type descriptions for modeling variables, tuples, and Java types, but they all look the same at runtime and we cannot easily differentiate between them - former two confusingly suggests they are like the latter.
We enhance the modeling of types and make types extensible in the code model.
A value has an instance of `TypeElement`, an unsealed interface from which one can extend to model any kind of type. The interface `JavaType` extends from `TypeElement` and symbolically models Java types. The types `VarType` and `TupleType` are general code model types that model variables and tuples, they are not Java types but they may contain Java types, or any other type elements (including themselves).
The Triton PoC example has also been updated. The types that were defined to model tensors and pointers can be embedded directly into code models.
The relationship between Java descriptors (method, method type, field, and record) are now a clearer.
In subsequent PRs we will iterate to further improve this area:
1. Replace the use of `MethodTypeDesc` in the core API with `FunctionType`, that models a function type (or arrow type).
2. Improve boundary between TypeElement and the parser. Currently we are reusing the original `TypeDesc` class for this as a temporary solution.
3. Devise a richer modeling of Java types. Currently `JavaType` is mostly a clone of `TypeDesc`. But we can do much better perhaps providing similar fidelity as the `javax.lang.model.type.TypeMirroer` API.
-------------
Commit messages:
- Merge remote-tracking branch 'upstream/code-reflection' into types
- Extensible code model types.
- WIP
Changes: https://git.openjdk.org/babylon/pull/18/files
Webrev: https://webrevs.openjdk.org/?repo=babylon&pr=18&range=00
Stats: 2999 lines in 79 files changed: 1406 ins; 751 del; 842 mod
Patch: https://git.openjdk.org/babylon/pull/18.diff
Fetch: git fetch https://git.openjdk.org/babylon.git pull/18/head:pull/18
PR: https://git.openjdk.org/babylon/pull/18
More information about the babylon-dev
mailing list