shader-slang / slang

Making it easier to work with shaders
MIT License
1.78k stars 159 forks source link

Unable to use `const` in `typedef` statement #4475

Open chaoticbob opened 4 days ago

chaoticbob commented 4 days ago

When using const in a typedef statement I get his error:

shader.hlsl(4): internal error 99999: unexpected condition encountered in Slang compiler: unknown type modifier in semantic checking
typedef const uint myConstUint;

Just curious if typedef is limited to just the type itself.

Shader

typedef int myInt;
typedef const uint myConstUint;

void main() {
    myInt v1;
    myConstUint v2;
}
jkwak-work commented 1 day ago

The same issue is observed with typealias.

a.slang(8): internal error 99999: unexpected condition encountered in Slang compiler: unknown type modifier in semantic checking
typealias myConstUint = const MyStruct;
                        ^~~~~

I don't think Slang will fully support const keyword in the way it works in C/C++. And I think we can make some changes to workaround this issue as a short term solution.

But there should be a long term plan to figure out how to handle the const keyword in general. @swoods-nv for visibility.

csyonghe commented 6 hours ago

In Slang, we currently treat const as a modifier for the var decl instead of a modifier for the type. Type modifiers are much harder to implement (need to take care of all the coercion and overloading rules etc.)

We may not want to allow it in slang for simplicity.