From b5078d12127f4ab348b8d6d4c4e8139ba7bfb47f Mon Sep 17 00:00:00 2001 From: Ronan Date: Wed, 17 Sep 2025 14:46:27 +0200 Subject: Added __magic_enum (#8436) Fixes #8406 (and #8410). `AddressSpace`, `MemoryScope` and `AccessQualifier` are no longer `BaseType`. I added a new `__magic_enum` (very similar to `__magic_type`) syntax to be able to easily create values or these enums from the compiler. (I don't know if it was the right way to do it, but it works and the changes are small enough?). I had a weird bug: `tests/language-feature/capability/address-of.slang` was failing in `IRBuilder::_findOrEmitConstant(IRConstant& keyInst)`. When needing a new `u64(0)`, it did not find it in the `ConstantMap` first, but then failed to add it right after because it already existed in the map! But this was triggered by `IRPtrType* IRBuilder::getPtrType(IROp op, IRType* valueType, AccessQualifier accessQualifier, AddressSpace addressSpace)`, which is a strange coincidence... but I could not find the issue in what I did. I ended up bumping unordered_dense, and it solved the issue (so there was a bug in there). --- source/slang/core.meta.slang | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'source/slang/core.meta.slang') diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index 5d2a80c29..5c4a35be2 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -1278,18 +1278,16 @@ struct __none_t { }; -// @hidden: this type is a BaseType since we want it to work with -// `registerBuiltinDecl` -__builtin_type($((int)BaseType::AddressSpace)) +/// @category misc_types +__magic_enum(AddressSpace) enum AddressSpace : uint64_t { Device = $((uint64_t)AddressSpace::UserPointer), GroupShared = $((uint64_t)AddressSpace::GroupShared), }; -// @hidden: this type is a BaseType since we want it to work with -// `registerBuiltinDecl` -__builtin_type($((int)BaseType::MemoryScope)) +/// @category misc_types +__magic_enum(MemoryScope) enum MemoryScope : int32_t { CrossDevice = $((int32_t)MemoryScope::CrossDevice), @@ -1300,9 +1298,8 @@ enum MemoryScope : int32_t QueueFamily = $((int32_t)MemoryScope::QueueFamily), } -// @hidden: this type is a BaseType since we want it to work with -// `registerBuiltinDecl` -__builtin_type($((int)BaseType::AccessQualifier)) +/// @category misc_types +__magic_enum(AccessQualifier) enum Access : uint64_t { ReadWrite = $((uint64_t)AccessQualifier::ReadWrite), -- cgit v1.2.3