How to use cached types in runtime?

You can also simplify the kinds mapping if you use the typeId from here:

2a3,15
> const TypeId = *const struct {
>     _: u8,
> };
> 
> pub inline fn typeId(comptime T: type) TypeId {
>     return &struct {
>         comptime {
>             _ = T;
>         }
>         var id: @typeInfo(TypeId).pointer.child = undefined;
>     }.id;
> }
> 
18c31
<                 try manager.kinds.put(manager.allocator, @typeName(ED), .{ .deinit = &ED.deinit });
---
>                 try manager.kinds.put(manager.allocator, typeId(ED), .{ .deinit = &ED.deinit });
35c48
< const KindMap = std.hash_map.StringHashMapUnmanaged(Kind);
---
> const KindMap = std.hash_map.AutoHashMapUnmanaged(TypeId, Kind);
1 Like