diff options
| author | Ronan <ro.cailleau@gmail.com> | 2025-09-17 14:46:27 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-17 12:46:27 +0000 |
| commit | b5078d12127f4ab348b8d6d4c4e8139ba7bfb47f (patch) | |
| tree | 01444cbb7cf9ab7b28b08b9b842fdcb3f9a72a84 /source/slang/slang-ast-builder.cpp | |
| parent | 64d23f2a56d9bd064557ae02a4f8a9d365cd9d60 (diff) | |
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).
Diffstat (limited to 'source/slang/slang-ast-builder.cpp')
| -rw-r--r-- | source/slang/slang-ast-builder.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/source/slang/slang-ast-builder.cpp b/source/slang/slang-ast-builder.cpp index 5da4e9521..a88db3155 100644 --- a/source/slang/slang-ast-builder.cpp +++ b/source/slang/slang-ast-builder.cpp @@ -461,6 +461,18 @@ Type* ASTBuilder::getSpecializedBuiltinType(ArrayView<Val*> genericArgs, const c return rsType; } +Type* ASTBuilder::getMagicEnumType(const char* magicEnumName) +{ + auto& cache = getSharedASTBuilder()->m_magicEnumTypes; + Type* res = nullptr; + if (!cache.tryGetValue(magicEnumName, res)) + { + res = getSpecializedBuiltinType({}, magicEnumName); + cache.add(magicEnumName, res); + } + return res; +} + PtrType* ASTBuilder::getPtrType(Type* valueType, Val* accessQualifier, Val* addrSpace) { return dynamicCast<PtrType>(getPtrType(valueType, accessQualifier, addrSpace, "PtrType")); @@ -545,10 +557,12 @@ PtrTypeBase* ASTBuilder::getPtrType( AddressSpace addrSpace, char const* ptrTypeName) { + Type* typeOfAccessQualifier = getMagicEnumType("AccessQualifier"); + Type* typeOfAddressSpace = getMagicEnumType("AddressSpace"); return as<PtrTypeBase>(getPtrType( valueType, - getIntVal(getBuiltinType(BaseType::AccessQualifier), (IntegerLiteralValue)accessQualifier), - getIntVal(getBuiltinType(BaseType::AddressSpace), (IntegerLiteralValue)addrSpace), + getIntVal(typeOfAccessQualifier, (IntegerLiteralValue)accessQualifier), + getIntVal(typeOfAddressSpace, (IntegerLiteralValue)addrSpace), ptrTypeName)); } |
