diff options
| author | Julius Ikkala <julius.ikkala@gmail.com> | 2025-05-03 23:27:03 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-03 23:27:03 +0300 |
| commit | 6f6103c4dbc77d5bceae7c8e766ec3cabc293364 (patch) | |
| tree | 5d00a97065771ff3dd95b837e6e005512797487e /source/slang/slang-lower-to-ir.cpp | |
| parent | 7f9283a34b4aaf3401cdb652a2f9208b2b4ff4f4 (diff) | |
Add IREnumType to distinguish enums from ints and each other (#6973)
* Add IREnumType to distinguish enums from ints and each other
* Add issue example as test
* format code
* Add expected test output
* Fix peephole optimization hanging
No idea why this PR triggered this, but there seems to have been a clear bug
here anyway, so may just as well fix it now.
* Move enum lowering later
* Add linkage decoration to enum type
* Use filecheck-buffer instead of expected.txt
* Fix comment
* Make enum casts actually use IR enum casts
They were all BuiltinCasts by accident
* Lower enum type before VM
* Deal with rate-qualified types in enum cast
* Allow any value marshalling for enum types
* Handle new enum instructions in a couple more switches
* Fix formatting
---------
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-lower-to-ir.cpp')
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 990090537..45efca2d9 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -9228,18 +9228,15 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> auto subContext = nestedContext.getContext(); auto outerGeneric = emitOuterGenerics(subContext, decl, decl); - // An `enum` declaration will currently lower directly to its "tag" - // type, so that any references to the `enum` become referenes to - // the tag type instead. - // // TODO: if we ever support `enum` types with payloads, we would // need to make the `enum` lower to some kind of custom "tagged union" // type. IRType* loweredTagType = lowerType(subContext, decl->tagType); + IRType* enumType = subBuilder->createEnumType(loweredTagType); + addLinkageDecoration(context, enumType, decl); - return LoweredValInfo::simple( - finishOuterGenerics(subBuilder, loweredTagType, outerGeneric)); + return LoweredValInfo::simple(finishOuterGenerics(subBuilder, enumType, outerGeneric)); } LoweredValInfo visitThisTypeDecl(ThisTypeDecl* decl) |
