Skip to content

Identity refactor - #5959

Draft
ab9rf wants to merge 6 commits into
DFHack:developfrom
ab9rf:identity-refactor
Draft

ab9rf wants to merge 6 commits into
DFHack:developfrom
ab9rf:identity-refactor

Conversation

@ab9rf

@ab9rf ab9rf commented Sep 20, 2026

Copy link
Copy Markdown
Member

This is most of a "magnum opus" I've been trying to achieve for about three years now. It's not 100% done but it's a huge step in the direction I've been trying to go.

type_identity (non-template, DataDefs.h) — the erased abstract base; all virtuals (type, getFullName, isPrimitive, lua_read/lua_write, build_metatable, allocate/copy/destroy) live here

type_identity_for<T> (DataIdentity.h) — the single leaf template. Its base is chosen by identity_base_of_t<T>:

T::df_identity_base typedef wins outright (codegen emits it into every compound type)
is_enum / enum_fieldenum_identity; bitfield_traits<T>bitfield_identity
types with _identitystruct_identity / union_identity / virtual_identity / other_vectors_identity via is_union/is_polymorphic/marker-typedef checks
char*/const char*primitive_identity_base; wchar_t*opaque_identity; other pointers → pointer_identity_base; arithmetic + bool → number_identity_base
std::string/std::filesystem::pathconstructed_identity; C arrays/std::arraybuffer_container_identity; STL/BitArray/DfArray/enum_list_attrdetail::container_impl<T>; other classes → opaque_identity
lua_read/lua_write/type()/getFullName()/isPrimitive()/build_metatable/isInteger() are implemented once with if constexpr on T. global_identity is type_identity<global_object> over an empty placeholder with df_identity_base = struct_identity.

For now this is a draft; there are still things I want to do this and I definitely don't want to drop this in on top of all the bugfixes and new features that are currently sitting in dev, so it's absolutely not going in before the next release.

combine `integer_identity`, `float_identity`, and `bool_identity` into a single type
`type_identity` (non-template, `DataDefs.h`) — the erased abstract base; all virtuals (`type`, `getFullName`, `isPrimitive`, `lua_read`/`lua_write`, `build_metatable`, `allocate`/`copy`/`destroy`) live here

`type_identity_for<T>` (`DataIdentity.h`) — the single leaf template. Its base is chosen by `identity_base_of_t<T>`:

`T::df_identity_base` typedef wins outright (codegen emits it into every compound type)
`is_enum` / `enum_field` → `enum_identity`; `bitfield_traits<T>` → `bitfield_identity`
types with `_identity` → `struct_identity` / `union_identity` / `virtual_identity` / `other_vectors_identity` via `is_union`/`is_polymorphic`/marker-typedef checks
`char*`/`const char*` → `primitive_identity_base`; `wchar_t*` → `opaque_identity`; other pointers → `pointer_identity_base`; arithmetic + bool → `number_identity_base`
`std::string/std::filesystem::path` → `constructed_identity`; C arrays/`std::array` → `buffer_container_identity`; STL/`BitArray`/`DfArray`/`enum_list_attr` → `detail::container_impl<T>`; other classes → `opaque_identity`
`lua_read`/`lua_write`/`type()`/`getFullName()`/`isPrimitive()`/`build_metatable`/`isInteger()` are implemented once with `if constexpr` on `T`. `global_identity` is `type_identity<global_object>` over an empty placeholder with `df_identity_base` = `struct_identity`.
@ab9rf ab9rf mentioned this pull request Sep 20, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant